I am working with a Raspberry Pico W that has to act as a MQTT client and I am programming it against the Pico-SDK for C / C++ API.
Since I am going to use the code for several Raspberry Pico W, I would like to be able to transfer a customizable configuration file to the pico using the BOOTSEL mode and then be able to read the custom file from my code running on the pico.
The configuration file will be pretty basic JSON file, which contains essentially only which WiFi to connect to along with password and a unique identifier for the pico.
I would rather compile one UF2 file and upload that to all devices in my network along with a customizable configuration file, than generate a unique UF2 file for each pico with all configurations hardcoded in the file.
Particularly since I want to be able to support over-the-air updates in the future, which is easier, if all units uses the same image.
--
A quick test revealed that I cannot copy paste a configuration file to the pico when it is in BOOTSEL mode, since the file will be gone the next time I put the pico in BOOTSEL mode.
So what are my options?
Is it possible with PICO-SDK to make a small dedicated FAT partition on the pico (like 1 MB), that can be read when mounting the device to a computer?
... or are the only option to use a dedicated SD card and read it via SPI?
I have a sample that fits this question.
Be careful. the BOOTSEL mode does not allow you to register anything other than a program image to the pico.
There are two options. Both configure Pico as a USB Mass Storage Class device with FAT file system and store the configuration values in the onboard flash memory.
The first sample is a configuration where a portion of the Pico's flash memory is formatted with a FAT file system and accessed by the Pico and the host PC. it uses TinyUSB and FatFs bundled with pico-sdk.
https://github.com/oyama/pico-usb-flash-drive
The second one stores a small struct on Pico in flash memory that looks like a USB flash drive with FAT file system to a USB-connected host PC, but in reality the file system is virtual. This one uses only TinyUSB bundled with pico-sdk.
https://github.com/oyama/pico-msc-wifi-setting
Enjoy.