大家好,我在 stm32 中遇到了引导加载程序的问题 当我从引导加载程序切换到应用程序时,一切都很好,但在用户应用程序中间的一个功能上,我面临着硬故障。 这是我在 main 函数中的初始化
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "BootLoader.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
Process_Recieved_Information(&analyze_Recieved_Packet);
Send_Information_InBootLoader_Lib(&Send_Data);
/* 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_USART2_UART_Init();
MX_TIM4_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim4);
HAL_TIM_Base_Start(&htim4);
USART2->CR1 |= USART_CR1_RXNEIE ;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
NVIC_EnableIRQ(USART2_IRQn);
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
Send_RxData_To_BootLoader_Lib();
}
/* USER CODE END 3 */
}
这是我跳转到用户应用程序的功能
static void Jump_To_User_Application(void)
{
/* Set the clock to the default state */
__disable_irq();
NVIC_DisableIRQ(USART2_IRQn);
HAL_NVIC_DisableIRQ(TIM4_IRQn);
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3);
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOF_CLK_DISABLE();
HAL_DeInit();
HAL_RCC_DeInit();
HAL_TIM_Base_DeInit(&htim4);
HAL_UART_DeInit(&huart2);
/* Disable Systick timer */
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/* Clear Interrupt Enable Register & Interrupt Pending Register */
for (uint16_t i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++)
{
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
/* Re-enable all interrupts */
__enable_irq();
/*
void(*User_App_Reset_Handler)(void) = (void *)(*((uint32_t *)(USER_APP_LOCATION)));
User_App_Reset_Handler();
*/
/*
void(* user_app_1)(void);
uint32_t temp_msp = *(__IO uint32_t *)PAGE_16_ADDRESS;
__set_MSP(temp_msp);
uint32_t user_app_1_rst_handler = *(__IO uint32_t *)(PAGE_16_ADDRESS+4);
user_app_1 = (void *)user_app_1_rst_handler;
user_app_1();
*/
__set_MSP(*(uint32_t *)PAGE_16_ADDRESS);
// Assign the address of the reset handler to the function pointer
app_reset_handler = (void *)*(volatile uint32_t *)reset_handler_address;
// Call the user application's reset handler function to start the application
app_reset_handler();
}
这是导致hardfault的函数
#define N 32
void fft()
{
uint16_t nm1 = 32-1;//N - 1;
uint16_t nd2 = N / 2;
uint16_t m = log10(N)/log10(2);
uint16_t j = nd2;
uint16_t i, k, l;
uint16_t le, le2;
float ur, ui, sr, si;
uint16_t jm1, ip;
float tr, ti;
}
如果我们使用像这样的数字而不是“N”宏:(32-1)一切都会好的,但是如果使用宏(N-1)我们就会遇到硬故障,这是我的硬故障分析器的图片
知道为什么会发生这种情况吗? 正如你所看到的,我禁用了我在跳转功能中使用的所有内容。 idk 还有其他事情吗?
知道为什么会发生这种情况吗?如你所见,我禁用了所有功能 我在跳转功能中使用的。 idk 还有其他事情吗?
您忘记将向量表设置为用户应用程序中的向量表。
您需要(假设
PAGE_16_ADDRESS
是 256 对齐):
SCB->VTOR = PAGE_16_ADDRESS;
在致电您的申请之前。
如果您的应用程序使用标准 STM32 启动,您需要通过注释设置的向量表行来修改
system_stm32YYxx.c
文件(其中 YY
取决于您的微模型)。