2005-11-22 03:21 AM
writing WMS into FLASH_CR0 causes undefined instruction exception.
2005-09-08 01:51 AM
Hi everyone,
As mentioned in the subject I'm having difficulty with writing to flash. In a nutshell the code will cause the exception with this simple bit of code: #define FLASHR_CR0 0x40100000 #define FLASHR_CR1 0x40100004 #define FLASHR_DR0 0x40100008 #define FLASHR_DR1 0x4010000C #define FLASHR_AR 0x40100010 #define FLASHR_ER 0x40100014 *((volatile u32 *)FLASHR_CR0) = 0x00000000; *((volatile u32 *)FLASHR_CR1) = 0x00000000; *((volatile u32 *)FLASHR_DR0) = 0xFFFFFFFF; *((volatile u32 *)FLASHR_DR1) = 0xFFFFFFFF; *((volatile u32 *)FLASHR_ER) = 0x00000000; while( *((volatile u32 *)FLASHR_CR0) & 0x16); *((volatile u32 *)FLASHR_CR0) |= 0x08000000; *((volatile u32 *)FLASHR_CR1) |= 0x00010000; *((volatile u32 *)FLASHR_CR0) |= 0x80000000; while( *((volatile u32 *)FLASHR_CR0) & 0x16); The undefined instruction exception is triggered on the last write to FLASH_CR0. If i single step the code no exception happens and everything works fine (it actually erases the flash). I've even got some code further down (which I've not included for simplicity) which writes data to flash and that also works fine as long as I single step. I have ensured, both by initialising the relevant registers and by checking their state when the exception happens, that the flash is in no way write protected (FLASH_NVWPAR and FLASH_NVAPR1 are 0xFFFFFFFF and FLASH_NVAPR0 is 0x3569ACFF). Does anyone have any idea what could possibly be causing this? I'm stumped. m@2005-09-08 02:42 AM
Hello,
Everything seems ok! From where you execute your code? Best regards, Bouha2005-09-08 02:49 AM
Hi,
I'm executing this from Bank 0 (sector 1) of flash which should be ok since I'm clearing bank 1 sector 0. m@2005-09-08 02:59 AM
Hi,
You can find an example which runs from Flash bank 0 and writes some data to Flash bank1 in this URL: http://mcu.st.com/mcu/modules.php?mop=modload&name=Splatt_Forums&file=viewtopic&topic=3043&forum=17 This example is tested and work fine. Best regards, Bouha2005-09-08 03:15 AM
:) That is where the second block of my example comes from. There must be something up with the timing since it works ok when single stepping...
2005-09-08 10:10 PM
I have just ruled out hardware failure by trying the same on a different (but identical) board (unless of course I have two faulty ones which seems rather unlikely). An additional bit of information is that when I start the board up from a debugger (Trace32) it doesn't cause the interrupt on startup even if i don't single step. If I try to flash again once running (eg. somewhere further down the flow) though it will cause the exception again. I also noticed that on one occasion it had flashed only every 6th or 7th word from the source.
Does anyone else have any clues? Guys from ST? Hardware gurus? Mom? m@2005-09-09 03:11 AM
Hello,
Could you please send to me your example to test it in my board? Best regards, Bouha2005-09-09 03:34 AM
Hi,
Would an elf suffice? I have the sources but my code is part of the flash drivers for Redboot which would require that you took all that to compile it from source. The elf includes all the symbols so It should be possible to see what's going on and certainly would show whether it causes an undefined instruction exception (jump to 0x4) or not. On my side I'm going to compile the example you pointed me to earlier to see if that works on my board. Thanks, m@2005-09-09 03:37 AM
And the file...