embeded/Cortex-M3 STM
stm32 부트로더로 부팅 전환하기
구차니
2025. 10. 21. 18:21
stm32 시리즈 마다 달라서 boot_addr를 확인해야 하지만
아무튼 아래와 같이 작성된 코드를 호출하면 boot0 쇼트한것 처럼 부트로더가 시작된다고 한다.
| /* USER CODE BEGIN 4 */ #define BOOT_ADDR 0x1FFFF000 // my MCU boot code base address #define MCU_IRQS 70u // no. of NVIC IRQ inputs struct boot_vectable_ { uint32_t Initial_SP; void (*Reset_Handler)(void); }; #define BOOTVTAB ((struct boot_vectable_ *)BOOT_ADDR) void JumpToBootloader(void) { /* Disable all interrupts */ __disable_irq(); /* Disable Systick timer */ SysTick->CTRL = 0; /* Set the clock to the default state */ HAL_RCC_DeInit(); /* Clear Interrupt Enable Register & Interrupt Pending Register */ for (uint8_t i = 0; i < (MCU_IRQS + 31u) / 32; i++) { NVIC->ICER[i]=0xFFFFFFFF; NVIC->ICPR[i]=0xFFFFFFFF; } /* Re-enable all interrupts */ __enable_irq(); // Set the MSP __set_MSP(BOOTVTAB->Initial_SP); // Jump to app firmware BOOTVTAB->Reset_Handler(); } /* USER CODE END 4 */ |