FreeRTOS_Freemodbus_stm32_RTO_CRC

所属分类:uCOS/RTOS
开发工具:C
文件大小:3525KB
下载次数:6
上传日期:2020-12-22 19:51:10
上 传 者sh-1993
说明:  这是一个结合了freemodbus、freertos、硬件crc、uart dma和uart rto的项目。
(This is a project combines freemodbus, freertos, hardware crc , uart dma and uart rto.)

文件列表:
Core (0, 2020-12-23)
Core\Inc (0, 2020-12-23)
Core\Inc\FreeRTOSConfig.h (6132, 2020-12-23)
Core\Inc\jpeg_utils_conf.h (2770, 2020-12-23)
Core\Inc\main.h (7531, 2020-12-23)
Core\Inc\modbus.h (3349, 2020-12-23)
Core\Inc\stm32f7xx_hal_conf.h (16666, 2020-12-23)
Core\Inc\stm32f7xx_it.h (3318, 2020-12-23)
Core\Inc\wavdecoder.h (524, 2020-12-23)
Core\Src (0, 2020-12-23)
Core\Src\main.cpp (32862, 2020-12-23)
Core\Src\modbus.c (33805, 2020-12-23)
Core\Src\stm32f7xx_hal_msp.c (21917, 2020-12-23)
Core\Src\stm32f7xx_hal_timebase_tim.c (5234, 2020-12-23)
Core\Src\stm32f7xx_it.c (10280, 2020-12-23)
Core\Src\syscalls.c (3259, 2020-12-23)
Core\Src\system_stm32f7xx.c (9630, 2020-12-23)
Drivers (0, 2020-12-23)
Drivers\BSP (0, 2020-12-23)
Drivers\BSP\Components (0, 2020-12-23)
Drivers\BSP\Components\Common (0, 2020-12-23)
Drivers\BSP\Components\Common\accelero.h (4538, 2020-12-23)
Drivers\BSP\Components\Common\audio.h (3560, 2020-12-23)
Drivers\BSP\Components\Common\camera.h (5306, 2020-12-23)
Drivers\BSP\Components\Common\epd.h (3274, 2020-12-23)
Drivers\BSP\Components\Common\gyro.h (4516, 2020-12-23)
Drivers\BSP\Components\Common\idd.h (6460, 2020-12-23)
Drivers\BSP\Components\Common\io.h (5299, 2020-12-23)
Drivers\BSP\Components\Common\lcd.h (3524, 2020-12-23)
Drivers\BSP\Components\Common\magneto.h (3537, 2020-12-23)
Drivers\BSP\Components\Common\ts.h (3190, 2020-12-23)
Drivers\BSP\Components\Common\tsensor.h (3609, 2020-12-23)
Drivers\BSP\Components\adv7533 (0, 2020-12-23)
Drivers\BSP\Components\adv7533\adv7533.c (14342, 2020-12-23)
Drivers\BSP\Components\adv7533\adv7533.h (7611, 2020-12-23)
Drivers\BSP\Components\ampire480272 (0, 2020-12-23)
Drivers\BSP\Components\ampire480272\ampire480272.h (3833, 2020-12-23)
Drivers\BSP\Components\ampire640480 (0, 2020-12-23)
Drivers\BSP\Components\ampire640480\ampire640480.h (3857, 2020-12-23)
... ...

# FreeRTOS DMA_Uart Freemodbus STM32_RTO and CRC_hardware_DMA This is a modbus STM32 project using Freemodbus. FreeRTOS manage various of different tasks. In order to achieve the maximum capability of STM32 hardware, DMA was used for diferent peripherals, such as uart, crc. As RTO (receiver timeout) in uart was used, a modbus frame can be obtain through uart RTO interrupt. CRC is used as well, and DMA will transfer data from uart receive memory to CRC data register, which can significantly reduce the CPU utilization. For this project, I use Atollic TrueStudio as my IDE, and it is supposed to word on other gcc based IDE such STM32CubeIDE and System Workbench for STM32. My board is stm32f769i-disco. ## UART DMA In this section I will explain how to use uart with DMA to send and receive data. ### UART DMA SEND I set uart baud width as 115200 bits/second, stopbit 1 and parity check as odd. Be careful here, the word length is set 9 bits, this 9 bits is 8 bits plus parity bit. For DMA part, I use normal mode, the address of peripheral is fixed, and the address of memory will increase at end of every DMA cycle. After initialize and link the uart and dma peripheral, just call __HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)__ to send data by DMA. ### UART DMA RECEIVE The DMA receiving scenario is different from sending. Every time uart sense data comes in, dma will automatically move data into destination, and not trigger interrupt. The interrupt will only be triggered when the waiting time is over 32 bits (9 bits * 3.5 = 31.5 bits round up to 32 bits). In the UART RTO interrupt, the CPU will send a signal to tell the modbus task that a frame is ready. As timeout receiving is automatically done by hardware, programmer does not have to worry about write a timer interrupt to judge whether a frame is ready or not. here is a flow chart shows difference between with RTO and without RTO. ![](https://github.com/Yuanzjls/FreeRTOS_Freemodbus_stm32_RTO_CRC/blob/master/RTO.bmp) ### CRC and DMA CRC is used to make sure there is no transmission error during transmission, and STM32 has hardware CRC, and it is able to come out a result with few cycle. In fact, transferring data to CRC data register will significantly reduce the usage of CPU. for more information check the document [Using the CRC peripheral in the STM32 family ](https://github.com/Yuanzjls/FreeRTOS_Freemodbus_stm32_RTO_CRC/blob/master/https://www.st.com/resource/en/application_note/dm00068118-using-the-crc-peripheral-in-the-stm32-family-stmicroelectronics.pdf). In addition, transferring data in dma from memory to CRC data register is memory to memory transfer, so it can be only done by DMA2 in STM32. ### Modbus Because RTO is used in this project, I don't need the whole Freemodbus framework. I ported function parts of Freemodbus into my project, and it works well. ## Result ![communicate with PC software](https://github.com/Yuanzjls/FreeRTOS_Freemodbus_stm32_RTO_CRC/blob/master/result.png)
Left side is the message (hex form) from PC sending to stm32, and the right side is the message stm32 send back to PC. ## Todo * Port TCP into the project. * Add some demos.

近期下载者

相关文件


收藏者