From d79674db09dd5085fb71a704644390e04233e85f Mon Sep 17 00:00:00 2001 From: Sebastian Holzapfel Date: Sun, 11 Feb 2018 09:39:13 +1100 Subject: [PATCH] tests: gadget0: efm32hg: add gadget0 test for efm32hg --- tests/gadget-zero/Makefile.efm32hg309-generic | 44 ++++++++++++++ tests/gadget-zero/delay_efm32.c | 45 +++++++++++++++ tests/gadget-zero/main-efm32hg309-generic.c | 57 +++++++++++++++++++ .../openocd.efm32hg309-generic.cfg | 14 +++++ 4 files changed, 160 insertions(+) create mode 100644 tests/gadget-zero/Makefile.efm32hg309-generic create mode 100644 tests/gadget-zero/delay_efm32.c create mode 100644 tests/gadget-zero/main-efm32hg309-generic.c create mode 100644 tests/gadget-zero/openocd.efm32hg309-generic.cfg diff --git a/tests/gadget-zero/Makefile.efm32hg309-generic b/tests/gadget-zero/Makefile.efm32hg309-generic new file mode 100644 index 00000000..00eac7d7 --- /dev/null +++ b/tests/gadget-zero/Makefile.efm32hg309-generic @@ -0,0 +1,44 @@ +## +## This file is part of the libopencm3 project. +## +## This library is free software: you can redistribute it and/or modify +## it under the terms of the GNU Lesser General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This library is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public License +## along with this library. If not, see . +## + +BOARD = efm32hg309-generic +PROJECT = usb-gadget0-$(BOARD) +BUILD_DIR = bin-$(BOARD) + +SHARED_DIR = ../shared + +CFILES = main-$(BOARD).c +CFILES += usb-gadget0.c +CFILES += delay_efm32.c + +VPATH += $(SHARED_DIR) + +INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) + +OPENCM3_DIR=../.. + +### This section can go to an arch shared rules eventually... +LDSCRIPT = ../../lib/efm32/hg/efm32hg309f64.ld +OPENCM3_LIB = opencm3_efm32hg +OPENCM3_DEFS = -DEFM32HG +FP_FLAGS ?= -mfloat-abi=soft +ARCH_FLAGS = -mthumb -mcpu=cortex-m0plus $(FP_FLAGS) +#OOCD_INTERFACE = stlink-v2-1 +#OOCD_TARGET = efm32 +OOCD_FILE = openocd.efm32hg309-generic.cfg + +include ../rules.mk diff --git a/tests/gadget-zero/delay_efm32.c b/tests/gadget-zero/delay_efm32.c new file mode 100644 index 00000000..0e94d26f --- /dev/null +++ b/tests/gadget-zero/delay_efm32.c @@ -0,0 +1,45 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2018 Seb Holzapfel + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include +#include +#include + +#include "delay.h" + +extern const uint32_t ahb_frequency; + +void delay_setup(void) +{ + cmu_periph_clock_enable(CMU_TIMER2); + /* efm32hg doesn't support a nice 1us prescaler */ + timer_start(TIMER2); +} + +void delay_us(uint16_t us) +{ + volatile uint16_t time_now = 0; + /* Convert microseconds into timer ticks */ + uint16_t delay_ahb_cycles = us * (ahb_frequency / 1000000); + + TIMER2_CNT = 0; + while (time_now < delay_ahb_cycles) { + time_now = TIMER2_CNT; + } +} diff --git a/tests/gadget-zero/main-efm32hg309-generic.c b/tests/gadget-zero/main-efm32hg309-generic.c new file mode 100644 index 00000000..503ef191 --- /dev/null +++ b/tests/gadget-zero/main-efm32hg309-generic.c @@ -0,0 +1,57 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2015 Karl Palsson + * Copyright (C) 2018 Seb Holzapfel + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include +#include +#include +#include + +#include +#include "usb-gadget0.h" + +/* no trace on cm0 #define ER_DEBUG */ +#ifdef ER_DEBUG +#define ER_DPRINTF(fmt, ...) \ + do { printf(fmt, ## __VA_ARGS__); } while (0) +#else +#define ER_DPRINTF(fmt, ...) \ + do { } while (0) +#endif + +const uint32_t ahb_frequency = 14000000; + +#include "trace.h" +void trace_send_blocking8(int stimulus_port, char c) +{ + (void)stimulus_port; + (void)c; +} + +int main(void) +{ + usbd_device *usbd_dev = gadget0_init(&efm32hg_usb_driver, + "efm32hg309-generic"); + + ER_DPRINTF("bootup complete\n"); + + while (1) { + gadget0_run(usbd_dev); + } +} diff --git a/tests/gadget-zero/openocd.efm32hg309-generic.cfg b/tests/gadget-zero/openocd.efm32hg309-generic.cfg new file mode 100644 index 00000000..39d2c03d --- /dev/null +++ b/tests/gadget-zero/openocd.efm32hg309-generic.cfg @@ -0,0 +1,14 @@ +# Generic efm32hg309 on Tomu board, using stm32l053-disco as debugger +source [find interface/stlink-v2-1.cfg] +transport select hla_swd +adapter_khz 1000 +set CHIPNAME efm32hg309 +set CPUTAPID 0x0bc11477 +source [find target/efm32.cfg] + +source openocd.common.cfg +optional_local "openocd.efm32hg309-generic.local.cfg" + +init +targets +reset halt