Skip to main content
Ali sadeghi
Associate III
Mar 16, 2021 12:44 PM UTC
Solved

How can i read from flash in spc560b ?

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 topic has been closed for replies.
    zambrano.luigi
    zambrano.luigiBest answer
    ST Employee
    Mar 18, 2021 7:07 AM UTC

    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

    8 replies

    Ali sadeghi
    Associate III
    Mar 17, 2021 11:27 AM UTC

    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
    ST Employee
    Mar 17, 2021 3:21 PM UTC

    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
    Mar 17, 2021 4:31 PM UTC

    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

    Tesla DeLorean
    Guru
    Mar 17, 2021 8:58 PM UTC

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

    You don't advance the pointer

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Ali sadeghi
    Associate III
    Mar 20, 2021 9:47 PM UTC

    the output data isnt correct according to the address.

    Ali sadeghi
    Associate III
    Mar 20, 2021 9:44 PM UTC

    Hi Luigi

    I apologize for my delay

    thanks for your answer

    I report my result after use that code.