Search code examples
cstm32stm32f7

Setting dual bank mode on STM32f779ii


I'm trying to set dual bank mode for STM32F779II, but it doesn't set at all.

So I tried in the main before doing anything the following code

  HAL_FLASH_Unlock();

  HAL_FLASH_OB_Unlock();

  FLASH->OPTCR |= FLASH_OPTCR_nDBANK_Msk;

  HAL_FLASH_OB_Lock();

  HAL_FLASH_Lock();

And When I tried to check if the memory is in Single or Dual Mode:

if((OBInit.USERConfig & OB_NDBANK_SINGLE_BANK) == OB_NDBANK_DUAL_BANK){
     printf("Dual bank mode is set");
    }

but that statement is never set true.


Solution

  • The process is described in the reference manual.

    To modify the user option value, follow the sequence below:

    1. Check that no Flash memory operation is ongoing by checking the BSY bit in the FLASH_SR register
    2. Write the desired option value in the FLASH_OPTCR register.
    3. Set the option start bit (OPTSTRT) in the FLASH_OPTCR register
    4. Wait for the BSY bit to be cleared.

    You have implemented Step 2 only.

    Note that to set dual bank mode, you have to clear that bit.

    Bit 29 nDBANK: Not dual bank mode

    1: The Flash user area is seen as a single bank with 256 bits read access.

    0: The Flash user area is seen as a dual bank with 128 bits read access (dual bank mode feature active)