port to token hardware

This commit is contained in:
Conor Patrick
2018-08-09 19:39:50 -04:00
parent 352178c8a8
commit a76564f488
21 changed files with 817 additions and 176 deletions

File diff suppressed because one or more lines are too long

View File

@@ -35,5 +35,15 @@
<type>2</type>
<location>C:/Users/conor/Desktop/u2f-one/fido2/</location>
</link>
<link>
<name>CMSIS/EFM32JG1B/startup_gcc_efm32jg1b.s</name>
<type>1</type>
<locationURI>STUDIO_SDK_LOC/platform/Device/SiliconLabs/EFM32JG1B/Source/GCC/startup_efm32jg1b.S</locationURI>
</link>
<link>
<name>CMSIS/EFM32JG1B/system_efm32jg1b.c</name>
<type>1</type>
<locationURI>STUDIO_SDK_LOC/platform/Device/SiliconLabs/EFM32JG1B/Source/system_efm32jg1b.c</locationURI>
</link>
</linkedResources>
</projectDescription>

View File

@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="ASCII"?>
<device:XMLDevice xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:device="http://www.silabs.com/ss/hwconfig/document/device.ecore" name="EFM32JG1B200F128GM32" partId="mcu.arm.efm32.jg1.efm32jg1b200f128gm32" contextId="%DEFAULT%">
<mode name="DefaultMode">
<property object="ADC0" propertyId="ABPeripheral.included" value="true"/>
<property object="CMU" propertyId="ABPeripheral.included" value="true"/>
<property object="CMU" propertyId="clocksettings.hfrcosettings.hfrcofrequency" value="38 MHz"/>
<property object="CMU" propertyId="clocksettings.lfclocksettings.ulfrcorequired" value="Yes"/>
<property object="CRYOTIMER" propertyId="ABPeripheral.included" value="true"/>
<property object="CRYOTIMER" propertyId="cryotimer.clocking.clocksourceforcryotimer" value="ULFRCO"/>
<property object="CRYOTIMER" propertyId="cryotimer.clocking.eventafterevery" value="1 cycle"/>
<property object="CRYPTO" propertyId="ABPeripheral.included" value="true"/>
<property object="DefaultMode" propertyId="mode.diagramLocation" value="100, 100"/>
<property object="EMU" propertyId="ABPeripheral.included" value="true"/>
<property object="EMU" propertyId="emu.powerconfiguration.externalpowercircuitwiring" value="Not wired for DCDC"/>
<property object="GPIO" propertyId="ABPeripheral.included" value="true"/>
<property object="PA0" propertyId="ports.settings.pinmode" value="Input"/>
<property object="PA1" propertyId="ports.settings.pinmode" value="Input"/>
<property object="PB11" propertyId="ports.settings.dout" value="1"/>
<property object="PB11" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PB11" propertyId="ports.settings.pinmode" value="Push-pull"/>
<property object="PB11" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PB11" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PB12" propertyId="ports.settings.dout" value="1"/>
<property object="PB12" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PB12" propertyId="ports.settings.pinmode" value="Input pull"/>
<property object="PB12" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PB12" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PB13" propertyId="ports.settings.dout" value="1"/>
<property object="PB13" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PB13" propertyId="ports.settings.pinmode" value="Push-pull"/>
<property object="PB13" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PB13" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PB15" propertyId="ports.settings.dout" value="1"/>
<property object="PB15" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PB15" propertyId="ports.settings.pinmode" value="Push-pull"/>
<property object="PB15" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PB15" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PD10" propertyId="ports.settings.dout" value="1"/>
<property object="PD10" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PD10" propertyId="ports.settings.pinmode" value="Push-pull"/>
<property object="PD10" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PD10" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PD11" propertyId="ports.settings.dout" value="1"/>
<property object="PD11" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PD11" propertyId="ports.settings.pinmode" value="Input pull"/>
<property object="PD11" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PD11" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PD12" propertyId="ports.settings.dout" value="1"/>
<property object="PD12" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PD12" propertyId="ports.settings.pinmode" value="Push-pull"/>
<property object="PD12" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PD12" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PD13" propertyId="ports.settings.dout" value="1"/>
<property object="PD13" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PD13" propertyId="ports.settings.pinmode" value="Input pull"/>
<property object="PD13" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PD13" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PD14" propertyId="ports.settings.dout" value="1"/>
<property object="PD14" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PD14" propertyId="ports.settings.pinmode" value="Push-pull"/>
<property object="PD14" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PD14" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PD15" propertyId="ports.settings.dout" value="1"/>
<property object="PD15" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PD15" propertyId="ports.settings.pinmode" value="Push-pull"/>
<property object="PD15" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PD15" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PD9" propertyId="ports.settings.dout" value="1"/>
<property object="PD9" propertyId="ports.settings.filter" value="Enabled"/>
<property object="PD9" propertyId="ports.settings.pinmode" value="Push-pull"/>
<property object="PD9" propertyId="ports.settings.pulldirection" value="Pullup"/>
<property object="PD9" propertyId="ports.settings.pullup" value="Enabled"/>
<property object="PORTIO" propertyId="portio.timer0.enable.cc0" value="Enabled"/>
<property object="PORTIO" propertyId="portio.timer0.enable.cc1" value="Enabled"/>
<property object="PORTIO" propertyId="portio.timer0.enable.cc2" value="Enabled"/>
<property object="PORTIO" propertyId="portio.timer0.location.timer0_cc0loc" value="18"/>
<property object="PORTIO" propertyId="portio.timer0.location.timer0_cc1loc" value="16"/>
<property object="PORTIO" propertyId="portio.timer0.location.timer0_cc2loc" value="20"/>
<property object="PORTIO" propertyId="portio.usart0.enable.rx" value="Enabled"/>
<property object="PORTIO" propertyId="portio.usart0.enable.tx" value="Enabled"/>
<property object="PORTIO" propertyId="portio.usart0.location.usart0_txloc" value="20"/>
<property object="PORTIO" propertyId="portio.usart1.enable.clk" value="Enabled"/>
<property object="PORTIO" propertyId="portio.usart1.enable.rx" value="Enabled"/>
<property object="PORTIO" propertyId="portio.usart1.enable.tx" value="Enabled"/>
<property object="PORTIO" propertyId="portio.usart1.location.usart1_rxloc" value="6"/>
<property object="PORTIO" propertyId="portio.usart1.location.usart1_txloc" value="8"/>
<property object="TIMER0" propertyId="ABPeripheral.included" value="true"/>
<property object="TIMER0" propertyId="timer.capturecomparech0.ccmode" value="PWM"/>
<property object="TIMER0" propertyId="timer.capturecomparech0.countermatchoutputaction" value="Toggle on event"/>
<property object="TIMER0" propertyId="timer.capturecomparech1.ccmode" value="PWM"/>
<property object="TIMER0" propertyId="timer.capturecomparech1.countermatchoutputaction" value="Toggle on event"/>
<property object="TIMER0" propertyId="timer.capturecomparech2.ccmode" value="PWM"/>
<property object="TIMER0" propertyId="timer.capturecomparech2.countermatchoutputaction" value="Toggle on event"/>
<property object="TIMER0" propertyId="timer.clocksettings.hfperprescaler" value="Divide by 512"/>
<property object="USART0" propertyId="ABPeripheral.included" value="true"/>
<property object="USART0" propertyId="usart.outputsettings.clockselect" value="Disabled"/>
<property object="USART1" propertyId="ABPeripheral.included" value="true"/>
<property object="USART1" propertyId="usart.asynchronoussettings.baudrate" value="130000"/>
<property object="USART1" propertyId="usart.mode.usartmode" value="Synchronous Mode (SPI / I2S)"/>
<property object="USART1" propertyId="usart.outputsettings.clockselect" value="Disabled"/>
<property object="USART1" propertyId="usart.synchronoussettings.baudrate" value="130000"/>
</mode>
<modeTransition>
<property object="RESET &#x2192; DefaultMode" propertyId="modeTransition.source" value="RESET"/>
<property object="RESET &#x2192; DefaultMode" propertyId="modeTransition.target" value="DefaultMode"/>
</modeTransition>
</device:XMLDevice>

View File

@@ -10,9 +10,9 @@
#define DEBUG_LEVEL 1
#define PRINTING_USE_VCOM
//#define PRINTING_USE_VCOM
#define USING_DEV_BOARD
//#define USING_DEV_BOARD
//#define BRIDGE_TO_WALLET
@@ -22,10 +22,12 @@
void printing_init();
#define TEST
#define TEST_POWER
//#define TEST
//#define TEST_POWER
// GPIO assignments
#define NFC_DEV_SS gpioPortF,2
#define LED_INIT_VALUE 0x001000
#endif /* SRC_APP_H_ */

View File

@@ -23,6 +23,7 @@
#include "em_cryotimer.h"
#include "em_crypto.h"
#include "em_gpio.h"
#include "em_timer.h"
#include "em_usart.h"
// [Library includes]$
@@ -38,6 +39,7 @@ extern void enter_DefaultMode_from_RESET(void) {
ADC0_enter_DefaultMode_from_RESET();
USART0_enter_DefaultMode_from_RESET();
USART1_enter_DefaultMode_from_RESET();
TIMER0_enter_DefaultMode_from_RESET();
CRYOTIMER_enter_DefaultMode_from_RESET();
PORTIO_enter_DefaultMode_from_RESET();
// [Config Calls]$
@@ -50,19 +52,8 @@ extern void enter_DefaultMode_from_RESET(void) {
extern void EMU_enter_DefaultMode_from_RESET(void) {
// $[EMU Initialization]
/* Initialize DCDC regulator */
EMU_DCDCInit_TypeDef dcdcInit = EMU_DCDCINIT_DEFAULT;
dcdcInit.powerConfig = emuPowerConfig_DcdcToDvdd;
dcdcInit.dcdcMode = emuDcdcMode_LowNoise;
dcdcInit.mVout = 1800;
dcdcInit.em01LoadCurrent_mA = 15;
dcdcInit.em234LoadCurrent_uA = 10;
dcdcInit.maxCurrent_mA = 200;
dcdcInit.anaPeripheralPower = emuDcdcAnaPeripheralPower_DCDC;
dcdcInit.reverseCurrentControl = 160;
EMU_DCDCInit(&dcdcInit);
/* External power circuit not wired for DCDC; shut down regulator */
EMU_DCDCPowerOff();
/* Initialize EM2/EM3 mode */
EMU_EM23Init_TypeDef em23Init = EMU_EM23INIT_DEFAULT;
@@ -102,7 +93,7 @@ extern void CMU_enter_DefaultMode_from_RESET(void) {
CMU_HFXOInit(&hfxoInit);
/* Setting system HFRCO frequency */
CMU_HFRCOFreqSet (cmuHFRCOFreq_4M0Hz);
CMU_HFRCOFreqSet (cmuHFRCOFreq_38M0Hz);
/* Using HFRCO as high frequency clock, HFCLK */
CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);
@@ -133,6 +124,9 @@ extern void CMU_enter_DefaultMode_from_RESET(void) {
/* Enable clock for CRYOTIMER */
CMU_ClockEnable(cmuClock_CRYOTIMER, true);
/* Enable clock for TIMER0 */
CMU_ClockEnable(cmuClock_TIMER0, true);
/* Enable clock for USART0 */
CMU_ClockEnable(cmuClock_USART0, true);
@@ -279,23 +273,23 @@ extern void USART0_enter_DefaultMode_from_RESET(void) {
// $[USART_InitIO]
/* Disable CLK pin */
USART0->ROUTELOC0 = (USART0->ROUTELOC0 & (~_USART_ROUTELOC0_CLKLOC_MASK))
| USART_ROUTELOC0_CLKLOC_LOC0;
| USART_ROUTELOC0_CLKLOC_LOC4;
USART0->ROUTEPEN = USART0->ROUTEPEN & (~USART_ROUTEPEN_CLKPEN);
/* Disable CS pin */
USART0->ROUTELOC0 = (USART0->ROUTELOC0 & (~_USART_ROUTELOC0_CSLOC_MASK))
| USART_ROUTELOC0_CSLOC_LOC0;
| USART_ROUTELOC0_CSLOC_LOC3;
USART0->ROUTEPEN = USART0->ROUTEPEN & (~USART_ROUTEPEN_CSPEN);
/* Set up CTS pin */
/* Disable CTS pin */
USART0->ROUTELOC1 = (USART0->ROUTELOC1 & (~_USART_ROUTELOC1_CTSLOC_MASK))
| USART_ROUTELOC1_CTSLOC_LOC30;
USART0->ROUTEPEN = USART0->ROUTEPEN | USART_ROUTEPEN_CTSPEN;
| USART_ROUTELOC1_CTSLOC_LOC2;
USART0->ROUTEPEN = USART0->ROUTEPEN & (~USART_ROUTEPEN_CTSPEN);
/* Set up RTS pin */
/* Disable RTS pin */
USART0->ROUTELOC1 = (USART0->ROUTELOC1 & (~_USART_ROUTELOC1_RTSLOC_MASK))
| USART_ROUTELOC1_RTSLOC_LOC30;
USART0->ROUTEPEN = USART0->ROUTEPEN | USART_ROUTEPEN_RTSPEN;
| USART_ROUTELOC1_RTSLOC_LOC1;
USART0->ROUTEPEN = USART0->ROUTEPEN & (~USART_ROUTEPEN_RTSPEN);
/* Set up RX pin */
USART0->ROUTELOC0 = (USART0->ROUTELOC0 & (~_USART_ROUTELOC0_RXLOC_MASK))
@@ -304,7 +298,7 @@ extern void USART0_enter_DefaultMode_from_RESET(void) {
/* Set up TX pin */
USART0->ROUTELOC0 = (USART0->ROUTELOC0 & (~_USART_ROUTELOC0_TXLOC_MASK))
| USART_ROUTELOC0_TXLOC_LOC0;
| USART_ROUTELOC0_TXLOC_LOC20;
USART0->ROUTEPEN = USART0->ROUTEPEN | USART_ROUTEPEN_TXPEN;
// [USART_InitIO]$
@@ -348,7 +342,7 @@ extern void USART1_enter_DefaultMode_from_RESET(void) {
initsync.databits = usartDatabits8;
initsync.master = 1;
initsync.msbf = 1;
initsync.clockMode = usartClockMode1;
initsync.clockMode = usartClockMode0;
#if defined( USART_INPUT_RXPRS ) && defined( USART_TRIGCTRL_AUTOTXTEN )
initsync.prsRxEnable = 0;
initsync.prsRxCh = 0;
@@ -371,32 +365,32 @@ extern void USART1_enter_DefaultMode_from_RESET(void) {
// $[USART_InitIO]
/* Set up CLK pin */
USART1->ROUTELOC0 = (USART1->ROUTELOC0 & (~_USART_ROUTELOC0_CLKLOC_MASK))
| USART_ROUTELOC0_CLKLOC_LOC11;
| USART_ROUTELOC0_CLKLOC_LOC4;
USART1->ROUTEPEN = USART1->ROUTEPEN | USART_ROUTEPEN_CLKPEN;
/* Disable CS pin */
USART1->ROUTELOC0 = (USART1->ROUTELOC0 & (~_USART_ROUTELOC0_CSLOC_MASK))
| USART_ROUTELOC0_CSLOC_LOC0;
| USART_ROUTELOC0_CSLOC_LOC3;
USART1->ROUTEPEN = USART1->ROUTEPEN & (~USART_ROUTEPEN_CSPEN);
/* Disable CTS pin */
USART1->ROUTELOC1 = (USART1->ROUTELOC1 & (~_USART_ROUTELOC1_CTSLOC_MASK))
| USART_ROUTELOC1_CTSLOC_LOC0;
| USART_ROUTELOC1_CTSLOC_LOC2;
USART1->ROUTEPEN = USART1->ROUTEPEN & (~USART_ROUTEPEN_CTSPEN);
/* Disable RTS pin */
USART1->ROUTELOC1 = (USART1->ROUTELOC1 & (~_USART_ROUTELOC1_RTSLOC_MASK))
| USART_ROUTELOC1_RTSLOC_LOC0;
| USART_ROUTELOC1_RTSLOC_LOC1;
USART1->ROUTEPEN = USART1->ROUTEPEN & (~USART_ROUTEPEN_RTSPEN);
/* Set up RX pin */
USART1->ROUTELOC0 = (USART1->ROUTELOC0 & (~_USART_ROUTELOC0_RXLOC_MASK))
| USART_ROUTELOC0_RXLOC_LOC11;
| USART_ROUTELOC0_RXLOC_LOC6;
USART1->ROUTEPEN = USART1->ROUTEPEN | USART_ROUTEPEN_RXPEN;
/* Set up TX pin */
USART1->ROUTELOC0 = (USART1->ROUTELOC0 & (~_USART_ROUTELOC0_TXLOC_MASK))
| USART_ROUTELOC0_TXLOC_LOC11;
| USART_ROUTELOC0_TXLOC_LOC8;
USART1->ROUTEPEN = USART1->ROUTEPEN | USART_ROUTEPEN_TXPEN;
// [USART_InitIO]$
@@ -477,21 +471,124 @@ extern void LDMA_enter_DefaultMode_from_RESET(void) {
extern void TIMER0_enter_DefaultMode_from_RESET(void) {
// $[TIMER0 I/O setup]
/* Set up CC0 */
TIMER0->ROUTELOC0 = (TIMER0->ROUTELOC0 & (~_TIMER_ROUTELOC0_CC0LOC_MASK))
| TIMER_ROUTELOC0_CC0LOC_LOC18;
TIMER0->ROUTEPEN = TIMER0->ROUTEPEN | TIMER_ROUTEPEN_CC0PEN;
/* Set up CC1 */
TIMER0->ROUTELOC0 = (TIMER0->ROUTELOC0 & (~_TIMER_ROUTELOC0_CC1LOC_MASK))
| TIMER_ROUTELOC0_CC1LOC_LOC16;
TIMER0->ROUTEPEN = TIMER0->ROUTEPEN | TIMER_ROUTEPEN_CC1PEN;
/* Set up CC2 */
TIMER0->ROUTELOC0 = (TIMER0->ROUTELOC0 & (~_TIMER_ROUTELOC0_CC2LOC_MASK))
| TIMER_ROUTELOC0_CC2LOC_LOC20;
TIMER0->ROUTEPEN = TIMER0->ROUTEPEN | TIMER_ROUTEPEN_CC2PEN;
/* Set up CDTI0 */
TIMER0->ROUTELOC2 = (TIMER0->ROUTELOC2 & (~_TIMER_ROUTELOC2_CDTI0LOC_MASK))
| TIMER_ROUTELOC2_CDTI0LOC_LOC3;
TIMER0->ROUTEPEN = TIMER0->ROUTEPEN & (~TIMER_ROUTEPEN_CDTI0PEN);
/* Set up CDTI1 */
TIMER0->ROUTELOC2 = (TIMER0->ROUTELOC2 & (~_TIMER_ROUTELOC2_CDTI1LOC_MASK))
| TIMER_ROUTELOC2_CDTI1LOC_LOC2;
TIMER0->ROUTEPEN = TIMER0->ROUTEPEN & (~TIMER_ROUTEPEN_CDTI1PEN);
/* Set up CDTI2 */
TIMER0->ROUTELOC2 = (TIMER0->ROUTELOC2 & (~_TIMER_ROUTELOC2_CDTI2LOC_MASK))
| TIMER_ROUTELOC2_CDTI2LOC_LOC1;
TIMER0->ROUTEPEN = TIMER0->ROUTEPEN & (~TIMER_ROUTEPEN_CDTI2PEN);
// [TIMER0 I/O setup]$
// $[TIMER0 initialization]
TIMER_Init_TypeDef init = TIMER_INIT_DEFAULT;
init.enable = 1;
init.debugRun = 0;
init.dmaClrAct = 0;
init.sync = 0;
init.clkSel = timerClkSelHFPerClk;
init.prescale = timerPrescale512;
init.fallAction = timerInputActionNone;
init.riseAction = timerInputActionNone;
init.mode = timerModeUp;
init.quadModeX4 = 0;
init.oneShot = 0;
init.count2x = 0;
init.ati = 0;
TIMER_Init(TIMER0, &init);
// [TIMER0 initialization]$
// $[TIMER0 CC0 init]
TIMER_InitCC_TypeDef initCC0 = TIMER_INITCC_DEFAULT;
initCC0.prsInput = false;
initCC0.prsSel = timerPRSSELCh0;
initCC0.edge = timerEdgeRising;
initCC0.mode = timerCCModePWM;
initCC0.eventCtrl = timerEventEveryEdge;
initCC0.filter = 0;
initCC0.cofoa = timerOutputActionNone;
initCC0.cufoa = timerOutputActionNone;
initCC0.cmoa = timerOutputActionToggle;
initCC0.coist = 0;
initCC0.outInvert = 0;
TIMER_InitCC(TIMER0, 0, &initCC0);
// [TIMER0 CC0 init]$
// $[TIMER0 CC1 init]
TIMER_InitCC_TypeDef initCC1 = TIMER_INITCC_DEFAULT;
initCC1.prsInput = false;
initCC1.prsSel = timerPRSSELCh0;
initCC1.edge = timerEdgeRising;
initCC1.mode = timerCCModePWM;
initCC1.eventCtrl = timerEventEveryEdge;
initCC1.filter = 0;
initCC1.cofoa = timerOutputActionNone;
initCC1.cufoa = timerOutputActionNone;
initCC1.cmoa = timerOutputActionToggle;
initCC1.coist = 0;
initCC1.outInvert = 0;
TIMER_InitCC(TIMER0, 1, &initCC1);
// [TIMER0 CC1 init]$
// $[TIMER0 CC2 init]
TIMER_InitCC_TypeDef initCC2 = TIMER_INITCC_DEFAULT;
initCC2.prsInput = false;
initCC2.prsSel = timerPRSSELCh0;
initCC2.edge = timerEdgeRising;
initCC2.mode = timerCCModePWM;
initCC2.eventCtrl = timerEventEveryEdge;
initCC2.filter = 0;
initCC2.cofoa = timerOutputActionNone;
initCC2.cufoa = timerOutputActionNone;
initCC2.cmoa = timerOutputActionToggle;
initCC2.coist = 0;
initCC2.outInvert = 0;
TIMER_InitCC(TIMER0, 2, &initCC2);
// [TIMER0 CC2 init]$
// $[TIMER0 DTI init]
TIMER_InitDTI_TypeDef initDTI = TIMER_INITDTI_DEFAULT;
initDTI.enable = 0;
initDTI.activeLowOut = 0;
initDTI.invertComplementaryOut = 0;
initDTI.autoRestart = 0;
initDTI.enablePrsSource = 0;
initDTI.prsSel = timerPRSSELCh0;
initDTI.prescale = timerPrescale1;
initDTI.riseTime = 1;
initDTI.fallTime = 1;
initDTI.enableFaultSourceCoreLockup = 1;
initDTI.enableFaultSourceDebugger = 1;
initDTI.faultSourcePrsSel0 = 0;
initDTI.faultSourcePrsSel0 = timerPRSSELCh0;
initDTI.faultSourcePrsSel1 = 0;
initDTI.faultSourcePrsSel1 = timerPRSSELCh0;
initDTI.faultAction = timerDtiFaultActionInactive;
initDTI.outputsEnableMask = 0 | TIMER_DTOGEN_DTOGCC0EN
| TIMER_DTOGEN_DTOGCC1EN | TIMER_DTOGEN_DTOGCC2EN;
TIMER_InitDTI(TIMER0, &initDTI);
// [TIMER0 DTI init]$
}
@@ -596,51 +693,51 @@ extern void PORTIO_enter_DefaultMode_from_RESET(void) {
// $[Port A Configuration]
/* Pin PA0 is configured to Push-pull */
GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
/* Pin PA0 is configured to Input enabled */
GPIO_PinModeSet(gpioPortA, 0, gpioModeInput, 0);
/* Pin PA1 is configured to Input enabled with pull-up */
GPIO_PinModeSet(gpioPortA, 1, gpioModeInputPull, 1);
/* Pin PA3 is configured to Push-pull */
GPIO_PinModeSet(gpioPortA, 3, gpioModePushPull, 0);
/* Pin PA4 is configured to Open-drain with pull-up and filter */
GPIO_PinModeSet(gpioPortA, 4, gpioModeWiredAndPullUpFilter, 1);
/* Pin PA5 is configured to Push-pull */
GPIO_PinModeSet(gpioPortA, 5, gpioModePushPull, 1);
/* Pin PA1 is configured to Input enabled */
GPIO_PinModeSet(gpioPortA, 1, gpioModeInput, 0);
// [Port A Configuration]$
// $[Port B Configuration]
/* Pin PB11 is configured to Push-pull */
GPIO_PinModeSet(gpioPortB, 11, gpioModePushPull, 1);
/* Pin PB12 is configured to Input enabled with pull-up */
GPIO_PinModeSet(gpioPortB, 12, gpioModeInputPull, 1);
/* Pin PB13 is configured to Push-pull */
GPIO_PinModeSet(gpioPortB, 13, gpioModePushPull, 1);
/* Pin PB15 is configured to Push-pull */
GPIO_PinModeSet(gpioPortB, 15, gpioModePushPull, 1);
// [Port B Configuration]$
// $[Port C Configuration]
/* Pin PC6 is configured to Push-pull */
GPIO_PinModeSet(gpioPortC, 6, gpioModePushPull, 1);
/* Pin PC7 is configured to Input enabled with pull-up */
GPIO_PinModeSet(gpioPortC, 7, gpioModeInputPull, 1);
/* Pin PC8 is configured to Push-pull */
GPIO_PinModeSet(gpioPortC, 8, gpioModePushPull, 1);
/* Pin PC9 is configured to Input enabled with pull-up */
GPIO_PinModeSet(gpioPortC, 9, gpioModeInputPull, 1);
/* Pin PC10 is configured to Push-pull */
GPIO_PinModeSet(gpioPortC, 10, gpioModePushPull, 1);
// [Port C Configuration]$
// $[Port D Configuration]
/* Pin PD9 is configured to Push-pull */
GPIO_PinModeSet(gpioPortD, 9, gpioModePushPull, 1);
/* Pin PD10 is configured to Push-pull */
GPIO_PinModeSet(gpioPortD, 10, gpioModePushPull, 1);
/* Pin PD11 is configured to Input enabled with pull-up */
GPIO_PinModeSet(gpioPortD, 11, gpioModeInputPull, 1);
/* Pin PD12 is configured to Push-pull */
GPIO_PinModeSet(gpioPortD, 12, gpioModePushPull, 1);
/* Pin PD13 is configured to Input enabled with pull-up */
GPIO_PinModeSet(gpioPortD, 13, gpioModeInputPull, 1);
/* Pin PD14 is configured to Push-pull */
GPIO_PinModeSet(gpioPortD, 14, gpioModePushPull, 1);
/* Pin PD15 is configured to Push-pull */
GPIO_PinModeSet(gpioPortD, 15, gpioModePushPull, 1);
// [Port D Configuration]$
@@ -649,21 +746,6 @@ extern void PORTIO_enter_DefaultMode_from_RESET(void) {
// [Port E Configuration]$
// $[Port F Configuration]
/* Pin PF2 is configured to Push-pull */
GPIO_PinModeSet(gpioPortF, 2, gpioModePushPull, 1);
/* Pin PF3 is configured to Open-drain with pull-up and filter */
GPIO_PinModeSet(gpioPortF, 3, gpioModeWiredAndPullUpFilter, 1);
/* Pin PF4 is configured to Push-pull */
GPIO_PinModeSet(gpioPortF, 4, gpioModePushPull, 0);
/* Pin PF5 is configured to Push-pull */
GPIO_PinModeSet(gpioPortF, 5, gpioModePushPull, 0);
/* Pin PF6 is configured to Input enabled with pull-up */
GPIO_PinModeSet(gpioPortF, 6, gpioModeInputPull, 1);
// [Port F Configuration]$
}

View File

@@ -15,6 +15,7 @@
#include "em_cmu.h"
#include "em_msc.h"
#include "em_i2c.h"
#include "em_timer.h"
#include "InitDevice.h"
#include "cbor.h"
@@ -26,6 +27,8 @@
#include "crypto.h"
#include "nfc.h"
#ifdef USING_DEV_BOARD
#define MSG_AVAIL_PIN gpioPortC,9
#define RDY_PIN gpioPortC,10
#define RW_PIN gpioPortD,11
@@ -33,19 +36,34 @@
#define LED1_PIN gpioPortF,4
#define LED2_PIN gpioPortF,5
#else
#define MSG_AVAIL_PIN gpioPortA,1
#define RDY_PIN gpioPortA,0
#define RW_PIN gpioPortD,15
#define RESET_PIN gpioPortB,15
#define LED1_PIN gpioPortD,9
#define LED2_PIN gpioPortD,10
#define LED3_PIN gpioPortD,14
#define BUTTON_PIN gpioPortD,13
#endif
#define PAGE_SIZE 2048
#define PAGES 128
#define COUNTER_PAGE 125
#define STATE1_PAGE 126
#define STATE2_PAGE 127
#define PAGES 64
#define COUNTER_PAGE (PAGES - 3)
#define STATE1_PAGE (PAGES - 2)
#define STATE2_PAGE (PAGES - 1)
#define APPLICATION_START_ADDR 0x8000
#define APPLICATION_START_PAGE (0x8000/PAGE_SIZE)
#define APPLICATION_START_ADDR 0x4000
#define APPLICATION_START_PAGE (0x4000/PAGE_SIZE)
#define APPLICATION_END_ADDR (PAGE_SIZE*(PAGES - 3)-4) // NOT included in application
#define APPLICATION_END_PAGE ((PAGES - 3)) // 125 is NOT included in application
#define AUTH_WORD_ADDR (PAGE_SIZE*(PAGES - 3)-4)
#define APPLICATION_END_ADDR (PAGE_SIZE*125-4) // NOT included in application
#define APPLICATION_END_PAGE (125) // 125 is NOT included in application
#define AUTH_WORD_ADDR (PAGE_SIZE*125-4)
static void init_atomic_counter()
{
@@ -105,6 +123,27 @@ uint32_t ctap_atomic_count(int sel)
return count;
}
static uint32_t _color;
uint32_t get_RBG()
{
return _color;
}
void RGB(uint32_t hex)
{
uint16_t r = 256 - ((hex & 0xff0000) >> 16);
uint16_t g = 256 - ((hex & 0xff00) >> 8);
uint16_t b = 256 - ((hex & 0xff) >> 0);
TIMER_CompareBufSet(TIMER0, 0, g); // green
TIMER_CompareBufSet(TIMER0, 1, r); // red
TIMER_CompareBufSet(TIMER0, 2, b); // blue
_color = hex;
}
#define IS_BUTTON_PRESSED() (GPIO_PinInGet(BUTTON_PIN) == 0)
// Verify the user
// return 1 if user is verified, 0 if not
int ctap_user_verification(uint8_t arg)
@@ -116,6 +155,30 @@ int ctap_user_verification(uint8_t arg)
// Return 1 for user is present, 0 user not present
int ctap_user_presence_test()
{
uint32_t t1 = millis();
RGB(0x304010);
while (IS_BUTTON_PRESSED())
{
if (t1 + 5000 < millis())
return 0;
}
t1 = millis();
do
{
if (t1 + 5000 < millis())
return 0;
if (! IS_BUTTON_PRESSED())
continue;
delay(1);
}
while (! IS_BUTTON_PRESSED());
RGB(0x001040);
delay(50);
return 1;
}
@@ -129,14 +192,60 @@ void ctaphid_write_block(uint8_t * data)
}
#endif
#ifdef IS_BOOTLOADER // two different colors between bootloader and app
void heartbeat()
{
GPIO_PinOutToggle(LED1_PIN);
GPIO_PinOutToggle(LED2_PIN);
nfc_test();
// printf("heartbeat %d %d\r\n", beat++,CRYOTIMER->CNT);
}
static int state = 0;
static uint32_t val = (LED_INIT_VALUE >> 8) & 0xff;
int but = IS_BUTTON_PRESSED();
if (state)
{
val--;
}
else
{
val++;
}
if (val > 30 || val < 1)
{
state = !state;
}
// if (but) RGB(val * 2);
// else
RGB((val << 16) | (val*2 << 8));
}
#else
void heartbeat()
{
static int state = 0;
static uint32_t val = (LED_INIT_VALUE >> 8) & 0xff;
int but = IS_BUTTON_PRESSED();
if (state)
{
val--;
}
else
{
val++;
}
if (val > 30 || val < 1)
{
state = !state;
}
if (but) RGB(val * 2);
else RGB(val << 8);
}
#endif
uint32_t millis()
{
return CRYOTIMER->CNT;
@@ -186,9 +295,9 @@ int usbhid_recv(uint8_t * msg)
wait_for_efm8_busy();
// msgs_to_recv--;
// printf(">> ");
// dump_hex(msg,64);
// // msgs_to_recv--;
// printf(">> ");
// dump_hex(msg,64);
return 64;
}
@@ -209,6 +318,8 @@ void usbhid_send(uint8_t * msg)
USART_SpiTransfer(USART1, *msg++);
}
wait_for_efm8_busy();
delay(10);
// uint32_t t2 = millis();
// printf("wait time: %u\n", (uint32_t)(t2-t1));
@@ -334,11 +445,14 @@ void bootloader_init(void)
// status LEDS
GPIO_PinModeSet(LED1_PIN,
gpioModePushPull,
0);
1); // red
GPIO_PinModeSet(LED2_PIN,
gpioModePushPull,
1);
1); // green
GPIO_PinModeSet(LED3_PIN,
gpioModePushPull,
1); // blue
// EFM8 RDY/BUSY
GPIO_PinModeSet(RDY_PIN, gpioModeInput, 0);
@@ -369,11 +483,14 @@ void device_init(void)
// status LEDS
GPIO_PinModeSet(LED1_PIN,
gpioModePushPull,
0);
1); // red
GPIO_PinModeSet(LED2_PIN,
gpioModePushPull,
1);
1); // green
GPIO_PinModeSet(LED3_PIN,
gpioModePushPull,
1); // blue
// EFM8 RDY/BUSY
GPIO_PinModeSet(RDY_PIN, gpioModeInput, 0);
@@ -387,6 +504,9 @@ void device_init(void)
// Reset EFM8
GPIO_PinModeSet(RESET_PIN, gpioModePushPull, 1);
TIMER_TopSet(TIMER0, 255);
RGB(LED_INIT_VALUE);
printing_init();

View File

@@ -20,7 +20,7 @@
#define NFC_DEV_ADDR (0xa0|(0x0<<1))
#define NFC_DEV_USART USART1
#ifndef IS_BOOTLOADER
I2C_TransferReturn_TypeDef I2CSPM_Transfer(I2C_TypeDef *i2c, I2C_TransferSeq_TypeDef *seq)
{
I2C_TransferReturn_TypeDef ret;
@@ -357,3 +357,5 @@ void nfc_test()
}
}
#endif

View File

@@ -27,7 +27,7 @@ void setupSWOForPrint(void)
/* Enable Serial wire output pin */
GPIO->ROUTEPEN |= GPIO_ROUTEPEN_SWVPEN;
/* Set location 0 */
/* Set location 0 */
GPIO->ROUTELOC0 = GPIO_ROUTELOC0_SWVLOC_LOC0;
/* Enable output on pin - GPIO Port F, Pin 2 */
@@ -76,7 +76,9 @@ int RETARGET_ReadChar(void)
void printing_init()
{
#ifdef USING_DEV_BOARD
// GPIO_PinModeSet(gpioPortA,5,gpioModePushPull,1); // VCOM enable
#endif
}
#endif