本帖最后由 HomeKit 于 2025-10-2 19:12 编辑  
 
我使用以下代码进行内存位置跳转: 
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); 
Jump_To_Application = (pFunction) JumpAddress; 
__set_MSP(*(__IO uint32_t*) (APPLICATION_ADDRESS)); 
Jump_To_Application(); 
我成功实现了仅使用一个GPIO时的跳转功能,但在引导程序中添加外设后,跳转就不再有效。 
 
参考了某个UART的参考实现(stm32f4xx_hal_uart.c): 
HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart) 
{ 
  /* Check the UART handle allocation */ 
  if (huart == NULL) 
  { 
    return HAL_ERROR; 
  } 
 
  /* Check the parameters */ 
  assert_param(IS_UART_INSTANCE(huart->Instance)); 
 
  huart->gState = HAL_UART_STATE_BUSY; 
 
  /* Disable the Peripheral */ 
  __HAL_UART_DISABLE(huart); 
 
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 
  if (huart->MspDeInitCallback == NULL) 
  { 
    huart->MspDeInitCallback = HAL_UART_MspDeInit; 
  } 
  /* DeInit the low level hardware */ 
  huart->MspDeInitCallback(huart); 
#else 
  /* DeInit the low level hardware */ 
  HAL_UART_MspDeInit(huart); 
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ 
 
  huart->ErrorCode = HAL_UART_ERROR_NONE; 
  huart->gState = HAL_UART_STATE_RESET; 
  huart->RxState = HAL_UART_STATE_RESET; 
  huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; 
 
  /* Process Unlock */ 
  __HAL_UNLOCK(huart); 
 
  return HAL_OK; 
} 
 
我查找HAL_UART_MspDeInit的参考时,出现了以下内容(stm32f4xx_hal_uart.c): 
__weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) 
{ 
  /* Prevent unused argument(s) compilation warning */ 
  UNUSED(huart); 
  /* NOTE: This function should not be modified, when the callback is needed, 
           the HAL_UART_MspDeInit could be implemented in the user file 
   */ 
 
} 
 
 
还有另一个已实现的参考文件(stm32f4xx_hal_msp.c): 
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 
{ 
  if(huart->Instance==USART1) 
  { 
  /* USER CODE BEGIN USART1_MspDeInit 0 */ 
  
  /* USER CODE END USART1_MspDeInit 0 */ 
    /* Peripheral clock disable */ 
    __HAL_RCC_USART1_CLK_DISABLE(); 
  
    /**USART1 GPIO Configuration 
    PA9     ------> USART1_TX 
    PA10     ------> USART1_RX 
    */ 
    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); 
  
  /* USER CODE BEGIN USART1_MspDeInit 1 */ 
  
  /* USER CODE END USART1_MspDeInit 1 */ 
  } 
  
 
} 
 
 |   
     
  
 |