Stm32cubemx Free RTOS Exmaple (Task and queue)

stm32cubemx freertos, Stm32cubemx Free RTOS Exmaple (Task and queue) . This post about a example of freertos by use stm32cubemx. Stm32f7-disco board used.
Stm32cubemx Free RTOS Exmaple (Task and queue)
Stm32cubemx Free RTOS Exmaple (Task and queue)

Stm32f7-disco board used.

DefaultTask --> Send data
myTask02     --> Receive data
myTask03     -->Blink Led

1. Pin out setting

RCC->High clock Clock->Crystal ceramic Resonater
Up system clock to 216Mhz 
Sys -> Time base -> Tim6

2. Free RTOS configuration

Add task and queue.

3. Source generation and edit code
In Src/main.c add

#include “stm32f7xx_hal.h”
#include “stm32f7xx_hal.h”
#include “stm32f7xx_hal_uart.h”
#include “stm32f7xx_hal_sdram.h”
#include “stm32f7xx_hal_ltdc.h”
#include “stm32746g_discovery.h”
#include “stm32746g_discovery_lcd.h”
#include “stm32746g_discovery_sdram.h”
#include “stm32f7xx_ll_fmc.h”
#include “cmsis_os.h”

osThreadId defaultTaskHandle;
osThreadId myTask02Handle;
osThreadId myTask03Handle;
osMessageQId myQueue01Handle;

void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
void StartDefaultTask(void const * argument);
void StartTask02(void const * argument);
void StartTask03(void const * argument);

int main(void)



    BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
    BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4));
    BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)”Start_Free_RTOS”, CENTER_MODE);

    osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
    defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

    osThreadDef(myTask02, StartTask02, osPriorityIdle, 0, 128);
    myTask02Handle = osThreadCreate(osThread(myTask02), NULL);

    osThreadDef(myTask03, StartTask03, osPriorityIdle, 0, 128);
    myTask03Handle = osThreadCreate(osThread(myTask03), NULL);

    osMessageQDef(myQueue01, 16, uint16_t);
    myQueue01Handle = osMessageCreate(osMessageQ(myQueue01), NULL);

      while (1)



/*Receive data*/ 
 void StartDefaultTask(void const * argument)

    osEvent evt;
        char buffer[15];
        evt = osMessageGet(myQueue01Handle,1000);
        if (evt.status == osEventMessage) {
            sprintf(buffer,”Data receive =%d”,(int)evt.value.p );
            BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)buffer, CENTER_MODE);
         } else {
              BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)”Failed”, CENTER_MODE);

/*Send data*/

void StartTask02(void const * argument)
    uint16_t i=0;
    char buffer_1[15];

        sprintf(buffer_1,”Data put = %d”,i );
        osMessagePut(myQueue01Handle, (uint16_t)i, 500);
        BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)buffer_1, CENTER_MODE);

/*Blink led*/
void StartTask03(void const * argument)


Video  Stm32cubemx Free RTOS Exmaple


osThreadCreate or xTaskCreate in freeRTOS for STM32

I was going through some freeRTOS examples for STM32. In most of the examples, osThreadCreate is used to create a task whereas the freeRTOS documentation says to use xTaskCreate. I think it is some CMSIS related stuff but it would be great if someone could explain the reason for two separate functions and which one is appropriate for use. Thanks.
it’s related to cmsis like you said. cmsis specifies an RTOS API (and they actually have their own rtos too). freertos obviously has their own rtos API (xBlahBlah). if you are using stm32’s cubemx to generate the freertos stuff, then they will incorporate translation functions to translate the cmsis api into the freertos api. they then call the cmsis rtos api instead of the freertos api. they do this to try and be compatible with the cmsis rtos layer. you can just directly use the freertos api though in your own code, unless you suspect you might change out rtoses later.
CMSIS wrapper for compatible OSes. It is similar in principle to POSIX. Basically an abstracted OS interface that vendors (or yourself) can implement. I think ST only provides FreeRTOS. But if you were to port your app to another micro that uses another RTOS, as long as you used the CMSIS OS interface you only need to replace the function definitions and you can leave your application layer alone.
If you do something similar with your hardware (hardware abstraction) you can really save yourself a lot of work later on when it comes to porting.

Sponsored Links: