STM32 CubeMX HAL UART interface API

来源:互联网 发布:淘宝网红店铺有哪些 编辑:程序博客网 时间:2024/06/07 05:30

How to use HAL interface API for STM32 CubeMX generated freeRTOS code?


I am trying to use  CubeMx auto-generated FreeRTOS code.  Choose the UART you need, set NVIC interruput. CubeMX will handle the source code generation. It's absolutely an efficient way to write code. It's CMSIS based, freeRTOS included, everything I need to develop my application. I'm using STM32F103RCT6.

Once the UART is OK. You can use printf() in stdio.h to output all the log info from UART port, quite easy.


Put below code into your UART source code. Then printf("%s\r\n", "hello") is working now. 

The reference link is: http://stm32f4-discovery.com/2014/10/use-printf-output-stream-stm32f4/

FILE __stdout;
int fputc(int ch, FILE *f) {    /* Do your stuff here */    /* Send your custom byte */    uint8_t c = (char) ch;    HAL_UART_Transmit(&huart1, (uint8_t*)&ch, 1, 10); // this is a blocking uart transmit function        /* If everything is OK, you have to return character written */    return ch;}


I remember the old days of write assembly code for uart configuration. Now with ARM cortex-m3, -m4 IC, I can use the standard C library instead. I did a cli (command line interface) with UART, so easy. Remember the old days of DOS, now you can use nowaday 48KB RAM, 256 KB ARM MCU to do it. Multi-thread OS embedded, quite cool!


spike yang





0 0
原创粉丝点击