microshell icon indicating copy to clipboard operation
microshell copied to clipboard

[Bug] Paste sometimes misses characters on STM32

Open cosmikwolf opened this issue 3 years ago • 4 comments

I have non blocking reads and writes set up over UART using HAL_UART_Transmit_IT and HAL_UART_Receive_IT, and when I paste into the terminal, it sometimes misses characters.

I have adjusted buffer sizes, and various UART settings to no avail.

Would be happy to gather some data to help troubleshoot this issue, but I am not entirely sure where to start.

cosmikwolf avatar Dec 01 '21 21:12 cosmikwolf

I have also attempted to adjust my terminal settings to add up to a 50ms delay between characters, and it helps, but it will still miss characters maybe 1 / 10 times

cosmikwolf avatar Dec 01 '21 22:12 cosmikwolf

awesome library btw :D I like it alot! I will be trying to implement a command history, so I will do a pull request if I can get it to work!

cosmikwolf avatar Dec 01 '21 22:12 cosmikwolf

Ok, I found the cause was that there was something else that was blocking in the main loop where ush_service is running.
This may indicate that the ush_service() would run best in an interrupt context on a single threaded MCU

cosmikwolf avatar Dec 01 '21 22:12 cosmikwolf

Yes, library is not thread-safe, so be careful in multi-thread environment. And calling ush_service from interrupt context is a very bad idea...

Regarding the missing characters, please make sure that in the read/write interfaces You will return 0 in case of not successful write (e.g. buffer overflow) and 1 in case of success (see examples). If You return 0 library will take to write/read attempt on the next service loop.

marcinbor85 avatar Dec 01 '21 22:12 marcinbor85