在这个例程里,列出的所有的复位源,用户可以选择需要的复位源进行测试:
每次复新启动开发板,都显示一下复位源和菜单:
菜单内容如下:
Menu:
* 0 - Reset Status information.
* 1 - User Reset enable.
* 2 - User Reset disable.
* 3 - User Reset interrupt enable.
* 4 - User Reset interrupt disable.
* 5 - Software Reset.
* 6 - Watchdog Reset.
* 7 - NRST assert.
显示复位原因清单如下:
static void display_reset_reason(void)
{
char msg[80];
strcpy(&msg[0], "\r\nReset info : ");
//! [reset_get_status]
uint32_t info = rstc_get_status(RSTC);
//! [reset_get_status]
/* Decode the reset reason. */
switch (info & RSTC_SR_RSTTYP_Msk) {
case RSTC_GENERAL_RESET:
strcat(&msg[0], "General Reset,");
break;
case RSTC_BACKUP_RESET:
strcat(&msg[0], "Backup Reset,");
break;
case RSTC_WATCHDOG_RESET:
strcat(&msg[0], "Watchdog Reset,");
break;
case RSTC_SOFTWARE_RESET:
strcat(&msg[0], "Software Reset,");
break;
case RSTC_USER_RESET:
strcat(&msg[0], "User Reset,");
break;
default:
strcat(&msg[0], "Invalid reset reason!,");
}
/* NRST level. */
if (info & RSTC_SR_NRSTL) {
strcat(&msg[0], " NRST=1,");
}
else {
strcat(&msg[0], " NRST=0,");
}
/* User reset status. */
if (info & RSTC_SR_URSTS) {
strcat(&msg[0], " User Reset=1\r");
}
else {
strcat(&msg[0], " User Reset=0\r");
}
puts(&msg[0]);
}
主循环检测如下:
while (1) {
/* Wait for a key press or reset IRQ to trigger. */
while (uart_read(CONSOLE_UART, &uc_key) && (!reset_interrupt_triggered));
//! [reset_irq_has_triggered]
if (reset_interrupt_triggered) {
/* Critical section to access a variable that is set in an IRQ. */
cpu_irq_enter_critical();
reset_interrupt_triggered = false;
cpu_irq_leave_critical();
puts("User Reset IRQ triggered. Press any console key for the menu\r");
}
//! [reset_irq_has_triggered]
else {
/* Act on the key press. */
switch (uc_key - '0') {
case 0: /* Display reset information. */
display_reset_reason();
break;
case 1: /* Enable User Reset. */
//! [reset_enable_user_reset]
rstc_enable_user_reset(RSTC);
//! [reset_enable_user_reset]
puts("User Reset enabled - Press evaluation kit RESET button to test.\r");
break;
case 2: /* Disable User Reset. */
//! [reset_disable_user_reset]
rstc_disable_user_reset(RSTC);
//! [reset_disable_user_reset]
puts("User Reset disabled - Press evaluation kit RESET button to test.\r");
break;
case 3: /* User Reset interrupt enable. */
reset_interrupt_triggered = false;
/* Configure and enable WDT interrupt. */
//! [reset_enable_user_reset_interrupt]
rstc_disable_user_reset(RSTC);
NVIC_DisableIRQ(RSTC_IRQn);
rstc_enable_user_reset_interrupt(RSTC);
NVIC_ClearPendingIRQ(RSTC_IRQn);
NVIC_SetPriority(RSTC_IRQn, 0);
NVIC_EnableIRQ(RSTC_IRQn);
//! [reset_enable_user_reset_interrupt]
puts("User Reset interrupt enabled.\r");
break;
case 4: /* User Reset interrupt disable. */
//! [reset_disable_user_reset_interrupt]
NVIC_DisableIRQ(RSTC_IRQn);
rstc_disable_user_reset_interrupt(RSTC);
rstc_enable_user_reset(RSTC);
//! [reset_disable_user_reset_interrupt]
puts("User Reset interrupt disabled.\r");
break;
case 5: /* Software Reset. */
puts("Software Reset activated.\r");
wait_for_message_gone();
rstc_start_software_reset(RSTC);
/* Spin. */
while (1);
break;
case 6: /* Watchdog Reset. */
configure_watchdog();
/* Stop tickling the watchdog. */
watchdog_enabled = false;
puts("Watchdog Reset will trigger in 3 seconds.\r\n\r");
/* Spin. */
while (1);
break;
case 7: /* NRST assert. */
puts("NRST asserted.\r");
//! [reset_assert_nrst]
rstc_set_external_reset(RSTC, 0); /* 60us */
rstc_reset_extern(RSTC);
//! [reset_assert_nrst]
break;
default:
puts("Invalid menu option!\r");
}
/* Display the menu. */
display_menu();
}
}
}
运行结果截图如下:
|