I'd suggest either ripping the code from CircuitPython, or reading the USB MSC spec. It's available online for free direct from the USB Implementer's Forum.
Something to note is that MSC doesn't have a concept of files; the host PC just tells the device to write blocks of data where ever it wants whenever it wants. The MSC spec doesn't really allow for the peripheral to say, no, you can't reformat me into ext2 or NTFS or something. If the Pico needs to be able to do any kind of validation on the PC asks it to write, MTP would be a better choice. The UF2 format is clever use/terrifying abuse of MSC.
You've already found examples that present an MSC device to a host. Instead of accessing data in the Pico's RAM or on an SD card, you want to use the Pico's on-board flash. You'd do that using the hardware_flash. and pico_flash APIs. You also should review the RP2040 datasheet, especially the address map and flash XIP blocks.
Something to note is that MSC doesn't have a concept of files; the host PC just tells the device to write blocks of data where ever it wants whenever it wants. The MSC spec doesn't really allow for the peripheral to say, no, you can't reformat me into ext2 or NTFS or something. If the Pico needs to be able to do any kind of validation on the PC asks it to write, MTP would be a better choice. The UF2 format is clever use/terrifying abuse of MSC.
You've already found examples that present an MSC device to a host. Instead of accessing data in the Pico's RAM or on an SD card, you want to use the Pico's on-board flash. You'd do that using the hardware_flash. and pico_flash APIs. You also should review the RP2040 datasheet, especially the address map and flash XIP blocks.
Statistics: Posted by DrDnar — Thu Jan 25, 2024 7:21 am