更新:也许更好的问题是我该如何调试这个问题?我正在使用带有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 的链接器文件
我可以将程序刷入分区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
}