Active-Semi Solutions for Sustainability
Chinese (Simplified)English

PAC5532 Flash write with interrupts

Ask an EngineerCategory: GeneralPAC5532 Flash write with interrupts
Robert McIntosh asked 6 months ago

I am able to erase flash and write to erased flash. I located those routines into RAM.
I found that if I do this with my interrupts enabled the write will succeed, but the PC will be pointing to bad memory location after. That seems to make sense because the interrupt routines are not located in RAM, but in flash. I tried to disable interrupts globally using __disable_irq() but that did not seem to prevent this problem. The only thing that seems to work is locating all the IRQ handlers and called routines into RAM.
Is that expected? Or should I be able to prevent the IRQ handler using __disable_irq?

2 Answers
Jose Quinones answered 8 months ago

Hi Robert,
You should be able to disable all interrupts by using the __disable_irq() function. This is standard of the Cortex Mx architecture. Now, if I recall, when you have code in RAM and FLASH, you have to be careful on how you do this. The problem is that depending on the compiler settings, you may be using some instructions which do not allow for calls with extended addressing. Since the RAM and FLASH are not in contiguous address spaces, running from RAM a code which calls a function existing in FLASH will not work unless you add a compiler directive allowing to do so. If I recall, the compiler directive used to achieve this would be “-mlong-calls”. Are you using it? Do note this adds code execution time to pretty much every function call, as now they are all tried up as long calls. Another option you can try is to go to the PAC52xx.h file and where we define the PAC5XXX_RAMFUNC, change the attribute from .data to .data.ramfunc. The only problem with this method is that when you compile the project, you will not be able to see the real code size. For some reason, GCC miscomputed the different sizes. BTW, all of this only applies to GCC and may not make sense if your IDE is IAR, Keil or a non GCC based one. Hope the info helps!

Robert McIntosh answered 8 months ago

I worked a little more on the problem and found that my real issue was that I was not waiting for the 10 microseconds after the write busy flag goes clear as is noted in the user guide. So, this was probably working more by coincidence than by good organization of the functions in RAM. Now I have disabled interrupts and I can leave those routines in flash and run only my small amount of flash routines from RAM.