地址 0x81006fe 处的 STM32H7 bank 交换中断

STM32H7 bank swap break at address 0x81006fe

我正在尝试使用 ST32 H743ZI2 进行银行交换。我浪费了很多时间来修复它,但我没有得到它。也许是因为我是 STM32 控制器的新手。

我从 STM32CubeH7 固件示例中复制了银行交换代码,并对 CubeMX 中的 gpio 配置做了一些修改。我这样做是因为我想在没有 stm32h7xx_nucleo headers.

的情况下将代码包含在现有项目中

遵循银行 1 的代码:

HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();

while (1)
{
    /* Wait for BUTTON_USER is released */
    if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == 1)
    {
  while (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == 1);

  /* Get the Dual boot configuration status */
  HAL_FLASHEx_OBGetConfig(&OBInit);

  /* Get FLASH_WRP_SECTORS write protection status */
  OBInit.Banks     = FLASH_BANK_1;
  HAL_FLASHEx_OBGetConfig(&OBInit);

  /* Check Swap FLASH banks  status */
  if ((OBInit.USERConfig & OB_SWAP_BANK_ENABLE) == OB_SWAP_BANK_DISABLE)
  {
    /*Swap to bank2 */
    /*Set OB SWAP_BANK_OPT to swap Bank2*/
    OBInit.OptionType = OPTIONBYTE_USER;
    OBInit.USERType   = OB_USER_SWAP_BANK;
    OBInit.USERConfig = OB_SWAP_BANK_ENABLE;
    HAL_FLASHEx_OBProgram(&OBInit);

    /* Launch Option bytes loading */
    HAL_FLASH_OB_Launch();

    /*
      as the  CPU is executing from the FLASH Bank1, and the I-Cache is enabled :
      Instruction cache must be invalidated after bank switching to ensure that
      CPU will fetch correct instructions from the FLASH.
    */
    SCB_InvalidateICache();


    HAL_NVIC_SystemReset();
  }
  else
  {
    /* Swap to bank1 */
    /*Set OB SWAP_BANK_OPT to swap Bank1*/
    OBInit.OptionType = OPTIONBYTE_USER;
    OBInit.USERType = OB_USER_SWAP_BANK;
    OBInit.USERConfig = OB_SWAP_BANK_DISABLE;
    HAL_FLASHEx_OBProgram(&OBInit);

    /* Launch Option bytes loading */
    HAL_FLASH_OB_Launch();

    /*
      as the  CPU is executing from the FLASH Bank1, and the I-Cache is enabled :
      Instruction cache must be invalidated after bank switching to ensure that
      CPU will fetch correct instructions from the FLASH.
    */
    SCB_InvalidateICache();
  }
}
else
    {
#ifdef FLASH_BANK1
    /* Toggle LED1 */

HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
/*Turn Off LED2*/
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, 0);

#else
      /* Toggle LED2 */
    HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1);
      /* Turn off LED1 */
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, 0);
#endif

  /* Insert 100 ms delay */
  HAL_Delay(100);
}

/* USER CODE END WHILE */

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

除了 linkerscript 之外,bank1 和 bank2 的代码是相同的。 我将 Flash 分成两个区域,每个区域有 1024kb。在下面您可以看到 bank1.

的代码
/* Specify the memory areas */
MEMORY
{

  RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 128K
  RAM_D1 (xrw)   : ORIGIN = 0x24000000, LENGTH = 512K
  RAM_D2 (xrw)   : ORIGIN = 0x30000000, LENGTH = 288K
  RAM_D3 (xrw)   : ORIGIN = 0x38000000, LENGTH = 64K
  ITCMRAM (xrw)  : ORIGIN = 0x00000000, LENGTH = 64K
  FLASH (rx)     : ORIGIN = 0x8000000, LENGTH = 1024K
}

在 bank2 的链接描述文件中,我将闪存起始地址更改为 0x08100000。

现在我有以下问题。如果我加载 bank1 的订单代码和 bank2 的代码,请按下 Button1 并按下 Reset 按钮,我会收到以下错误消息:

Break at address "0x81006fe" with no debug information available, or outside of program code.

我已经用STM32 Utility 成功检查了是否放置了一些代码。

如果我以相反的顺序加载代码,银行将被交换一次。独立于 Button1 在系统重置之前是否被按下..

我已经查了一些论坛都没有成功。

有人知道问题出在哪里吗?

代码中有两个问题。

  1. 链接描述文件分为两部分。链接描述文件必须在与闪存相关的原始状态下重建。 bank2(0x081000000)的代码现在需要用stm32 utility之类的外部软件定位。

  2. Vector table 在 system_stm32h7xx.c

    中被重新定位到错误的地址