简体   繁体   中英

STM32F4 read memory flash per pages

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);

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM