[SOLVED] Problem with flash memory read ...

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
Darklakebridge78
Posts: 136
Joined: 12 May 2007 14:04
Location: Italy
Contact:

[SOLVED] Problem with flash memory read ...

#1 Post by Darklakebridge78 » 12 Apr 2022 16:32

Hello everyone!
I am using for the first time the Mikromedia 3 for PIC32MZ board, with the PIC32MZ2048EFH100 processor on board. I would need to store two measurement parameters (bytes) in the internal Flash of the MCU. To do this, I chose the last two unused memory locations, also in view of future code expansions. Using the libraries of the MikroC for PIC32 compiler, I was able to store the data (and the reading of the flash with the programmer confirms this), but I did not understand how I can extract them at startup to use them in the program. Has anyone had a similar need? Can you help me understand better? :|

Code: Select all

  Flash_Erase_Page(0x9D1FFFE0);
  Flash_Write_Word(0x9D1FFFE0,1);                                               
  Flash_Write_Word(0x9D1FFFF0,22);                                              
  Delay_ms(100);

Attachments
FLASH.jpg
FLASH.jpg (168.92 KiB) Viewed 1010 times
MikroC PRO for PIC, MikroC PRO for dsPIC, MikroC PRO for PIC32, MikroC PRO for ARM, Visual TFT, Visual GLCD,
http://www.teolab.it

Darklakebridge78
Posts: 136
Joined: 12 May 2007 14:04
Location: Italy
Contact:

Re: [SOLVED] Problem with flash memory read ...

#2 Post by Darklakebridge78 » 13 Apr 2022 08:30

Good morning everyone!
I solved my problem. I leave the code on this board so that it can be useful to those who need it. :D These routines will allow you to use the mcu's Flash program, like an EEPROM.

PS Pay attention to the stall in reading of the MCU; especially if you use interrupts ...

Variables declaration:

Code: Select all

unsigned long NVM1,NVM2;
char TXT1[64],TXT2[64];

Routine to write the last two locations of the Program Flash:

Code: Select all

void WriteNvmData() {
 Flash_Erase_Page(0x9D1FFFE0);
 Flash_Write_Word(0x9D1FFFE0,1);
 Flash_Write_Word(0x9D1FFFF0,22);
 Delay_ms(100);
}
Routine to read the last two locations of the Program Flash:

Code: Select all

void ReadNvmData() {
 NVM1 = *(int*)(0x9D1FFFE0);
 LongWordToStr(NVM1,TXT1);
 TFT_Set_Font(&Verdana12x13_Regular, CL_BLACK, FO_HORIZONTAL);
 TFT_Write_Text("DEC1: ",19,50);
 Ltrim(TXT1);
 TFT_Write_Text(TXT1,110,50);
 LongWordToHex(NVM1,TXT1);
 TFT_Write_Text("HEX1: ",19,60);
 TFT_Write_Text(TXT1,110,60);
 
 NVM2 = *(int*)(0x9D1FFFF0);
 LongWordToStr(NVM2,TXT2);
 TFT_Set_Font(&Verdana12x13_Regular, CL_BLACK, FO_HORIZONTAL);
 TFT_Write_Text("DEC2: ",19,75);
 Ltrim(TXT2);
 TFT_Write_Text(TXT2,110,75);
 LongWordToHex(NVM2,TXT2);
 TFT_Write_Text("HEX2: ",19,85);
 TFT_Write_Text(TXT2,110,85);
}
MikroC PRO for PIC, MikroC PRO for dsPIC, MikroC PRO for PIC32, MikroC PRO for ARM, Visual TFT, Visual GLCD,
http://www.teolab.it

Post Reply

Return to “mikroC PRO for PIC32 General”