How to use STM32 Flash Settings Storage with 2 motors

Hi everyone,

I am using SimpleFOC on different projects since one year an I really enjoy it, a big thank you to all the developers and the community.

I have recently added the ‘STM32 Flash Settings Storage’ to a project using the STM32G431 and it is working fine, I can save and restore the registers that I have selected.

I have another project with the same MCU controlling 2 motors, also working fine, and I want to add this feature on it but as I understand it is supporting only one motor.

I think I can set 2 different settingsRegisters with a different name for each motor but then how can I assign settings.addMotor(&Motor) settings.init() settings.loadSettings() and settings.saveSettings() to each motor settings ?

Hi @Pat , welcome to SimpleFOC!

I’m really glad to hear someone is using the settings storage, and that it is working in at least some cases :slight_smile:

I think it’s the first feedback we have received about it!

In terms of the multi-motor use cases, it is perhaps not yet fully ready in terms of its support, and certainly not well tested, so please be patient :-/

The idea, roughly speaking, is that you can add more than one motor to the settings:

settings.addMotor(motor1);
settings.addMotor(motor2);

Its important to keep the same order for the motors and not change it between firmware versions :slight_smile:

Then, when you load or store settings it always loads/stores all the chosen registers for each motor you added.
This should probably be mentioned in the README file…

Oh another option is to use more than one instance of the settings storage class, and just use a seperate one for each motor. Then you can load/store them individually.

The second (and subsequent) settings storage objects have to be initialized at different memory addresses:

// or use an address of your choice, in this case 10kB below the end of flash:
#define SETTINGS2_ADDRESS (FLASH_BASE + FLASH_SIZE - (1024*10))
STM32FlashSettingsStorage settings2 = STM32FlashSettingsStorage(SETTINGS2_ADDRESS);

Hi @runger,

I’m really surprised how fast you answer to such queries, I saw that already within all the other posts and I didn’t believe it, really appreciated :slight_smile:

I will try tomorrow and let you know, thank you !

Hi @runger,

The first solution seems to work fine !

BTW I think this feature is underestimated, actually it allows to tune some settings or parameters like PIDs and store them on the fly which prevent to have to flash the code at every change.

It allows also to change parameters on a user site where flashing is not desired or where flashing equipment is not available.

Of course it needs some extra coding to add a dialog or another way for launching the saving and loading process.

Thanks for this thread, I also didn’t realize it’s possible to do this all with the registers! I need to break out some projects again, I think this would be really helpful…