mcuboot: HARD FAULT writing or reading flash on a stm32f0
I’m trying to swap images from slot1 to slot0 with boot_request_upgrade(0) and I’m having problems. When the mcuboot try to manipulate some region of flash like slot0, slot1 or scratch through flash_area_write or flash_area_erase I get this error:
***** HARD FAULT *****
***** Hardware exception *****
Current thread ID = 0x00000000
Faulting instruction address = 0xfffffffe
More precisely the error is happening after to call this function flash_write_protection_set(flash_dev, false).
I was wondering if my problem was that I couldn’t access flash for some reason, so I erased my memory flash and flashed a code with these statements and no errors occurred.
u8_t buff[] = "aaaaaaa";
int err = flash_area_open(SCRATCH_ID, &fap);
if (!err) {
printk("scratch -> fa_off: %X, fa_size: %X, fa_id: %d, fa_device_id: %d\n", fap->fa_off,
fap->fa_size, fap->fa_id, fap->fa_device_id);
}
err = flash_area_write(fap, 0, buff, strlen(buff));
if (err) {
printk("Error writing...\n");
}
err = flash_area_erase(fap, 0, fap->fa_size);
if (err) {
printk("Error erasing...\n");
}
After that, I got this same code and put it in the begin of mcuboot’s main and I got HARD FAULT again. So the same code results in HARD FAULT when I use it in mcuboot code and results in no error when I use it in a blank project.
I’m using the code in the branch master.
@EDIT: I’m using mcuboot for zephyr. @EDIT2: The function flash_write_protection_set(flash_dev, false) is inside of flash_area_erase and flash_area_write, I don’t call it directly. @edit3: This print “printk(“scratch -> fa_off: %X, fa_size: %X, fa_id: %d, fa_device_id: %d\n”, fap->fa_off, fap->fa_size, fap->fa_id, fap->fa_device_id);” is correct in both mcuboot and my blank project, the error is just in flash_area_write or flash_area_erase. Note that the flash_area_erase(fap, 0, fap->fa_size) is exactly the same statement that the mcuboot makes in boot_erase_sector(where my hard fault occurs) function, when the mcuboot is trying to erase the scratch region.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 20 (5 by maintainers)
On second thought, I think we should convert this line so that these files are only built using
target_sources_ifdef(CONFIG_MULTITHREADING ...)
or so as appropriate (e.g. for sem.c).Otherwise this is just going to continue to break randomly – which is why I wonder how Andy Ross feels about this.
The problem was exactly this! I enabled CONFIG_MULTITHREADING and it worked right away. Thanks for your help @utzig!
I’m closing this issue since the problem is solved.