Skip to main content
TARHAN SAMAH
Senior
May 23, 2018
Solved

writing half word 16 bits on flash stm32f429ZI

  • May 23, 2018
  • 13 replies
  • 3759 views
Posted on May 23, 2018 at 10:05

Hello evry body , i can write a byte on flash of stm32f429ZI WİTH success . for info i use nucleo 144 and sector 23 the last sector .

for example :

with these adresses 

uint32_t locip1_adress=0x081E0001;//LAST sector for STM32429ZI sector 23

uint32_t locip2_adress=0x081E0002;//LAST sector for STM32429ZI sector 23

uint32_t locip3_adress=0x081E0003;//LAST sector for STM32429ZI sector 23

uint32_t locip4_adress=0x081E0004;//LAST sector for STM32429ZI sector 23

uint32_t remip1_adress=0x081E0005;//LAST sector for STM32429ZI sector 23

uint32_t remip2_adress=0x081E0006;//LAST sector for STM32429ZI sector 23

uint32_t remip3_adress=0x081E0007;//LAST sector for STM32429ZI sector 23

uint32_t remip4_adress=0x081E0008;//LAST sector for STM32429ZI sector 23

uint32_t ROV_min_adress=0x081E0009;//LAST sector for STM32429ZI sector 23 this data needs two bytes

uint32_t ROV_max_adress=0x081E00B;//LAST sector for STM32429ZI sector 23 this data needs two bytes

/* Unlock the Flash to enable the flash control register access *************/

HAL_FLASH_Unlock();

/* Fill EraseInit structure*/

EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;

EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

EraseInitStruct.Sector = FLASH_SECTOR_23;

EraseInitStruct.NbSectors = 1;

//you need to erase entire sector before write anything

HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);//we need to erase the sector before write

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, locip1_adress,locip1);//write one byte

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, locip2_adress,locip2);//write one byte

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, locip3_adress,locip3);//write one byte

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, locip4_adress,locip4);//write one byte

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, remip1_adress,remip1);//write one byte// we need to write also all other parameter because we delete all sector 23

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, remip2_adress,remip2);//write one byte

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, remip3_adress,remip3);//write one byte

HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, remip4_adress,remip4);//write one byte

HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,ROV_min_adress,Rover_ID_min[0]);//write one 16 bit

HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,ROV_max_adress,Rover_ID_max[0]);//write one 16 bit

HAL_FLASH_Lock();

But in THE HALFWORD writing i have prblm with 16 bit writing looks these adresses are not accepted 

uint32_t ROV_min_adress=0x081E0009;  ----> in my idea for one word ill use 0x081E0009+ 0x081E000A Two bytes --->is it right

uint32_t ROV_max_adress=0x081E00B;-----> WİLL use 0x081E000B+0x081E000C  two bytes 

but the data at the reading of  ROV_max_adress are wrong strangely ??

how should i select the adresses separation between them for writing half word can someone give me an example . thanks 

could not find detail about mem data adresses in detail .

    This topic has been closed for replies.
    Best answer by Tilen MAJERLE
    Posted on May 24, 2018 at 14:39

    Hello

    doumandjisamah

    ‌,

    To know when you have 16-bit aligned address, you can check LSB bit which must be 0, thus:

    • Every address is byte aligned, no matter on LSB bit value
    • Every second address is 16-bit (half-word) aligned

      • 0 = 0b000

        0

        , 2 = 0b001

        0

        , 4 = 010

        0

        , 6 = 0b011

        0

    • Every 4th address is 32-bit (word) aligned, LSB and LSB-1 bits must be 0.

      • 0 = 0b00

        00

        ;4 = 0b01

        00

        ;8 = 0b10

        00

    In your case, address

    0x081E0009

    is odd,

    LSB =1 => not 16-bit aligned, while

    0x081E000A

    or

    0x081E000C

    is even number,

    LSB = 0 => 16-bit aligned.

    If we go back to flash write process:

    • To be able to write in BYTE mode, you may use any valid flash address (LSB don't care)
    • To be able to write in HALF-WORD mode, your address must be 16-bits aligned (LSB must be 0)
    • To be able to write in WORD mode, your address must be 32-bits aligned (LSB and LSB - 1 must be 0)
    • To be able to write in QWORD mode, your address must be 64-bits aligned (LSB, LSB - 1 and LSB - 2 must be 0).

    Hope it is clear now.

    Best regards,

    Tilen

    13 replies

    Tilen MAJERLE
    ST Employee
    May 23, 2018
    Posted on May 23, 2018 at 10:22

    Dear

    ‌,

    please check FLASH_SR register for possible errors when programming.

    Address must be 16-bits aligned, which is not your case.

    uint32_t ROV_min_adress=0x081E0009;�?

    should be

    uint32_t ROV_min_adress=0x081E0008; //Either 8 and then it will use 8 + 9 bytesuint32_t ROV_min_adress=0x081E000A; //Or A and then it will use A + B bytes�?�?

    Best regards,

    Tilen

    TARHAN SAMAH
    Senior
    May 23, 2018
    Posted on May 23, 2018 at 13:23

    Hello Mister Tilen , thanks for answering but i think you didnt understand my question , 

     i have two datas to save for example:

    Rover_ID_min[0]=0x0012;

    Rover_ID_max[0]=

    0x0044;

    in these adresses 

    uint32_t ROV_min_adress=0x081E0009;

    uint32_t ROV_min_adress=0x081E000B;

    HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,ROV_min_adress,Rover_ID_min[0]);//write one 16 bit

     ,------> İLL use 9 and A

     

    HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,ROV_max_adress,Rover_ID_max[0]);//write one 16 bit

     ----->İLL USE B AND C 

    SO WHY THERE İS A MİSTAKE ON MY READED DATA since i separate wel the adresses 

    Tilen MAJERLE
    ST Employee
    May 23, 2018
    Posted on May 23, 2018 at 13:52

    Dear

    doumandjisamah

    ‌,

    what are the values you read back in this case?

    Please note, addresses0x081E0009 and0x081E000Bare not 16-bits aligned and you cannot program to these addresses as 16-bits (HALFWORD). You may use addresses0x081E0008

    and

    0x081E000A or

    0x081E000A

    and

    0x081E000C or use byte programming width.

    Best regards,

    Tilen

    chum
    Associate III
    March 29, 2019

    Anyone done with STM32F429ZI LwIP_TFTP_Server application ?

    Using Ethernet i want to transfer file on host server to target board memory or USB.

    I'm using Linux with eclipse IDE, USB with OTG.

    How to done this ?