在线时间563 小时
UID3072817
ST金币0
蝴蝶豆93
注册时间2014-11-6
版主
- 最后登录
- 2020-9-9
|
a0a.1 32b0c
[Nucleo-L4R5] STM32L4R5外观评测
[Nucleo-L4R5] STM32L4R5低功耗评测
[Nucleo-L4R5] STM32L4R5 CoreMark测试
CubeMax自带FreeRTOS系统,并且可以通过软件自动生成OS框架,对于初学者来说,一般还是先接触的uCOS的多,所以让L4R5运行一下ucOS是否好玩。
移植的过程就是复制黏贴,加上编译路径后稍微改动一下代码即可,所以就不详细说了,这里主要添加两个User Task和1个软件定时器
创建User任务(STM32中文官网)
- static void App_TaskCreate (void)
- {
- OS_ERR err;
- CPU_SR_ALLOC();
- OS_CRITICAL_ENTER();
- OSTaskCreate((OS_TCB * )&FloatTaskTCB,
- (CPU_CHAR * )"float test task",
- (OS_TASK_PTR )float_task,
- (void * )0,
- (OS_PRIO )FLOAT_TASK_PRIO,
- (CPU_STK * )&FLOAT_TASK_STK[0],
- (CPU_STK_SIZE)FLOAT_STK_SIZE/10,
- (CPU_STK_SIZE)FLOAT_STK_SIZE,
- (OS_MSG_QTY )0,
- (OS_TICK )0,
- (void * )0,
- (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
- (OS_ERR * )&err);
-
- OSTaskCreate((OS_TCB * )&LEDTaskTCB,
- (CPU_CHAR * )"LED task",
- (OS_TASK_PTR )led_task,
- (void * )0,
- (OS_PRIO )LED_TASK_PRIO,
- (CPU_STK * )&LED_TASK_STK[0],
- (CPU_STK_SIZE)LED_STK_SIZE/10,
- (CPU_STK_SIZE)LED_STK_SIZE,
- (OS_MSG_QTY )0,
- (OS_TICK )0,
- (void * )0,
- (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
- (OS_ERR * )&err);
- //OS_TaskSuspend((OS_TCB *)&App_TaskStartTCB, (OS_ERR *)&err);
- OS_CRITICAL_EXIT();
- OSTaskDel((OS_TCB *)&App_TaskStartTCB, (OS_ERR *)&err);
- } //!< End of Create
复制代码
1、浮点运算测试任务
- /*
- * !brief task for test float point
- * !param void *p_arg
- * !retval none
- */
- void float_task(void *p_arg)
- {
- OS_ERR err;
- UNUSED(p_arg);
- static float float_num=0.0001;
- while(1)
- {
- float_num+=0.0001f;
- ifs_printf("float task runing!\r\n");
- ifs_printf("float_num inc : %.4f\r\n",float_num);
- OSTimeDlyHMSM(0,0,1,0,OS_OPT_TIME_HMSM_STRICT,&err); //ÑÓʱ500ms
- }
- }
复制代码 2、LED翻转任务
- /*
- * !brief task for test led
- * !param void *p_arg
- * !retval none
- */
- void led_task(void *p_arg)
- {
- static ifs_uint8_t fsm_blink = 0;
- OS_ERR err;
-
- UNUSED(p_arg);
- while (1) {
- ifs_printf("led task runing!\r\n");
- switch (fsm_blink) {
- case 0:
- ifs_printf("led 1 on!\r\n");
- BSP_LED_On(LED1);
- break;
- case 1:
- ifs_printf("led 2 on!\r\n");
- BSP_LED_On(LED2);
- break;
- // case 2:
- // ifs_printf("led 3 on!\r\n");
- // BSP_LED_On(LED3);
- // break;
- case 2:
- ifs_printf("led 1 off!\r\n");
- BSP_LED_Off(LED1);
- break;
- case 3:
- ifs_printf("led 2 off!\r\n");
- BSP_LED_Off(LED2);
- break;
- // case 5:
- // ifs_printf("led 3 off!\r\n");
- // BSP_LED_Off(LED3);
- // break;
- }
- if (++fsm_blink > 3) fsm_blink = 0;
- OSTimeDlyHMSM(0,0,1,0,OS_OPT_TIME_HMSM_STRICT,&err);
- }
- }
复制代码 3、创建一个软件定时器
- static void App_ObjCreate (void)
- {
- OS_ERR err;
- OSTmrCreate((OS_TMR * )&tmr1,
- (CPU_CHAR * )"tmr1",
- (OS_TICK )2,
- (OS_TICK )1000 / OSCfg_TickRate_Hz,
- (OS_OPT )OS_OPT_TMR_PERIODIC,
- (OS_TMR_CALLBACK_PTR)tmr1_callback,
- (void * )0,
- (OS_ERR * )&err);
- if (err == OS_ERR_NONE) {
- OSTmrStart((OS_TMR *)&tmr1, &err);
- }
- }
复制代码 定时器callback函数
- static void tmr1_callback(void *p_tmr, void *p_arg)
- {
- ifs_printf("tmr1 callback running!\r\n");
- BSP_LED_Toggle(LED3);
- }
复制代码 编译后正常运行
PS:代码见以下链接 https://www.stmcu.org.cn/module/forum/thread-614478-1-1.html
|
|