GRBL (running on AVR) uses EEPROM for storing some of its state, but STM32-s doesn't have this type of memory due to its high cost. By the way brand new NXP i MX RT MCUs (at least the fastest ones I think) doesn't even contain the flash memory. I could probably live without the eeprom.c ported because the plotter as it is now seems to draw pretty fine, but I wanted to make my project complete. Default settings are stored in the defaults.h, and although I can change them from the UGS, they are not persisted in the machine.
I tried to get the Zephyr's non volatile storage (NVS) to work, but I quickly ran into problems with my MCU flash layout. STM32F446RE has 512kB. Sectors 0-3 are 16kB, 4 is 64, and lastly sectors 5, 6 and 7 are 128kB long. And now the porblems :
- First, by default Zephyr defines the storage_partition at address 0x00010000 (counting from the start of the flash) for my MCU, which corresponds to sector 4. And this is problematic because NVS requires at least 2 physical (flash) sectors to operate, and here we have only one. So my idea was to shrink the boot_partition from 64 to 32kB, and then in the sectors 2 and 3 make another storage_partition for the NVS. So far so good.
- Second, the so called "fixed flash partitions" are used by the Zephyr only when a bootloader is used, and I didn't have one.
After compiling the MCUBoot, to my surprise I discovered that the smallest binary I could get is ~36kB in size (only for the bootloader), so there is no way it would fit into sectors 0 and 1. To make things even worse, my main program is ~140kB big (and it's not even finished) while the two partitions for storing it are 128kB. In other words there are strict requirements as to how the flash has to be organized and I can't satisfy them with the current chip.
Alternatives : external EEPROM (takes PCB space, increases complexity), using a SD card (but what if user removes it?), using a MCU with bigger flash (overkill, GRBL stores everything in mere 1kB), using a MCU with smaller flash pages / sectors.
I hit the local distributor website (naive me) to discover that, indeed, the situation hasn't changed, and there's almost no STM32F4xxx available, and only one or two types STM32G4.
So I started to look around my office and found old scrapped boards we did for a client once, and to my delight they all have STM32F405-s with 1M flash. Flash layout is basically the same, and I think I'll finally manage to get it done.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.