STM32CubeMX systick bug?

发觉用新版(V6.9.1)的它生成代码,会有问题。可能是 BUG。具体如下:

一个简单的点灯程序,用 Keil MDK 5.38a(compiler version 6)编译。

如果在变量前,不加上关键字“volatile”,是不会闪灯的。

V6.8.1 也同样,但好象如果你的工程是在旧版本中,慢慢升一步步上来的,不会有事,如果是新建的就出问题。

大家可以试试?

main.c 中

extern volatile uint32_t u32LedFlashTimeAdd;

/* 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 */

	u32LedFlashTimeAdd = 0;
  /* 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();
  /* USER CODE BEGIN 2 */
	
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		//HAL_Delay(1);
		if(u32LedFlashTimeAdd > 5000)
		{
			u32LedFlashTimeAdd = 0;
			HAL_GPIO_TogglePin(Led_Flash_GPIO_Port,Led_Flash_Pin);
		}
    /* USER CODE END WHILE */

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

stm32g0xx_it.c 中

volatile uint32_t u32LedFlashTimeAdd;


//...

void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */
	u32LedFlashTimeAdd++;
	

  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
  /* USER CODE BEGIN SysTick_IRQn 1 */

  /* USER CODE END SysTick_IRQn 1 */
}

你可能感兴趣的:(硬件,stm32,bug,嵌入式硬件)