QuickLogic-Corp / qorc-sdk

Open source FreeRTOS SDK for EOS S3 MCU+eFPGA SoC including gateware, software and documentation under QuickLogic Open Reconfigurable Computing (QORC) Initiative
Apache License 2.0
43 stars 27 forks source link

fix uart hal for spurious rx with floating rx pin #142

Closed coolbreeze413 closed 2 years ago

coolbreeze413 commented 2 years ago

Symptom:

qf_apps/qf_bootloader_uart : if UART cable is not connected from HOST to the EOSS3 (specifically the Rx pin of the EOSS3): the board keeps resetting after pressing the 'USR' button, and never stays in the 'programming' mode.

Cause:

EOSS3 gets Rx interrupts due to the UART Rx pin floating - the 'data' in the register is always '0' and the 'framing_error' bit is always set. This happens continuously and does not die down. As the 'data' part of this is pushed into the Rx Buffer, the bootloader loop gets a '0' which is considered to be the 'boot' command in normal scenarios, causing the reset of the board.

Fix:

2 parts:

  1. For Rx Interrupts where the 'framing_error' is set, do not consider the 'data' part of the register as valid bytes, so add a 'return'
  2. Also, when the 'framing_error' count reaches a threshold, disable the UART interrupts, otherwise the interrupt handler hogs the CPU indefinitely. A nominal threshold of '5' errors is currently used, as the ideal scenario is '0' errors.

Test

Current:

  1. Keep the UART cable unconnected to the QuickFeather, and then run the qf_bootloader_uart, and press 'USR' button to enter 'programming' mode: board continuously resets
  2. Keep the UART cable connected, and then run the qf_bootloader_uart and press 'USR' button to enter 'programming' mode: board works as expected (stays in 'programming' mode)

With Fix:

With either UART cable unconnected, or connected, with the qf_bootloader_uart, and press 'USR' button to enter 'programming' mode: the board works as expected (stays in 'progamming' mode)