Erase addr size / section of the flash memory with st-flash#1213
Erase addr size / section of the flash memory with st-flash#1213Nightwalker-87 merged 8 commits intostlink-org:developfrom
Conversation
|
Hi. For example, I've tested erase sections with STM32F746G-DISCO. st-flash.exe erase 0x8000000 4096And the application erased 2 sectors with a total volume of 64kB, instead of 1 sector. >st-flash.exe erase 0x8000000 4096
st-flash 1.7.0-130-g42790f3
2022-01-09T16:06:02 INFO common.c: F74x/F75x: 320 KiB SRAM, 1024 KiB flash in at least 2 KiB pages.
EraseFlash - Sector:0x0 Size:0x8000 -> Flash page at 0/ 2 erased
EraseFlash - Sector:0x1 Size:0x8000 -> Flash page at 1/ 2 erased |
|
I could have spotted that indeed... Good that we usually have at least two reviewers. |
|
Hi, |
|
@antoinefaure |
|
@antoinefaure Please read the respective value from the .chip files located in |
|
I've just pushed 3 new commits:
@slyshykO
Is there something else that needs to be checked ? @Nightwalker-87 |
|
@antoinefaure Take a look at |
|
Ah, I see - this is still an old implementation from |
|
That's what I understood when going through |
|
@Nightwalker-87 |
|
@slyshykO I thought about that also at first, but actually as I'm not planning to change anything in |
|
@antoinefaure In my opinion, this changes does not check the correctness of entering the starting address of the first page. I would add checks like these: Lines 3472 to 3514 in 7cc1fda It would also be nice to fix |
|
@Ant-ON Correct me if I'm wrong, but I think most of the checks you've linked are wrong:
That leaves us with 2 tests :
Both of them are done here: The alignment checks are done here : And here : Unless I missed something, I think we are all good with the checks.
That's a good catch, I'll fix this! |
Sorry. At a cursory glance, I missed these checks. It is better to separate the checks so that the user understands the problem better. if (base_addr < sl->flash_base || base_addr >= (sl->flash_base + sl->flash_size)) {
ELOG("Address is out of the flash (0x%08X - 0x%08X)\n", sl->flash_base, sl->flash_base + sl->flash_size);
return (-1);
}
if ((base_addr + size) > (sl->flash_base + sl->flash_size)) {
ELOG("The size exceeds the size of the flash (%u bytes available)\n", sl->flash_base + sl->flash_size - base_addr);
return (-1);
}There is still some redundancy. Lines 3472 to 3499 in 7cc1fda This code can be shortened to (all checks done in the stlink_erase_flash_section):
if (len & 1) {
WLOG("unaligned len 0x%x -- padding with zero\n", len);
len += 1;
} |
|
@antoinefaure @Ant-ON Thanks for the comments. Both looks good to me. |
|
Hey @Ant-ON @Nightwalker-87 Testing this has been a bit frustrating, as after running |
|
@antoinefaure Thank you! Everything looks very good! |
|
@antoinefaure Very good and valuable contribution. Thank you. 🥇 |
|
@slyshykO No, we shouldn't continue with this practise of continued explicit conversions. |
|
Hey guys, thanks for your help and for getting this merged in! |
The root of the problem is C-lang itself and its many realizations for numerous platforms. You will never guess which base type equal |
|
A solution to this is to work with fixed-length typedefs like int16_t, int32_t, etc. Have you tested this in the meanwhile? |
Please, hear me. This is no solution at all when we deal with printf format lines cause its syntax to know nothing about sized types. |
|
|
Please open a new PR for this issue and reference the respective comment above. |
Hi,
This PR is to add the possibility to only erase a section of the flash, whereas as of today it is only possible to erase the whole flash (as far as I know).
I've added this functionality in a different function, as I didn't want to mess with the parallelism in
stlink_erase_flash_massCalling erase without specifying an address or size will have the same behavior as before, i.e. erasing the whole flash.
Let me know if you have any remarks.
Thanks!