This week I was tasked with migrating our PIC32 code so it would use the superior FreeRTOS architecture instead of a superloop. Having no experience in FreeRTOS whatsoever I began by skimming through the first 3 chapters of documentation to get me started.
Later I simply enabled the FreeRTOS third party library in Harmony Configurator which automatically setup almost everything for me ¯\_(ツ)_/¯ minus some minor adjustments for function priorities/delays. The real hassle was getting everything to work properly when put together. A single program would work fine alone. But three together was more difficult:
2- Programming the FPGA
3- USB CDC
The PIC handles programming the FPGA and they communicate through SPI protocol. However SPI wasn’t working on the new boards due to a hardware connection issue. A software hack had to be made and thankfully the code was already written by a previous intern, I just needed to utilize it. The concept is Bit Banging where pins are manipulated through software to send data instead of using dedicated hardware (SPI). The program starts by performing a “handshake” with the FPGA which puts it into configuration mode, after which we may send the bit stream. While I admire previous people’s work, I get thoughts that would send me straight to jail when documentation is lacking. Which was the case with the issue above, therefore it took me quite some time comparing between the schematic, wiki, and code to figure out the actual pins I should be using for the bit banging. Thankfully I got it working.
But wait, there’s more:
The configuration mode handshake (see page 29) is done by:
Pull PROG_B LOW > Check for INIT_B going LOW > Pull PROG_B HIGH > Check for INIT_B going HIGH.
If the TCP/IP stack is initialized init_b never goes high again. Therefore the stack must be deinitialized before programming the FPGA.
I continued migrating the system, I’m not finished troubleshooting the code but I’ll make everything work soon. Mind you, I should have finished this by last week, but I was slow.
Oh I also characterized two more new prototypes (like in previous blogs). Before I could do my tests two pins had to be soldered to the ground. Since I had no intention of sinking into thousands of debt when I mess up the soldering, I asked Alya (senior intern) to do it, so that I could blame her just in case. But everything went fine. Thanks Alya.