2019-05-15 12:08 AM
I am working on a embedded board using STM32H743ZI MCU. My test App ABC on windows PC send commands to the MCU over USB. STM32 MCU after receiving this
command as input, sends a part of it to the chip XYZ presnt on the same board using UART. Now chip XYZ is supposed to return some reply bytes which are unknown in length
and depend on the command being sent by the App ABC on the PC. I am using Interrupt mode for UART communication between STM32 MCU and chip XYZ, and since
the length of the response is unknown for UART so I have modified the HAL to use custom UART code where there comes an interrupt on each byte received and it is working fine.
My use case is: the response received from chip XYZ has to be sent back to the App ABC in PC by MCU as it is. So to be precise my question is how do I know
that chip XYZ has sent all the response bytes and now MCU can send those response bytes to the PC App , as the legth of the response is unknown and there is no fixed time limit also.
Is there any other way to do read write over UART using HAL (or otherwise) when length of the response is unknown.
2019-05-15 12:38 AM
This is called a "protocol", and means you have a defined start and end signature for each message.
GPS (NMEA 183) sentences, for example, always start with a "$" character, and end with "\r\n".
OTOH, Modbus RTU uses only defined idle times to separate messages, and not specific characters.
If your are not bound to e specific protocol, pick your best matching favourite, or define your own.
Some consistency check (CRC, checksum) and perhaps a retry mechanism is recommended.
> Is there any other way to do read write over UART using HAL (or otherwise) when length of the response is unknown.
Check for the message termination character, and sync with the message start character.
Sending shouldn't be a problem.
I'm no Cube user.
2019-05-15 08:37 AM
Use LL for USART.
Some USART can generate interrupt on specific termination byte (like console /n)
Otherwise, you can also fill a rolling buffer with DMA and check every 1 msec what happened (time slice vs byte by byte), latency compromise
2019-06-07 02:41 AM
Or you could use the IDLE Interrupt or Receiver timeout function.... depense on your incomming datastream timing
2019-06-07 06:11 PM
The first step is to write down how the MCU "in between" knows when the reply of the XZY is complete. Until it is, MCU can't reply to host PC and this will trigger lots of "hang" situation. Define Timeout and protocol. If possible reuse one so you won't have to debug it all the way or toss it down the line once reaching practical tests.
There is an alternate to this which would be to send 2x8 bit when sending one byte, the first byte is the "destination device ID". Then it can be interleaved and decoded/reconstruted.
2019-06-10 11:08 PM
The keyword here is "framing"
If the google translater does a good job, maybe my blog artikel is a good startup:
2019-06-24 06:45 AM
I haven't tested for STM32H7 but this might be useful.