move to targets/

This commit is contained in:
Conor Patrick
2018-09-12 21:25:40 -04:00
parent 364e552ae9
commit 86aa5ec657
26 changed files with 15 additions and 7739 deletions

308
targets/nrf52840/Makefile Normal file
View File

@@ -0,0 +1,308 @@
PROJECT_NAME := blinky_pca10056
TARGETS := nrf52840_xxaa
OUTPUT_DIRECTORY := _build
SDK_ROOT := ./sdk_15.0.0
PROJ_DIR := .
$(OUTPUT_DIRECTORY)/nrf52840_xxaa.out: \
LINKER_SCRIPT := blinky_gcc_nrf52.ld
# Source files common to all targets
SRC_FILES += \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \
$(PROJ_DIR)/../main.c \
$(PROJ_DIR)/usb.c \
$(PROJ_DIR)/retarget.c \
$(PROJ_DIR)/device.c \
$(PROJ_DIR)/../util.c \
$(PROJ_DIR)/../log.c \
$(PROJ_DIR)/../stubs.c \
$(PROJ_DIR)/../ctaphid.c \
$(PROJ_DIR)/../ctap.c \
$(PROJ_DIR)/../ctap_parse.c \
$(PROJ_DIR)/../u2f.c \
$(PROJ_DIR)/../test_power.c \
\
$(PROJ_DIR)/crypto.c \
$(PROJ_DIR)/../crypto/sha256.c \
$(PROJ_DIR)/../crypto/tiny-AES-c/aes.c \
$(PROJ_DIR)/../crypto/micro-ecc/uECC.c \
\
$(SDK_ROOT)/components/boards/boards.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/libraries/util/nrf_assert.c \
$(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
$(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_rtc.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \
\
$(SDK_ROOT)/components/libraries/button/app_button.c \
$(SDK_ROOT)/components/libraries/fifo/app_fifo.c \
$(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
$(SDK_ROOT)/components/libraries/timer/app_timer.c \
$(SDK_ROOT)/components/libraries/uart/app_uart_fifo.c \
$(SDK_ROOT)/components/libraries/usbd/app_usbd.c \
$(SDK_ROOT)/components/libraries/usbd/app_usbd_core.c \
$(SDK_ROOT)/components/libraries/usbd/class/hid/app_usbd_hid.c \
$(SDK_ROOT)/components/libraries/usbd/class/hid/generic/app_usbd_hid_generic.c \
$(SDK_ROOT)/components/libraries/usbd/class/hid/kbd/app_usbd_hid_kbd.c \
$(SDK_ROOT)/components/libraries/usbd/class/hid/mouse/app_usbd_hid_mouse.c \
$(SDK_ROOT)/components/libraries/usbd/app_usbd_string_desc.c \
$(SDK_ROOT)/external/fnmatch/fnmatch.c \
$(SDK_ROOT)/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c \
$(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c \
$(SDK_ROOT)/components/libraries/atomic_fifo/nrf_atfifo.c \
$(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \
$(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c \
$(SDK_ROOT)/components/libraries/experimental_memobj/nrf_memobj.c \
$(SDK_ROOT)/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c \
$(SDK_ROOT)/components/libraries/queue/nrf_queue.c \
$(SDK_ROOT)/components/libraries/experimental_ringbuf/nrf_ringbuf.c \
$(SDK_ROOT)/components/libraries/experimental_section_vars/nrf_section_iter.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_power.c \
$(SDK_ROOT)/components/drivers_nrf/usbd/nrf_drv_usbd.c \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd/nrf_nvic.c \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd/nrf_soc.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_power.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_power_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
$(SDK_ROOT)/components/libraries/bsp/bsp.c \
$(SDK_ROOT)/components/libraries/bsp/bsp_cli.c \
\
$(SDK_ROOT)/external/cifra_AES128-EAX/blockwise.c \
$(SDK_ROOT)/external/cifra_AES128-EAX/cifra_cmac.c \
$(SDK_ROOT)/external/cifra_AES128-EAX/cifra_eax_aes.c \
$(SDK_ROOT)/external/cifra_AES128-EAX/eax.c \
$(SDK_ROOT)/external/cifra_AES128-EAX/gf128.c \
$(SDK_ROOT)/components/libraries/mem_manager/mem_manager.c \
$(SDK_ROOT)/external/cifra_AES128-EAX/modes.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_rng.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_rng.c \
# Include folders common to all targets
INC_FOLDERS += \
$(SDK_ROOT)/components \
$(SDK_ROOT)/components/libraries/experimental_memobj \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/modules/nrfx/mdk \
$(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/components/libraries/balloc \
$(SDK_ROOT)/components/libraries/experimental_log \
$(SDK_ROOT)/components/libraries/experimental_log/src \
$(SDK_ROOT)/components/libraries/delay \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/components/libraries/bsp \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
$(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/components/boards \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/modules/nrfx \
$(SDK_ROOT)/external/segger_rtt \
$(PROJ_DIR) \
$(PROJ_DIR)/.. \
$(PROJ_DIR)/../tinycbor/src \
\
$(PROJ_DIR)/../crypto/ \
$(PROJ_DIR)/../crypto/micro-ecc \
$(PROJ_DIR)/../crypto/tiny-AES-c \
\
$(SDK_ROOT)/components/libraries/util \
$(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/modules/nrfx/drivers/include \
$(SDK_ROOT)/components/libraries/cli \
$(SDK_ROOT)/components/libraries/scheduler \
$(SDK_ROOT)/components/libraries/experimental_log \
$(SDK_ROOT)/components/libraries/queue \
$(SDK_ROOT)/components/libraries/pwr_mgmt \
$(SDK_ROOT)/components/libraries/fifo \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/components/libraries/timer \
$(SDK_ROOT)/components/libraries/bsp \
$(SDK_ROOT)/components/libraries/usbd/class/hid/generic \
$(SDK_ROOT)/components/libraries/usbd/class/hid/kbd \
$(SDK_ROOT)/components/libraries/balloc \
$(SDK_ROOT)/components/drivers_nrf/usbd \
$(SDK_ROOT)/components/libraries/usbd/class/hid \
$(SDK_ROOT)/components/libraries/hardfault/nrf52 \
$(SDK_ROOT)/components/libraries/hardfault \
$(SDK_ROOT)/components/libraries/uart \
$(SDK_ROOT)/external/fnmatch \
$(SDK_ROOT)/components/libraries/button \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/components/libraries/usbd \
$(SDK_ROOT)/components/libraries/mutex \
$(PROJ_DIR) \
$(SDK_ROOT)/components/libraries/experimental_log/src \
$(SDK_ROOT)/components/libraries/delay \
$(SDK_ROOT)/external/segger_rtt \
$(SDK_ROOT)/components/libraries/atomic_fifo \
$(SDK_ROOT)/components/libraries/experimental_ringbuf \
$(SDK_ROOT)/components/libraries/atomic \
$(SDK_ROOT)/components/boards \
$(SDK_ROOT)/components/libraries/experimental_memobj \
$(SDK_ROOT)/components/libraries/usbd/config \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
$(SDK_ROOT)/components/libraries/usbd/class/hid/mouse \
$(SDK_ROOT)/modules/nrfx/drivers/include \
$(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/external/fprintf \
\
$(SDK_ROOT)/external/fprintf \
$(PROJ_DIR) \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/components/libraries/experimental_log \
$(SDK_ROOT)/components/libraries/experimental_memobj \
$(SDK_ROOT)/components/libraries/stack_info \
$(SDK_ROOT)/components/libraries/delay \
$(SDK_ROOT)/external/nrf_oberon/include \
$(SDK_ROOT)/components/libraries/crypto \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/components/libraries/balloc \
$(SDK_ROOT)/components/libraries/mem_manager \
$(SDK_ROOT)/external/nrf_oberon \
$(SDK_ROOT)/components/libraries/atomic \
$(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/modules/nrfx/drivers/include \
$(SDK_ROOT)/external/mbedtls/include \
$(SDK_ROOT)/components/libraries/experimental_log/src \
$(SDK_ROOT)/components/libraries/util \
$(SDK_ROOT)/modules/nrfx \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
$(SDK_ROOT)/external/segger_rtt \
$(SDK_ROOT)/modules/nrfx/mdk \
$(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/components/libraries/mutex \
$(SDK_ROOT)/components/libraries/queue \
$(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/external/cifra_AES128-EAX \
$(SDK_ROOT)/components/boards \
$(SDK_ROOT)/external/nrf_cc310/include \
# Libraries common to all targets
LIB_FILES += $(SDK_ROOT)/external/nrf_cc310/lib/libnrf_cc310_0.9.9.a \
$(PROJ_DIR)/../tinycbor/lib/libtinycbor.a
# Optimization flags
OPT = -O3 -g3
# Uncomment the line below to enable link time optimization
#OPT += -flto
# C flags common to all targets
CFLAGS += $(OPT)
CFLAGS += -DBOARD_PCA10056
CFLAGS += -DNRF52
#CFLAGS += -DBSP_DEFINES_ONLY
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DNRF52840_XXAA
#CFLAGS += -DSTUB_CTAPHID
#CFLAGS += -DSTUB_CTAP
CFLAGS += -DuECC_PLATFORM=5
#CFLAGS += -DTEST_POWER -DTEST
CFLAGS += -std=gnu11
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs
CFLAGS += -Wall -Wno-format
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in a separate section, this allows linker to discard unused ones
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin -fshort-enums
CFLAGS += -DNRF_CRYPTO_MAX_INSTANCE_COUNT=1
# C++ flags common to all targets
CXXFLAGS += $(OPT)
# Assembler flags common to all targets
ASMFLAGS += -g3
ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -DBOARD_PCA10056
ASMFLAGS += -DBSP_DEFINES_ONLY
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += -DNRF52840_XXAA
# Linker flags
LDFLAGS += $(OPT)
LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# let linker dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs
nrf52840_xxaa: CFLAGS += -D__HEAP_SIZE=8192
nrf52840_xxaa: CFLAGS += -D__STACK_SIZE=8192
nrf52840_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192
nrf52840_xxaa: ASMFLAGS += -D__STACK_SIZE=8192
# Add standard libraries at the very end of the linker input, after all objects
# that may need symbols provided by these libraries.
LIB_FILES += -lc -lnosys -lm
.PHONY: default help
# Default target - first one defined
default: nrf52840_xxaa
# Print all targets that can be built
help:
@echo following targets are available:
@echo nrf52840_xxaa
@echo sdk_config - starting external tool for editing sdk_config.h
@echo flash - flashing binary
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
include $(TEMPLATE_PATH)/Makefile.common
#include $(PROJ_DIR)/../tinycbor/Makefile
#$(shell echo )
#$(shell )
$(foreach target, $(TARGETS), $(call define_target, $(target)))
.PHONY: flash erase
cbor:
cd $(PROJ_DIR)/../tinycbor/ && make clean
cd $(PROJ_DIR)/../tinycbor/ && make CC="$(CC)" \
LDFLAGS="-lc -lnosys --specs=nosys.specs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -mabi=aapcs " \
CFLAGS=" -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -mabi=aapcs -DFLOAT_ABI_HARD -std=gnu11"
# Flash the program
flash: $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex
@echo Flashing: $<
nrfjprog -f nrf52 --program $< --sectorerase
nrfjprog -f nrf52 --reset
erase:
nrfjprog -f nrf52 --eraseall
SDK_CONFIG_FILE := ../config/sdk_config.h
CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar
sdk_config:
java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)

View File

@@ -0,0 +1,45 @@
// <h> segger_rtt - SEGGER RTT
//==========================================================
// <o> SEGGER_RTT_CONFIG_BUFFER_SIZE_UP - Size of upstream buffer.
// <i> Note that either @ref NRF_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE
// <i> or this value is actually used. It depends on which one is bigger.
#ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_UP
#define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 4096
#endif
// <o> SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS - Size of upstream buffer.
#ifndef SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS
#define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 16
#endif
// <o> SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN - Size of upstream buffer.
#ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN
#define SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN 8
#endif
// <o> SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS - Size of upstream buffer.
#ifndef SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS
#define SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS 2
#endif
// <o> SEGGER_RTT_CONFIG_DEFAULT_MODE - RTT behavior if the buffer is full.
// <i> The following modes are supported:
// <i> - SKIP - Do not block, output nothing.
// <i> - TRIM - Do not block, output as much as fits.
// <i> - BLOCK - Wait until there is space in the buffer.
// <0=> SKIP
// <1=> TRIM
// <2=> BLOCK_IF_FIFO_FULL
#ifndef SEGGER_RTT_CONFIG_DEFAULT_MODE
#define SEGGER_RTT_CONFIG_DEFAULT_MODE 1
#define APP_FIFO_ENABLED 2
#endif

View File

@@ -0,0 +1,57 @@
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x100000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000
}
SECTIONS
{
}
SECTIONS
{
. = ALIGN(4);
.mem_section_dummy_ram :
{
}
.log_dynamic_data :
{
PROVIDE(__start_log_dynamic_data = .);
KEEP(*(SORT(.log_dynamic_data*)))
PROVIDE(__stop_log_dynamic_data = .);
} > RAM
} INSERT AFTER .data;
SECTIONS
{
.mem_section_dummy_rom :
{
}
.crypto_data :
{
PROVIDE(__start_crypto_data = .);
KEEP(*(SORT(.crypto_data*)))
PROVIDE(__stop_crypto_data = .);
} > FLASH
.log_const_data :
{
PROVIDE(__start_log_const_data = .);
KEEP(*(SORT(.log_const_data*)))
PROVIDE(__stop_log_const_data = .);
} > FLASH
.nrf_balloc :
{
PROVIDE(__start_nrf_balloc = .);
KEEP(*(.nrf_balloc))
PROVIDE(__stop_nrf_balloc = .);
} > FLASH
} INSERT AFTER .text
INCLUDE "nrf_common.ld"

468
targets/nrf52840/crypto.c Normal file
View File

@@ -0,0 +1,468 @@
/*
* Wrapper for crypto implementation on device
*
* */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
#include "crypto.h"
#include "sha256.h"
#include "uECC.h"
#include "aes.h"
#include "ctap.h"
#include "ssi_pal_types.h"
#include "ssi_pal_mem.h"
#include "sns_silib.h"
#include "crys_ecpki_build.h"
#include "crys_ecpki_ecdsa.h"
#include "crys_ecpki_dh.h"
#include "crys_ecpki_kg.h"
#include "crys_ecpki_domain.h"
#include "crys_rnd.h"
#include "nrf52840.h"
const uint8_t attestation_cert_der[];
const uint16_t attestation_cert_der_size;
const uint8_t attestation_key[];
const uint16_t attestation_key_size;
/*static SHA256_CTX sha256_ctx;*/
struct CRYS_HASHUserContext_t sha256_ctx;
const CRYS_ECPKI_Domain_t* _es256_curve;
CRYS_RND_State_t rndState_ptr;
CRYS_RND_WorkBuff_t rndWorkBuff_ptr;
static const uint8_t * _signing_key = NULL;
// Secrets for testing only
static uint8_t master_secret[32] = "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
"\xff\xee\xdd\xcc\xbb\xaa\x99\x88\x77\x66\x55\x44\x33\x22\x11\x00";
static uint8_t transport_secret[32] = "\x10\x01\x22\x33\x44\x55\x66\x77\x87\x90\x0a\xbb\x3c\xd8\xee\xff"
"\xff\xee\x8d\x1c\x3b\xfa\x99\x88\x77\x86\x55\x44\xd3\xff\x33\x00";
void crypto_sha256_init()
{
/*sha256_init(&sha256_ctx);*/
int ret = CRYS_HASH_Init(&sha256_ctx, CRYS_HASH_SHA256_mode);
if (ret != CRYS_OK )
{
printf("sha init fail\n");
exit(1);
}
}
void crypto_reset_master_secret()
{
ctap_generate_rng(master_secret, 32);
}
void crypto_sha256_update(uint8_t * data, size_t len)
{
/*sha256_update(&sha256_ctx, data, len);*/
int ret = CRYS_HASH_Update(&sha256_ctx, data, len);
if (ret != CRYS_OK )
{
printf("sha update fail\n");
exit(1);
}
}
void crypto_sha256_update_secret()
{
/*sha256_update(&sha256_ctx, master_secret, 32);*/
int ret = CRYS_HASH_Update(&sha256_ctx, master_secret, 32);
if (ret != CRYS_OK )
{
printf("sha update secret fail\n");
exit(1);
}
}
void crypto_sha256_final(uint8_t * hash)
{
/*sha256_final(&sha256_ctx, hash);*/
int ret = CRYS_HASH_Finish(&sha256_ctx, (uint32_t*)hash);
if (ret != CRYS_OK )
{
printf("sha finish fail\n");
exit(1);
}
}
void crypto_sha256_hmac_init(uint8_t * key, uint32_t klen, uint8_t * hmac)
{
uint8_t buf[64];
int i;
memset(buf, 0, sizeof(buf));
if (key == CRYPTO_MASTER_KEY)
{
key = master_secret;
klen = sizeof(master_secret);
}
if(klen > 64)
{
printf("Error, key size must be <= 64\n");
exit(1);
}
memmove(buf, key, klen);
for (i = 0; i < sizeof(buf); i++)
{
buf[i] = buf[i] ^ 0x36;
}
crypto_sha256_init();
crypto_sha256_update(buf, 64);
}
void crypto_sha256_hmac_final(uint8_t * key, uint32_t klen, uint8_t * hmac)
{
uint8_t buf[64];
int i;
crypto_sha256_final(hmac);
memset(buf, 0, sizeof(buf));
if (key == CRYPTO_MASTER_KEY)
{
key = master_secret;
klen = sizeof(master_secret);
}
if(klen > 64)
{
printf("Error, key size must be <= 64\n");
exit(1);
}
memmove(buf, key, klen);
for (i = 0; i < sizeof(buf); i++)
{
buf[i] = buf[i] ^ 0x5c;
}
crypto_sha256_init();
crypto_sha256_update(buf, 64);
crypto_sha256_update(hmac, 32);
crypto_sha256_final(hmac);
}
void crypto_ecc256_init()
{
int ret;
NVIC_EnableIRQ(CRYPTOCELL_IRQn);
NRF_CRYPTOCELL->ENABLE = 1;
ret = SaSi_LibInit();
if (ret != SA_SILIB_RET_OK) {
printf("Failed SaSi_LibInit - ret = 0x%x\n", ret);
exit(1);
}
memset(&rndState_ptr, 0, sizeof(CRYS_RND_State_t));
memset(&rndWorkBuff_ptr, 0, sizeof(CRYS_RND_WorkBuff_t));
ret = CRYS_RndInit(&rndState_ptr, &rndWorkBuff_ptr);
if (ret != SA_SILIB_RET_OK) {
printf("Failed CRYS_RndInit - ret = 0x%x\n", ret);
exit(1);
}
_es256_curve = CRYS_ECPKI_GetEcDomain(CRYS_ECPKI_DomainID_secp256r1);
//
uECC_set_rng((uECC_RNG_Function)ctap_generate_rng);
//
}
void crypto_ecc256_load_attestation_key()
{
_signing_key = attestation_key;
}
void crypto_ecc256_sign(uint8_t * data, int len, uint8_t * sig)
{
CRYS_ECPKI_UserPrivKey_t UserPrivKey;
CRYS_ECDSA_SignUserContext_t SignUserContext;
uint32_t sigsz = 64;
int ret = CRYS_ECPKI_BuildPrivKey(_es256_curve,
_signing_key,
32,
&UserPrivKey);
if (ret != SA_SILIB_RET_OK){
printf(" CRYS_ECPKI_BuildPrivKey failed with 0x%x \n",ret);
exit(1);
}
ret = CRYS_ECDSA_Sign(&rndState_ptr,
CRYS_RND_GenerateVector,
&SignUserContext,
&UserPrivKey,
CRYS_ECPKI_AFTER_HASH_SHA256_mode,
data,
len,
sig,
&sigsz);
if (ret != SA_SILIB_RET_OK){
printf(" CRYS_ECDSA_Sign failed with 0x%x \n",ret);
exit(1);
}
}
/*int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key, uECC_Curve curve);*/
void derive_private_key_pair(uint8_t * data, int len, uint8_t * data2, int len2, uint8_t * privkey, uint8_t * pubkey);
void crypto_ecc256_derive_public_key(uint8_t * data, int len, uint8_t * x, uint8_t * y)
{
uint8_t privkey[32];
uint8_t pubkey[64];
derive_private_key_pair(data,len,NULL,0,privkey,pubkey);
/*memset(pubkey,0,sizeof(pubkey));*/
/*uECC_compute_public_key(privkey, pubkey, uECC_secp256r1());*/
memmove(x,pubkey,32);
memmove(y,pubkey+32,32);
}
void crypto_ecc256_load_key(uint8_t * data, int len, uint8_t * data2, int len2)
{
static uint8_t privkey[32];
generate_private_key(data,len,data2,len2,privkey);
_signing_key = privkey;
}
void crypto_ecc256_make_key_pair(uint8_t * pubkey, uint8_t * privkey)
{
CRYS_ECPKI_UserPrivKey_t nrfpriv;
CRYS_ECPKI_UserPublKey_t nrfpub;
CRYS_ECPKI_KG_TempData_t tmp;
uint8_t pubkey1[65];
int ret;
uint32_t sz;
ret = CRYS_ECPKI_GenKeyPair(&rndState_ptr,
CRYS_RND_GenerateVector,
_es256_curve,
&nrfpriv, &nrfpub, &tmp, NULL);
if (ret != SA_SILIB_RET_OK){
printf(" gen key failed with 0x%x \n",ret);
exit(1);
}
sz = 32;
CRYS_ECPKI_ExportPrivKey(&nrfpriv, privkey, &sz);
sz = 65;
CRYS_ECPKI_ExportPublKey(&nrfpub,CRYS_EC_PointUncompressed, pubkey1, &sz);
memmove(pubkey, pubkey1+1, 64);
}
void crypto_ecc256_shared_secret(const uint8_t * pubkey, const uint8_t * privkey, uint8_t * shared_secret)
{
if (uECC_shared_secret(pubkey, privkey, shared_secret, uECC_secp256r1()) != 1)
{
printf("Error, uECC_shared_secret failed\n");
exit(1);
}
}
uint8_t fixed_vector_hmac[32];
int fixed_vector_iter = 31;
uint32_t fixed_vector(void * rng, uint16_t sz, uint8_t * out)
{
while(sz--)
{
*out++ = fixed_vector_hmac[fixed_vector_iter--];
if (fixed_vector_iter == -1)
{
fixed_vector_iter = 31;
}
}
return 0;
}
void derive_private_key_pair(uint8_t * data, int len, uint8_t * data2, int len2, uint8_t * privkey, uint8_t * pubkey)
{
CRYS_ECPKI_UserPrivKey_t nrfpriv;
CRYS_ECPKI_UserPublKey_t nrfpub;
CRYS_ECPKI_KG_TempData_t tmp;
uint32_t ret;
uint32_t sz;
int i;
uint8_t pubkey1[65];
crypto_sha256_hmac_init(CRYPTO_MASTER_KEY, 0, privkey);
crypto_sha256_update(data, len);
crypto_sha256_update(data2, len2);
crypto_sha256_update(master_secret, 32);
crypto_sha256_hmac_final(CRYPTO_MASTER_KEY, 0, privkey);
memmove(fixed_vector_hmac, privkey, 32);
fixed_vector_iter=31;
/*privkey[31] += 1;*/
for (i = 31; i > -1; i++)
{
privkey[i] += 1;
if (privkey[i] != 0)
break;
}
// There isn't a CC310 function for calculating a public key from a private,
// so to get around it, we can "fix" the RNG input to GenKeyPair
if(pubkey != NULL)
{
ret = CRYS_ECPKI_GenKeyPair(&rndState_ptr,
fixed_vector,
/*CRYS_RND_GenerateVector,*/
_es256_curve,
&nrfpriv, &nrfpub, &tmp, NULL);
if (ret != SA_SILIB_RET_OK){
printf(" gen key failed with 0x%x \n",ret);
exit(1);
}
/*sz = 32;*/
/*ret = CRYS_ECPKI_ExportPrivKey(&nrfpriv, privkey, &sz);*/
/*if (ret != 0)*/
/*{*/
/*printf("privkey export fail\n");*/
/*exit(1);*/
/*}*/
sz = 65;
ret = CRYS_ECPKI_ExportPublKey(&nrfpub,CRYS_EC_PointUncompressed , pubkey1, &sz);
if (ret != 0 || sz != 65)
{
printf("pubkey export fail 0x%04x\n",ret);
exit(1);
}
if (pubkey1[0] != 0x04)
{
printf("pubkey uncompressed export fail 0x%02x\n",(int)pubkey1[0]);
exit(1);
}
memmove(pubkey, pubkey1+1 , 64);
}
}
void generate_private_key(uint8_t * data, int len, uint8_t * data2, int len2, uint8_t * privkey)
{
derive_private_key_pair(data,len,data2,len2,privkey,NULL);
}
struct AES_ctx aes_ctx;
void crypto_aes256_init(uint8_t * key, uint8_t * nonce)
{
if (key == CRYPTO_TRANSPORT_KEY)
{
AES_init_ctx(&aes_ctx, transport_secret);
}
else
{
AES_init_ctx(&aes_ctx, key);
}
if (nonce == NULL)
{
memset(aes_ctx.Iv, 0, 16);
}
else
{
memmove(aes_ctx.Iv, nonce, 16);
}
}
// prevent round key recomputation
void crypto_aes256_reset_iv(uint8_t * nonce)
{
if (nonce == NULL)
{
memset(aes_ctx.Iv, 0, 16);
}
else
{
memmove(aes_ctx.Iv, nonce, 16);
}
}
void crypto_aes256_decrypt(uint8_t * buf, int length)
{
AES_CBC_decrypt_buffer(&aes_ctx, buf, length);
}
void crypto_aes256_encrypt(uint8_t * buf, int length)
{
AES_CBC_encrypt_buffer(&aes_ctx, buf, length);
}
const uint8_t attestation_cert_der[] =
"\x30\x82\x01\xfb\x30\x82\x01\xa1\xa0\x03\x02\x01\x02\x02\x01\x00\x30\x0a\x06\x08"
"\x2a\x86\x48\xce\x3d\x04\x03\x02\x30\x2c\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13"
"\x02\x55\x53\x31\x0b\x30\x09\x06\x03\x55\x04\x08\x0c\x02\x4d\x44\x31\x10\x30\x0e"
"\x06\x03\x55\x04\x0a\x0c\x07\x54\x45\x53\x54\x20\x43\x41\x30\x20\x17\x0d\x31\x38"
"\x30\x35\x31\x30\x30\x33\x30\x36\x32\x30\x5a\x18\x0f\x32\x30\x36\x38\x30\x34\x32"
"\x37\x30\x33\x30\x36\x32\x30\x5a\x30\x7c\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13"
"\x02\x55\x53\x31\x0b\x30\x09\x06\x03\x55\x04\x08\x0c\x02\x4d\x44\x31\x0f\x30\x0d"
"\x06\x03\x55\x04\x07\x0c\x06\x4c\x61\x75\x72\x65\x6c\x31\x15\x30\x13\x06\x03\x55"
"\x04\x0a\x0c\x0c\x54\x45\x53\x54\x20\x43\x4f\x4d\x50\x41\x4e\x59\x31\x22\x30\x20"
"\x06\x03\x55\x04\x0b\x0c\x19\x41\x75\x74\x68\x65\x6e\x74\x69\x63\x61\x74\x6f\x72"
"\x20\x41\x74\x74\x65\x73\x74\x61\x74\x69\x6f\x6e\x31\x14\x30\x12\x06\x03\x55\x04"
"\x03\x0c\x0b\x63\x6f\x6e\x6f\x72\x70\x70\x2e\x63\x6f\x6d\x30\x59\x30\x13\x06\x07"
"\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48\xce\x3d\x03\x01\x07\x03\x42\x00"
"\x04\x45\xa9\x02\xc1\x2e\x9c\x0a\x33\xfa\x3e\x84\x50\x4a\xb8\x02\xdc\x4d\xb9\xaf"
"\x15\xb1\xb6\x3a\xea\x8d\x3f\x03\x03\x55\x65\x7d\x70\x3f\xb4\x02\xa4\x97\xf4\x83"
"\xb8\xa6\xf9\x3c\xd0\x18\xad\x92\x0c\xb7\x8a\x5a\x3e\x14\x48\x92\xef\x08\xf8\xca"
"\xea\xfb\x32\xab\x20\xa3\x62\x30\x60\x30\x46\x06\x03\x55\x1d\x23\x04\x3f\x30\x3d"
"\xa1\x30\xa4\x2e\x30\x2c\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x55\x53\x31"
"\x0b\x30\x09\x06\x03\x55\x04\x08\x0c\x02\x4d\x44\x31\x10\x30\x0e\x06\x03\x55\x04"
"\x0a\x0c\x07\x54\x45\x53\x54\x20\x43\x41\x82\x09\x00\xf7\xc9\xec\x89\xf2\x63\x94"
"\xd9\x30\x09\x06\x03\x55\x1d\x13\x04\x02\x30\x00\x30\x0b\x06\x03\x55\x1d\x0f\x04"
"\x04\x03\x02\x04\xf0\x30\x0a\x06\x08\x2a\x86\x48\xce\x3d\x04\x03\x02\x03\x48\x00"
"\x30\x45\x02\x20\x18\x38\xb0\x45\x03\x69\xaa\xa7\xb7\x38\x62\x01\xaf\x24\x97\x5e"
"\x7e\x74\x64\x1b\xa3\x7b\xf7\xe6\xd3\xaf\x79\x28\xdb\xdc\xa5\x88\x02\x21\x00\xcd"
"\x06\xf1\xe3\xab\x16\x21\x8e\xd8\xc0\x14\xaf\x09\x4f\x5b\x73\xef\x5e\x9e\x4b\xe7"
"\x35\xeb\xdd\x9b\x6d\x8f\x7d\xf3\xc4\x3a\xd7";
const uint16_t attestation_cert_der_size = sizeof(attestation_cert_der)-1;
const uint8_t attestation_key[] = "\xcd\x67\xaa\x31\x0d\x09\x1e\xd1\x6e\x7e\x98\x92\xaa\x07\x0e\x19\x94\xfc\xd7\x14\xae\x7c\x40\x8f\xb9\x46\xb7\x2e\x5f\xe7\x5d\x30";
const uint16_t attestation_key_size = sizeof(attestation_key)-1;

265
targets/nrf52840/device.c Normal file
View File

@@ -0,0 +1,265 @@
/*
* Device specific functionality here
* */
#define DEBUG
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "nrf.h"
#include "nrf_error.h"
#include "nrf_drv_power.h"
#include "nrf_strerror.h"
#include "nrf_drv_rtc.h"
#include "nrf_drv_clock.h"
#include "nrf_drv_usbd.h"
#include "nrf_gpio.h"
#include "bsp.h"
#include "app_error.h"
#include "app_fifo.h"
#include "util.h"
#include "usb.h"
#include "device.h"
#include "cbor.h"
#include "log.h"
extern int _SEGGER_TERM;
void set_output_terminal(uint32_t term)
{
_SEGGER_TERM = term;
}
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{
error_info_t * e = (error_info_t *)info;
printf("Error: %d: %s at %d:%s\n",e->err_code, nrf_strerror_get(e->err_code), e->line_num, e->p_file_name);
while(1)
;
}
void log_resetreason(void)
{
/* Reset reason */
uint32_t rr = nrf_power_resetreas_get();
printf("Reset reasons:\n");
if (0 == rr)
{
printf("- NONE\n");
}
if (0 != (rr & NRF_POWER_RESETREAS_RESETPIN_MASK))
{
printf("- RESETPIN\n");
}
if (0 != (rr & NRF_POWER_RESETREAS_DOG_MASK ))
{
printf("- DOG\n");
}
if (0 != (rr & NRF_POWER_RESETREAS_SREQ_MASK ))
{
printf("- SREQ\n");
}
if (0 != (rr & NRF_POWER_RESETREAS_LOCKUP_MASK ))
{
printf("- LOCKUP\n");
}
if (0 != (rr & NRF_POWER_RESETREAS_OFF_MASK ))
{
printf("- OFF\n");
}
if (0 != (rr & NRF_POWER_RESETREAS_LPCOMP_MASK ))
{
printf("- LPCOMP\n");
}
if (0 != (rr & NRF_POWER_RESETREAS_DIF_MASK ))
{
printf("- DIF\n");
}
if (0 != (rr & NRF_POWER_RESETREAS_NFC_MASK ))
{
printf("- NFC\n");
}
if (0 != (rr & NRF_POWER_RESETREAS_VBUS_MASK ))
{
printf("- VBUS\n");
}
}
static const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(0); /**< Declaring an instance of nrf_drv_rtc for RTC0. */
uint64_t millis()
{
return (uint64_t)nrf_drv_rtc_counter_get(&rtc);
}
static void rtc_config(void)
{
uint32_t err_code;
//Initialize RTC instance
nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
config.prescaler = 32;
err_code = nrf_drv_rtc_init(&rtc, &config, NULL);
APP_ERROR_CHECK(err_code);
//Power on RTC instance
nrf_drv_rtc_enable(&rtc);
}
static void init_power_clock(void)
{
ret_code_t ret;
/* Initializing power and clock */
ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
ret = nrf_drv_power_init(NULL);
APP_ERROR_CHECK(ret);
nrf_drv_clock_hfclk_request(NULL);
nrf_drv_clock_lfclk_request(NULL);
while (!(nrf_drv_clock_hfclk_is_running() &&
nrf_drv_clock_lfclk_is_running()))
{
/* Just waiting */
}
}
void device_init()
{
if ((nrf_power_resetreas_get() & NRF_POWER_RESETREAS_RESETPIN_MASK) == 0)
{
// Hard reset. this is for engineering A sample to work for USB ...
nrf_power_resetreas_clear(nrf_power_resetreas_get());
nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0,31));
nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(0,31));
while (1)
;
}
nrf_power_resetreas_clear(nrf_power_resetreas_get());
set_output_terminal(0);
init_power_clock();
rtc_config();
usbhid_init();
srand(millis());
nrf_gpio_cfg_output(LED_1);
nrf_gpio_cfg_output(LED_2);
nrf_gpio_cfg_output(LED_3);
nrf_gpio_cfg_output(LED_4);
nrf_gpio_pin_toggle(LED_2);
nrf_gpio_pin_toggle(LED_3);
}
static uint8_t fifo_buf[1024];
app_fifo_t USBHID_RECV_FIFO;
void usbhid_init()
{
#ifndef TEST_POWER
app_fifo_init(&USBHID_RECV_FIFO, fifo_buf, sizeof(fifo_buf));
usb_init();
#endif
}
// Receive 64 byte USB HID message, don't block, return size of packet, return 0 if nothing
#ifndef TEST_POWER
int usbhid_recv(uint8_t * msg)
{
uint32_t size = 64;
app_fifo_read(&USBHID_RECV_FIFO, msg, &size);
return size;
}
#endif
// Send 64 byte USB HID message
void usbhid_send(uint8_t * msg)
{
static nrf_drv_usbd_transfer_t transfer;
transfer.p_data.tx = msg;
transfer.size = 64;
while (nrf_drv_usbd_ep_is_busy(NRF_DRV_USBD_EPIN1))
;
nrf_drv_usbd_ep_transfer(
NRF_DRV_USBD_EPIN1,
&transfer);
}
void usbhid_close()
{
}
void main_loop_delay()
{
// no delay on embedded system
}
void heartbeat()
{
nrf_gpio_pin_toggle(LED_1);
nrf_gpio_pin_toggle(LED_2);
nrf_gpio_pin_toggle(LED_3);
nrf_gpio_pin_toggle(LED_4);
}
#ifndef TEST_POWER
void ctaphid_write_block(uint8_t * data)
{
printf1(TAG_DUMP,"<< "); dump_hex1(TAG_DUMP,data, 64);
usbhid_send(data);
}
#endif
int ctap_user_presence_test()
{
return 1;
}
int ctap_user_verification(uint8_t arg)
{
return 1;
}
uint32_t ctap_atomic_count(int sel)
{
static uint32_t counter1 = 25;
static uint32_t counter2 = 25;
/*return 713;*/
if (sel == 0)
{
printf1(TAG_RED,"counter1: %d\n", counter1);
return counter1++;
}
else
{
return counter2++;
}
}
int ctap_generate_rng(uint8_t * dst, size_t num)
{
int i;
for (i = 0; i < num; i++)
{
*dst++ = (uint8_t)rand();
}
return 1;
}

21
targets/nrf52840/list.py Normal file
View File

@@ -0,0 +1,21 @@
from fido2.hid import CtapHidDevice
from fido2.client import Fido2Client
from fido2.pyu2f import hidtransport
import sys
from random import randint
import array
# Locate a device
for d in CtapHidDevice.list_devices():
print(d)
#selector = hidtransport.HidUsageSelector
#for d in hidtransport.hid.Enumerate():
#print('1',d)
#if selector(d):
#try:
#dev = hidtransport.hid.Open(d['path'])
#print('2',dev)
#except OSError:
## Insufficient permissions to access device
#pass

101
targets/nrf52840/main.c Normal file
View File

@@ -0,0 +1,101 @@
/**
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
*
* @defgroup blinky_example_main main.c
* @{
* @ingroup blinky_example
* @brief Blinky Example Application main file.
*
* This file contains the source code for a sample application to blink LEDs.
*
*/
#define DEBUG
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "nrf.h"
#include "nrf_delay.h"
#include "boards.h"
#include "device.h"
#include "time.h"
#include "util.h"
int main(void)
{
/* Configure board. */
uint8_t hidmsg[64];
uint32_t count = 0;
uint32_t beat = 0;
uint32_t t1 = 0;
printf("hello FIDO2\r\n");
device_init();
while(1)
{
if (millis() - t1 > 1000)
{
printf("heartbeat %ld\n", beat++);
t1 = millis();
}
if (usbhid_recv(hidmsg) > 0)
{
printf("%d>> ",count++); dump_hex(hidmsg,sizeof(hidmsg));
/*ctaphid_handle_packet(hidmsg);*/
memset(hidmsg, 0, sizeof(hidmsg));
}
/*u2f_hid_check_timeouts();*/
main_loop_delay();
}
}

View File

@@ -0,0 +1,18 @@
#!/usr/bin/python
import serial, sys
from sys import argv
if len(argv) not in [2,3]:
print('usage: %s <com-port> [baud-rate]' % argv[0])
sys.exit(1)
baud = 115200
if len(argv) > 2:
baud = int(argv[2])
ser = serial.Serial(argv[1],baud)
print('reading..')
sys.stdout.flush()
while True:
sys.stdout.write(ser.read())

View File

@@ -0,0 +1,81 @@
#include "nrf.h"
#include "SEGGER_RTT.h"
int _SEGGER_TERM = 0;
void set_logging_tag(uint32_t tag)
{
int term = 0;
while (tag)
{
if (tag & 1)
break;
term++;
tag = tag >> 1;
}
_SEGGER_TERM = term;
}
#if defined(__CC_ARM)
int fgetc(FILE * p_file)
{
return '0';
}
int fputc(int ch, FILE * p_file)
{
SEGGER_RTT_PutChar(_SEGGER_TERM, ch);
return ch;
}
#elif defined(__GNUC__) && defined(__SES_ARM)
int __getchar(FILE * p_file)
{
return '0';
}
int __putchar(int ch, FILE * p_file)
{
SEGGER_RTT_PutChar(_SEGGER_TERM, ch);
return ch;
}
#elif defined(__GNUC__) && !defined(__SES_ARM)
int _write(int file, const char * p_char, int len)
{
int i;
static int lastterm = -1;
/*char buf[2];*/
/*buf[1] = 0;*/
UNUSED_PARAMETER(file);
if (_SEGGER_TERM != lastterm)
{
SEGGER_RTT_SetTerminal(_SEGGER_TERM);
lastterm = _SEGGER_TERM;
}
for (i = 0; i < len; i++)
{
/*buf[0] = *p_char++;*/
SEGGER_RTT_PutChar(0, *p_char++);
/*SEGGER_RTT_TerminalOut(_SEGGER_TERM, buf);*/
}
return len;
}
int _read(int file, char * p_char, int len)
{
*p_char = '0';
return 1;
}
#else
/*#elif defined(__ICCARM__)*/
#error "No read/write for printing implemented for compiler"
#endif

12131
targets/nrf52840/sdk_config.h Normal file

File diff suppressed because it is too large Load Diff

1147
targets/nrf52840/usb.c Normal file

File diff suppressed because it is too large Load Diff

10
targets/nrf52840/usb.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef _USB_H
#define _USB_H
#include "app_fifo.h"
void usb_init(void);
extern app_fifo_t USBHID_RECV_FIFO;
#endif

View File

@@ -0,0 +1 @@