@mattytrog Hey buddy, been a while since I poked my head in here, looking great!
Wanted to stop by to see if the recent work done for the DI might be useful for you as well. I'm not completely caught up on everything your firmware does, but I do see two things I think I can help with:
1) Flash storage of settings. I noticed you're using the FlashStorage library with the alternate EEPROM functions. While the EEPROM calls are a little more verbose than the default functions, it still doesn't do any wear leveling of any kind, and the SAMD21 flash area has a fairly low rated cycle count (min 25k, average 150k cycles). In addition, FlashStorage is a bit of a space hog, though with your 256kb of flash area compared to my 64kb, maybe that's not an issue for you.
To combat this I wrote (and optimized with the help of stuckpixel) a 16 "bin" wear-leveling algorithm for user settings. It works as such, with byte 1 of each bin indicating a full or empty bin:
This brings our rated cycle count up to min 400k, average 2.4M cycles, at the cost of the last 1kb of flash area. The code takes advantage of the fact we have row erase granularity but page write granularity with SAMD21. With SAMD21, each page is 64 bytes, so that's how much we have for data storage. It looks like you're currently using 41 bytes for data storage, and a lot of those uint32_t's look like they could be uint8_t's, so you would have lots of room for extra settings.
Plus, since we're using defined memory locations, all your user settings will persist through both user code and bootloader updates, so long as your flash area has at least 1k of free space.
The source for it is here: https://github.com/dragoninjector-project/DragonInjector-Firmware/blob/master/main/main.ino
2) A CLI. I'm sure you're aware that the UF2 bootloader can emulate a USBSerial device and does so by default for BOSSA. However, I saw this as an opportunity for easier configuration of user settings and/or an easier way for apps to configure them. Rather than poking and prodding CURRENT.UF2 (which I don't think would work for FlashStorage anyways without a magic number) we can just talk plaintext. This potentially opens up the door for fancy Homebrew right on-console which can configure our modchips - I've been told support for USB Serial would be far easier to implement than FAT16 MSC. Pretty much everything already has it. Attached is an image of me configuring a DI with my phone, and Jerome is working hard on adding a nice configuration screen to the Windows app.
Source for the CLI: https://github.com/dragoninjector-project/DragonInjector-Bootloader/blob/master/src/sam_ba_monitor.c
Source for the Windows app: https://github.com/dragoninjector-project/DragonInjector-UpdateTool
Anyways, let me know what you think!
Wanted to stop by to see if the recent work done for the DI might be useful for you as well. I'm not completely caught up on everything your firmware does, but I do see two things I think I can help with:
1) Flash storage of settings. I noticed you're using the FlashStorage library with the alternate EEPROM functions. While the EEPROM calls are a little more verbose than the default functions, it still doesn't do any wear leveling of any kind, and the SAMD21 flash area has a fairly low rated cycle count (min 25k, average 150k cycles). In addition, FlashStorage is a bit of a space hog, though with your 256kb of flash area compared to my 64kb, maybe that's not an issue for you.
To combat this I wrote (and optimized with the help of stuckpixel) a 16 "bin" wear-leveling algorithm for user settings. It works as such, with byte 1 of each bin indicating a full or empty bin:
Code:
READING VALUES:
1) Code checks last row page 4, if byte 1 is > 0 then it loads the values, if not then:
2) Code checks last row page 3, if byte 1 is > 0 then it loads the values, if not then:
3) ...
15) Code checks fourth last row page 2, if byte 1 is > 0 then it loads the values, if not then:
16) Code checks fourth last row page 1, if byte 1 is > 0 then it loads the values, if not then it sets default values.
WRITING VALUES:
1) Check fourth last row page 1, if byte 1 == 0 then write the values and set byte 1 > 0, if not then:
2) Check fourth last row page 2, if byte 1 == 0 then write the values and set byte 1 > 0, if not then:
3) ...
15) Check last row page 4, if byte 1 == 0 then write the values and set byte 1 > 0, if not then:
16) Erase last four rows, write the values and set byte 1 > 0 at fourth last row page 1.
This brings our rated cycle count up to min 400k, average 2.4M cycles, at the cost of the last 1kb of flash area. The code takes advantage of the fact we have row erase granularity but page write granularity with SAMD21. With SAMD21, each page is 64 bytes, so that's how much we have for data storage. It looks like you're currently using 41 bytes for data storage, and a lot of those uint32_t's look like they could be uint8_t's, so you would have lots of room for extra settings.
Plus, since we're using defined memory locations, all your user settings will persist through both user code and bootloader updates, so long as your flash area has at least 1k of free space.
The source for it is here: https://github.com/dragoninjector-project/DragonInjector-Firmware/blob/master/main/main.ino
2) A CLI. I'm sure you're aware that the UF2 bootloader can emulate a USBSerial device and does so by default for BOSSA. However, I saw this as an opportunity for easier configuration of user settings and/or an easier way for apps to configure them. Rather than poking and prodding CURRENT.UF2 (which I don't think would work for FlashStorage anyways without a magic number) we can just talk plaintext. This potentially opens up the door for fancy Homebrew right on-console which can configure our modchips - I've been told support for USB Serial would be far easier to implement than FAT16 MSC. Pretty much everything already has it. Attached is an image of me configuring a DI with my phone, and Jerome is working hard on adding a nice configuration screen to the Windows app.
Source for the CLI: https://github.com/dragoninjector-project/DragonInjector-Bootloader/blob/master/src/sam_ba_monitor.c
Source for the Windows app: https://github.com/dragoninjector-project/DragonInjector-UpdateTool
Anyways, let me know what you think!
Last edited by MatinatorX,