cancel
Showing results for 
Search instead for 
Did you mean: 

I'm not able to print hello world in RTOS console

Akshay_
Associate II
void StartDefaultTask(void const * argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
printf("Hello world!");
//HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
//HAL_Delay(1000);
//osDelay(1);
}
/* USER CODE END 5 */
}


Greetings! this is the code for printing hello world on the console of RTOS in stm32 cube IDE but I'm not able to see the results on the console is anything wrong here??

I have created a task to print hello world on the console

8 REPLIES 8
Pierre_Paris
ST Employee

Hello @Akshay_,

Have you read the article named How to redirect a printf function to a UART for debug messages

It may help !

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Use this button to properly post source code:

AndrewNeil_0-1707319643510.png

SofLit
ST Employee

Hello,

  1. Do you have test printf without RTOS?
  2. Did you already configure CubeIDE SWV console?
  3. Why osDelay(x) is commented?
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@Akshay_  what RTOS are you using? Have you checked its documentation for specific support?

 


@Pierre_Paris wrote:

Have you read the article named How to redirect a printf function to a UART for debug messages

 


@Pierre_Paris  That's the "bare metal" approach - are you sure it'll work with an (unknown) RTOS ?

 

eg, https://forums.freertos.org/t/implementation-of-printf-that-works-in-threads/8117/2 

Pavel A.
Evangelist III

@Akshay_ There is no such thing as "RTOS console". RTOS, such as RTX or FreeRTOS, is not a Linux. You print just to what happens to be the stdout of the C runtime library linked to your firmware. In case of CubeIDE it is the newlib (nano), in Keil or IAR - their proprietary runtime libraries. So just research how printf and its friends work in the used library, with multiple threads. FreeRTOS has a set of extensions, FreeRTOS+, among them is a "CLI" library which can be used to make a console.

 

 

Pierre_Paris
ST Employee

Hello @Akshay_  & @Andrew Neil,

Q : Are you sure it'll work with an (unknown) RTOS ?

A : It will work with FreeRTOS. 

You need to configure at least :

  • UART as asynchronous under CubeMX and make sure that pins selected match with hardware. Which STM32 are you using ? with a nucleo/dev board ?
  • FREERTOS section under CubeMX (enable USE_NEWLIB_REENTRANT) and create tasks, queues, semaphores... as needed.
  • SYS with a timebase source such as TIM1.

I advise you to watch this great YouTube video done by an other developer.

Kind Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


@Pierre_Paris wrote:

Hello @Akshay_  & @Andrew Neil,

A : It will work with FreeRTOS. 

But will it be Thread-safe ?

Pierre_Paris
ST Employee

Hello @Andrew Neil,

Q : But will it be Thread-safe ?

A : Indeed, basic functions malloc() and free() are not thread safe. To be thread safe, you need to implement a locking mechanism. This is well explained in this article and comments. Here is the newlib documentation for __malloc_lock() and __malloc_unlock().

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.