0
votes

How can I read flash memory per page? I have not been able to read it by sector.

I have to read 2 memory sectors (2*16kbytes).

I am under FreeRtos and I am using STM32F401RE.

I am using pointer, I just need to read two sectors of memory flash.

uint32_t data_store0[4096] = {0};
uint32_t data_store1[4096] = {0};

uint32_t *words0 = (uint32_t *) BASE_ADDR_SECTOR_0;
uint32_t *words1 = (uint32_t *) BASE_ADDR_SECTOR_1;

unsigned int buffer_firmware[8192] = {0};
unsigned char firmware[32768] = {0};

int k, m, i, j = 0;
int count_time = 0;

for(int i=0; i<4096; i++)
{
    data_store0[i] += words0[i];
    buffer_firmware[i] = data_store0[i];
}

for(int j=0; j<4096; j++)
{
    data_store1[j] += words1[j];
}

for(m = 0, k = 4096; k < 8192 && m < 4096; m++, k++)
{
    buffer_firmware[k] = data_store1[m];
}

SHA256Input(&ctx, (const uint8_t *) buffer_firmware, 8192);
1
What exactly are you trying to do? To read the flash all you need to do is dereference a pointer.Colin
Thanks for your reply #Colin, i am using pointer, i just need to read tow sectors of memory flash. but i can't execute the code in freeRTOS !simo
what is tow sector?0___________

1 Answers

0
votes

First of all, you must use volatile keyword while accessing memory map, furthermore, while reading the two page if you accept it is 4096 bytes, then have to use uint8_t because it has 4096 bytes. However, you want to access it a uint32_t pointer then the max value of for loop must be 4096/4 since it has 4096/4 words.

uint8_t buffer_firmware[4096]
uint8_t *words0 = (volatile uint8_t *) BASE_ADDR_SECTOR_0;
uint8_t *words1 = (volatile uint8_t *) BASE_ADDR_SECTOR_1;

for(uint16_t i=0; i<4096; i++){
    buffer_firmware[i] = words0[i];
}