-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable flash / ram split with minichlink #369
Conversation
Sorry for hijacking the PR, I just recalled this has actually been confirmed - https://cpldcpu.wordpress.com/2024/05/01/decapsulating-the-ch32v203-reveals-a-separate-flash-die/ |
Oh no, I already have something like this in another one of my branches. But I do it in the Makefile. I have it working with the 307. Sorry I just noticed this now. This is much more comprehensive than my change though. Blahhh I will see if I can find common ground. |
Could you rebase the branch to the current upstream branch? |
Rebase done. I'm not currently in the discord, but you can send an invite link to my email in the It's probably worth restructuring how this patch works. The current approach feels inconsistent with the rest of minichlink. Ideally setting the split would be its own operation. Right now it just changes the behavior of the flash erase (?) sequence of the flash write function. I'm working now on a version that uses |
Invite sent. I'd like to chat before we merge this. |
I've rewritten my code in minichlink to be more generic by using Overall the |
This adds support for changing the amount of SRAM available in parts where the flash / SRAM split is configurable. Right now, this only works for the wch-linke adapter. The split is given as a command line flag and applied during the bulk memory write. Without this, the CH32V307 is limited to 32k of SRAM of a possible 128k. Adding this setting addresses issues #232, #280, and (in part) #303.
As referenced in issues #232, #280, and #303, some of the CH32V20x and CH32V30x parts have a user configurable option trading flash size for user RAM size. As described by the CH32V307 datasheet (pg 4):
Speculation is that the chips cannot execute from flash and instead copy the entire contents of the firmware image to hidden internal SRAM. This flag would then be configuring the amount of that internal RAM used for code storage vs user RAM.
This information is stored in the user option section of flash. According to #232, the official programmer sets this via a special command, the same one used to set readout protection. This patch uses the command described there, however does sanity checks based on chip id and applies the setting only if appropriate for the target.
I suspect there is a more general solution to be had here. The flag can be set by firmware running on the chip. Updates require unlocking the flash, making the write, and then become active after a reset. One generic possibility would be to upload a code stub that sets the flag. Another would be to use the read word and write word functionality to set it.
Another drawback to this patch is the setting is only applied during the bulk memory write. This is fine for the common case of uploading code. One weirdness is that the new
-S [FLASH kB] [RAM kB]
flag needs to appear before the-w
flag. Note that the current erase and program workflow clears this flag to the default (32k SRAM for the '307). I'm open to suggestions on how to improve that aspect.I've tested this patch with my WCH CH32V307V-EVT dev board and its integrated WCH programmer. My testing has been somewhat limited, but an application that allocates a 48k SRAM buffer and uses it seems to be working as expected. I don't currently have other hardware to test on.