-
Notifications
You must be signed in to change notification settings - Fork 48
FLASH driver #91
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
base: main
Are you sure you want to change the base?
FLASH driver #91
Conversation
Is there any particular blocker to merging this? I need this for embassy-boot support |
I will try to take a look at this soon.
…On Fri, Aug 15, 2025, at 07:04, Khionu Sybiern wrote:
*khionu* left a comment (ch32-rs/ch32-hal#91) <#91 (comment)>
Is there any particular blocker to merging this? I need this for embassy-boot support
—
Reply to this email directly, view it on GitHub <#91 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACIP5IENMN7PDCHEYUFG2AL3NXSHFAVCNFSM6AAAAABZQNL2WGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCOJRGU4DANJVGQ>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
@Codetector1374 all done on my side. Maybe pinning the rust version in the CI would be a good idea |
Yeah let me work on fixing that soon, then we can merge |
I pushed a fix onto main, I believe you need to do a rebase then it should pass |
FYI: these chips have a Weird flash erase value of 0xe339 which isn't quite compatible with embedded-storage's trait and therefore embassy-boot. see rust-embedded-community/embedded-storage#35 and also my embassy fork (only just saw this, busy moving) |
Changing that const in embassy-boot is actually a decent use case for cargo-patch. That would unblock people at least |
@chmousset
At least, we should be able to read/write/erase beyond the zero-wait area instead on depending on https://github.com/chmousset/rs-ch32-hal/blob/add_flash/src/flash/common.rs impl<'d, MODE> Flash<'d, MODE> {
/// Blocking read.
///
/// NOTE: `offset` is an offset from the flash start, NOT an absolute address.
/// For example, to read address `0x0800_1234` you have to use offset `0x1234`.
pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
blocking_read(FLASH_BASE as u32, FLASH_SIZE as u32, offset, bytes)
}
/// Blocking write.
///
/// NOTE: `offset` is an offset from the flash start, NOT an absolute address.
/// For example, to write address `0x0800_1234` you have to use offset `0x1234`.
pub fn blocking_write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> {
unsafe {
blocking_write(
FLASH_BASE as u32,
FLASH_SIZE as u32,
offset,
bytes,
write_chunk_unlocked,
)
}
}
/// Blocking erase.
///
/// NOTE: `from` and `to` are offsets from the flash start, NOT an absolute address.
/// For example, to erase address `0x0801_0000` you have to use offset `0x1_0000`.
pub fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> {
unsafe { blocking_erase(FLASH_BASE as u32, from, to, erase_sector_unlocked) }
}
} |
@jsprog TBH I didn't want to open that can of worms.
So really the only approach I think makes sense is the one taken with STM32, where the Flash sectors are exposed in ch32-data and handled in ch32-hal. As plenty of WCH chips have non-zero wait Flash sectors, a generic approach would benefit tons of parts at once. It's a bit more than I can chew on right now, hence the working-but-not-ideal solution I PRd here. |
@chmousset I understand that going beyond the non-zero-wait area is more involved and not just providing a different value instead of FLASH_SIZE. According to a note in the reference manual:
Beyond the non-zero wait area there is the standard programming mode
Likely I'll bear with the current limits for storing serialized configuration and taking benefits from other embedded-storage wrappers for wear-leveling, kv-storage, and less erase cycles, and use the non-zero-wait area for logs keeping (custom code). Finally, I'll appreciate if you could answer this question:
|
Unfortunately I didn't find any clue in the documentation or online... like most people I found out when trying to read a blank device. Anyways, I gave more thoughts on the current API and its limitations. @Codetector1374 is there anything blocking this PR on your side? |
Adds sync API for most CH32 parts.
Tested on 208 and 307 (see examples)