Efm32 in-chip peripherals-RMU basic operations

Source: Internet
Author: User

There must be many reasons for MCU reset. But how to find the cause of the reset is sometimes difficult to find. EFM32 provides RMU modules, which are called Reset Magagement Unit and Reset management units. With this unit, you can easily find the cause of the reset.

While the MCU is running, RMU constantly detects various Reset sources, such as POR Power-on Reset, BOD Brown-out Detection, and external Reset foot Reset, watchdog reset, software reset, or EM4 wake-up. You can query RMU-> RSTCAUSE to find out the cause of the reset. Note that sometimes resetting is not caused by a single reason, for example, when both an external reset and a watchdog reset occur.

By viewing the tables in reference manual, you can know what specific digits mean.

At first glance, you will find that this table is a little more complex. In fact, it is very simple. We do not need to remember this table. Please directly use the letter RMU_ResetCauseGet () in EMLib to learn the cause of the reset.

After you know that you can know the reset source, you must also think about how to clear this register and prepare for the next query. Check the Reference manual and find that the RMU-> RSTCAUSE register is read-only. to clear this register, follow these three steps:

Write 1 to RCCLR in RMU-> CMD, 1 to bit0 in EMU-> AUXCTRL, and 0 to bit0 in EMU-> AUXCTRL.

Or call: RMU_ResetCauseClear () to complete this complex task. Haha. You can also refer to the following small code (based on tg stk ).

# Include <stdint. h>
# Include <stdbool. h>
# Include "efm32.h"
# Include "em_chip.h"
# Include "em_cmu.h"
# Include "em_rmu.h"
# Include "em_gpio.h"
# Include "segmentlcd. H"
# Include "lcdtest. H"
# Include "trace. H"

/*************************************** ***********************************//**
* @ Brief gpio interrupt handler (pb11)
**************************************** *************************************/
Void gpio_odd_irqhandler (void)
{
Gpio_intclear (1 <11 );
Rmu_resetcauseclear (); // use the buttons to clear the reset flag
}

/*************************************** ***********************************//**
* @ Brief gpio interrupt handler (pd8)
**************************************** *************************************/
Void gpio_even_irqhandler (void)
{
GPIO_IntClear (1 <8 );
RMU_ResetCauseClear (); // use the buttons to clear the reset flag
}

/*************************************** ***********************************//**
* @ Brief Main function
**************************************** *************************************/
Int main (void)
{
/* Chip errata */
CHIP_Init ();

/* Enable GPIO in CMU */
CMU_ClockEnable (cmuClock_GPIO, true );

/* Configure PD8 and PB11 as input */
GPIO_PinModeSet (gpioPortD, 8, gpioModeInput, 0 );
GPIO_PinModeSet (gpioPortB, 11, gpioModeInput, 0 );

/* Set falling edge interrupt for both ports */
GPIO_IntConfig (gpioPortD, 8, false, true, true );
GPIO_IntConfig (gpioPortB, 11, false, true, true );

/* Enable interrupt in core for even and odd gpio interrupts */
NVIC_ClearPendingIRQ (GPIO_EVEN_IRQn );
NVIC_EnableIRQ (GPIO_EVEN_IRQn );

NVIC_ClearPendingIRQ (GPIO_ODD_IRQn );
NVIC_EnableIRQ (GPIO_ODD_IRQn );

/* Enable LCD without voltage boost */
SegmentLCD_Init (false );

SegmentLCD_AllOff ();

While (1)
{
Unsigned long ulDelay = 500000;
While (ulDelay --);
SegmentLCD_Number (RMU_ResetCauseGet (); // display the reset flag on the LCD.
// SegmentLCD_Number (RMU-> RSTCAUSE );
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.