cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0B1KCT6 how to use dual bank as single bank to use full 256KB.

Sneha
Associate II

I am using STM32G0B1KCT6 MCU, i would like to use the full flash of 256KB starting from 0x8000000 to 0x803FFFF. but am unable to flash in bank 2 (ranging from 0x8020000 to 0x803FFFF).
if i reduce the flash size to Bank1 only, then am able to flash and run the code.
I am aware its default dual bank MCU. PFA code snippet for changing it to single bank.
Also tried changing it single bank using the stcubeprogrammer but still fails to flash the MCU.

 
 
 
void ConfigureFlashToSingleBank(void)
{
    FLASH_OBProgramInitTypeDef OBInit;

    HAL_FLASHEx_OBGetConfig(&OBInit);

    /* Check if Dual Bank mode is enabled */
    if (OBInit.USERConfig & FLASH_OPTR_DUAL_BANK)
    {
        HAL_FLASH_Unlock();
        HAL_FLASH_OB_Unlock();

        OBInit.OptionType = OPTIONBYTE_USER;

        /* Disable Dual Bank (enable linear 256KB flash) */
        OBInit.USERConfig &= ~FLASH_OPTR_DUAL_BANK;

        if (HAL_FLASHEx_OBProgram(&OBInit) == HAL_OK)
        {
            HAL_FLASH_OB_Launch();   // triggers reset
        }

        HAL_FLASH_OB_Lock();
        HAL_FLASH_Lock();
    }
}

 the .icf file for the same is 

/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_end__   = 0x0803FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__   = 0x20023FFB;

/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_heap__   = 0x200;
/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;
define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];

define block CSTACK    with alignment = 8, size = __ICFEDIT_size_cstack__   { };
define block HEAP      with alignment = 8, size = __ICFEDIT_size_heap__     { };

initialize by copy { readwrite };
do not initialize  { section .noinit };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };

place in ROM_region   { readonly };
place in RAM_region   { readwrite,
                        block CSTACK, block HEAP };

export symbol __ICFEDIT_region_RAM_start__;
export symbol __ICFEDIT_region_RAM_end__;

Also the flash region defined for dfu use is used as @Internal Flash /0x08000000/128*002Kg where it fails ...
but works when reduced to single bank with flash region defined as @Internal Flash /0x08000000/64*002Kg 

 

Attached image error appears when tried flashing through the IAR IDE. 
How do i resolve this to use full flash as single bank without bank separation.
Please guide through to work as per the requirement

 

1 ACCEPTED SOLUTION

Accepted Solutions
Sneha
Associate II

The IAR IDE flasher used by the for flashing the MCU via debugger used the below attached files and spec that defines the banks separately and does not allow write over bank2. 

Sneha_0-1776331759860.png

These files are now modified with full memory usage for the given MCU., which now allows writing into BANK2.

Sneha_1-1776332030780.pngSneha_2-1776332070912.pngSneha_3-1776332109911.png

Regards,

Sneha

View solution in original post

6 REPLIES 6
mƎALLEm
ST Employee

Hello,

Check if you have enabled any security feature starting from BANK2 address: for example the FLASH write protection (WRP).

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
 
 

 Hi.,
Write protection on the MCU is disabled.

Thanks and regards,

Sneha

Are you able to erase all the Flash and to write to the second bank using CubeProgrammer?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

attaching the image of successful mass erase.

When few selected sectors is tried for erase it returns the pop-up as shown in the image.
with previous image showing that protection is disabled but sector erase giving pop-up that protected memory is not erased.. Is a little confusing. 

Regards.

Unfortunately I don't have that part number to test and the Pop-up message seems to be generic no matter some sectors are protected or not.

Are you able to write starting from 0x8020000 address with CubeProgrammer?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Sneha
Associate II

The IAR IDE flasher used by the for flashing the MCU via debugger used the below attached files and spec that defines the banks separately and does not allow write over bank2. 

Sneha_0-1776331759860.png

These files are now modified with full memory usage for the given MCU., which now allows writing into BANK2.

Sneha_1-1776332030780.pngSneha_2-1776332070912.pngSneha_3-1776332109911.png

Regards,

Sneha