• AVR Freaks

Hot!Harmony v3 NVM

Author
Ryan_NM
Starting Member
  • Total Posts : 29
  • Reward points : 0
  • Joined: 2015/04/18 13:50:34
  • Location: 0
  • Status: offline
2020/03/31 11:19:16 (permalink)
5 (1)

Harmony v3 NVM

I'm having a tough time writing to NVM on a PIC32MZ2064DAS169 with Harmony v3.  I'm trying to follow the sync/nvm_sst26_read_write example but keep getting errors when erasing using DRV_MEMORY_SyncEraseWrite or DRV_MEMORY_SyncErase functions.  Current HW is PIC32MZ DA Starter Kit and MEBII, no RTOS.
 
NVM Harmony Config: 
NVM Media Start Address: 9d100000 (also tried 9d1FBFFF )
NVM Media Size (KB): 1024 (also tried 16)
NVM Erase Buffer Size: 16,384
Enable Interupt = true
 
Memory Harmony Config:
Driver Mode: Synchronous
 
Initialization completes with no errors:

SYS_MEDIA_GEOMETRY *nvmGeometry = NULL;
APP_NVM_DATA CACHE_ALIGN appNvmData;
#define NVM_BUFFER_SIZE (16384U)
#define NVM_GEOMETRY_TABLE_READ_ENTRY (0)
#define NVM_GEOMETRY_TABLE_WRITE_ENTRY (1)
#define NVM_GEOMETRY_TABLE_ERASE_ENTRY (2)
#define BLOCK_START 0x0
 
void InitializeNVM()
{
appNvmData.memoryHandle = DRV_MEMORY_Open(DRV_MEMORY_INDEX_0, DRV_IO_INTENT_READWRITE);

    if (DRV_HANDLE_INVALID != appNvmData.memoryHandle)
    {
        //All Good
        //memoryHandle set to 0x00010000
    }
    else
    {
         //would be a problem, but the code doesn't get here
        test++;
    }
    
    nvmGeometry = DRV_MEMORY_GeometryGet(appNvmData.memoryHandle);

    if (nvmGeometry == NULL)
    {
        //would be a problem, but the code doesn't get here
        test++;
    }

    appNvmData.numReadBlocks = (NVM_BUFFER_SIZE / nvmGeometry->geometryTable[NVM_GEOMETRY_TABLE_READ_ENTRY].blockSize);//set to 0x4000
    appNvmData.numWriteBlocks = (NVM_BUFFER_SIZE / nvmGeometry->geometryTable[NVM_GEOMETRY_TABLE_WRITE_ENTRY].blockSize);//set to 8
    appNvmData.numEraseBlocks = (NVM_BUFFER_SIZE / nvmGeometry->geometryTable[NVM_GEOMETRY_TABLE_ERASE_ENTRY].blockSize); //set to 1
}
     

 
And then when I try to erase or write, I get an error:
 

void WriteSettingsToFile()
{
 int i;
    int charPointer=0;
    DWORD_VAL tmp;
    
    for (i=0;i<MAX_NUMBER_SETTINGS;i++)
    {
        //store 32 bit settings to write buffer
        tmp.Val=Settings[SETTING_VALUE][i];
        appNvmData.writeBuffer[charPointer++]=tmp.v[0];
        appNvmData.writeBuffer[charPointer++]=tmp.v[1];
        appNvmData.writeBuffer[charPointer++]=tmp.v[2];
        appNvmData.writeBuffer[charPointer++]=tmp.v[3];
             
    }
    
    if(DRV_MEMORY_SyncEraseWrite(appNvmData.memoryHandle, &appNvmData.writeBuffer, BLOCK_START, appNvmData.numWriteBlocks) == false)
    {
        // ERROR IS THROWN HERE
        test++;
    }
}

 
When I change compiler optimization from 1 to zero, I get a software reset from the error handler.  with the optimization set to 1, it gets to my "// ERROR IS THROWN HERE" but doesn't reset.
 
the same thing happens when I try to use:
DRV_MEMORY_SyncErase(appNvmData.memoryHandle, BLOCK_START, appNvmData.numEraseBlocks);

and
DRV_MEMORY_SyncWrite(appNvmData.memoryHandle, (void *)&appNvmData.writeBuffer, BLOCK_START, appNvmData.numWriteBlocks);

 
the documentation says that the reasons it could return false are:
If the client opened the driver for read only
If the number of blocks to be erased is either zero or more than the number of blocks actually available
If the driver handle is invalid

 
The driver shows it is open for read/write intent (3).  I think that 0x00010000 is a valid handle?  does that just leave number of blocks erased = 0 or more than available?
 
I've tried stepping through with the ICD4 but can't seem to figure out what is causing it to hang up.  In the drv_memory.c, DRV_MEMORY_CLIENT_OBJECT() the dObj->status is = 1 (SYS_STATUS_BUSY).  Would that have anything to do with it?  It's already set to that when the DRV_MEMORY_GeometryGet() calls it it the initialization code.
 
Am I using the correct memory location (9d100000)?  Can I use the last page of flash instead so it is out of the way of my program?  I'm only needing to store 200 bytes.  I tried using 9d1FBFFF in the harmony config, but got the same result.
 
What am I missing? I sure appreciate the help.  
 
 
 
 
 
#1

4 Replies Related Threads

    Ryan_NM
    Starting Member
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2015/04/18 13:50:34
    • Location: 0
    • Status: offline
    Re: Harmony v3 NVM 2020/03/31 13:10:39 (permalink)
    0
    I found the much simpler example in Harmony3\csp\apps\nvm\flash_read_write .
     
    I copied that and it worked great.  Thank you very much.
     
     
    #2
    optimus_jack
    Junior Member
    • Total Posts : 83
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: Harmony v3 NVM 2020/03/31 20:24:14 (permalink)
    0
    Ryan_NM
    I'm having a tough time writing to NVM on a PIC32MZ2064DAS169 with Harmony v3.  I'm trying to follow the sync/nvm_sst26_read_write example but keep getting errors when erasing using DRV_MEMORY_SyncEraseWrite or DRV_MEMORY_SyncErase functions.  Current HW is PIC32MZ DA Starter Kit and MEBII, no RTOS.
     
    NVM Harmony Config: 
    NVM Media Start Address: 9d100000 (also tried 9d1FBFFF )
    NVM Media Size (KB): 1024 (also tried 16)
    NVM Erase Buffer Size: 16,384
    Enable Interupt = true
     
    Memory Harmony Config:
    Driver Mode: Synchronous
     
    Initialization completes with no errors:

     
    SYS_MEDIA_GEOMETRY *nvmGeometry = NULL;
    APP_NVM_DATA CACHE_ALIGN appNvmData;
     
    #define NVM_BUFFER_SIZE (16384U)
     
    #define NVM_GEOMETRY_TABLE_READ_ENTRY (0)
    #define NVM_GEOMETRY_TABLE_WRITE_ENTRY (1)
    #define NVM_GEOMETRY_TABLE_ERASE_ENTRY (2)
     
    #define BLOCK_START 0x0
     
     
     
    void InitializeNVM()
    {
     
    appNvmData.memoryHandle = DRV_MEMORY_Open(DRV_MEMORY_INDEX_0, DRV_IO_INTENT_READWRITE);

        if (DRV_HANDLE_INVALID != appNvmData.memoryHandle)
        {
            //All Good
     
            //memoryHandle set to 0x00010000
        }
        else
        {
             //would be a problem, but the code doesn't get here
            test++;
        }
        
        nvmGeometry = DRV_MEMORY_GeometryGet(appNvmData.memoryHandle);

        if (nvmGeometry == NULL)
        {
            //would be a problem, but the code doesn't get here
            test++;
        }

        appNvmData.numReadBlocks = (NVM_BUFFER_SIZE / nvmGeometry->geometryTable[NVM_GEOMETRY_TABLE_READ_ENTRY].blockSize);//set to 0x4000
        appNvmData.numWriteBlocks = (NVM_BUFFER_SIZE / nvmGeometry->geometryTable[NVM_GEOMETRY_TABLE_WRITE_ENTRY].blockSize);//set to 8
        appNvmData.numEraseBlocks = (NVM_BUFFER_SIZE / nvmGeometry->geometryTable[NVM_GEOMETRY_TABLE_ERASE_ENTRY].blockSize); //set to 1
     
    }
         

     
    And then when I try to erase or write, I get an error:
     

     
    void WriteSettingsToFile()
    {
     
     int i;
        int charPointer=0;
        DWORD_VAL tmp;
        
        for (i=0;i<MAX_NUMBER_SETTINGS;i++)
        {
            //store 32 bit settings to write buffer
            tmp.Val=Settings[SETTING_VALUE][i];
            appNvmData.writeBuffer[charPointer++]=tmp.v[0];
            appNvmData.writeBuffer[charPointer++]=tmp.v[1];
            appNvmData.writeBuffer[charPointer++]=tmp.v[2];
            appNvmData.writeBuffer[charPointer++]=tmp.v[3];
                 
        }
        
        if(DRV_MEMORY_SyncEraseWrite(appNvmData.memoryHandle, &appNvmData.writeBuffer, BLOCK_START, appNvmData.numWriteBlocks) == false)
        {
            // ERROR IS THROWN HERE
            test++;
        }
     
    }
     

     
    When I change compiler optimization from 1 to zero, I get a software reset from the error handler.  with the optimization set to 1, it gets to my "// ERROR IS THROWN HERE" but doesn't reset.
     
    the same thing happens when I try to use:
    DRV_MEMORY_SyncErase(appNvmData.memoryHandle, BLOCK_START, appNvmData.numEraseBlocks);

    and
    DRV_MEMORY_SyncWrite(appNvmData.memoryHandle, (void *)&appNvmData.writeBuffer, BLOCK_START, appNvmData.numWriteBlocks);

     
    the documentation says that the reasons it could return false are:
    If the client opened the driver for read only
    If the number of blocks to be erased is either zero or more than the number of blocks actually available
    If the driver handle is invalid

     
    The driver shows it is open for read/write intent (3).  I think that 0x00010000 is a valid handle?  does that just leave number of blocks erased = 0 or more than available?
     
    I've tried stepping through with the ICD4 but can't seem to figure out what is causing it to hang up.  In the drv_memory.c, DRV_MEMORY_CLIENT_OBJECT() the dObj->status is = 1 (SYS_STATUS_BUSY).  Would that have anything to do with it?  It's already set to that when the DRV_MEMORY_GeometryGet() calls it it the initialization code.
     
    Am I using the correct memory location (9d100000)?  Can I use the last page of flash instead so it is out of the way of my program?  I'm only needing to store 200 bytes.  I tried using 9d1FBFFF in the harmony config, but got the same result.
     
    What am I missing? I sure appreciate the help.  
     
    Hi,
    I found this documentation from GitHub which says that the Memory driver in Sync Mode should be used in RTOS environment only. As it is a blocking mode memory driver uses semaphores to block the thread untill transfer is complete. That might be the reason it is returning false.
     
    Use Async Mode instead if you need want baremetal environment. Also if you want simpller quick to use intrerface (Without Queue) use the PLIB directly.
     
    Documentation --> https://github.com/Microc...c/help_harmony_csp.chm
     
    Drivere Example --> https://github.com/Microchip-MPLAB-Harmony/core/tree/master/apps/driver/memory/async/nvm_sst26_read_write/firmware
     
    Plib Example --> https://github.com/Microchip-MPLAB-Harmony/csp/tree/master/apps/nvm/flash_read_write/firmware
     
    #3
    optimus_jack
    Junior Member
    • Total Posts : 83
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: Harmony v3 NVM 2020/03/31 20:25:43 (permalink)
    0
    Attaching the snapshot
    post edited by optimus_jack - 2020/03/31 20:27:13

    Attached Image(s)

    #4
    Ryan_NM
    Starting Member
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2015/04/18 13:50:34
    • Location: 0
    • Status: offline
    Re: Harmony v3 NVM 2020/04/01 05:07:33 (permalink)
    0
    Thank you optimus_jack
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5