• AVR Freaks

Hot!PIC32MZ Harmony Flash_modify Reading Problem:

Author
karan123
Super Member
  • Total Posts : 791
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
2019/05/08 09:56:49 (permalink)
0

PIC32MZ Harmony Flash_modify Reading Problem:

Hi,
 
I am using Microchip Harmony V2_06 . I am able to run flash_modify and work successfully check after printing SUCCESS
on USART .
C:\microchip\harmony\v2_06\apps\examples\peripheral\flash

void PutString(char *str)
{
while(*str)
{
DRV_USART_WriteByte(myUSARTHandle,*str++);
for(loop=0;loop<30000;loop++){}
}
}
void APP_Tasks ( void )
{
unsigned int x;
switch(appData.state)
{
case APP_STATE_INIT:
appData.flashHandle = DRV_FLASH_Open(DRV_FLASH_INDEX_0, intent);
appData.state = APP_STATE_NVM_FILL_DATABUF_AND_ERASE_STATE;
break;
case APP_STATE_NVM_FILL_DATABUF_AND_ERASE_STATE:
for (x = 0; x < APP_DATABUFF_SIZE; x++)
{
databuff[x] = x;
}
BSP_LEDOff(USERLED_SUCCESS);
BSP_LEDOff(USERLED_ERROR);
/* Erase the page which consist of the row to be written */
DRV_FLASH_ErasePage(appData.flashHandle, APP_PROGRAM_FLASH_BASE_ADDRESS);
appData.state = APP_STATE_NVM_ERASE_COMPLETION_CHECK;
break;
case APP_STATE_NVM_ERASE_COMPLETION_CHECK:
if(!DRV_FLASH_IsBusy(appData.flashHandle))
{
appData.state = APP_STATE_NVM_WRITE_START;
}
break;
case APP_STATE_NVM_WRITE_START:
/* Erase Success */
/* Write a row of data to PROGRAM_FLASH_BASE_ADDRESS, using databuff array as the source */
DRV_FLASH_WriteRow(appData.flashHandle, APP_PROGRAM_FLASH_BASE_ADDRESS, databuff);
appData.state = APP_STATE_NVM_WRITE_COMPLETION_CHECK_AND_VERIFY_CHECK;
break;
case APP_STATE_NVM_WRITE_COMPLETION_CHECK_AND_VERIFY_CHECK:
if(!DRV_FLASH_IsBusy(appData.flashHandle))
{
/* Verify that data written to flash memory is valid (databuff array read from kseg1) */

if (!memcmp(databuff, (void *)APP_PROGRAM_FLASH_BASE_ADDRESS_VALUE, sizeof(databuff)))
{

appData.state = APP_STATE_NVM_SUCCESS_STATE;
}
else
{
appData.state = APP_STATE_NVM_ERROR_STATE;
}
}
break;

case APP_STATE_NVM_ERROR_STATE:
/*stay here, nvm had a failure*/
BSP_LEDOn(USERLED_ERROR);
BSP_LEDOff(USERLED_SUCCESS);
break;
case APP_STATE_NVM_SUCCESS_STATE:
BSP_LEDOn(USERLED_SUCCESS);
BSP_LEDOff(USERLED_ERROR);
PutString("\r\n  SUCCESS") ;
break;
}
}

But How I can read the values from FlashAddress and display on USART ?
In previous plib without harmony i am able to Read as below:

#define NVM_PAGE_SIZE 4096
// Note that if you don't put an initializer list, these are initialized
// to all zeros.
// That's OK if you intend to erase them before writing.
// Tell the compiler where you want it:
#define ROMDATA1_ADDR 0x9d008000
const uint8_t __attribute__ ((space(prog), address(ROMDATA1_ADDR))) RomData1[NVM_PAGE_SIZE];
// Let the compiler/linker put this anywhere it wants to
const uint8_t __attribute__ ((space(prog), aligned(NVM_PAGE_SIZE))) RomData2[NVM_PAGE_SIZE];
 
printf("Erasing ..\n");
// Erase second page of Program Flash
NVMErasePage((void *)ROMDATA1_ADDR);
// Write 128 words starting at Row Address NVM_PROGRAM_PAGE
printf("Write Value \n");
NVMWriteRow((void *)ROMDATA1_ADDR, (void*)databuff);
printf("Display Written Value\n");
printf((void *)ROMDATA1_ADDR) ;
printf((void *)ROMDATA1_ADDR+4) ;
printf((void *)ROMDATA1_ADDR+8) ;
printf((void *)ROMDATA1_ADDR+12) ;

 
--Karan
#1

6 Replies Related Threads

    karan123
    Super Member
    • Total Posts : 791
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MZ Harmony Flash_modify Reading Problem: 2019/05/08 23:18:20 (permalink)
    0
    Now I am able to read the values from FlashAddress and display on USART  by Below 

     
    memcpy(databuff2, (void *)APP_PROGRAM_FLASH_BASE_ADDRESS_VALUE, sizeof(databuff2)) ;
    PutString("\r\n READ \r\n") ;
    for (x = 0x45; x < 0x50; x++)
    {
    PutHexWord( databuff2[x] );
    PutString(" ");
    }
     

    What How to Set Preserve Memory Range in MPLAB X IDE ?
     
    post edited by karan123 - 2019/05/08 23:19:26

    Attached Image(s)

    #2
    Paul PortSol
    Super Member
    • Total Posts : 439
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: PIC32MZ Harmony Flash_modify Reading Problem: 2019/05/09 06:11:58 (permalink)
    0
    a) You don't need to memcpy from flash to databuffer. PIC32 has flat memory space so you can directly read flash data using a pointer. I suggest defining a structure that maps everything into one block, and then accessing that with a simple pointer. Attached some examples.
    NVM_Flash_V00PR.zip
     
    b) You should ensure linker file appropriately reserves a full PAGE of flash on a flash boundary, otherwise an erase may overlap into code space and be a mess.
    Easiest is reserve a block at beginning or end of normal Program Flash, or a block of unused BootFLASH (Careful to look deep into PIC32MZ boot flash map because it has bits reserved within for DevCfg etc., etrasing that would be a real mess!
    I got into linker file with Bootloader. You can copy default linker from the default folder and place in project folder, then build will use it.
    Default Linker files:    C:\Program Files (x86)\Microchip\xc32\v2.15\pic32mx\lib\proc   (By PIC32 type)
    Project Linker file:      D:\microchip\harmony\v2_06\xxx\projectxxx\firmware\src\system_config\default
     
    PIC32MX reserved 0xXXXX at beginning for each Page (Check Datasheet for Erase Size)
    kseg0_program_mem (rx) : ORIGIN = (0x9D000000 + 0xXXXX), LENGTH = (0x80000 - 0xXXXX) /* All C Files will be located here */
     
    PIC32MZ reserved 0x4000 for Each Page at end (Check Datasheet for erase size)
    kseg0_program_mem (rx) : ORIGIN = 0x9D000000 + 0x480, LENGTH = 0x200000 - 0x480 - 0x4000/* All C files will be located here */
     
    Paul
    #3
    NKurzman
    A Guy on the Net
    • Total Posts : 17345
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC32MZ Harmony Flash_modify Reading Problem: 2019/05/09 09:34:37 (permalink)
    0
    To read programed flash on a PIC32 you need a ordinary pointer to the non cached address of the flash memory ( all memory has 3 addresses physical, cached, and non-cached)
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 17345
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC32MZ Harmony Flash_modify Reading Problem: 2019/05/09 09:34:37 (permalink)
    0
    To read programed flash on a PIC32 you need a ordinary pointer to the non cached address of the flash memory ( all memory has 3 addresses physical, cached, and non-cached)
    #5
    karan123
    Super Member
    • Total Posts : 791
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: PIC32MZ Harmony Flash_modify Reading Problem: 2019/05/09 09:48:55 (permalink)
    0
    NKurzman
    To read programed flash on a PIC32 you need a ordinary pointer to the non cached address of the flash memory ( all memory has 3 addresses physical, cached, and non-cached)
    Thanks ... How?
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 17345
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC32MZ Harmony Flash_modify Reading Problem: 2019/05/09 14:33:13 (permalink)
    0
    Create a C pointer to why you what to read.
    Use one of the compiler macros to change the what I assume is Physical address you used to write the flash to non-cacheable.
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5