HAL_FLASH_Unlock(); HAL_FLASH_OB_Unlock(); /* USER CODE END 2 */ /* Unlock the User FLASH area */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { // HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); //LED1 GrĂ¼n // // HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1); //LED2 Gelb /* Wait for BUTTON_USER is released */ if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == 1) { while (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == 1); /* Get the Dual boot configuration status */ HAL_FLASHEx_OBGetConfig(&OBInit); /* Get FLASH_WRP_SECTORS write protection status */ OBInit.Banks = FLASH_BANK_1; HAL_FLASHEx_OBGetConfig(&OBInit); /* Check Swap FLASH banks status */ if ((OBInit.USERConfig & OB_SWAP_BANK_ENABLE) == OB_SWAP_BANK_DISABLE) { /*Swap to bank2 */ /*Set OB SWAP_BANK_OPT to swap Bank2*/ OBInit.OptionType = OPTIONBYTE_USER; OBInit.USERType = OB_USER_SWAP_BANK; OBInit.USERConfig = OB_SWAP_BANK_ENABLE; HAL_FLASHEx_OBProgram(&OBInit); /* Launch Option bytes loading */ HAL_FLASH_OB_Launch(); /* as the CPU is executing from the FLASH Bank1, and the I-Cache is enabled : Instruction cache must be invalidated after bank switching to ensure that CPU will fetch correct instructions from the FLASH. */ SCB_InvalidateICache(); } else { /* Swap to bank1 */ /*Set OB SWAP_BANK_OPT to swap Bank1*/ OBInit.OptionType = OPTIONBYTE_USER; OBInit.USERType = OB_USER_SWAP_BANK; OBInit.USERConfig = OB_SWAP_BANK_DISABLE; HAL_FLASHEx_OBProgram(&OBInit); /* Launch Option bytes loading */ HAL_FLASH_OB_Launch(); /* as the CPU is executing from the FLASH Bank1, and the I-Cache is enabled : Instruction cache must be invalidated after bank switching to ensure that CPU will fetch correct instructions from the FLASH. */ SCB_InvalidateICache(); } } else { #ifdef FLASH_BANK1 /* Toggle LED1 */ HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); /*Turn Off LED2*/ HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, 0); #else /* Toggle LED2 */ HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1); /* Turn off LED1 */ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, 0); #endif /* Insert 100 ms delay */ HAL_Delay(100); } } /* USER CODE END 3 */ }