Should i turn off interrupts when i write(or erase) flash memory in bootload mode?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Should i turn off interrupts when i write(or erase) flash memory in bootload mode?

Jump to solution
7,191 Views
eunseokjung
Contributor II

Hi all,

I am programming the bootloader for Kinetis K10 series. I already read an2295 note and use its SW.

When i practiced without any interrupts code, it was working well.

After then, i add some special interrupts for display, measure and communication(uart system).

But the flash write and erase is not working properly.

Should i turn off interrupts for writing(or erasing) flash memory?

My code is based on an2295 sw.

Labels (1)
0 Kudos
Reply
1 Solution
5,078 Views
ndavies
Contributor V

Once again, if the ISR is in the flash block you re writing to or erasing, You must turn it off.

It does not matter that the programming commands are in RAM. If an ISR in that flash block goes off while you are programming or erasing anything in that flash block you will get a hard fault.

View solution in original post

0 Kudos
Reply
7 Replies
5,078 Views
scottthompson
Contributor II

Hello,

I have written a bootloader but also rely on interrupts for UART, etc.

What might seem confusing is that the actual flash command processing must occur in SRAM (e.g., FlashCommandSequence), but separately if you are going to overwrite your ROM vector table, it has to get relocated to SRAM as well.

For my bootloader, if I'm going to flash sections like my boot config tables, I have to ensure that all of this is running in SRAM as well.  I use scatter loading and have a dedicated region in SRAM to hold a copy of my main bootloader application.  I copy all of my flash memory over to the SRAM location and adjust the SRAM copy of the vector table to be offset by the SRAM base (see below).

pastedImage_1.png

Once you relocate your code and change VTOR to point to the newly updated vector table, you can "jump" to the bootloader in SRAM and re-enable interrupts.  Your UART ISR, etc. will get called from your relocated copy in SRAM.

0 Kudos
Reply
5,078 Views
eunseokjung
Contributor II

Thanks Mark.

I have another question.

I read AN2295 note and AN4695 note.

According to AN4695, the flash write is possible if flash write command is operated in SRAM region.

So, the AN2295 example code is made by this reason. The flash write function which AN2295 example code provided is running in SRAM region.

In this case, should i disable all interrupts?

I'm confusing about this problem.

One more question, when i run the flash wirte code, "Unable to retrieve disassembly data from backend" error is occured.

How to solve this problem?

0 Kudos
Reply
5,078 Views
mjbcswitzerland
Specialist V

Hi

Flash will be written by code operating in SRAM. If there are interrupts in the system they should also be blocked.

This is made clear by AN4695:

pastedImage_0.png

Note that AN2295 doesn't look to be using interrupts so it can't be takes as a general reference.

"Unable to retrieve disassembly data from backend" I believe that this may occur when trying to debug in SRAM based code when the debugger can't relate the disassembled code to any source code. You should still be able to step the code in disassemble mode and ignore such error messages. Alternativey, just run across the routine in SRAM.

Note that the uTasker serial loader now also includes optional AN2295 compatibility, which operates on all KE, KEA, KL, KV and K parts and can be built with most IDEs without any development/porting effort: http://www.utasker.com/docs/uTasker/uTaskerSerialLoader.PDF

Regards

Mark

Kinetis: µTasker Kinetis support

K20: µTasker Kinetis TWR-K20D72M support  / µTasker Kinetis FRDM-K20D50M support  / µTasker Kinetis TWR-K20D50M support  / µTasker Teensy3.1 support

Serial Bootloader (Ethernet, USB, MSD, KBOOT, AN2295, SREC, SD-card): KBOOT Loader Compatibilty and extra features  /  http://www.utasker.com/docs/uTasker/uTaskerSerialLoader.PDF

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos
Reply
5,078 Views
ndavies
Contributor V

You must turn off interrupts, If the interrupt service routine or the interrupt vector table is in the flash block you are writing to. If you need an interrupt to stay on, you must move the interrupt vector table and the interrupts service routine to either another flash block or RAM.

0 Kudos
Reply
5,078 Views
eunseokjung
Contributor II

Thanks Davies.

My curious thing is this.

ISR is in Flash and Flash write function is in SRAM.

In this case, i should disable interrupt or not?

0 Kudos
Reply
5,079 Views
ndavies
Contributor V

Once again, if the ISR is in the flash block you re writing to or erasing, You must turn it off.

It does not matter that the programming commands are in RAM. If an ISR in that flash block goes off while you are programming or erasing anything in that flash block you will get a hard fault.

0 Kudos
Reply
5,077 Views
mjbcswitzerland
Specialist V

Hi

When writing or erasing Flash the Flash is not available for running code from. This is also true when the code is executed due to interrupts. Therefore, if the interrupts are not run in RAM or their code cannot be located in an alternative Flash block that is still free, interrupts MUST be disabled to avoid a failure due to the interrupt trying to use the unavailable Flash to run from.

Regards

Mark

Kinetis: µTasker Kinetis support

K20: µTasker Kinetis TWR-K20D72M support  / µTasker Kinetis FRDM-K20D50M support  / µTasker Kinetis TWR-K20D50M support  / µTasker Teensy3.1 support

For the complete "out-of-the-box" Kinetis experience and faster time to market