STM32 CubeMX HAL UART interface API

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值