在要复位的位置加上如下两句, 即可实现系统复位
__set_FAULTMASK(1);
NVIC_SystemReset();
DEMO:
代码中实现了LED的闪烁,使用不断复位系统实现循环。
int main(void)
{
/* USER CODE BEGIN 1 */
/* 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_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_9);
HAL_Delay(1000);
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_9);
HAL_Delay(1000);
__set_FAULTMASK(1);
NVIC_SystemReset();