SAML21XPlained pro apws not working after system reset

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone,

 

I am working on the evaluation board SAML21Plained pro and my goal is to use the Battery to power the RTC (Backup mode) when main power is removed.
I configured everything, it is working except the 1st reboot after flashing the board. I am using openocd to flash the board through the USB debug:

 

openocd -f board/atmel_saml21_xplained_pro.cfg -c "program main.elf verify reset exit"

 

The reset in the openocd command is a system reset and makes the board directly run the new application just flashed.
Once the board flashed, if I unplug and plug again the USB power, I can see that the apws (automatic power switch) has not worked. I check the RCAUSE register that gives me POR (power reset) and not BACKUP. This is for the first reboot after the flash.
If I do it again it is working as expected, the system enters in backup mode with the RTC running correctly. If I use the reset button of the board just after flashing it, it I do not have this issue. The reset button gives EXT reset in RCAUSE register.

My question is why after flashing the board with a system reset, the first reboot does not make the board enter in backup mode? I checked my register with debug mode, everything is configured as planned.

Here my code (I initialize RTC only the first time, not after backup):

 

if(0 == RSTC->RCAUSE.bit.BACKUP)
	{
		OSC32KCTRL->RTCCTRL.bit.RTCSEL = 0x4;	                                                       // 1024Hz xosc32
		OSC32KCTRL->XOSC32K.bit.EN1K = 0x1;		                                               // 1kHz output enabled
		OSC32KCTRL->XOSC32K.bit.XTALEN = 0x1;	                                                       // enable hardware connection with external osc
		OSC32KCTRL->XOSC32K.bit.ENABLE = 0x1;	                                                       // enable oscillator

		SUPC->BBPS.bit.WAKEEN = 0x1;								       // Wake enable when power switch from battery backup to main power
		SUPC->BBPS.bit.CONF = 0x1;								       // Automatic Power Switch (to VBAT)

		RTC->MODE2.CTRLA.bit.SWRST = 1;                       			                       // Software reset the RTC
		while (RTC->MODE2.SYNCBUSY.bit.SWRST)			              	                       // Wait for synchronization ...
		{
		}

		RTC->MODE2.CTRLA.reg = RTC_MODE2_CTRLA_PRESCALER_DIV1024 |                                     // Set prescaler to 1024
				       RTC_MODE2_CTRLA_MODE_CLOCK |                                            // Set RTC to mode 2, clock/calendar mode
				       RTC_MODE2_CTRLA_CLOCKSYNC;			                       // Read synchronization is enabled

		RTC->MODE2.CTRLA.bit.ENABLE = 1;                      			                       // Enable the RTC
		while (RTC->MODE2.SYNCBUSY.bit.ENABLE)
		{
		}
	}

Thanks in advance,

 

Cédric

Last Edited: Fri. Jul 23, 2021 - 07:34 AM