本帖最后由 yklstudent 于 2020-4-10 22:12 编辑
终于周末,可以有时间来整理之前研究的知识,分享到论坛首先上传新买的Thinkpad T490,颜值个人感觉还可以,I5-10210处理器,512G的固态硬盘,8G的内存,后续考虑升级下
图1
接下来进入正题,分享STM32L552下怎么移植uCOS-III和uC-Probe;
uCOS-III和uC-Probe的下载地址,https://github.com/SiliconLabs?page=2
micrium开源的全家桶源码都可以免费下载使用
移植uCOS-III和uC-Probe很简单,创建工程STM32L552ZET6_uCOSIII_uCProbe,拷贝相关库文件到工程文件路径下,在打开的工程文件下添加所有所需的文件,设置相关头文件的路径,如下图所示:
图2
图3
图4
图5
工程首先由main创建AppTaskStart启动任务,然后再由AppTaskStart启动任务去创建三个用户任务,分别为AppTaskLed1、AppTaskLed2和AppTaskCore;
1、main函数如下所示:
int main(void)
{
OS_ERR err;
SystemClock_Config();
BSP_ClkInit(); /* Initialize the main clock */
BSP_IntInit(); /* Initialize the interrupt vector table. */
BSP_OS_TickInit(); /* Initialize kernel tick timer */
Mem_Init(); /* Initialize Memory Managment Module */
CPU_IntDis(); /* Disable all Interrupts */
CPU_Init(); /* Initialize the uC/CPU services */
OSInit(&err);
OSTaskCreate((OS_TCB *)&AppTaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR ) AppTaskStart,
(void *) NULL,
(OS_PRIO ) APP_CFG_STARTUP_TASK_PRIO,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE) APP_CFG_STARTUP_TASK_STK_SIZE / 10,
(CPU_STK_SIZE) APP_CFG_STARTUP_TASK_STK_SIZE,
(OS_MSG_QTY ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTimeSet(0, &err);
OSStart(&err);
}
2、AppTaskStart启动任务如下所示:
static void AppTaskStart (void *p_arg)
{
OS_ERR err;
OS_TRACE_INIT(); /* Initialize the uC/OS-II Trace recorder */
BSP_OS_TickEnable(); /* Enable the tick timer and interrupt */
sInitMCU(); /* Initialize BSP functions */
#if OS_CFG_STAT_TASK_EN > 0u
OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
//Shell_Init(); /*Initialize uC/Shell*/
//ShShell_Init();
//Terminal_Init();
App_OS_SetAllHooks();
PROBE_TERM_ERR term_err;
ProbeCom_Init(); /* Initialize the Generic module */
ProbeRS232_Init(115200); /* Initialize the USART3 interface */
ProbeRS232_RxIntEn(); /* Initialize the USART3 Rx interrupts */
ProbeTermAppHookRxPtr = AppProbeTermHookRx;
ProbeTermInit(&term_err); /* Initialize the uC/Probe terminal window. */
ProbeTermTrcPrint("system initialization success!\n"); /*Output info to uC/Probe terminal window*/
OSTaskCreate((OS_TCB *)&AppTaskLed1TCB, /* Create the Led1 task */
(CPU_CHAR *)"App Task Led1",
(OS_TASK_PTR ) AppTaskLed1,
(void *) p_arg,
(OS_PRIO ) APP_CFG_TASK_LED1_PRIO,
(CPU_STK *)&AppTaskLed1Stk[0],
(CPU_STK_SIZE) APP_CFG_TASK_LED1_STK_SIZE / 10,
(CPU_STK_SIZE) APP_CFG_TASK_LED1_STK_SIZE,
(OS_MSG_QTY ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTaskCreate((OS_TCB *)&AppTaskLed2TCB, /* Create the Led2 task */
(CPU_CHAR *)"App Task Led2",
(OS_TASK_PTR ) AppTaskLed2,
(void *) p_arg,
(OS_PRIO ) APP_CFG_TASK_LED2_PRIO,
(CPU_STK *)&AppTaskLed2Stk[0],
(CPU_STK_SIZE) APP_CFG_TASK_LED2_STK_SIZE / 10,
(CPU_STK_SIZE) APP_CFG_TASK_LED2_STK_SIZE,
(OS_MSG_QTY ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTaskCreate((OS_TCB *)&AppTaskCoreTCB, /* Create the Core task */
(CPU_CHAR *)"App Task Core",
(OS_TASK_PTR ) AppTaskCore,
(void *) p_arg,
(OS_PRIO ) APP_CFG_TASK_CORE_PRIO,
(CPU_STK *)&AppTaskCoreStk[0],
(CPU_STK_SIZE) APP_CFG_TASK_CORE_STK_SIZE / 10,
(CPU_STK_SIZE) APP_CFG_TASK_CORE_STK_SIZE,
(OS_MSG_QTY ) 5u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
//OSTaskDel ( & AppTaskStartTCB, & err );
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
/*Period handle uC/Probe terminal window*/
//ProbeTermCmdRxTaskHandler();
//ProbeTermCmdTxTaskHandler();
ProbeTermTrcTaskHandler();
OSTimeDly ( 50, OS_OPT_TIME_DLY, & err );
}
}
调用uC-Probe初始化设置函数,50ms周期处理uC-Probe与配套上位机的数据交互;
3、AppTaskLed1任务
static void AppTaskLed1 ( void * p_arg )
{
OS_ERR err;
(void)p_arg;
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
GPIOA->ODR ^= GPIO_ODR_OD9;
OSTimeDly ( 500, OS_OPT_TIME_DLY, & err );
}
}
4、AppTaskLed2任务
static void AppTaskLed2 ( void * p_arg )
{
OS_ERR err;
(void)p_arg;
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
GPIOB->ODR ^= GPIO_ODR_OD7;
OSTimeDly ( 500, OS_OPT_TIME_DLY, & err );
}
}
5、AppTaskCore任务
uint32_t gobalcount = 0;
static void AppTaskCore ( void * p_arg )
{
OS_ERR err;
(void)p_arg;
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
gobalcount++;
GPIOC->ODR ^= GPIO_ODR_OD7;
OSTimeDly ( 500, OS_OPT_TIME_DLY, & err );
}
}
创建了一个gobalcount全局变量,用于演示uC-Probe功能;
6、安装Micrium uC-Probe (4.8.1.0)软件,这个软件已经可以免费使用,不需要**,大家去官网就可以下载
图7
7、导入工程编译生成的.axf文件
图8
8、由于采用串**互数据,所以设置串口配置
图9
10、添加控件,拖到gobalcount到控件上,最后演示运行效果(不会制作动图)
图10
通过uC-Probe可以在线查看工程相关变量的实时运行值,也可以在线修改,是个开发调试的好工具
最后上工程,大家可以自行研究
STM32L552ZET6_uCOSIII_uCProbe.rar
(5.01 MB)
|
|