本帖最后由 yklstudent 于 2020-3-23 17:16 编辑
在周末发布的“【NUCLEO试用】NUCLEO-L552ZE-Q之移植uCOS-II工程(KEIL V2.93.00版本)”帖子基础上,移植micrium公司全家桶源码的uC-Shell功能代码。下面就简单介绍下如何移植:
1、首先micrium全家桶源码如何获得,感兴趣的小伙伴可以去GitHub下搜索SiliconLab信息下载
2、拷贝uC-Shell文件夹下全部内容到工程文件下的micrium文件夹下
3、打开KEIL软件,打开STM32L552ZET6_uCOSII_uCShell工程文件,添加uC-Shell内容到工程文件夹下
4、设置uC-Shell相关所需头文件的路径
5、添加uC-Shell用户功能代码
文件路径:E:\UserProj\STM32L552ZET6_uCOSII_uCShell(KEIL V2.93.00)\Micrium\uC-Shell\Cmd\General
文件名:sh_shell.c
新增Sh_add和Sh_sub指令功能函数
Sh_add功能函数:
/*
*********************************************************************************************************
* ShShell_add()
*
* Description : List all commands or invoke '--help' for another command.
*
* Argument(s) : argc The number of arguments.
*
* argv Array of arguments.
*
* out_fnct The output function.
*
* pcmd_param Pointer to the command parameters.
*
* Return(s) : SHELL_EXEC_ERR, if an error is encountered.
* SHELL_ERR_NONE, otherwise.
*
* Caller(s) : Shell, in response to command execution.
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_INT16S ShShell_add (CPU_INT16U argc,
CPU_CHAR *argv[],
SHELL_OUT_FNCT out_fnct,
SHELL_CMD_PARAM *pcmd_param)
{
CPU_CHAR *cmd_pstr;
CPU_CHAR cmd_str[32] = {0};
CPU_INT32S a, b;
if (argc < 3) {
if (Str_Cmp(argv[1], SH_SHELL_STR_HELP) == 0) {
(void)out_fnct(SH_SHELL_ARG_ERR_ADD, (CPU_INT16U)Str_Len(SH_SHELL_ARG_ERR_HELP), pcmd_param->pout_opt);
(void)out_fnct(SH_SHELL_NEW_LINE, 2, pcmd_param->pout_opt);
(void)out_fnct(SH_SHELL_CMD_EXP_HELP, (CPU_INT16U)Str_Len(SH_SHELL_CMD_EXP_HELP), pcmd_param->pout_opt);
(void)out_fnct(SH_SHELL_NEW_LINE, 2, pcmd_param->pout_opt);
return (SHELL_ERR_NONE);
}
}
a = Str_ParseNbr_Int32S(argv[1], &cmd_pstr, 10);
b = Str_ParseNbr_Int32S(argv[2], &cmd_pstr, 10);
snprintf(cmd_str, sizeof(cmd_str), "Ok.\n %d+%d=%d\n",a, b, a + b);
(void)out_fnct(cmd_str, (CPU_INT16U)Str_Len(cmd_str), pcmd_param->pout_opt);
(void)out_fnct(SH_SHELL_NEW_LINE, 2, pcmd_param->pout_opt);
return (SHELL_ERR_NONE);
}
Sh_sub功能函数:
/*
*********************************************************************************************************
* ShShell_sub()
*
* Description : List all commands or invoke '--help' for another command.
*
* Argument(s) : argc The number of arguments.
*
* argv Array of arguments.
*
* out_fnct The output function.
*
* pcmd_param Pointer to the command parameters.
*
* Return(s) : SHELL_EXEC_ERR, if an error is encountered.
* SHELL_ERR_NONE, otherwise.
*
* Caller(s) : Shell, in response to command execution.
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_INT16S ShShell_sub (CPU_INT16U argc,
CPU_CHAR *argv[],
SHELL_OUT_FNCT out_fnct,
SHELL_CMD_PARAM *pcmd_param)
{
CPU_CHAR *cmd_pstr;
CPU_CHAR cmd_str[32] = {0};
CPU_INT32S a, b;
if (argc < 3) {
if (Str_Cmp(argv[1], SH_SHELL_STR_HELP) == 0) {
(void)out_fnct(SH_SHELL_ARG_ERR_ADD, (CPU_INT16U)Str_Len(SH_SHELL_ARG_ERR_HELP), pcmd_param->pout_opt);
(void)out_fnct(SH_SHELL_NEW_LINE, 2, pcmd_param->pout_opt);
(void)out_fnct(SH_SHELL_CMD_EXP_HELP, (CPU_INT16U)Str_Len(SH_SHELL_CMD_EXP_HELP), pcmd_param->pout_opt);
(void)out_fnct(SH_SHELL_NEW_LINE, 2, pcmd_param->pout_opt);
return (SHELL_ERR_NONE);
}
}
a = Str_ParseNbr_Int32S(argv[1], &cmd_pstr, 10);
b = Str_ParseNbr_Int32S(argv[2], &cmd_pstr, 10);
snprintf(cmd_str, sizeof(cmd_str), "Ok.\n %d-%d=%d\n",a, b, a - b);
(void)out_fnct(cmd_str, (CPU_INT16U)Str_Len(cmd_str), pcmd_param->pout_opt);
(void)out_fnct(SH_SHELL_NEW_LINE, 2, pcmd_param->pout_opt);
return (SHELL_ERR_NONE);
}
6、修改uC-Shell所需串口驱动文件的底层配置
文件路径:E:\UserProj\STM32L552ZET6_uCOSII_uCShell(KEIL V2.93.00)\Micrium\uC-Shell\Terminal\Serial
文件名:terminal_serial.c
7、调用uC-Shell所需的初始化设置函数,
Shell_Init(); /*Initialize uC/Shell*/
ShShell_Init();
Terminal_Init();
8、串口是否能正常工作,跟系统工作时钟有关,添加系统时钟初始化配置函数(这部分可以依靠STM32CubeMX软件来自动完成)
/**
* @brief System Clock Configur
LL_FLASH_SetLatency(LL_FLASH_LATENCY_5);
if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_5)
{
};
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE0);
LL_RCC_MSI_Enable();
/* Wait till MSI is ready */
while(LL_RCC_MSI_IsReady() != 1)
{
};
LL_RCC_MSI_EnableRangeSelection();
LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_6);
LL_RCC_MSI_SetCalibTrimming(0);
//LL_PWR_EnableBkUpAccess();
//LL_RCC_ForceBackupDomainReset();
//LL_RCC_ReleaseBackupDomainReset();
//LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_LOW);
//LL_RCC_LSE_Enable();
/* Wait till LSE is ready */
//while(LL_RCC_LSE_IsReady() != 1)
//{
//};
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_MSI, LL_RCC_PLLM_DIV_1, 55, LL_RCC_PLLR_DIV_2);
LL_RCC_PLL_EnableDomain_SYS();
LL_RCC_PLL_Enable();
/* Wait till PLL is ready */
while(LL_RCC_PLL_IsReady() != 1)
{
};
/* Intermediate AHB prescaler 2 when target frequency clock is higher than 80 MHz */
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
/* Wait till System clock is ready */
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
{
};
/* Insure 1?s transition state at intermediate medium speed clock based on DWT*/
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
DWT->CYCCNT = 0;
while(DWT->CYCCNT < 100);
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_SetSystemCoreClock(110000000);
}
9、uC-Shell运行效果图如下所示:
10、上传工程文件
STM32L552ZET6_uCOSII_uCShell-1(KEIL V2.93.00).rar
(4.61 MB)
|
共1人点赞
|