Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Jump to System Memory from User code
- * NOTE: Code tested on STM32F107
- */
- #define SYSTEM_MEMORY_ADDRESS 0x1FFFB000
- uint32_t JumpAddress;
- /* Disable all peripheral clocks */
- RCC->APB1ENR = 0x0;
- RCC->APB2ENR = 0x0;
- /* Disable all interrupts */
- __disable_irq();
- /* Clear Enable Interrupts */
- NVIC->ICER[0] = (uint32_t) ~0ul;
- NVIC->ICER[1] = (uint32_t) ~0ul;
- NVIC->ICER[2] = (uint32_t) ~0ul;
- /* Clear Pending Interrupts */
- NVIC->ICPR[0] = (uint32_t) ~0ul;
- NVIC->ICPR[1] = (uint32_t) ~0ul;
- NVIC->ICPR[2] = (uint32_t) ~0ul;
- /* Disable and reset System Timer */
- /* AN2606 - Used to automatically detect the serial baud rate from the host
- * for USARTx bootloaders. */
- SysTick->CTRL = 0x0;
- SysTick->LOAD = 0x0;
- SysTick->VAL = 0x0;
- /* Reset the RCC clock configuration to the default reset state */
- HAL_RCC_DeInit();
- /* Load bootloader vector */
- JumpAddress = *(__IO uint32_t*) (SYSTEM_MEMORY_ADDRESS + 4);
- void (*JumpToBootloader)(void) = (void (*)(void)) JumpAddress;
- /* Reinitialize the Stack pointer and jump to bootloader */
- __set_MSP(*(__IO uint32_t*) SYSTEM_MEMORY_ADDRESS);
- JumpToBootloader();
Add Comment
Please, Sign In to add comment