0
votes

For the context, I'm writting a bootloader for my STM32H743XI cause I want to erase and upload code through USB without using pin.

So my bootloader start at 0x08000000, it's size is 21kB (17% of the first sector of 128kB), and I want to read/write data at the end of the sector which will be shared with my App. When I say end of the sector it's the last 10kB of the sector which means I start to R/W at 0x0801D800.

The structure that I want to R/W is 8x32bits cause if I understand well this is the size of a WORD on STM32H74x/5X devices.

This is my struct:

typedef struct
{
    int32_t     BootLoaderMode;
    int32_t     StartingPartition;
    int32_t     AppStartingError;
    int32_t     temp4;
    int32_t     temp5;
    int32_t     temp6;
    int32_t     temp7;
    int32_t     temp8;

} ExchangeWord_1;

I've got a pointer to an allocated struct:

ExchangeWord_1* m_ExchangeWord_1 = (ExchangeWord_1*)malloc(sizeof(ExchangeWord_1));

Before writing i unlock memory with:

HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();

The write operation looks like (id=0 and the second parameter is my allocated struct):

void writeExchangeWord(uint16_t id, ExchangeWord_1* exchangeWord )
{
   //unlock function

    uint32_t flash_address = (0x0801D800+id*32);
    uint32_t data_address = (uint32_t)exchangeWord;
    HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, flash_address, data_address);

    //lock function
}

Then I lock the memory :

HAL_FLASH_Lock();
HAL_FLASH_OB_Lock();

So the first call of this works well and the debugger confirms it when I look at the memory:

[Flash memory on first call][1]: https://i.stack.imgur.com/cH9fI.png

But on on the next call the memory is filled with 0, more weird at the third call it's mulpiple words starting at 0x0801D800 who are filled with 0.

The adress of my struct is well aligned (m_ExchangeWord_1 = 0x20001D60).

What I am missing? Do I need to clear some flags before/after writting?

Thank you (=;

1
caveat: I haven't got the manual for the indicated chip: However, usually there is a 'busy' indicator in the list of registers and lock/unlock operations are not instanious so need to assure the built in peripheral is not busy before changing it's lock/unlock state (and similar when unlocking to write the data and there is a specific sequence of operations needed to write datauser3629249

1 Answers

0
votes

Ok it's seems that it is impossible to write two time in a row at the same adress, i've read somewhere that we are only allow to switch a bit from 1 to 0 if we want to write multiple time without erasing. I moved my "shared area" in a specific sector that I have to erase each time I want to write on it.

My problem is solved.