embeded/Cortex-M3 STM2026. 3. 6. 10:33

이런식으로 코드가 보이길래 했더니 실행이 안되서 디버거 물려보니

그냥 먼가.. 무한루프만 돌고 원하는 곳의 코드가 실행이 되지 않길래

/* USER CODE BEGIN 1 */
typedef  void (*pFunction)(void);
uint32_t JumpAddress;
void (*Jump_To_Application)();
/* USER CODE END 1 */

/* USER CODE BEGIN 2 */
  if (HAL_GPIO_ReadPin(Firmup_Pin_GPIO_Port, Firmup_Pin_Pin) != GPIO_PIN_RESET)
  {
    if (((*(__IO uint32_t*)USBD_DFU_APP_DEFAULT_ADD - 1) & 0x2FFFB000 ) == 0x20000000)
    {
      JumpAddress = *(__IO uint32_t*) (USBD_DFU_APP_DEFAULT_ADD + 4);
      Jump_To_Application = (pFunction) JumpAddress;
      __set_MSP(*(__IO uint32_t*) USBD_DFU_APP_DEFAULT_ADD);
      Jump_To_Application();
    }
  }
  MX_USB_DEVICE_Init();
  /* USER CODE END 2 */

[링크 : https://www.os4all.com/69]

 

먼가 더 필요한거 같아서 검색!

​1. 링커스크립트에서 인터럽트벡터가 있는 .isr_vector 섹션의 위치를 수정
2. SystemInit() 함수에서 SCB->VTOR 레지스터를 변경하고자 하는 섹션의 위치로 수정

SCB->VTOR = (uint32_t)&__isr_vector_addr;

[링크 : https://m.blog.naver.com/chcbaram/222580261732]

[링크 : https://m.blog.naver.com/chcbaram/221347218232]

 

먼가 초기화 하면서 손대는게 점점 많아지는 느낌..

아무튼 스택포인터를 옮겨주고 isr 테이블의 리셋 핸들러를 실행해줌으로서 초기화 하고 전체 프로그램을 다시 돌리는 구조인 듯.

void JumpToBootloader(void) {
    // Deinit HAL and Clocks
    HAL_DeInit();
    HAL_RCC_DeInit();
    
    // Disable all interrupts
    __disable_irq();

    // Disable Systick
    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL = 0;

    // Disable interrupts and clear pending ones
    for (size_t i = 0; i < sizeof(NVIC->ICER)/sizeof(NVIC->ICER[0]); i++) {
        NVIC->ICER[i]=0xFFFFFFFF;
        NVIC->ICPR[i]=0xFFFFFFFF;
    }

    // Re-enable interrupts
    __enable_irq();

    // Map Bootloader (system flash) memory to 0x00000000. This is STM32 family dependant.
    __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
    
    // Set embedded bootloader vector table base offset
    WRITE_REG(SCB->VTOR, SCB_VTOR_TBLOFF_Msk & 0x00000000);

    // Switch to Main Stack Pointer (in case it was using the Process Stack Pointer)
    __set_CONTROL(0);
    
    // Instruction synchronization barrier
    __ISB();

    // Set Main Stack Pointer to the Bootloader defined value.
    __set_MSP(BOOTLOADER_VECTOR_TABLE->stack_pointer);

    __DSB(); // Data synchronization barrier
    __ISB(); // Instruction synchronization barrier

    // Jump to Bootloader Reset Handler
    BOOTLOADER_VECTOR_TABLE->reset_handler();
    
    // The next instructions will not be reached
    while (1){}
}

[링크 : https://gist.github.com/gonzabrusco/fd47e89e4c6fb302fc54b83637a3a101

[링크 : https://blog.naver.com/alfee0/224043194861]

 

'embeded > Cortex-M3 STM' 카테고리의 다른 글

stm32cubeide cpp 변환이후 generate code  (0) 2026.02.25
mbed + stm32cube hal...?  (0) 2026.02.23
Mbed studio on ubuntu 22.04  (0) 2026.02.23
stm32f103c8t6 cpp std::cout 실패  (0) 2026.02.18
stm32 rtc tamper  (0) 2026.01.29
Posted by 구차니