So, I didn’t realize it has been so long since I wrote the last update. It was a pretty eventful summer with some good progress. But, I did not get as much done as I had hoped. I faced a major problem and dealt with a harsh truth: hardware design is hard if you haven’t done it before!
I have essentially finished migrating the entire RN-9090 onto the STM32. I have written libraries to control all the peripherals that I need and verified that they work. I migrated the algorithm over and ended up redoing most of it because I had originally written the code before I knew much about proper data structures, programming, and processor behavior. My code was a mess of global variables thanks to the Arduino IDE and I just had to re-do everything. In the process of upgrading the code, I implemented a dynamically allocated memory system for everything because why not? Dynamic memory is an efficient use of space and good programming techniques. Or at least that was what I thought until I started testing the new code I had written. I spent many days and nights struggling to understand why I was getting hardfault errors at benign locations in my code and it significantly slowed down my progress. Eventually, I learned that dynamic memory allocation for an embedded system is not so cut and dry as it might be when programming on a PC with virtually unlimited memory. Dynamic memory allocation suffers from two problems: determinism and fragmentation. Fragmentation occurs when a block of memory is freed but subsequent further requests cannot fit in the freed block. Memory locations become fragmented and lost and it is not an efficient use of the limited amount of memory in the heap. Determinism was the problem that I was suffering from. Allocating and freeing memory is non-deterministic meaning that the time it takes to perform the action can vary. This was the source of my frustrations. It took me a while to come to grips that the things my CS teacher always tried to hammer home about dynamic memory allocation was not a rule carved in stone. Eventually, I came around to using static memory allocations, and I don’t know what took me so long. I’m not even using 50% of the available memory anyways.
I am now at the point where I am ready to finish the PCB design for the new RN-9090. Ordering the new PCBs could cost up to $200. I have not designed a PCB with such a chip as this STM32 and I am not a 100% certain that it will work the first time. I am considering making a smaller “dev board” first just to make sure my design works. While that will slow things down, I think it could save me some money if there is a problem. Fortunately, I have the design finished, I just need to place the order. I will definitely update when that happens.
I will finish this project!