cancel
Showing results for 
Search instead for 
Did you mean: 

How can i read from flash in spc560b ?

Ali sadeghi
Associate III

Hi Friend

I want Read from speciefic address in flash and save it In ram and then write to another Address in flash. My problem is how can i read from flash.

I am waiting for your help

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

in order to read the Flash memory, it is enough to use a pointer to the address you want to read. The following code shows how to read the content of the flash memory at the address 0xFC0000.

/* Inclusion of the main header files of all the imported components in the
   order specified in the application wizard. The file is generated
   automatically.*/
#include "components.h"
 
/*
 * Application entry point.
 */
int main(void) {
 
  uint32_t flash_address_pointer = 0xFC0000;
  vuint32_t flash_value;
 
  flash_value = *((vuint32_t*)(flash_address_pointer));
 
  /* Initialization of all the imported components in the order specified in
     the application wizard. The function is generated automatically.*/
  componentsInit();
 
  /* Enable Interrupts */
  irqIsrEnable();
 
 
  /* Application main loop.*/
  for ( ; ; ) {
    printf("Address = 0x%08X - Value = 0x%08X\n\r", (unsigned int)flash_address_pointer, (unsigned int)flash_value);
    pal_lld_togglepad(PORT_E, LED_4);
    pal_lld_togglepad(PORT_A, LED_3);
    pal_lld_togglepad(PORT_D, LED_5);
    osalThreadDelayMilliseconds(250);
  }
}

Regards,

Luigi

View solution in original post

8 REPLIES 8
Ali sadeghi
Associate III

my code is

uint32_t *p=0x000000AC;

 int myvar[8] ;

 for(uint8_t jj=0;jj<8;jj++)

{

myvar[jj] = *p ;

}

the output is constant. whats my problems code?

zambrano.luigi
Senior III

Hi,

if you use SPC5Studio, it includes a lot of example. One of this (SPC560Bxx_RLA Flash Test Application for Discovery) shows you how to use the integrated Flash Driver that allows you to read/write/erase the Flash Memory.

Regards,

Luigi

Ali sadeghi
Associate III

Hi my deer friend

you are right spc studio has a lot of example like you mentioned it but unfortunately read function isnt one of them.

I send you a list of function that work in flash operation0693W000008xBi9QAE.pngas you can see in UM1627 user manual and this pic there isnt read function.

I try pointer solution to get read flash but it doesnt work.

I am waiting for your answer

thanks a lot man

>>the output is constant. whats my problems code?

You don't advance the pointer

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi,

in order to read the Flash memory, it is enough to use a pointer to the address you want to read. The following code shows how to read the content of the flash memory at the address 0xFC0000.

/* Inclusion of the main header files of all the imported components in the
   order specified in the application wizard. The file is generated
   automatically.*/
#include "components.h"
 
/*
 * Application entry point.
 */
int main(void) {
 
  uint32_t flash_address_pointer = 0xFC0000;
  vuint32_t flash_value;
 
  flash_value = *((vuint32_t*)(flash_address_pointer));
 
  /* Initialization of all the imported components in the order specified in
     the application wizard. The function is generated automatically.*/
  componentsInit();
 
  /* Enable Interrupts */
  irqIsrEnable();
 
 
  /* Application main loop.*/
  for ( ; ; ) {
    printf("Address = 0x%08X - Value = 0x%08X\n\r", (unsigned int)flash_address_pointer, (unsigned int)flash_value);
    pal_lld_togglepad(PORT_E, LED_4);
    pal_lld_togglepad(PORT_A, LED_3);
    pal_lld_togglepad(PORT_D, LED_5);
    osalThreadDelayMilliseconds(250);
  }
}

Regards,

Luigi

Ali sadeghi
Associate III

Hi Luigi

I apologize for my delay

thanks for your answer

I report my result after use that code.

the output data isnt correct according to the address.

Hi luigi

Your code work.

Thanks for your time