Guest User

Untitled

a guest
Jan 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /*
  2. * Jump to System Memory from User code
  3. * NOTE: Code tested on STM32F107
  4. */
  5.  
  6. #define SYSTEM_MEMORY_ADDRESS 0x1FFFB000
  7. uint32_t JumpAddress;
  8.  
  9. /* Disable all peripheral clocks */
  10. RCC->APB1ENR = 0x0;
  11. RCC->APB2ENR = 0x0;
  12.  
  13. /* Disable all interrupts */
  14. __disable_irq();
  15. /* Clear Enable Interrupts */
  16. NVIC->ICER[0] = (uint32_t) ~0ul;
  17. NVIC->ICER[1] = (uint32_t) ~0ul;
  18. NVIC->ICER[2] = (uint32_t) ~0ul;
  19. /* Clear Pending Interrupts */
  20. NVIC->ICPR[0] = (uint32_t) ~0ul;
  21. NVIC->ICPR[1] = (uint32_t) ~0ul;
  22. NVIC->ICPR[2] = (uint32_t) ~0ul;
  23.  
  24. /* Disable and reset System Timer */
  25. /* AN2606 - Used to automatically detect the serial baud rate from the host
  26. * for USARTx bootloaders. */
  27. SysTick->CTRL = 0x0;
  28. SysTick->LOAD = 0x0;
  29. SysTick->VAL = 0x0;
  30.  
  31. /* Reset the RCC clock configuration to the default reset state */
  32. HAL_RCC_DeInit();
  33.  
  34. /* Load bootloader vector */
  35. JumpAddress = *(__IO uint32_t*) (SYSTEM_MEMORY_ADDRESS + 4);
  36. void (*JumpToBootloader)(void) = (void (*)(void)) JumpAddress;
  37.  
  38. /* Reinitialize the Stack pointer and jump to bootloader */
  39. __set_MSP(*(__IO uint32_t*) SYSTEM_MEMORY_ADDRESS);
  40. JumpToBootloader();
Add Comment
Please, Sign In to add comment