stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.83k stars 975 forks source link

Hardware Flow control for serial communication #394

Closed mayurharge closed 3 years ago

mayurharge commented 5 years ago

Hello, I am using the STM32f103c series controller with GSM module. Sometimes Serial buffer of GSM is getting full and the communication is not happening as expected. During my search, I came across Hardware Flow control using RTS/CTS. As stm has dedicated H/W flow control pins [For UART 2 PA0:- CTS2 & PA1:-RTS2] is there any option available in board files to enable hardware flow control? if yes please let me know how to enable it if not then it would be really helpful if you can integrate this in next version.

Thanks

fpistm commented 5 years ago

HW flow control is not implemented.

mayurharge commented 5 years ago

Okay, thanks.

mayurharge commented 5 years ago

Hey are you going to implement this feature in future, also please give me some suggestions to implement by myself

fpistm commented 5 years ago

If I well remember it is based on how MBed implement UART. And if I well remember, flow control is also implemented on MBed side. So this could be a good starting point.

mayurharge commented 5 years ago

Thanks i will look into it

fpistm commented 5 years ago

@mayurharge You could let this issue opened as a requested feature. Do not hesitate to provide a PR if you get it up and running.

arihantdaga commented 5 years ago

@fpistm I saw this line in cores/arduino/stm32/uart.c https://github.com/stm32duino/Arduino_Core_STM32/blob/7b48eff35f425ab3d51106d4182bcd0e3cd30f74/cores/arduino/stm32/uart.c#L272 . Does making the HwFlowCtl to UART_HWCONTROL_CTS or UART_HWCONTROL_RTS is all thats required ? I am not sure yet, testing it. But if it works, I'll add this configuration using macros and make it user configurable...

fpistm commented 5 years ago

I guess you have also to init the RTS/CTS pin also.

fpistm commented 5 years ago

Just a quick thought if the buffer is full. By default , the Rx and Tx buffer of the core is 64. https://github.com/stm32duino/Arduino_Core_STM32/blob/bad5b56870ce311a4d591f789cbe5d47450097e4/cores/arduino/HardwareSerial.h#L42

You can redefined them by adding a new file (Tab on Arduino IDE) named _buildopt.h Then in this file put: -DSERIAL_RX_BUFFER_SIZE=256 -DSERIAL_TX_BUFFER_SIZE=256

Increasing only one of both works also but I advise to keep them aligned.

mayurharge commented 5 years ago

@fpistm I am already using the BUFFER_SIZE =256. the need for me to use hardware flow control is that the slave device SIM800c is lagging behind over time When I searched for this issue I figured out this

Flow control is very important for correct communication between the GSM engine and DTE. For in the case such as a data or fax call, the sending device is transferring data faster than the receiving side is ready to accept. When the receiving buffer reaches its capacity, the receiving device should be capable to cause the sending device to pause until it catches up

This was mentioned in the datasheet of SIM800.

benwaffle commented 5 years ago

@mayurharge you can of course use the HAL manually for now by calling HALGPIO and HALUART functions

fpistm commented 3 years ago

Added to [U(S)ART] request list #1418

fpistm commented 2 years ago

Done thanks #1634