Dual-bank mode to switch and boot with the firmware present in the Bank-2 of the flash from the Bank-1
Hi,
I am using LED blink firmware generated using CUBE-MX by Disabling all the modes and Clearing the pinouts.
I flashed one firmware in the bank-1 (0x08000000) and
second firmware(with few changes the way the led blinks) flashed into the bank-2 (0x08018000) using the stm32 programmer.
First I writing the firmware-2 into bank-2 like this.
Next I am flashing the firmware-1 in the bank-1 and running .
I kept the bank switch logic in firmware-1.
My main() fun will look like this:
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
__HAL_RCC_SYSCFG_CLK_ENABLE();
int i = 9;
while (i > 0)
{
// printf("LED BLINK\n");
/* USER CODE END WHILE */
HAL_GPIO_WritePin(GPIOB, greenLed_Pin, GPIO_PIN_RESET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOB, greenLed_Pin, GPIO_PIN_SET);
HAL_Delay(1000);
i--;
}
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
FLASH_OB_BootConfig(OB_BOOT_BANK2);
if(READ_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_MEM_MODE) == 0)
{
HAL_GPIO_WritePin(GPIOB, RedLed_Pin|BlueLed_Pin, GPIO_PIN_SET);
HAL_Delay(2000);
HAL_GPIO_WritePin(GPIOB, RedLed_Pin| BlueLed_Pin, GPIO_PIN_RESET);
HAL_Delay(2000);
SET_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_UFB);
if(READ_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_UFB) == 1)
{
HAL_GPIO_WritePin(GPIOB, BlueLed_Pin, GPIO_PIN_SET);
HAL_Delay(2000);
HAL_GPIO_WritePin(GPIOB, BlueLed_Pin, GPIO_PIN_RESET);
HAL_Delay(2000);
HAL_GPIO_WritePin(GPIOB, greenLed_Pin, GPIO_PIN_RESET);
HAL_Delay(2000);
}
else
{
HAL_GPIO_WritePin(GPIOB, RedLed_Pin, GPIO_PIN_SET);
HAL_Delay(2000);
HAL_GPIO_WritePin(GPIOB, RedLed_Pin, GPIO_PIN_RESET);
HAL_Delay(2000);
HAL_GPIO_WritePin(GPIOB, greenLed_Pin, GPIO_PIN_RESET);
HAL_Delay(2000);
}
}
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
NVIC_SystemReset();
}Leds I kept for the debug. The code is executing till the leds BLUE and RED glowing together and fading (line 36) after that I am not able to see the leds. So I am thinking it got stuck at
SET_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_UFB);Is this aporach is right? Anything else is required? Please suggest?
Thanks
Shabaz
