I am having a problem trying to use internal flash (bank1)as EEPROM of STR71x family microprocessor. Using a HITEX eval board (purchased from Keil) and I copied code directly from the sample files came with the compiler --- the result was, system hung immediately when I ran it. Could the ARM expert(s) this forum kindly take a look at the code below and then please tell me what I did wrong here? Thanks in advance, JIMMY
int main(void) { u32 Read_Data; /* Initialize the FLASH */ FLASH_Init () ; /* Disable temporarily the FLASH protection on Bank 1 sector 0 */ FLASH_WritePrConfig (FLASH_B1F0,DISABLE) ; //<<< SYSTEM HANG !! begins here /* Erase Bank 1 sector 0 */ FLASH_SectorErase (FLASH_B1F0) ; /* Write 0x12345678 to Bank 1 sector 0 */ FLASH_WordWrite (0x000C0000,0x12345678) ; /* Read back the written data at address 0x400C0000*/ Read_Data = FLASH_WordRead(0x000C0000); /* Display the read data on the debugger output window. You can use also the debugger memory window to verify the good content of the flash at 0x400C0000 address and see the value "0x12345678"*/ printf(" The data written at address 0x400C0000 is %x\n",Read_Data); printf("\n"); /* Warning!! : The write protection can be enabled ONLY on a permanent way */ /* Enable the FLASH protection on Bank 1 sector 0 */ /* FLASH_WritePrConfig (FLASH_B1F0,ENABLE) ; */ while(1); }
The problem comes from the line of code in the STR7x library that looks like this FLASHR->CR0 |= FLASH_WMS_MASK Until this operation completes, you cannot read from flash. You are most likely running you code from flash. To fix (more than 1 way) - You can make sure that any instruction that sets FLASH_WMS_Mask in FLASHR->CR0 runs out of RAM. You are supposed to be able Modify Bank1 while running from Bank0, but I have heard from somewhere, that the first access to FLASHR->CR0 = FLASH_WMS_Mask will cause of of FLASH to become unreadble until it completes. I have found if best to just that small amount of code that sets CR0 and test for completion from RAM. Nothing else needs to run from ram (make sure interrupts are disabled when you hit this register, because they will try to read from flash)
Robert is right on the spot here. See also this thread: http://mcu.st.com/mcu/modules.php?mop=modload&name=Splatt_Forums&file=viewtopic&topic=2611&forum=17
View all questions in Keil forum