跳转至应用程序时中断不起作用(STM32)

3
更新:也许更好的问题是我该如何调试这个问题?我正在使用带有OpenOCD调试器的VS Code。我总是进行清理构建。当我JumpToApplication()后,我能做的最好的事情就是看看调试器在暂停/步入时停止的地址。
我可以将程序刷入分区A(@地址0x8060000)并通过CRC检查进行验证。while循环中的任何东西都可以正常运行(LED3闪烁,UART); 然而,基于定时器中断的LED2闪烁未能工作。当我正常刷写程序时(即没有使用我的引导加载程序),它可以100%地工作,包括LED2的闪烁。
这是我处理过的一些资源(1, 2, 3, AN2606)。如何使我的第二个应用程序中断起作用?这些资源建议我清除待处理中断,但我不知道最好的方法是什么。在我的引导加载程序应用程序中,我使用了ETH、UART和GPIO外设,因此我将通过手册并读取寄存器来清除中断标志,但其他中断如NMI、HardFault,我也需要想办法清除吗?通过我的谷歌搜索,我没有找到任何方便的函数来清除所有待处理中断,它是否存在?
以下是引导加载程序(位于0x8000000)的跳转函数/链接文件和应用程序(位于0x8060000)的main.c/链接文件:

引导加载程序中的跳转函数,位于0x8000000:

void ApplicationManager::RunActivePartition()
{     
    JumpToApplication = (void (*)(void)) (*((uint32_t *) (active_partition.address + 4)));

    /* Set vector table offset register */
    SetVectorTable(MemoryInfo::BTLR_ADDRESS, MemoryInfo::PARTITION_A_OFFSET_FROM_BTLR);

    /* STM32 needs the stack pointer to start at the beginning of
    ** the application in flash. This must happen last */ 
    __set_MSP(*(__IO uint32_t*) active_partition.address);

    JumpToApplication();


    /*************** Other things I have tried ***************/
    /* Reset RCC clock configuration */
    // HAL_RCC_DeInit();

    /* Disable peripheral clocks */
    // __HAL_RCC_GPIOA_CLK_DISABLE();
    // __HAL_RCC_GPIOB_CLK_DISABLE();
    // __HAL_RCC_GPIOC_CLK_DISABLE();
    // __HAL_RCC_GPIOD_CLK_DISABLE();
    // __HAL_RCC_GPIOG_CLK_DISABLE();
    // __HAL_RCC_GPIOH_CLK_DISABLE();
    // __HAL_RCC_PWR_CLK_DISABLE();

    /* Disable Peripherals */
    // HAL_CRC_MspDeInit(&hcrc);
    // HAL_UART_DeInit(&huart3);

    /* Disable and reset systick timer */
    // SysTick->CTRL= 0;
    // SysTick->LOAD = 0;
    // SysTick->VAL = 0;

    /* Disable all interrupts */
    // __disable_irq();

    /* Clear pending interrupts */

    /* Remap system memory */
    // SYSCFG->MEMRMP = SYSCFG_MEMRMP_MEM_MODE_0; // 

    /*************** What I want to add when more basic implementation works ***************/
    // /* Relocate vector interrupt table to RAM */
    // CopyVectorInterruptTable();

    // /* TODO: Patch VIT with bootloader interrupt handlers (ex: hard fault handler) */
    // PatchVectorInterruptTable();

    // if (!CopyandPatchOkay())
    // {
    //     LOG_DEBUG("Vector interrupt table not probably copied and/or patched \n");
    // }
    // else
    // {
    //     LOG_DEBUG("Device ready to jump into application \n");
    // }
}

应用程序(引导加载程序)0x8000000 的链接器文件
/* Highest address of the user mode stack */
_estack = 0x20010000;    /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200;      /* required amount of heap  */
_Min_Stack_Size = 0x400; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 192K
CCMRAM (rw)      : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 2048K
}

跳转到0x8060000的应用程序

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim10)
{
 HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
}
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
  SCB->VTOR = 0x8060000; //---- @berendi's suggestion
  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART3_UART_Init();
  MX_TIM10_Init();
  /* USER CODE BEGIN 2 */
  uint32_t count = 0;
  HAL_TIM_Base_Start_IT(&htim10);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    for (uint32_t i=0; i < 100000; i++);
    HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
    _printf("Hi %d \n", count);
    count++;
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

应用程序(中断闪烁)链接文件 0x8060000

/* Highest address of the user mode stack */
_estack = 0x20010000;    /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200;      /* required amount of heap  */
_Min_Stack_Size = 0x400; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 192K
CCMRAM (rw)      : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx)      : ORIGIN = 0x8060000, LENGTH = 1024K
}

1
你的“引导程序”代码似乎禁用了所有中断。你的主“应用程序”代码是否重新启用了中断? - Some programmer dude
我在我的闪烁程序的main函数中添加了__enable_irq()作为第一行。现在两个LED都不会切换了。 - mbards
FYI:ARM KEIL:ARM:如何编写引导加载程序:http://www.keil.com/support/docs/3913.htm - Gabriel Staples
1个回答

5
在STM32CubeMX生成的项目中,位于system_stm32f4xx.c文件中的SystemInit()函数会在main()之前由启动代码调用,将向量表地址寄存器重置为FLASH的开头。请注意保留HTML标签。
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET  0x00 /*!< Vector Table base offset field.
                                   This value must be a multiple of 0x200. */

/* -- snip -- */

#ifdef VECT_TAB_SRAM
  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif

您可以直接编辑此文件(而无需再次运行STM32CubeMX项目,因为它 似乎会覆盖此文件),或者在启用中断之前在main()中再次设置正确的值。

2
我在我的应用程序中添加了 SCB->VTOR = 0x8060000;,它可以正常工作!感谢 @berendi。不知道为什么调试器在我跳转后没有更新我的查看器中的 VTOR 寄存器?我一直在关注这个。 - mbards
非常感谢。对我来说,“SCB->VTOR = ((uint32_t)FIRMWARE_START_ADDR);”也可以使用。 - AdvancedNewbie

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接