‎2021-01-18 08:04 AM
In my own application , I noticed that Flash page erase stopped working once i cleared the DBANK flag in the option bits.
While i start debug this, i see a irregularity
It looks there is a difference in datasheet and ST-Link , the datasheet says when DBANK = 0 we use single bank configuration, but the tiptool in ST-link says the opposite. I suppose the datasheet is correct?
To debug this issue i downloaded the FLASH_EraseProgram example for the NUCLEO-G474RE board.
This example works fine in DUAL bank mode, but i wonder how to test in SINGLE bank mode.
i see in stm32g4xx_hal_flash.h this line : #if defined (FLASH_OPTR_DBANK)
This checks the DBANK FLAG , and when this is set , the flash HAL defines will be configured for a single bank FLASH ? This seems like a a bug in the hal files?
How do i test the single bank flash HAL codes properly , at this moment this is all very confusing?
Thank you
#if defined (FLASH_OPTR_DBANK)
#define FLASH_SIZE ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFFU)) ? (0x200UL << 10U) : \
(((*((uint32_t *)FLASH_SIZE_DATA_REGISTER)) & 0xFFFFUL) << 10U))
#define FLASH_BANK_SIZE (FLASH_SIZE >> 1)
#define FLASH_PAGE_NB 128U
#define FLASH_PAGE_SIZE_128_BITS 0x1000U /* 4 KB */
#else
#define FLASH_SIZE ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFFU)) ? (0x80UL << 10U) : \
(((*((uint32_t *)FLASH_SIZE_DATA_REGISTER)) & 0xFFFFUL) << 10U))
#define FLASH_BANK_SIZE (FLASH_SIZE)
#define FLASH_PAGE_NB ((FLASH_SIZE == 0x00080000U) ? 256U : 64U)
#endif
#define FLASH_PAGE_SIZE 0x800U /* 2 KB */
#define FLASH_TIMEOUT_VALUE 1000U /* 1 s */
Solved! Go to Solution.
‎2021-01-19 05:01 AM
found the issue,
these 2 instructions needed to be before all other commands, they where at a wrong location
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Clear OPTVERR bit set on virgin samples */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
‎2021-01-18 10:32 AM
Hello @sde c.1​ ,
Welcome to the STM32 Community :smiling_face_with_smiling_eyes:
Which Cube package release are you using ? Please ensure that you are using latest release of MCU package and tool.
You should adjust the bank, page and number of pages to erase from Dual bank mode to Single bank mode.
Check the bit Flash_OPTR_DBANK for the Single/Dual Bank configuration. You can use the STM32CubeProgrammer tool: click on OB>>User Configuration>>DBANK.
Imen
‎2021-01-19 12:40 AM
Hi Imen,
Thank you for aswering. Its good to be here ! i transited frim microchip to STM, so this is all new for me =)
i use STM32Cube_FW_G4_V1.3.0 , FLASH_EraseProgram V1.2.0.
bit Flash_OPTR_DBANK is cleared in OB>>User Configuration>>DBANK , as expected, there the information is also correct. the tooltip in ST-Link utility shows it wrong. I also dont understand why it says 1MB banks , while it is 2x256KB. the device info is correct though.
I'm now rewriting the example program to get it work for 1 bank, to bad STM do not offer this option with a define or seprate example.
Though i'm not understanding the code in stm32g4xx_hal_flash.h starting at line 859.
Clearly the FLASH_OPTR_DBANK is always defined for this device, so i'm now try to undefine , if that not works, i will rewrite the example.
Do you see the issue?
i will update you if i find the solution.
Cheers
‎2021-01-19 05:01 AM
found the issue,
these 2 instructions needed to be before all other commands, they where at a wrong location
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Clear OPTVERR bit set on virgin samples */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
‎2021-01-19 06:02 AM
Hi @sde c.1​ ,
Thank you for sharing your solution. I'm glad to know that the issue is solved :smiling_face_with_smiling_eyes:
Imen