move things around and add efm8 and efm32 builds
This commit is contained in:
547
efm32/src/InitDevice.c
Normal file
547
efm32/src/InitDevice.c
Normal file
@@ -0,0 +1,547 @@
|
||||
//=========================================================
|
||||
// src/InitDevice.c: generated by Hardware Configurator
|
||||
//
|
||||
// This file will be regenerated when saving a document.
|
||||
// leave the sections inside the "$[...]" comment tags alone
|
||||
// or they will be overwritten!
|
||||
//=========================================================
|
||||
|
||||
// USER INCLUDES
|
||||
#include "InitDevice.h"
|
||||
|
||||
// USER PROTOTYPES
|
||||
// USER FUNCTIONS
|
||||
|
||||
// $[Library includes]
|
||||
#include "em_system.h"
|
||||
#include "em_emu.h"
|
||||
#include "em_cmu.h"
|
||||
#include "em_device.h"
|
||||
#include "em_chip.h"
|
||||
#include "em_assert.h"
|
||||
#include "em_cryotimer.h"
|
||||
#include "em_gpio.h"
|
||||
#include "em_usart.h"
|
||||
// [Library includes]$
|
||||
|
||||
//==============================================================================
|
||||
// enter_DefaultMode_from_RESET
|
||||
//==============================================================================
|
||||
extern void enter_DefaultMode_from_RESET(void) {
|
||||
// $[Config Calls]
|
||||
CHIP_Init();
|
||||
|
||||
EMU_enter_DefaultMode_from_RESET();
|
||||
CMU_enter_DefaultMode_from_RESET();
|
||||
USART0_enter_DefaultMode_from_RESET();
|
||||
CRYOTIMER_enter_DefaultMode_from_RESET();
|
||||
PORTIO_enter_DefaultMode_from_RESET();
|
||||
// [Config Calls]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// EMU_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
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);
|
||||
/* Initialize EM2/EM3 mode */
|
||||
EMU_EM23Init_TypeDef em23Init = EMU_EM23INIT_DEFAULT;
|
||||
|
||||
em23Init.em23VregFullEn = 0;
|
||||
|
||||
EMU_EM23Init(&em23Init);
|
||||
/* Initialize EM4H/S mode */
|
||||
EMU_EM4Init_TypeDef em4Init = EMU_EM4INIT_DEFAULT;
|
||||
|
||||
em4Init.retainLfrco = 0;
|
||||
em4Init.retainLfxo = 0;
|
||||
em4Init.retainUlfrco = 0;
|
||||
em4Init.em4State = emuEM4Shutoff;
|
||||
em4Init.pinRetentionMode = emuPinRetentionDisable;
|
||||
|
||||
EMU_EM4Init(&em4Init);
|
||||
// [EMU Initialization]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// LFXO_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void LFXO_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// CMU_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void CMU_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[High Frequency Clock Setup]
|
||||
/* Initializing HFXO */
|
||||
CMU_HFXOInit_TypeDef hfxoInit = CMU_HFXOINIT_DEFAULT;
|
||||
|
||||
CMU_HFXOInit(&hfxoInit);
|
||||
|
||||
/* Setting system HFRCO frequency */
|
||||
CMU_HFRCOFreqSet (cmuHFRCOFreq_38M0Hz);
|
||||
|
||||
/* Using HFRCO as high frequency clock, HFCLK */
|
||||
CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);
|
||||
// [High Frequency Clock Setup]$
|
||||
|
||||
// $[LE clocks enable]
|
||||
/* Enable LFRCO oscillator, and wait for it to be stable */
|
||||
CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
|
||||
|
||||
// [LE clocks enable]$
|
||||
|
||||
// $[LFACLK Setup]
|
||||
/* LFACLK is disabled */
|
||||
// [LFACLK Setup]$
|
||||
// $[LFBCLK Setup]
|
||||
/* LFBCLK is disabled */
|
||||
// [LFBCLK Setup]$
|
||||
// $[LFECLK Setup]
|
||||
/* LFECLK is disabled */
|
||||
// [LFECLK Setup]$
|
||||
// $[Peripheral Clock enables]
|
||||
/* Enable clock for HF peripherals */
|
||||
CMU_ClockEnable(cmuClock_HFPER, true);
|
||||
|
||||
/* Enable clock for CRYOTIMER */
|
||||
CMU_ClockEnable(cmuClock_CRYOTIMER, true);
|
||||
|
||||
/* Enable clock for USART0 */
|
||||
CMU_ClockEnable(cmuClock_USART0, true);
|
||||
|
||||
/* Enable clock for GPIO by default */
|
||||
CMU_ClockEnable(cmuClock_GPIO, true);
|
||||
|
||||
// [Peripheral Clock enables]$
|
||||
|
||||
// $[Clock output]
|
||||
/* Disable CLKOUT0 output */
|
||||
CMU->CTRL = (CMU->CTRL & ~_CMU_CTRL_CLKOUTSEL0_MASK)
|
||||
| CMU_CTRL_CLKOUTSEL0_DISABLED;
|
||||
/* Disable CLKOUT1 output */
|
||||
CMU->CTRL = (CMU->CTRL & ~_CMU_CTRL_CLKOUTSEL1_MASK)
|
||||
| CMU_CTRL_CLKOUTSEL1_DISABLED;
|
||||
|
||||
// [Clock output]$
|
||||
|
||||
// $[CMU_IO]
|
||||
/* Disable CLKOUT0 pin */
|
||||
CMU->ROUTEPEN &= ~CMU_ROUTEPEN_CLKOUT0PEN;
|
||||
|
||||
/* Disable CLKOUT1 pin */
|
||||
CMU->ROUTEPEN &= ~CMU_ROUTEPEN_CLKOUT1PEN;
|
||||
|
||||
// [CMU_IO]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// ADC0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void ADC0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[ADC0_Init]
|
||||
// [ADC0_Init]$
|
||||
|
||||
// $[ADC0_InputConfiguration]
|
||||
// [ADC0_InputConfiguration]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// ACMP0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void ACMP0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[ACMP0_Init]
|
||||
// [ACMP0_Init]$
|
||||
|
||||
// $[ACMP0_IO]
|
||||
// [ACMP0_IO]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// ACMP1_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void ACMP1_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[ACMP1_Init]
|
||||
// [ACMP1_Init]$
|
||||
|
||||
// $[ACMP1_IO]
|
||||
// [ACMP1_IO]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// IDAC0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void IDAC0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// RTCC_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void RTCC_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[Compare/Capture Channel 0 init]
|
||||
// [Compare/Capture Channel 0 init]$
|
||||
|
||||
// $[Compare/Capture Channel 1 init]
|
||||
// [Compare/Capture Channel 1 init]$
|
||||
|
||||
// $[Compare/Capture Channel 2 init]
|
||||
// [Compare/Capture Channel 2 init]$
|
||||
|
||||
// $[RTCC init]
|
||||
// [RTCC init]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// USART0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void USART0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[USART_InitAsync]
|
||||
USART_InitAsync_TypeDef initasync = USART_INITASYNC_DEFAULT;
|
||||
|
||||
initasync.enable = usartDisable;
|
||||
initasync.baudrate = 115200;
|
||||
initasync.databits = usartDatabits8;
|
||||
initasync.parity = usartNoParity;
|
||||
initasync.stopbits = usartStopbits1;
|
||||
initasync.oversampling = usartOVS16;
|
||||
#if defined( USART_INPUT_RXPRS ) && defined( USART_CTRL_MVDIS )
|
||||
initasync.mvdis = 0;
|
||||
initasync.prsRxEnable = 0;
|
||||
initasync.prsRxCh = 0;
|
||||
#endif
|
||||
|
||||
USART_InitAsync(USART0, &initasync);
|
||||
// [USART_InitAsync]$
|
||||
|
||||
// $[USART_InitSync]
|
||||
// [USART_InitSync]$
|
||||
|
||||
// $[USART_InitPrsTrigger]
|
||||
USART_PrsTriggerInit_TypeDef initprs = USART_INITPRSTRIGGER_DEFAULT;
|
||||
|
||||
initprs.rxTriggerEnable = 0;
|
||||
initprs.txTriggerEnable = 0;
|
||||
initprs.prsTriggerChannel = usartPrsTriggerCh0;
|
||||
|
||||
USART_InitPrsTrigger(USART0, &initprs);
|
||||
// [USART_InitPrsTrigger]$
|
||||
|
||||
// $[USART_InitIO]
|
||||
/* Disable CLK pin */
|
||||
USART0->ROUTELOC0 = (USART0->ROUTELOC0 & (~_USART_ROUTELOC0_CLKLOC_MASK))
|
||||
| USART_ROUTELOC0_CLKLOC_LOC0;
|
||||
USART0->ROUTEPEN = USART0->ROUTEPEN & (~USART_ROUTEPEN_CLKPEN);
|
||||
|
||||
/* Disable CS pin */
|
||||
USART0->ROUTELOC0 = (USART0->ROUTELOC0 & (~_USART_ROUTELOC0_CSLOC_MASK))
|
||||
| USART_ROUTELOC0_CSLOC_LOC0;
|
||||
USART0->ROUTEPEN = USART0->ROUTEPEN & (~USART_ROUTEPEN_CSPEN);
|
||||
|
||||
/* Set up CTS pin */
|
||||
USART0->ROUTELOC1 = (USART0->ROUTELOC1 & (~_USART_ROUTELOC1_CTSLOC_MASK))
|
||||
| USART_ROUTELOC1_CTSLOC_LOC30;
|
||||
USART0->ROUTEPEN = USART0->ROUTEPEN | USART_ROUTEPEN_CTSPEN;
|
||||
|
||||
/* Set up RTS pin */
|
||||
USART0->ROUTELOC1 = (USART0->ROUTELOC1 & (~_USART_ROUTELOC1_RTSLOC_MASK))
|
||||
| USART_ROUTELOC1_RTSLOC_LOC30;
|
||||
USART0->ROUTEPEN = USART0->ROUTEPEN | USART_ROUTEPEN_RTSPEN;
|
||||
|
||||
/* Set up RX pin */
|
||||
USART0->ROUTELOC0 = (USART0->ROUTELOC0 & (~_USART_ROUTELOC0_RXLOC_MASK))
|
||||
| USART_ROUTELOC0_RXLOC_LOC0;
|
||||
USART0->ROUTEPEN = USART0->ROUTEPEN | USART_ROUTEPEN_RXPEN;
|
||||
|
||||
/* Set up TX pin */
|
||||
USART0->ROUTELOC0 = (USART0->ROUTELOC0 & (~_USART_ROUTELOC0_TXLOC_MASK))
|
||||
| USART_ROUTELOC0_TXLOC_LOC0;
|
||||
USART0->ROUTEPEN = USART0->ROUTEPEN | USART_ROUTEPEN_TXPEN;
|
||||
|
||||
// [USART_InitIO]$
|
||||
|
||||
// $[USART_Misc]
|
||||
/* Disable CTS */
|
||||
USART0->CTRLX = USART0->CTRLX & (~USART_CTRLX_CTSEN);
|
||||
/* Set CTS active low */
|
||||
USART0->CTRLX = USART0->CTRLX & (~USART_CTRLX_CTSINV);
|
||||
/* Set RTS active low */
|
||||
USART0->CTRLX = USART0->CTRLX & (~USART_CTRLX_RTSINV);
|
||||
/* Set CS active low */
|
||||
USART0->CTRL = USART0->CTRL & (~USART_CTRL_CSINV);
|
||||
/* Set TX active high */
|
||||
USART0->CTRL = USART0->CTRL & (~USART_CTRL_TXINV);
|
||||
/* Set RX active high */
|
||||
USART0->CTRL = USART0->CTRL & (~USART_CTRL_RXINV);
|
||||
// [USART_Misc]$
|
||||
|
||||
// $[USART_Enable]
|
||||
|
||||
/* Enable USART if opted by user */
|
||||
USART_Enable(USART0, usartEnable);
|
||||
// [USART_Enable]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// USART1_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void USART1_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[USART_InitAsync]
|
||||
// [USART_InitAsync]$
|
||||
|
||||
// $[USART_InitSync]
|
||||
// [USART_InitSync]$
|
||||
|
||||
// $[USART_InitPrsTrigger]
|
||||
// [USART_InitPrsTrigger]$
|
||||
|
||||
// $[USART_InitIO]
|
||||
// [USART_InitIO]$
|
||||
|
||||
// $[USART_Misc]
|
||||
// [USART_Misc]$
|
||||
|
||||
// $[USART_Enable]
|
||||
// [USART_Enable]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// LEUART0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void LEUART0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[LEUART0 initialization]
|
||||
// [LEUART0 initialization]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// WDOG0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void WDOG0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[WDOG Initialization]
|
||||
// [WDOG Initialization]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// I2C0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void I2C0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[I2C0 I/O setup]
|
||||
// [I2C0 I/O setup]$
|
||||
|
||||
// $[I2C0 initialization]
|
||||
// [I2C0 initialization]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// GPCRC_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void GPCRC_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// LDMA_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void LDMA_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// TIMER0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void TIMER0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[TIMER0 I/O setup]
|
||||
// [TIMER0 I/O setup]$
|
||||
|
||||
// $[TIMER0 initialization]
|
||||
// [TIMER0 initialization]$
|
||||
|
||||
// $[TIMER0 CC0 init]
|
||||
// [TIMER0 CC0 init]$
|
||||
|
||||
// $[TIMER0 CC1 init]
|
||||
// [TIMER0 CC1 init]$
|
||||
|
||||
// $[TIMER0 CC2 init]
|
||||
// [TIMER0 CC2 init]$
|
||||
|
||||
// $[TIMER0 DTI init]
|
||||
// [TIMER0 DTI init]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// TIMER1_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void TIMER1_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[TIMER1 I/O setup]
|
||||
// [TIMER1 I/O setup]$
|
||||
|
||||
// $[TIMER1 initialization]
|
||||
// [TIMER1 initialization]$
|
||||
|
||||
// $[TIMER1 CC0 init]
|
||||
// [TIMER1 CC0 init]$
|
||||
|
||||
// $[TIMER1 CC1 init]
|
||||
// [TIMER1 CC1 init]$
|
||||
|
||||
// $[TIMER1 CC2 init]
|
||||
// [TIMER1 CC2 init]$
|
||||
|
||||
// $[TIMER1 CC3 init]
|
||||
// [TIMER1 CC3 init]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// LETIMER0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void LETIMER0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[LETIMER0 Compare Values]
|
||||
// [LETIMER0 Compare Values]$
|
||||
|
||||
// $[LETIMER0 Repeat Values]
|
||||
// [LETIMER0 Repeat Values]$
|
||||
|
||||
// $[LETIMER0 Initialization]
|
||||
// [LETIMER0 Initialization]$
|
||||
|
||||
// $[LETIMER0 PRS Input Triggers]
|
||||
// [LETIMER0 PRS Input Triggers]$
|
||||
|
||||
// $[LETIMER0 I/O setup]
|
||||
// [LETIMER0 I/O setup]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// CRYOTIMER_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void CRYOTIMER_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[CRYOTIMER_Init]
|
||||
CRYOTIMER_Init_TypeDef cryoInit = CRYOTIMER_INIT_DEFAULT;
|
||||
|
||||
/* General settings */
|
||||
cryoInit.enable = 1;
|
||||
cryoInit.debugRun = 0;
|
||||
cryoInit.em4Wakeup = 0;
|
||||
|
||||
/* Clocking settings */
|
||||
/* With a frequency of 32768Hz on LFRCO, this will result in a 0.98 ms timeout */
|
||||
cryoInit.osc = cryotimerOscLFRCO;
|
||||
cryoInit.presc = cryotimerPresc_32;
|
||||
cryoInit.period = cryotimerPeriod_1;
|
||||
CRYOTIMER_Init(&cryoInit);
|
||||
// [CRYOTIMER_Init]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// PCNT0_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void PCNT0_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[PCNT0 I/O setup]
|
||||
// [PCNT0 I/O setup]$
|
||||
|
||||
// $[PCNT0 initialization]
|
||||
// [PCNT0 initialization]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// PRS_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
extern void PRS_enter_DefaultMode_from_RESET(void) {
|
||||
|
||||
// $[PRS initialization]
|
||||
// [PRS initialization]$
|
||||
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// PORTIO_enter_DefaultMode_from_RESET
|
||||
//================================================================================
|
||||
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 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 PA5 is configured to Push-pull */
|
||||
GPIO_PinModeSet(gpioPortA, 5, gpioModePushPull, 1);
|
||||
// [Port A Configuration]$
|
||||
|
||||
// $[Port B Configuration]
|
||||
// [Port B Configuration]$
|
||||
|
||||
// $[Port C Configuration]
|
||||
// [Port C Configuration]$
|
||||
|
||||
// $[Port D Configuration]
|
||||
// [Port D Configuration]$
|
||||
|
||||
// $[Port E Configuration]
|
||||
// [Port E Configuration]$
|
||||
|
||||
// $[Port F Configuration]
|
||||
|
||||
/* 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);
|
||||
// [Port F Configuration]$
|
||||
|
||||
}
|
||||
|
18
efm32/src/app.h
Normal file
18
efm32/src/app.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* app.h
|
||||
*
|
||||
* Created on: Jun 26, 2018
|
||||
* Author: conor
|
||||
*/
|
||||
|
||||
#ifndef SRC_APP_H_
|
||||
#define SRC_APP_H_
|
||||
|
||||
#define PRINTING_USE_VCOM
|
||||
|
||||
#define USING_DEV_BOARD
|
||||
|
||||
void printing_init();
|
||||
|
||||
|
||||
#endif /* SRC_APP_H_ */
|
131
efm32/src/device.c
Normal file
131
efm32/src/device.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* device.c
|
||||
*
|
||||
* Created on: Jun 27, 2018
|
||||
* Author: conor
|
||||
*/
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "em_chip.h"
|
||||
#include "em_gpio.h"
|
||||
|
||||
#include "cbor.h"
|
||||
#include "log.h"
|
||||
#include "ctaphid.h"
|
||||
#include "util.h"
|
||||
|
||||
// Generate @num bytes of random numbers to @dest
|
||||
// return 1 if success, error otherwise
|
||||
int ctap_generate_rng(uint8_t * dst, size_t num)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
*dst++ = rand();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t _c1 = 0, _c2 = 0;
|
||||
uint32_t ctap_atomic_count(int sel)
|
||||
{
|
||||
if (sel == 0)
|
||||
{
|
||||
_c1++;
|
||||
return _c1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_c2++;
|
||||
return _c2;
|
||||
}
|
||||
}
|
||||
|
||||
// Verify the user
|
||||
// return 1 if user is verified, 0 if not
|
||||
int ctap_user_verification(uint8_t arg)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Test for user presence
|
||||
// Return 1 for user is present, 0 user not present
|
||||
int ctap_user_presence_test()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Must be implemented by application
|
||||
// data is HID_MESSAGE_SIZE long in bytes
|
||||
void ctaphid_write_block(uint8_t * data)
|
||||
{
|
||||
dump_hex(data, HID_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
void heartbeat()
|
||||
{
|
||||
static int beat = 0;
|
||||
GPIO_PinOutToggle(gpioPortF,4);
|
||||
GPIO_PinOutToggle(gpioPortF,5);
|
||||
// printf("heartbeat %d\r\n", CRYOTIMER->CNT);
|
||||
}
|
||||
|
||||
uint64_t millis()
|
||||
{
|
||||
return CRYOTIMER->CNT;
|
||||
}
|
||||
|
||||
|
||||
void usbhid_init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int usbhid_recv(uint8_t * msg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usbhid_send(uint8_t * msg)
|
||||
{
|
||||
}
|
||||
|
||||
void usbhid_close()
|
||||
{
|
||||
}
|
||||
|
||||
void main_loop_delay()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void device_init(void)
|
||||
{
|
||||
/* Chip errata */
|
||||
CHIP_Init();
|
||||
enter_DefaultMode_from_RESET();
|
||||
|
||||
GPIO_PinModeSet(gpioPortF,
|
||||
4,
|
||||
gpioModePushPull,
|
||||
0);
|
||||
|
||||
GPIO_PinModeSet(gpioPortF,
|
||||
5,
|
||||
gpioModePushPull,
|
||||
1);
|
||||
|
||||
|
||||
|
||||
|
||||
printing_init();
|
||||
|
||||
CborEncoder test;
|
||||
uint8_t buf[20];
|
||||
cbor_encoder_init(&test, buf, 20, 0);
|
||||
|
||||
printf("Device init\r\n");
|
||||
|
||||
}
|
13
efm32/src/main.c
Normal file
13
efm32/src/main.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "em_chip.h"
|
||||
#include "em_cmu.h"
|
||||
#include "em_emu.h"
|
||||
#include "em_core.h"
|
||||
#include "em_gpio.h"
|
||||
|
||||
#include "InitDevice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "cbor.h"
|
82
efm32/src/printing.c
Normal file
82
efm32/src/printing.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "em_chip.h"
|
||||
#include "em_cmu.h"
|
||||
#include "em_emu.h"
|
||||
#include "em_core.h"
|
||||
#include "em_usart.h"
|
||||
#include "em_gpio.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "app.h"
|
||||
#ifndef PRINTING_USE_VCOM
|
||||
int RETARGET_WriteChar(char c)
|
||||
{
|
||||
return ITM_SendChar(c);
|
||||
}
|
||||
|
||||
int RETARGET_ReadChar(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setupSWOForPrint(void)
|
||||
{
|
||||
/* Enable GPIO clock. */
|
||||
CMU_ClockEnable(cmuClock_GPIO, true);
|
||||
|
||||
/* Enable Serial wire output pin */
|
||||
GPIO->ROUTEPEN |= GPIO_ROUTEPEN_SWVPEN;
|
||||
|
||||
/* Set location 0 */
|
||||
GPIO->ROUTELOC0 = GPIO_ROUTELOC0_SWVLOC_LOC0;
|
||||
|
||||
/* Enable output on pin - GPIO Port F, Pin 2 */
|
||||
GPIO->P[5].MODEL &= ~(_GPIO_P_MODEL_MODE2_MASK);
|
||||
GPIO->P[5].MODEL |= GPIO_P_MODEL_MODE2_PUSHPULL;
|
||||
|
||||
/* Enable debug clock AUXHFRCO */
|
||||
CMU_OscillatorEnable(cmuOsc_AUXHFRCO, true, true);
|
||||
CMU->OSCENCMD = CMU_OSCENCMD_AUXHFRCOEN;
|
||||
|
||||
/* Wait until clock is ready */
|
||||
while (!(CMU->STATUS & CMU_STATUS_AUXHFRCORDY));
|
||||
|
||||
/* Enable trace in core debug */
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
ITM->LAR = 0xC5ACCE55;
|
||||
ITM->TER = 0x0;
|
||||
ITM->TCR = 0x0;
|
||||
TPI->SPPR = 2;
|
||||
TPI->ACPR = 0x15; // changed from 0x0F on Giant, etc. to account for 19 MHz default AUXHFRCO frequency
|
||||
ITM->TPR = 0x0;
|
||||
DWT->CTRL = 0x400003FE;
|
||||
ITM->TCR = 0x0001000D;
|
||||
TPI->FFCR = 0x00000100;
|
||||
ITM->TER = 0x1;
|
||||
}
|
||||
|
||||
|
||||
void printing_init()
|
||||
{
|
||||
setupSWOForPrint();
|
||||
}
|
||||
#else
|
||||
|
||||
int RETARGET_WriteChar(char c)
|
||||
{
|
||||
USART_Tx(USART0,c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RETARGET_ReadChar(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void printing_init()
|
||||
{
|
||||
// GPIO_PinModeSet(gpioPortA,5,gpioModePushPull,1); // VCOM enable
|
||||
}
|
||||
|
||||
#endif
|
475
efm32/src/retargetio.c
Normal file
475
efm32/src/retargetio.c
Normal file
@@ -0,0 +1,475 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Provide stdio retargeting for all supported toolchains.
|
||||
* @version 5.5.0
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2015 Silicon Labs, Inc. http://www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* This file is licensed under the Silabs License Agreement. See the file
|
||||
* "Silabs_License_Agreement.txt" for details. Before using this software for
|
||||
* any purpose, you must agree to the terms of that agreement.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup RetargetIo
|
||||
* @{ This module provide low-level stubs for retargetting stdio for all
|
||||
* supported toolchains.
|
||||
* The stubs are minimal yet sufficient implementations.
|
||||
* Refer to chapter 12 in the reference manual for newlib 1.17.0
|
||||
* for details on implementing newlib stubs.
|
||||
******************************************************************************/
|
||||
|
||||
extern int RETARGET_ReadChar(void);
|
||||
extern int RETARGET_WriteChar(char c);
|
||||
|
||||
#if !defined(__CROSSWORKS_ARM) && defined(__GNUC__)
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "em_device.h"
|
||||
|
||||
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
|
||||
int fileno(FILE *);
|
||||
/** @endcond */
|
||||
|
||||
int _close(int file);
|
||||
int _fstat(int file, struct stat *st);
|
||||
int _isatty(int file);
|
||||
int _lseek(int file, int ptr, int dir);
|
||||
int _read(int file, char *ptr, int len);
|
||||
caddr_t _sbrk(int incr);
|
||||
int _write(int file, const char *ptr, int len);
|
||||
|
||||
extern char _end; /**< Defined by the linker */
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Close a file.
|
||||
*
|
||||
* @param[in] file
|
||||
* File you want to close.
|
||||
*
|
||||
* @return
|
||||
* Returns 0 when the file is closed.
|
||||
*****************************************************************************/
|
||||
int _close(int file)
|
||||
{
|
||||
(void) file;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Exit the program.
|
||||
* @param[in] status The value to return to the parent process as the
|
||||
* exit status (not used).
|
||||
*****************************************************************************/
|
||||
void _exit(int status)
|
||||
{
|
||||
(void) status;
|
||||
while (1) {
|
||||
} /* Hang here forever... */
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Status of an open file.
|
||||
*
|
||||
* @param[in] file
|
||||
* Check status for this file.
|
||||
*
|
||||
* @param[in] st
|
||||
* Status information.
|
||||
*
|
||||
* @return
|
||||
* Returns 0 when st_mode is set to character special.
|
||||
*****************************************************************************/
|
||||
int _fstat(int file, struct stat *st)
|
||||
{
|
||||
(void) file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Get process ID.
|
||||
*****************************************************************************/
|
||||
int _getpid(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Query whether output stream is a terminal.
|
||||
*
|
||||
* @param[in] file
|
||||
* Descriptor for the file.
|
||||
*
|
||||
* @return
|
||||
* Returns 1 when query is done.
|
||||
*****************************************************************************/
|
||||
int _isatty(int file)
|
||||
{
|
||||
(void) file;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Send signal to process.
|
||||
* @param[in] pid Process id (not used).
|
||||
* @param[in] sig Signal to send (not used).
|
||||
*****************************************************************************/
|
||||
int _kill(int pid, int sig)
|
||||
{
|
||||
(void)pid;
|
||||
(void)sig;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Set position in a file.
|
||||
*
|
||||
* @param[in] file
|
||||
* Descriptor for the file.
|
||||
*
|
||||
* @param[in] ptr
|
||||
* Poiter to the argument offset.
|
||||
*
|
||||
* @param[in] dir
|
||||
* Directory whence.
|
||||
*
|
||||
* @return
|
||||
* Returns 0 when position is set.
|
||||
*****************************************************************************/
|
||||
int _lseek(int file, int ptr, int dir)
|
||||
{
|
||||
(void) file;
|
||||
(void) ptr;
|
||||
(void) dir;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Read from a file.
|
||||
*
|
||||
* @param[in] file
|
||||
* Descriptor for the file you want to read from.
|
||||
*
|
||||
* @param[in] ptr
|
||||
* Pointer to the chacaters that are beeing read.
|
||||
*
|
||||
* @param[in] len
|
||||
* Number of characters to be read.
|
||||
*
|
||||
* @return
|
||||
* Number of characters that have been read.
|
||||
*****************************************************************************/
|
||||
int _read(int file, char *ptr, int len)
|
||||
{
|
||||
int c, rxCount = 0;
|
||||
|
||||
(void) file;
|
||||
|
||||
while (len--) {
|
||||
if ((c = RETARGET_ReadChar()) != -1) {
|
||||
*ptr++ = c;
|
||||
rxCount++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rxCount <= 0) {
|
||||
return -1; /* Error exit */
|
||||
}
|
||||
|
||||
return rxCount;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Increase heap.
|
||||
*
|
||||
* @param[in] incr
|
||||
* Number of bytes you want increment the program's data space.
|
||||
*
|
||||
* @return
|
||||
* Rsturns a pointer to the start of the new area.
|
||||
*****************************************************************************/
|
||||
caddr_t _sbrk(int incr)
|
||||
{
|
||||
static char *heap_end;
|
||||
char *prev_heap_end;
|
||||
|
||||
if (heap_end == 0) {
|
||||
heap_end = &_end;
|
||||
}
|
||||
|
||||
prev_heap_end = heap_end;
|
||||
heap_end += incr;
|
||||
|
||||
return (caddr_t) prev_heap_end;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Write to a file.
|
||||
*
|
||||
* @param[in] file
|
||||
* Descriptor for the file you want to write to.
|
||||
*
|
||||
* @param[in] ptr
|
||||
* Pointer to the text you want to write
|
||||
*
|
||||
* @param[in] len
|
||||
* Number of characters to be written.
|
||||
*
|
||||
* @return
|
||||
* Number of characters that have been written.
|
||||
*****************************************************************************/
|
||||
int _write(int file, const char *ptr, int len)
|
||||
{
|
||||
int txCount;
|
||||
|
||||
(void) file;
|
||||
|
||||
for (txCount = 0; txCount < len; txCount++) {
|
||||
RETARGET_WriteChar(*ptr++);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
#endif /* !defined( __CROSSWORKS_ARM ) && defined( __GNUC__ ) */
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
/*******************
|
||||
*
|
||||
* Copyright 1998-2003 IAR Systems. All rights reserved.
|
||||
*
|
||||
* $Revision: 38614 $
|
||||
*
|
||||
* This is a template implementation of the "__write" function used by
|
||||
* the standard library. Replace it with a system-specific
|
||||
* implementation.
|
||||
*
|
||||
* The "__write" function should output "size" number of bytes from
|
||||
* "buffer" in some application-specific way. It should return the
|
||||
* number of characters written, or _LLIO_ERROR on failure.
|
||||
*
|
||||
* If "buffer" is zero then __write should perform flushing of
|
||||
* internal buffers, if any. In this case "handle" can be -1 to
|
||||
* indicate that all handles should be flushed.
|
||||
*
|
||||
* The template implementation below assumes that the application
|
||||
* provides the function "MyLowLevelPutchar". It should return the
|
||||
* character written, or -1 on failure.
|
||||
*
|
||||
********************/
|
||||
|
||||
#include <yfuns.h>
|
||||
#include <stdint.h>
|
||||
#include "em_common.h"
|
||||
|
||||
_STD_BEGIN
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Transmit buffer to USART1
|
||||
* @param buffer Array of characters to send
|
||||
* @param nbytes Number of bytes to transmit
|
||||
* @return Number of bytes sent
|
||||
*****************************************************************************/
|
||||
static int TxBuf(uint8_t *buffer, int nbytes)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
RETARGET_WriteChar(*buffer++);
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the __write implementation uses internal buffering, uncomment
|
||||
* the following line to ensure that we are called with "buffer" as 0
|
||||
* (i.e. flush) when the application terminates.
|
||||
*/
|
||||
size_t __write(int handle, const unsigned char * buffer, size_t size)
|
||||
{
|
||||
/* Remove the #if #endif pair to enable the implementation */
|
||||
|
||||
size_t nChars = 0;
|
||||
|
||||
if (buffer == 0) {
|
||||
/*
|
||||
* This means that we should flush internal buffers. Since we
|
||||
* don't we just return. (Remember, "handle" == -1 means that all
|
||||
* handles should be flushed.)
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This template only writes to "standard out" and "standard err",
|
||||
* for all other file handles it returns failure. */
|
||||
if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) {
|
||||
return _LLIO_ERROR;
|
||||
}
|
||||
|
||||
/* Hook into USART1 transmit function here */
|
||||
if (TxBuf((uint8_t *) buffer, size) != size) {
|
||||
return _LLIO_ERROR;
|
||||
} else {
|
||||
nChars = size;
|
||||
}
|
||||
|
||||
return nChars;
|
||||
}
|
||||
|
||||
size_t __read(int handle, unsigned char * buffer, size_t size)
|
||||
{
|
||||
/* Remove the #if #endif pair to enable the implementation */
|
||||
int nChars = 0;
|
||||
|
||||
/* This template only reads from "standard in", for all other file
|
||||
* handles it returns failure. */
|
||||
if (handle != _LLIO_STDIN) {
|
||||
return _LLIO_ERROR;
|
||||
}
|
||||
|
||||
for (/* Empty */; size > 0; --size) {
|
||||
int c = RETARGET_ReadChar();
|
||||
if (c < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer++ = c;
|
||||
++nChars;
|
||||
}
|
||||
|
||||
return nChars;
|
||||
}
|
||||
|
||||
_STD_END
|
||||
|
||||
#endif /* defined( __ICCARM__ ) */
|
||||
|
||||
#if defined(__CROSSWORKS_ARM)
|
||||
|
||||
/* Pass each of these function straight to the USART */
|
||||
int __putchar(int ch)
|
||||
{
|
||||
return(RETARGET_WriteChar(ch));
|
||||
}
|
||||
|
||||
int __getchar(void)
|
||||
{
|
||||
return(RETARGET_ReadChar());
|
||||
}
|
||||
|
||||
#endif /* defined( __CROSSWORKS_ARM ) */
|
||||
|
||||
#if defined(__CC_ARM)
|
||||
/******************************************************************************/
|
||||
/* RETARGET.C: 'Retarget' layer for target-dependent low level functions */
|
||||
/******************************************************************************/
|
||||
/* This file is part of the uVision/ARM development tools. */
|
||||
/* Copyright (c) 2005-2006 Keil Software. All rights reserved. */
|
||||
/* This software may only be used under the terms of a valid, current, */
|
||||
/* end user licence from KEIL for a compatible version of KEIL software */
|
||||
/* development tools. Nothing else gives you the right to use this software. */
|
||||
/******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* #pragma import(__use_no_semihosting_swi) */
|
||||
|
||||
struct __FILE{
|
||||
int handle;
|
||||
};
|
||||
|
||||
/**Standard output stream*/
|
||||
FILE __stdout;
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Writes character to file
|
||||
*
|
||||
* @param[in] f
|
||||
* File
|
||||
*
|
||||
* @param[in] ch
|
||||
* Character
|
||||
*
|
||||
* @return
|
||||
* Written character
|
||||
*****************************************************************************/
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
return(RETARGET_WriteChar(ch));
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Reads character from file
|
||||
*
|
||||
* @param[in] f
|
||||
* File
|
||||
*
|
||||
* @return
|
||||
* Character
|
||||
*****************************************************************************/
|
||||
int fgetc(FILE *f)
|
||||
{
|
||||
return(RETARGET_ReadChar());
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Tests the error indicator for the stream pointed
|
||||
* to by file
|
||||
*
|
||||
* @param[in] f
|
||||
* File
|
||||
*
|
||||
* @return
|
||||
* Returns non-zero if it is set
|
||||
*****************************************************************************/
|
||||
int ferror(FILE *f)
|
||||
{
|
||||
/* Your implementation of ferror */
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Writes a character to the console
|
||||
*
|
||||
* @param[in] ch
|
||||
* Character
|
||||
*****************************************************************************/
|
||||
void _ttywrch(int ch)
|
||||
{
|
||||
RETARGET_WriteChar(ch);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief
|
||||
* Library exit function. This function is called if stack
|
||||
* overflow occurs.
|
||||
*
|
||||
* @param[in] return_code
|
||||
* Return code
|
||||
*****************************************************************************/
|
||||
void _sys_exit(int return_code)
|
||||
{
|
||||
label: goto label;/* endless loop */
|
||||
}
|
||||
#endif /* defined( __CC_ARM ) */
|
||||
|
||||
/** @} (end group RetargetIo) */
|
Reference in New Issue
Block a user