|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 617 Location: Des Moines, Iowa, USA
|
24EP256GP202 and and erase_program_memory() |
Posted: Mon Jan 20, 2025 11:57 am |
|
|
Datasheet: https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/DataSheets/dsPIC33EPXXXGP50X-dsPIC33EPXXXMC20X-50X-and-PIC24EPXXXGP-MC20X-Family-Data-Sheet-DS70000657J.pdf
From the CCS documentation on "erase_program_memory()":
Quote: | Erases FLASH_ERASE_SIZE bytes to 0xFFFF in program memory. |
For "write_program_memory()":
Quote: | Writes count bytes to program memory from dataptr to address. This function is most effective when count is a multiple of FLASH_WRITE_SIZE, but count needs to be a multiple of MIN_FLASH_WRITE. Whenever this function is about to write to a location that is a multiple of FLASH_ERASE_SIZE then an erase is performed on the whole block. Due to the 24 bit instruction length on PCD parts, every fourth byte of data is ignored. Fill the ignored bytes with 0x00. |
The code I maintain, which looks to have originated about ten years ago (using, at one point, five different PIC24s, and today just three) follows this. During firmware upgrading, a write to the start of an ERASE_SIZE boundary should erase that block and then the write proceeds. All writes are done on these boundaries. We do not use "erase_program_memory()" in our existing codebase.
For my current project, I wanted to start out by erasing all the sectors from 0x0 up to where the running program starts. I mask interrupts, and do this loop:
Code: | disable_interrupts (GLOBAL);
for (uint32_t address=0; address<APP_START; address=address+getenv("FLASH_ERASE_SIZE"))
{
DEBUG_PRINTF ("Erasing 0x%lx.\r\n", address);
erase_program_memory (address);
}
|
I am having intermittent issues with boards using the 24EP256GP202. One seems to work all the time, another never works. Clearly some hardware difference (they were manufactured years apart). But during my investigation, I pulled the flash from each board (good and bad) and compared.
I see from debug output that the "bad" board ran all the erase steps, but the flash memory was clearly not erased like I expected.
While I think it may just be environmental or some issue with this old board revision, I wanted to post that "erase loop" code and get some feedback from anyone who has done this.
Should that loop work? ERASE_SIZE is reported as 4096 on this PIC24.
(My root problem is after my "installer" program works, it should have copied const ROM data into 0x0 memory, building a new vector table and bootloader app. This has been working fine, then I moved it to an older board variant, and it is acting differently -- maybe some errata with this PIC24, possibly an older revision). It could be as simple as that, but I wanted to confirm my code (which "appears to be working fine") is actually proper.
Thanks for any feedback. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1638 Location: Perth, Australia
|
|
Posted: Mon Jan 20, 2025 10:05 pm |
|
|
Your code is erasing the reset vector. Did you mean to do that? _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|