Skip to content
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

write-mem seems not to be working? #44

Open
thirstyone opened this issue Nov 30, 2023 · 3 comments
Open

write-mem seems not to be working? #44

thirstyone opened this issue Nov 30, 2023 · 3 comments
Labels
question Further information is requested

Comments

@thirstyone
Copy link

something strange is going on.
the first time I did wlink dump 0x08003fc0 64 i got:

23:56:02 [INFO] WCH-Link v2.11 (WCH-LinkE-CH32V305)
23:56:02 [INFO] Attached chip: CH32V003 [CH32V003J4M6] (ChipID: 0x00330500)
23:56:02 [INFO] Read memory from 0x08003fc0 to 0x08004000
Length: 64 (0x40) bytes | printable whitespace ascii_other non_ascii
08003fc0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003fd0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003fe0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003ff0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××

Then immediately I did it the second time: wlink dump 0x08003fc0 64
I got:

23:56:05 [INFO] WCH-Link v2.11 (WCH-LinkE-CH32V305)
23:56:05 [INFO] Attached chip: CH32V003 (ChipID: 0x73655207)
23:56:05 [INFO] Read memory from 0x08003fc0 to 0x08004000
Length: 64 (0x40) bytes | printable whitespace ascii_other non_ascii
08003fc0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003fd0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003fe0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003ff0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××

See the changes in chip id?
then I did wlink write-mem 0x08003fc0 0:
23:57:28 [INFO] WCH-Link v2.11 (WCH-LinkE-CH32V305) 23:57:28 [INFO] Attached chip: CH32V003 (ChipID: 0xffffffff) 23:57:28 [INFO] Write memory 0x00000000 to 0x08003fc0
Then I rechecked it with wlink dump 0x08003fc0 64 and got:

23:57:34 [INFO] WCH-Link v2.11 (WCH-LinkE-CH32V305)
23:57:34 [INFO] Attached chip: CH32V003 (ChipID: 0x74617405)
23:57:34 [INFO] Read memory from 0x08003fc0 to 0x08004000
Length: 64 (0x40) bytes | printable whitespace ascii_other non_ascii
08003fc0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003fd0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003fe0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003ff0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××

So, I tried once again: wlink write-mem 0x08003fc0 10 and got

23:58:29 [INFO] WCH-Link v2.11 (WCH-LinkE-CH32V305)
23:58:30 [INFO] Attached chip: CH32V003 (ChipID: 0xffffffff)
23:58:30 [INFO] Write memory 0x0000000a to 0x08003fc0

After checking with wlink dump 0x08003fc0 64 I got:

23:58:37 [INFO] WCH-Link v2.11 (WCH-LinkE-CH32V305)
23:58:37 [INFO] Attached chip: CH32V003 (ChipID: 0x0000000a)
23:58:37 [INFO] Read memory from 0x08003fc0 to 0x08004000
Length: 64 (0x40) bytes | printable whitespace ascii_other non_ascii
08003fc0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003fd0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003fe0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××
08003ff0:   ff ff ff ff  ff ff ff ff  ff ff ff ff  ff ff ff ff   ××××××××××××××××

What is going on with chip-id? am I doing something wrong?

@andelf
Copy link
Contributor

andelf commented Nov 30, 2023

write-mem is not for "write-flash".
You can check out the chip manual for memory split.

@thirstyone
Copy link
Author

I am looking at Figure 1-2. Memory address map.
So, what are the valid addresses for write-mem (and btw, what are the valid addresses for write-reg?)
So, there's no way to alter a few bytes in the flash with wlink?

@andelf
Copy link
Contributor

andelf commented Nov 30, 2023

wlink/src/dmi.rs

Lines 495 to 508 in 59459e2

pub fn program_page(&mut self, address: u32, data: &[u8]) -> Result<()> {
// require unlock
self.unlock_flash()?;
const FLASH_STATR: u32 = 0x4002200C;
const BUSY_MASK: u32 = 0x00000001;
const WRITE_BUSY_MASK: u32 = 1 << 1;
const WPROTECT_ERR_MASK: u32 = 1 << 4;
const FLASH_CTLR: u32 = 0x40022010;
const PAGE_START_MASK: u32 = 1 << 21; // start page program
const PAGE_PROG_MASK: u32 = 1 << 16; //
if address & 0xff != 0 {

It's more complex.
Flash requires erasing by pages and programming by sectors.

You cannot expect a command line tool to flash with complex erase and program sequence.
But you can always use it as a library to do it.

@andelf andelf added the question Further information is requested label Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants