Stm32cubemx Free RTOS Exmaple (Task and queue)

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

Most views

Leave a Reply

Your email address will not be published. Required fields are marked *