14 Getting Started with Software Development
By design, this device has functional safety features that cannot be disabled. The Error
Controller (ERRCTRL), in particular, can generate interrupts, float I/O pins, and even
reset the device. Refer to the ERRCTRL - Error Controller section for additional
information. Although these features may be required in a completed system, they can
make initial software development difficult because there is not yet any code to
properly handle these situations. For getting started with software development, it is
thus recommended to immediately configure the ERRCTRL as follows at device start-up:
- Read the ERRCTRL.ESF (Error Status Flags) register; if it is not zero, write
‘
0xFFFFFFFF
’ to the register to clear it - Place the ERRCTRL in the configuration state by performing a protected write of CONFIG to the STATE bit field of the CTRLA (Control A) register
- Select an error severity level of NOTIFICATION for each ESCn (Error Source Control n) register by writing NOTIFICATION to the ERRLVL bit field; this ensures that the ERRCTRL will neither generate interrupts nor reset the system
- Place the ERRCTRL back in the normal state by performing a protected write of NORMAL to the STATE bit field of the CTRLA register
Example code for performing these steps is as
follows:
if (ERRCTRL.ESF)
{
ERRCTRL.ESF = 0xFFFFFFFF; // Clear all Error Status Flags
}
_PROTECTED_WRITE(ERRCTRL.CTRLA, ERRCTRL_STATE_CONFIG_gc); // Place ERRCTRL in CONFIG state
ERRCTRL.ESCVREGFAIL = ERRCTRL_ERRLVL_NOTIFICATION_gc; // Select severity level of
ERRCTRL.ESCBUSERR = ERRCTRL_ERRLVL_NOTIFICATION_gc; // NOTIFICATION for all error channels
ERRCTRL.ESCRAM2 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCFLASH2 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCOPC = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCSPLIM = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCRAM1 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCFLASH1 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCVREGWARN = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCCFD0 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCCFD1 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCCFM0 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCCFM1 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCSWDT = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCEEPROM = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCEVSYS0 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
ERRCTRL.ESCEVSYS1 = ERRCTRL_ERRLVL_NOTIFICATION_gc;
_PROTECTED_WRITE(ERRCTRL.CTRLA, ERRCTRL_STATE_NORMAL_gc); // Place ERRCTRL in NORMAL state
Attention: As software development
progresses, alter the individual severity levels to either NONCRITICAL or CRITICAL
where appropriate.