Hello, I have some problem when I try to write to Flash memory. I read AN201 "WRITING TO FLASH FROM FIRMWARE" and I use write functions for F350 (page 100). There is no problem with a light program. But now I try to integrate these functions on a large program. When I look at memory, any data has been written. In AN20 (page 3), I found this : "Be cautious when using the 'Large' and 'Compact' memory models, which target xdata and pdata spaces for user variables, both of which generate MOVX write opcodes." Indeed, my first program use small memory model (no pb) and my last program use large one. Is there a solution to write to flash memory with a large program ?
"Is there a solution to write to flash memory with a large program ?" I'm not familiar with your particular derivative, but I'm assuming that the procedure to write to the flash is something like: 1) Map the flash into xdata space 2) Write to flash 3) Map the flash back out of xdata space If an interrupt occurs during this sequence and the associated ISR accesses the xdata memory space you are in trouble. One solution is to disable interrupts before step (1) and reenable them after step (3).
yes, interrupts MUSt, of course be disabled, the trouble the OP is seing is the compiler wiring/reading XDATA (with large memory model) after the SFR (whatever the name, whatever the bit) is cahnged to redirect XDATA operations/writes to flash. an illustration from my codes where I use the high part of a f126 flash as permanent data storage
U8 ReadFlashChar (U8 code * RFSaddr) { U8 RFCintsav; U8 RFCdata; RFCintsav = SG_IE; SG_IE = 0; SG_SFRPAGE = 0; if (RFSaddr > 0x7fff) { SG_PSBANK = 0x30; } else { SG_PSBANK = 0x20; RFSaddr += 0x8000 ; } RFCdata = *RFSaddr; SG_PSBANK = 0x10 ; SG_IE = RFCintsav; return (RFCdata) ; } If RFCdata were mapped to XDATA, it would be written to flash. Erik
Thank you for your help, Finally, I just forgot a word (very important). In my write function, i declared the write pointer like this :
char xdata * pwrite;
char xdata * data pwrite;