打印
[APM32F4]

【APM32F402R Micro-EVB】-6-FreeRTOS体验

[复制链接]
113|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本文体验在keil环境下CMSIS-FreeRTOS在APM32F402上的使用。

内核初始化:
/*
  Initialize the RTOS Kernel.
*/
osStatus_t osKernelInitialize (void) {
  osStatus_t stat;
  BaseType_t state;

  if (IRQ_Context() != 0U) {
    stat = osErrorISR;
  }
  else {
    state = xTaskGetSchedulerState();

    /* Initialize if scheduler not started and not initialized before */
    if ((state == taskSCHEDULER_NOT_STARTED) && (KernelState == osKernelInactive)) {
      #if defined(USE_TRACE_EVENT_RECORDER)
        /* Initialize the trace macro debugging output channel */
        EvrFreeRTOSSetup(0U);
      #endif
      #if defined(USE_FreeRTOS_HEAP_5) && (HEAP_5_REGION_SETUP == 1)
        /* Initialize the memory regions when using heap_5 variant */
        vPortDefineHeapRegions (configHEAP_5_REGIONS);
      #endif
      KernelState = osKernelReady;
      stat = osOK;
    } else {
      stat = osError;
    }
  }

  /* Return execution status */
  return (stat);
}


创建线程:
    /* Create the thread */
    ledThreadID = osThreadNew(Led_Thread, NULL, &ledThreadattr);
    if (ledThreadID == NULL)
    {
        printf("Create led thread failed!\r\n");
    }

    usartThreadID = osThreadNew(Usart_TestThread, NULL, &usartThreadattr);
    if (usartThreadID == NULL)
    {
        printf("Create usart thread failed!\r\n");
    }


启动调度器:
    /* Start the RTOS scheduler */
    osKernelStart();


其中LED线程与USART任务定义如下:
void Led_Thread(void *argument)
{
    UNUSED(argument);

    while (1)
    {
        /* Toggle LED2 */
        BOARD_LED_Toggle(LED2);
        osDelay(1000);
    }
}

/**
* [url=home.php?mod=space&uid=247401]@brief[/url]   Usart1 test task
*
* @param   argument  Not used
*
* @retval  None
*/
void Usart_TestThread(void *argument)
{
    UNUSED(argument);

    while (1)
    {
        /* Print message */
        printf("Hello, world!\r\n");
        osDelay(1000);
    }
}


实物演示:

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

69

主题

290

帖子

2

粉丝