Page 1 of 1

PSOC4 Reading of flash

PostPosted: Wed Feb 19, 2014 4:10 am
by dmi
Hi,

I've tried to read the flash memory of PSOC4 Cortex-M0, but I haven't successful (I've always read the RAM - using const char* pointer). There's lots of code about writing to that via bootloader, but I haven't found the reading method. Is there any simple way to realize that?

Thanks you

Re: PSOC4 Reading of flash

PostPosted: Wed Feb 19, 2014 7:35 am
by bobmarlowe
You have to define some variables in flash and assign a value to them. The "const" attribute will do.
Accessing the variable is done easily as long as it is used as a "right-side term" meaning nothing is assigned to that var again.
Alternatively you may define a pointer to which you assign the required read-address.

Bob

Re: PSOC4 Reading of flash

PostPosted: Wed Feb 19, 2014 12:00 pm
by dmi
It's OK, but I need read full flash, started at 0x00000000.

I've tried this code:

Code: Select all
int main(void)
{
    uint32_t array[5];
    uint8_t i;
    const uint32_t *ptr;
   
    ptr = 0x00;
   
    for(i = 0; i < 5; i++)
    {
        array[i] = *ptr;
        ptr++;
    }
   
    return 0;
}


The result is filling array variable by SRAM bytes instead of FLASH bytes.

Re: PSOC4 Reading of flash

PostPosted: Wed Feb 19, 2014 12:46 pm
by bobmarlowe
Double check that, I am reading from flash address 0. Compare that in debugger it is starting with 20002000 and is the initial stackpointer value.
You may leave the "const" here, since you provide the pointer's value yourself.

Bob

Re: PSOC4 Reading of flash

PostPosted: Wed Feb 19, 2014 10:44 pm
by dmi
I have PSoc Creator 3.0 Componenet Pack 7 and CY8C8485LQI 483. Can you send me your project ? I would like to compare the project settings and another stuff. Watch window show right value in *ptr, but after the coping to array variable, data is wrong.

Thanks

Re: PSOC4 Reading of flash

PostPosted: Thu Feb 20, 2014 2:42 am
by bobmarlowe
This is simply your project running on a PSoC4 (I also tried a PSoC5).

ReadFlash.jpg


Project in next post

Bob

Re: PSOC4 Reading of flash

PostPosted: Thu Feb 20, 2014 2:43 am
by bobmarlowe
Project archieve attached.


Bob

Re: PSOC4 Reading of flash

PostPosted: Thu Feb 20, 2014 3:45 am
by dmi
Now, when I open output HEX in notepad, result is:

:40 0000 00 0010002011000000A1020000A1020...

We have same result - this data are from SRAM memory 0x20000000. First bytes are same, there is different in 5. byte...

Re: PSOC4 Reading of flash

PostPosted: Thu Feb 20, 2014 5:55 am
by bobmarlowe
You are probably looking at the array which resides in sram. Take it for granted: a pointer addresses exactly what you let it point to. ARM Cortex do not make any differences between memory areas like the 8051 core in PSoC3. Have a look at the PSoC5 memory map in this document


Bob