Close

Storing configuration values

A project log for SD/Serial Card Loader

Load/Save files from/to an SD card to/from a Serial Port

land-boards.comland-boards.com 06/16/2022 at 09:070 Comments

I'd like to store the default configuration values for the uart. At first blush it seemed like the Flash memory could be used for that function. Turns out it's a bit painful to use the Flash memory. The reason is that the Flash system gets locked by the USB when connected to the Host Computer. CircuitPython does this to avoid data corruption. This isn't an insurmountable problem because this application doesn't need to use the Serial port, but I'd still like the USB Serial for development and convenience.

The Adafruit Learning Guide for Storage shows a method with a boot.py file that reads an input pin to determine r/w state of the drive at power. It makes the Flash read-only to the Host Computer and thereby read-write to the application on the card.

I do have 1 spare input but I'd rather not use the last spare pin. If you set the boot.py to always make the drive read-only then there's no way to edit it later as the drive will always mount as read-only to the host computer.

Better solution

I think a better approach is to create a file on the SD card that loads/stores the configuration. That has the value that a target specific file would be created. I envision using different SD cards for various target systems. 

Created /sd/SDLdr.cfg file to store the configuration as a comma separated list of baudRate, serProtocol, handShake.

If there's no SDLdr.cfg file on the SD it creates a file with default values:

Created three functions:

# initConfig() - Initialize the configuration parameter values
# loadConfig() - Load the configuration parameters from the SD card
# storeConfig() - Store the configuration parameters to the SD card

Tested and it works! It's nice to not have to set up the COM ports every time I run the code.

Created zip file QT-Py/SDLoader_V2-20220616.zip of the current source code.

Discussions