This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

cmsis-rtos v2 - printf not working inside threads

Hello,

I am working with STM32WB55RG platform. I have successfully use printf function with uart. However when I try to use this same function inside cmsis-rtos v2 threads it's not working. Basically thread hangs.

My code implementing printf:

#ifdef __GNUC__
  /* With GCC, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */

PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);

  return ch;
}

Code starting thread:

// ...
osKernelInitialize();

const osThreadAttr_t main_attributes = {
    .name = "main",
    .priority = (osPriority_t) osPriorityNormal,
    .stack_size = 1024
  };
  mainHandle = osThreadNew(mainFunction, NULL, &main_attributes);
  
osKernelStart();

// ...

void mainFunction(void *argument)
{
    uint8_t message[40] = "Hello World! This is mine.\n\r";
    for(;;)
    {
    printf("Hello this is printf!\n");
    //HAL_UART_Transmit(&huart1,message,sizeof(message),10);
    vTaskDelay(1000/portTICK_RATE_MS);
    }
}

If I remove printf HAL_UART_Transmit works properly. Any thoughts?

Best regards,

zurek

  • Where does it hang? Inseide printf?

    It seems that you are using GCC. printf tends to be resource hungry. Try to increase global heap settings and also stack size of mainFunction.

    BTW: vTaskDelay is not really defined in CMSIS-RTOS2, osDelay is.