2.2 问题重现 使用NUCLEO-F412ZG板尝试重现客户问题,主要代码如下: int main(void) {
/* USER CODE BEGIN 1 */ uint32_t beginTick =0,endTick =0; uint32_t curSysTick=0,endSysTick =0; /* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init();
/* Configure the system clock */ SystemClock_Config();
/* Initialize all configured peripherals */ MX_GPIO_Init(); MX_IWDG_Init();
/* USER CODE BEGIN 2 */ if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET) //如果是看门狗复位 { /* Clear reset flags */ HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7,GPIO_PIN_SET); __HAL_RCC_CLEAR_RESET_FLAGS(); Error_Handler(); }
HAL_FLASH_Unlock(); /* Fill EraseInit structure*/ EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; EraseInitStruct.Sector = FLASH_SECTOR_8; EraseInitStruct.NbSectors = 1;
// if(HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK) // { // Error_Handler(); // }
beginTick =HAL_GetTick(); HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_SET); curSysTick =SysTick->VAL; if(HAL_FLASHEx_Erase_IT(&EraseInitStruct)!= HAL_OK) //擦除sector8 { Error_Handler(); } endSysTick =SysTick->VAL; // curSysTick, endSysTick保存着SysTick寄存器的值 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET); //PC8波形表示擦除FLASH的时间间隔 endTick =HAL_GetTick(); // beginTick, endTick保存着全局变量Tick的值 g_TickCount =endTick -beginTick; //变量Tick的时间差 HAL_IWDG_Refresh(&hiwdg); /* USER CODE END 2 */
/* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) { /* Refresh Error */ Error_Handler(); } HAL_Delay(10); } /* USER CODE END 3 */ }
|