Skip to main content
Daniel Hatcher
Associate II
January 15, 2018
Question

STM32F746 Page Size

  • January 15, 2018
  • 2 replies
  • 810 views
Posted on January 15, 2018 at 17:31

Hi, 

I am in the process and nearly completely writing a bootloader. The bootloader will load small sized programs, however if I load a large file then it goes wrong. I ave tracked this does to the writing by reading the device memory after erasing/flashing and comparing with the original file. 

I am using the function below to write to the flash. 

#define BUFFERSIZE ((uint16_t)1*8192)

uint8_t RAMBuf[BUFFERSIZE] = { 0x00 };

static uint32_t LastPGAddress = APPLICATION_ADDRESS;

__IO uint32_t read_size = 0x00, tmp_read_size = 0x00;

uint32_t read_flag = TRUE;

/* Erase address init */

LastPGAddress = APPLICATION_ADDRESS;

/* While file still contain data */

while (read_flag == TRUE) {

/* Read maximum 'BUFFERSIZE' Kbyte from the selected file */

if (f_read(&MyFile, RAMBuf, BUFFERSIZE, (uint_t*) &read_size)

!= FR_OK) {

return DOWNLOAD_FILE_FAIL;

}

/* Temp variable */

tmp_read_size = read_size;

/* The read data < 'BUFFERSIZE' Kbyte */

if (tmp_read_size < BUFFERSIZE) {

read_flag = FALSE;

}

/* Program flash memory */

if (FLASH_If_Write(LastPGAddress, (uint32_t*) RAMBuf, read_size)

!= FLASHIF_OK) {

return DOWNLOAD_WRITE_FAIL;

}

/* Update last programmed address value */

LastPGAddress = LastPGAddress + tmp_read_size;

}

I am 99% sure it has something to do with the 

BUFFERSIZE because when comparing the flashed program and the orignal file, it does wrong after 1FFF which is 8192. The while loop should take of writing the next 8192 bytes until the file has all been flashed. 

So is there a page size (like on other processors I have used) that I need to set correctly. 

Thanks

    This topic has been closed for replies.

    2 replies

    Daniel Hatcher
    Associate II
    January 17, 2018
    Posted on January 17, 2018 at 12:05

    Issue solved!!!

    Technical Moderator
    January 17, 2018
    Posted on January 17, 2018 at 12:29

    Hi

    daniel.014

    ,

    We are interested to know how you resolved this issue. It may be helpful for other users.

    Best Regards,

    Imen

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    Daniel Hatcher
    Associate II
    January 17, 2018
    Posted on January 17, 2018 at 12:44

    I read back the device and then checked which areas of the processor are programmed and which areas are not. I then calculated how large my program was. Then found that I needed to change 

    #define BUFFERSIZE ((uint16_t)1*8192) 

    to

    #define BUFFERSIZE ((uint32_t)16*8192)

    I then added on extra to allow for updates to expand. I checked this numberous times with different programs and it works. 

    Also, I had cpu cache enable in both the bootloader and the application. This causes it to crash, so I only had it in the bootloader application.