Bug in the USART Harmony/FreeRTOS module(?)

Note: I posted this in the Microchip/Harmony forum, but I think it is a FreeRTOS problem. Platform: Curiosity PIC32MZ EF (100 pin) with 2 Clik board slots WiFi4 Clik Board MPLABX IDE v4.20 Harmony 2.06 XC32 v2.10 FreeRTOS v10.0.1 (the default version selected in MHC) The WiFi4 uses a USART (Tx/Rx) interface to the PIC32MZ host. MHC configures the USART and a RESET signal to control the WiFi4 board. The USART driver uses an interrupt with byte-mode at a 115200 baud rate. I used MHC to configure 2 COM ports with the USB CDC library — COM1 is a console port to enter AT commands for the WiFi4 Clik board and COM2 is a log port to display logging messages created during run-time. I developed a superloop app that talks to the WiFi4 board. All of the interfaces and features work as expected. The logic running under the superloop is a little complicated because it relies on multiple state machines and a lot of flags to implement a command/response element. [This is a standard interface characteristic in many serial interfaces, such as Modbus.] An RTOS simplifies the implementation of the command/response element by including delays and waits for the back-and-forth communications, so I converted the superloop logic to use the FreeRTOS module included in the Harmony distro. It crashed. After many hours of checking configurations, debugging (sometimes) showed the PC was in the port_asm.S file (a FreeRTOS source file). No documentation on what that file does but it appears to deal with some interrupt vector locations. I was able to isolate the “bug” to be in the Rx and Error callbacks defined in the USART driver (byte-mode). If I commented out the callbacks, the code did not crash (but it did not execute properly). These same callbacks worked correctly in the superloop version. Conclusion: there appears to be a bug in the USART Harmony/FreeRTOS module.

Bug in the USART Harmony/FreeRTOS module(?)

Hi, I’m afraid I have no idea how Harmony has written its drivers. A couple of hints though: 1) Did you include FreeRTOS through the harmony configurator? That may ensure the driver is compatible with FreeRTOS. 2) There are two ways of writing FreeRTOS compatible ISRs on the PIC32 – see the “interrupt service routines” section on this page to ensure you are following one of the methods: https://www.freertos.org/PIC32MZRTOSMIPS_M14K.html

Bug in the USART Harmony/FreeRTOS module(?)

Richard, thanks for responding…. 1. Yes, I am using the Harmony Configurator (MHC) and the FreeRTOS source code included in the standard Harmony 2.06 distro.
2. I will have to study the reference you provided. I really appreciste the good documentation that FreeRTOS provides. However, there is nothing that I can find that describes the port_asm.S and other .S files in the FreeRTOS source code. My theory is that the Harmony callbacks are not properly accounted for in FreeRTOS. Are they considered part of the ISR or not?

Bug in the USART Harmony/FreeRTOS module(?)

FreeRTOS just provides the context save/restore required on interrupt entry/exit, then the additional context save/restore should a context switch be required. Callbacks executed within the ISR should follow the description on the page link I provided – which basically just means to call the ‘yield from ISR’ function at the appropriate time.

Bug in the USART Harmony/FreeRTOS module(?)

Richard was correct. The bug is in the Harmony interrupt/byte mode driver. I posted a fix in the Microchip Harmony forum.

Bug in the USART Harmony/FreeRTOS module(?)

Thanks for taking the time to report back.