ATSAME70, User Signature Area

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im having trouble reading and writing to the User Signature Area on the ATSAME70. I generated a basic project in MPLABX v5.5 using Harmony 3.

It seems to get stuck waiting for the EEFC_FSR.FRDY bit to go low after programming the STUS command to the EFFC. Any ideas ?

 

Here is my code


#include <stddef.h>                     // Defines NULL
#include <stdbool.h>                    // Defines true
#include <stdlib.h>                     // Defines EXIT_FAILURE
#include "definitions.h"
#include "User_Signature_Memory.h"


#define FLASH_BASE_ADDRESS  IFLASH_ADDR
// in bytes
#define FLASH_PAGE_SIZE     512


// Temporary test code for User Sig area
void USA_Test()
{
    uint32_t Buffer[128];
    uint32_t BufferO[128];

    Buffer[0] = 1;
    Buffer[1] = 100;
    Buffer[2] = 56789;
   
    UIA_Read(BufferO);
    USA_Read(BufferO);
    USA_Write(Buffer);
    USA_Read(BufferO);
}


// Write the full page to the User Signature Area
void __attribute__ ((section(".ramfunc"), long_call, unique_section,noinline)) USA_Write(uint32_t* Buffer)
{
    uint32_t* Destination = (uint32_t*)FLASH_BASE_ADDRESS;
    uint32_t I =0;

    
    // You can write the data to any address
    for (I=0; I < FLASH_PAGE_SIZE/sizeof(uint32_t); I++)
    {
        Destination[I] = Buffer[I];
    }
    
    // close the User Signature Area and store it
    __disable_irq();
    EFC_REGS->EEFC_FCR = EEFC_FCR_FCMD_WUS | EEFC_FCR_FKEY_PASSWD;
    
    // Wait until the EEFC_FSR.FRDY bit falls to complete operation
    while ((EFC_REGS->EEFC_FSR & EEFC_FSR_FRDY_Msk) != 0){};
    __enable_irq();
}




// Read the entire the User Signature Area
void __attribute__ ((section(".ramfunc"), long_call, unique_section,noinline)) USA_Read(uint32_t* Buffer)
{
    __disable_irq();
    uint32_t* USAAddr = (uint32_t*)FLASH_BASE_ADDRESS;
    uint32_t I =0;
    
    
    // First open the USA for reading
    EFC_REGS->EEFC_FMR |= EEFC_FMR_SCOD_Msk;
    EFC_REGS->EEFC_FCR = EEFC_FCR_FCMD_STUS | EEFC_FCR_FKEY_PASSWD;
    
    // Wait until the EEFC_FSR.FRDY bit falls to read the user signature area
    while ((EFC_REGS->EEFC_FSR & EEFC_FSR_FRDY_Msk) != 0){};
    
    // The USA is unlocked, so read out
    for (I=0; I < (uint32_t)(FLASH_PAGE_SIZE/sizeof(uint32_t)); I++)
    {
        Buffer[I] = USAAddr[I];
    }
    
    // close the User Signature Area for reading
    EFC_REGS->EEFC_FCR = EEFC_FCR_FCMD_SPUS | EEFC_FCR_FKEY_PASSWD;
    // Wait until the EEFC_FSR.FRDY bit falls to read the user signature area
    while ((EFC_REGS->EEFC_FSR & EEFC_FSR_FRDY_Msk) == 0){};
    EFC_REGS->EEFC_FMR &= ~EEFC_FMR_SCOD_Msk;
    __enable_irq();
}

 

Gary