├── captouch ├── Makefile ├── capsenseconfig.h ├── printf.h └── printf.c ├── cbmbasic ├── Makefile ├── fake6502.h └── README.md ├── coinflip ├── Makefile └── capsenseconfig.h ├── ledpulse ├── Makefile ├── README.md └── ledpulse.c ├── opticspy ├── Makefile └── README.md ├── usb-hid ├── Makefile └── README.md ├── usb-midi ├── Makefile └── README.md ├── usb-msc ├── Makefile ├── README.md ├── ramdisk.h └── usb-msc.c ├── bare-minimum ├── Makefile ├── main.c └── README.md ├── miniblink ├── Makefile ├── README.md └── miniblink.c ├── pwm-shell ├── Makefile └── README.md ├── usb-cdcacm ├── Makefile └── README.md ├── usb-synth ├── Makefile ├── tomu_pins.h ├── usb_isochronous.h ├── midi_events.h ├── synth_core.h ├── usb_descriptors.h ├── README.md └── usb_synth.c ├── usb-audiostream ├── Makefile └── README.md ├── usb-hid-keyboard └── Makefile ├── bin ├── dfu-util.exe ├── dfu-suffix.exe └── README.md ├── prebuilt ├── cbmbasic.dfu ├── miniblink.dfu ├── opticspy.dfu ├── pwm-shell.dfu ├── usb-hid.dfu ├── usb-midi.dfu ├── usb-msc.dfu ├── usb-synth.dfu ├── usb-cdcacm.dfu ├── bare-minimum.dfu └── usb-audiostream.dfu ├── .gitmodules ├── libopencm3 ├── lib │ ├── libopencm3_efm32hg.a │ └── cortex-m-generic.ld └── include │ ├── libopencm3 │ ├── cm3 │ │ ├── doc-cm3.h │ │ ├── sync.h │ │ ├── vector.h │ │ ├── fpb.h │ │ ├── common.h │ │ ├── memorymap.h │ │ ├── itm.h │ │ ├── tpiu.h │ │ ├── systick.h │ │ ├── mpu.h │ │ ├── assert.h │ │ └── nvic.h │ ├── usb │ │ ├── doc-usb.h │ │ ├── hid.h │ │ ├── dfu.h │ │ ├── msc.h │ │ ├── cdc.h │ │ └── dwc │ │ │ └── otg_fs.h │ ├── docmain.dox │ ├── efm32 │ │ ├── hg │ │ │ ├── doc-efm32hg.h │ │ │ ├── irq.json │ │ │ ├── gpio.h │ │ │ ├── wdog.h │ │ │ ├── timer.h │ │ │ ├── nvic.h │ │ │ ├── usb.h │ │ │ └── memorymap.h │ │ ├── common │ │ │ ├── opamp_common.h │ │ │ ├── rmu_common.h │ │ │ ├── rtc_common.h │ │ │ ├── wdog_common.h │ │ │ ├── wdog_common_hglg.h │ │ │ ├── uart_common.h │ │ │ └── msc_common.h │ │ ├── adc.h │ │ ├── dac.h │ │ ├── dma.h │ │ ├── emu.h │ │ ├── i2c.h │ │ ├── msc.h │ │ ├── prs.h │ │ ├── rmu.h │ │ ├── rtc.h │ │ ├── acmp.h │ │ ├── uart.h │ │ ├── burtc.h │ │ ├── opamp.h │ │ ├── usart.h │ │ ├── letimer.h │ │ ├── cmu.h │ │ ├── usb.h │ │ ├── gpio.h │ │ ├── wdog.h │ │ ├── timer.h │ │ └── memorymap.h │ ├── license.dox │ └── dispatch │ │ └── nvic.h │ └── libopencmsis │ ├── efm32 │ └── hg │ │ └── irqhandlers.h │ ├── dispatch │ └── irqhandlers.h │ └── core_cm3.h ├── .gitignore ├── generate-libopencm3.sh ├── tomu-efm32hg309.ld ├── Makefile.common ├── include └── toboot.h └── README.md /captouch/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /cbmbasic/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /coinflip/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /ledpulse/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /opticspy/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /usb-hid/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /usb-midi/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /usb-msc/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /bare-minimum/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /miniblink/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /pwm-shell/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /usb-cdcacm/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /usb-synth/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /usb-audiostream/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /usb-hid-keyboard/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.common -------------------------------------------------------------------------------- /bin/dfu-util.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/bin/dfu-util.exe -------------------------------------------------------------------------------- /bin/dfu-suffix.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/bin/dfu-suffix.exe -------------------------------------------------------------------------------- /prebuilt/cbmbasic.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/cbmbasic.dfu -------------------------------------------------------------------------------- /prebuilt/miniblink.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/miniblink.dfu -------------------------------------------------------------------------------- /prebuilt/opticspy.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/opticspy.dfu -------------------------------------------------------------------------------- /prebuilt/pwm-shell.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/pwm-shell.dfu -------------------------------------------------------------------------------- /prebuilt/usb-hid.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/usb-hid.dfu -------------------------------------------------------------------------------- /prebuilt/usb-midi.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/usb-midi.dfu -------------------------------------------------------------------------------- /prebuilt/usb-msc.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/usb-msc.dfu -------------------------------------------------------------------------------- /prebuilt/usb-synth.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/usb-synth.dfu -------------------------------------------------------------------------------- /prebuilt/usb-cdcacm.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/usb-cdcacm.dfu -------------------------------------------------------------------------------- /prebuilt/bare-minimum.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/bare-minimum.dfu -------------------------------------------------------------------------------- /prebuilt/usb-audiostream.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/prebuilt/usb-audiostream.dfu -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libopencm3-upstream"] 2 | path = libopencm3-upstream 3 | url = https://github.com/libopencm3/libopencm3 4 | -------------------------------------------------------------------------------- /libopencm3/lib/libopencm3_efm32hg.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-tomu/tomu-quickstart/HEAD/libopencm3/lib/libopencm3_efm32hg.a -------------------------------------------------------------------------------- /usb-hid/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This example implements a USB Human Interface Device (HID) 4 | to demonstrate the use of the USB device stack. 5 | -------------------------------------------------------------------------------- /usb-msc/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This example implements a USB Mass Storage Class (MSC) device 4 | to demonstrate the use of the USB device stack. 5 | -------------------------------------------------------------------------------- /opticspy/README.md: -------------------------------------------------------------------------------- 1 | # OpticSpy Transmitter 2 | 3 | This demo combines the `usb-cdcacm` demo with some bit-banged output used to communicate with an [OpticSpy](http://www.grandideastudio.com/opticspy/). -------------------------------------------------------------------------------- /bin/README.md: -------------------------------------------------------------------------------- 1 | # Binaries for Windows 2 | 3 | These binaries are precompiled versions of dfu-util, mirrored from 4 | [dfu-util.sourceforge.net](http://dfu-util.sourceforge.net/releases/dfu-util-0.8-binaries/win32-mingw32/). 5 | -------------------------------------------------------------------------------- /usb-synth/tomu_pins.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define LED_GREEN_PORT GPIOA 6 | #define LED_GREEN_PIN GPIO0 7 | #define LED_RED_PORT GPIOB 8 | #define LED_RED_PIN GPIO7 9 | -------------------------------------------------------------------------------- /cbmbasic/fake6502.h: -------------------------------------------------------------------------------- 1 | void reset6502(); 2 | void exec6502(uint32_t tickcount); 3 | void step6502(); 4 | void irq6502(); 5 | void nmi6502(); 6 | void hookexternal(void *funcptr); 7 | 8 | extern uint16_t pc; 9 | extern uint8_t sp, a, x, y, status; 10 | -------------------------------------------------------------------------------- /ledpulse/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This example demonstrates the following: 4 | * Configuring GPIO pins 5 | * Toggling GPIO pins 6 | * Controlling the system clock 7 | * Configuring a SysTick 8 | 9 | Toggles between the Red and Green LEDs on the board. 10 | A SysTick interrupt is used to trigger LED toggling. 11 | -------------------------------------------------------------------------------- /miniblink/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This example demonstrates the following: 4 | * Configuring GPIO pins 5 | * Toggling GPIO pins 6 | * Controlling the system clock 7 | * Configuring a SysTick 8 | 9 | Toggles between the Red and Green LEDs on the board. 10 | A SysTick interrupt is used to trigger LED toggling. 11 | -------------------------------------------------------------------------------- /bare-minimum/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) { 4 | (void)argc; /* Indicate argc is not used */ 5 | (void)argv; /* Indicate argv is not used, either */ 6 | 7 | /* Disable the watchdog that the bootloader started. 8 | * Without this, Tomu would reboot after a short time. 9 | */ 10 | WDOG_CTRL = 0; 11 | 12 | /* Loop forever */ 13 | while (1) 14 | ; 15 | } -------------------------------------------------------------------------------- /usb-cdcacm/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This example implements a USB CDC-ACM device (aka Virtual Serial Port) 4 | to demonstrate the use of the USB device stack. 5 | 6 | When a terminal is connected the green LED will light up. When disconnected, 7 | the green LED will turn off. 8 | 9 | When data is recieved, it will echo the data back to the host. 10 | 11 | The red LED is toggled constantly and a string is sent over USB every 12 | time the LED changes state as a heartbeat. 13 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/doc-cm3.h: -------------------------------------------------------------------------------- 1 | /** @mainpage libopencm3 Core CM3 2 | 3 | @version 1.0.0 4 | 5 | @date 14 September 2012 6 | 7 | API documentation for Cortex M3 core features. 8 | 9 | LGPL License Terms @ref lgpl_license 10 | */ 11 | 12 | /** @defgroup CM3_defines CM3 Defines 13 | 14 | @brief Defined Constants and Types for Cortex M3 core features 15 | 16 | @version 1.0.0 17 | 18 | @date 14 September 2012 19 | 20 | LGPL License Terms @ref lgpl_license 21 | */ 22 | 23 | -------------------------------------------------------------------------------- /bare-minimum/README.md: -------------------------------------------------------------------------------- 1 | # Bare Minimum 2 | 3 | This project is an example of the absolute minimum required to get a Tomu project running. 4 | 5 | The code first disables the watchdog, which is required to prevent Tomu from restarting immediately. Then it loops forever. 6 | 7 | The Makefile takes care of compiling everything and linking it all, as well as determining dependencies. That is, if you modify a header file, then all files that depend on it will be rebuilt. 8 | 9 | The resulting .dfu file is based on the directory name. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | *.ihex 31 | *.bin 32 | *.dfu 33 | 34 | # Debug files 35 | *.dSYM/ 36 | *.su 37 | 38 | # Tarballs/compressed files 39 | *.zip 40 | *.tar 41 | *.tar.gz 42 | *.tar.bz2 43 | 44 | # Extra files 45 | *.dump 46 | *.map 47 | *.d 48 | 49 | # Swap files 50 | *.swp 51 | *.swo 52 | *~ 53 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/usb/doc-usb.h: -------------------------------------------------------------------------------- 1 | /** @mainpage libopencm3 Generic USB 2 | 3 | @version 1.0.0 4 | 5 | @date 10 March 2013 6 | 7 | API documentation for Generic USB. 8 | 9 | LGPL License Terms @ref lgpl_license 10 | */ 11 | 12 | /** @defgroup USB Generic USB 13 | Libraries for Generic USB. 14 | 15 | @version 1.0.0 16 | 17 | @date 10 March 2013 18 | 19 | LGPL License Terms @ref lgpl_license 20 | */ 21 | 22 | /** @defgroup USB_defines Generic USB Defines 23 | 24 | @brief Defined Constants and Types for Generic USB. 25 | 26 | @version 1.0.0 27 | 28 | @date 10 March 2013 29 | 30 | LGPL License Terms @ref lgpl_license 31 | */ 32 | 33 | -------------------------------------------------------------------------------- /generate-libopencm3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | cd libopencm3-upstream 4 | make 5 | 6 | mkdir -p ../libopencm3/lib 7 | cp lib/libopencm3_efm32hg.a ../libopencm3/lib 8 | cp lib/cortex-m-generic.ld ../libopencm3/lib/cortex-m-generic.ld 9 | 10 | for dir in libopencmsis libopencmsis/dispatch libopencmsis/efm32/hg \ 11 | libopencm3 \ 12 | libopencm3/cm3 libopencm3/dispatch \ 13 | libopencm3/efm32 libopencm3/efm32/common libopencm3/efm32/hg \ 14 | libopencm3/usb libopencm3/usb/dwc 15 | do 16 | mkdir -p ../libopencm3/include/$dir 17 | cp include/$dir/* ../libopencm3/include/$dir/ > /dev/null 2>&1|| true 18 | done 19 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/docmain.dox: -------------------------------------------------------------------------------- 1 | /** @mainpage libopencm3 Developer Documentation 2 | 3 | @version 1.0.0 4 | 5 | @date 7 September 2012 6 | 7 | * The libopencm3 project (previously known as libopenstm32) aims to create 8 | * a free/libre/open-source (LGPL v3, or later) firmware library for various 9 | * ARM Cortex-M microcontrollers, including ST STM32, Atmel SAM, NXP LPC, 10 | * TI Stellaris/Tiva/MSP432, Silabs (Energy Micro) and others. 11 | * 12 | * @par "" 13 | * 14 | * See the libopencm3 wiki for 15 | * more information. 16 | 17 | LGPL License Terms @ref lgpl_license 18 | */ 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/hg/doc-efm32hg.h: -------------------------------------------------------------------------------- 1 | /** @mainpage libopencm3 EFM32 Happy Gecko 2 | 3 | @version 1.0.0 4 | 5 | @date 28 January 2018 6 | 7 | API documentation for Energy Micro EFM32 Happy Gecko Cortex M0+ series. 8 | 9 | LGPL License Terms @ref lgpl_license 10 | */ 11 | 12 | /** @defgroup EFM32LG EFM32 HappyGecko 13 | Libraries for Energy Micro EFM32 Happy Gecko series. 14 | 15 | @version 1.0.0 16 | 17 | @date 28 January 2018 18 | 19 | LGPL License Terms @ref lgpl_license 20 | */ 21 | 22 | /** @defgroup EFM32HG_defines EFM32 Happy Gecko Defines 23 | 24 | @brief Defined Constants and Types for the Energy Micro EFM32 Happy Gecko 25 | series 26 | 27 | @version 1.0.0 28 | 29 | @date 28 January 2018 30 | 31 | LGPL License Terms @ref lgpl_license 32 | */ 33 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/license.dox: -------------------------------------------------------------------------------- 1 | /** @page lgpl_license libopencm3 License 2 | 3 | libopencm3 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by the Free 5 | Software Foundation, either version 3 of the License, or (at your option) any 6 | later version. 7 | 8 | libopencm3 is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 11 | 12 | You should have received a copy of the GNU Lesser General Public License along with this 13 | program. If not, see . 14 | 15 | */ 16 | 17 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/hg/irq.json: -------------------------------------------------------------------------------- 1 | { 2 | "_source": "The names and sequence are taken from EFM32HG-RM.pdf table 4.1.", 3 | "irqs": [ 4 | "dma", 5 | "gpio_even", 6 | "timer0", 7 | "acmp0", 8 | "adc0", 9 | "i2c0", 10 | "gpio_odd", 11 | "timer1", 12 | "usart1_rx", 13 | "usart1_tx", 14 | "leuart0", 15 | "pcnt0", 16 | "rtc", 17 | "cmu", 18 | "vcmp", 19 | "msc", 20 | "aes", 21 | "usart0_rx", 22 | "usart0_tx", 23 | "usb", 24 | "timer2" 25 | ], 26 | "partname_humanreadable": "EFM32 Happy Gecko series", 27 | "partname_doxygen": "EFM32HG", 28 | "includeguard": "LIBOPENCM3_EFM32HG_NVIC_H" 29 | } 30 | -------------------------------------------------------------------------------- /usb-synth/usb_isochronous.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* HACK: upstream libopencm3 currently does not handle isochronous endpoints 6 | * correctly. We must program the USB peripheral with an even/odd frame bit, 7 | * toggling it so that we respond to every iso IN request from the host. 8 | * If this toggling is not performed, we only get half the bandwidth. */ 9 | 10 | #define USB_REBASE(x) MMIO32((x) + (USB_OTG_FS_BASE)) 11 | #define USB_DIEPCTLX_SD1PID (1 << 29) /* Odd frames */ 12 | #define USB_DIEPCTLX_SD0PID (1 << 28) /* Even frames */ 13 | 14 | static void isochronous_frame_toggle(uint8_t ep) 15 | { 16 | static int toggle = 0; 17 | if (toggle++ % 2 == 0) { 18 | USB_REBASE(OTG_DIEPCTL(ep)) |= USB_DIEPCTLX_SD0PID; 19 | } else { 20 | USB_REBASE(OTG_DIEPCTL(ep)) |= USB_DIEPCTLX_SD1PID; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/hg/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * This library is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this library. If not, see . 16 | */ 17 | 18 | #ifndef LIBOPENCM3_GPIO_H 19 | #define LIBOPENCM3_GPIO_H 20 | 21 | #include 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/hg/wdog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * This library is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this library. If not, see . 16 | */ 17 | 18 | #ifndef LIBOPENCM3_WDOG_H 19 | #define LIBOPENCM3_WDOG_H 20 | 21 | #include 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/common/opamp_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* OpAmp register are in dac.h */ 21 | #include 22 | -------------------------------------------------------------------------------- /usb-midi/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This example implements a USB MIDI device to demonstrate the use of the 4 | USB device stack. It implements the device configuration found in Appendix 5 | B of the Universal Serial Bus Device Class Definition for MIDI Devices. 6 | 7 | The board will continuously send note on/note off messages. 8 | 9 | The board will also react to identity request (or any other data sent to 10 | the board) by transmitting an identity message in reply. 11 | 12 | ## Testing 13 | 14 | To list midi devices, which should include this demo device 15 | 16 | $ amidi -l 17 | Dir Device Name 18 | IO hw:2,0,0 MIDI demo MIDI 1 19 | $ 20 | 21 | To record events 22 | 23 | $ amidi -d -p hw:2,0,0 24 | 25 | 90 3C 40 -- key down 26 | 80 3C 40 -- key up 27 | 90 3C 40 28 | 80 3C 40^C 29 | 12 bytes read 30 | $ 31 | 32 | To query the system identity, note this dump matches sysex\_identity[] in the 33 | source. 34 | 35 | $ amidi -d -p hw:2,0,0 -s Sysexdump.syx 36 | 37 | F0 7E 00 7D 66 66 51 19 00 00 01 00 F7 38 | ^C 39 | 13 bytes read 40 | $ 41 | -------------------------------------------------------------------------------- /cbmbasic/README.md: -------------------------------------------------------------------------------- 1 | # Commodore BASIC Emulator 2 | 3 | This implements a USB CDC-ACM device (aka Virtual Serial Port), which is an interface to the Commodore 64 BASIC interpreter running inside a 6502 emulator. 4 | 5 | **** COMMODORE 64 BASIC V2 **** 6 | 7 | 64K RAM SYSTEM 6380 BASIC BYTES FREE 8 | 9 | READY. 10 | 11 | Connect to Tomu using a terminal emulator (like minicom) and start hacking in BASIC, like this: 12 | 13 | 10 REM SIEVE 14 | 20 FORI=1TO120000 15 | 30 FORJ=2TOSQR(I) 16 | 40 IFI/J=INT(I/J)GOTO70 17 | 50 NEXTJ 18 | 60 PRINTI; 19 | 70 NEXTI 20 | RUN 21 | 22 | Because Tomu only has 8 KB of RAM, only about 6 KB bytes are avaiable to BASIC. A few more hundred bytes could be squeezed out of the device, for example by reusing $0090-$00ff and $0259-$02ff for other data (e.g. the input buffer), since these areas are meant for the KERNAL and unused by BASIC. 23 | 24 | The KERNAL interface only implements the most important calls to get BASIC running. File I/O will crash the interpreter. [The cbmbasic project](https://github.com/mist64/cbmbasic) has a more complete KERNAL implemenation. 25 | -------------------------------------------------------------------------------- /libopencm3/include/libopencmsis/efm32/hg/irqhandlers.h: -------------------------------------------------------------------------------- 1 | /* This file is part of the libopencm3 project. 2 | * 3 | * It was generated by the irq2nvic_h script. 4 | * 5 | * These definitions bend every interrupt handler that is defined CMSIS style 6 | * to the weak symbol exported by libopencm3. 7 | */ 8 | 9 | #define DMA_IRQHandler dma_isr 10 | #define GPIO_EVEN_IRQHandler gpio_even_isr 11 | #define TIMER0_IRQHandler timer0_isr 12 | #define ACMP0_IRQHandler acmp0_isr 13 | #define ADC0_IRQHandler adc0_isr 14 | #define I2C0_IRQHandler i2c0_isr 15 | #define GPIO_ODD_IRQHandler gpio_odd_isr 16 | #define TIMER1_IRQHandler timer1_isr 17 | #define USART1_RX_IRQHandler usart1_rx_isr 18 | #define USART1_TX_IRQHandler usart1_tx_isr 19 | #define LEUART0_IRQHandler leuart0_isr 20 | #define PCNT0_IRQHandler pcnt0_isr 21 | #define RTC_IRQHandler rtc_isr 22 | #define CMU_IRQHandler cmu_isr 23 | #define VCMP_IRQHandler vcmp_isr 24 | #define MSC_IRQHandler msc_isr 25 | #define AES_IRQHandler aes_isr 26 | #define USART0_RX_IRQHandler usart0_rx_isr 27 | #define USART0_TX_IRQHandler usart0_tx_isr 28 | #define USB_IRQHandler usb_isr 29 | #define TIMER2_IRQHandler timer2_isr 30 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/adc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/dac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/dma.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/emu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/msc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/prs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/rmu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/rtc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/acmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/burtc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/hg/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * This library is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this library. If not, see . 16 | */ 17 | 18 | #ifndef LIBOPENCM3_TIMER_H 19 | #define LIBOPENCM3_TIMER_H 20 | 21 | #include 22 | 23 | /* efm32hg specific registers */ 24 | 25 | /* TIMER_ROUTE */ 26 | #define TIMER_ROUTE_LOCATION_LOC6 TIMER_ROUTE_LOCATION_LOCx(6) 27 | 28 | /* TIMER_CCx_CTRL */ 29 | #define TIMER_CC_CTRL_PRSCONF (1 << 28) 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/opamp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/usart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/letimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32WG) 23 | # include 24 | #elif defined(EZR32WG) 25 | # include 26 | #else 27 | # error "efm32 family not defined." 28 | #endif 29 | -------------------------------------------------------------------------------- /usb-msc/ramdisk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2013 Andrzej Surowiec 5 | * Copyright (C) 2013 Pavol Rusnak 6 | * 7 | * This library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this library. If not, see . 19 | */ 20 | 21 | #ifndef __RAMDISK_H 22 | #define __RAMDISK_H 23 | 24 | #include 25 | 26 | extern int ramdisk_init(void); 27 | extern int ramdisk_read(uint32_t lba, uint8_t *copy_to); 28 | extern int ramdisk_write(uint32_t lba, const uint8_t *copy_from); 29 | extern int ramdisk_blocks(void); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /usb-synth/midi_events.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* USB-MIDI Event Packet structure 6 | * See: http://www.usb.org/developers/docs/devclass_docs/midi10.pdf */ 7 | 8 | typedef struct _midi_usb_event_packet_t { 9 | uint8_t code_index_number : 4; 10 | uint8_t cable_number : 4; 11 | uint8_t midi0; 12 | uint8_t midi1; 13 | uint8_t midi2; 14 | } __attribute((packed)) midi_usb_event_packet_t; 15 | 16 | /* MIDI message structure 17 | * See: https://ccrma.stanford.edu/~craig/articles/linuxmidi/misc/essenmidi.html */ 18 | 19 | /* Command types (shared by usb code index numbers) */ 20 | #define MIDI_NOTE_OFF 0x8 21 | #define MIDI_NOTE_ON 0x9 22 | #define MIDI_AFTERTOUCH 0xA 23 | #define MIDI_CONTINUOUS 0xB 24 | #define MIDI_PATCH_CHANGE 0xC 25 | #define MIDI_CHANNEL_PRESSURE 0xD 26 | #define MIDI_PITCH_BEND 0xE 27 | #define MIDI_SYSTEM_MESSAGE 0xF 28 | 29 | /* Some more MIDI defines */ 30 | #define MIDI_NOTE_MAX 127 31 | #define MIDI_NOTE_MIN 0 32 | #define MIDI_N_NOTES 128 33 | #define MIDI_CHANNEL_MAX 15 34 | #define MIDI_CHANNEL_MIN 0 35 | #define MIDI_N_CHANNELS 16 36 | 37 | #define MIDI_CC_SUSTAIN 0x40 /* Sustain pedal CC code */ 38 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/cmu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32HG) 23 | # include 24 | #elif defined(EFM32WG) 25 | # include 26 | #elif defined(EZR32WG) 27 | # include 28 | #else 29 | # error "efm32 family not defined." 30 | #endif 31 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32HG) 23 | # include 24 | #elif defined(EFM32WG) 25 | # include 26 | #elif defined(EZR32WG) 27 | # include 28 | #else 29 | # error "efm32 family not defined." 30 | #endif 31 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32HG) 23 | # include 24 | #elif defined(EFM32WG) 25 | # include 26 | #elif defined(EZR32WG) 27 | # include 28 | #else 29 | # error "efm32 family not defined." 30 | #endif 31 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/wdog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32HG) 23 | # include 24 | #elif defined(EFM32WG) 25 | # include 26 | #elif defined(EZR32WG) 27 | # include 28 | #else 29 | # error "efm32 family not defined." 30 | #endif 31 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #if defined(EFM32LG) 21 | # include 22 | #elif defined(EFM32HG) 23 | # include 24 | #elif defined(EFM32WG) 25 | # include 26 | #elif defined(EZR32WG) 27 | # include 28 | #else 29 | # error "efm32 family not defined." 30 | #endif 31 | -------------------------------------------------------------------------------- /tomu-efm32hg309.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2010 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for Tomu board with EFM32HG309. */ 21 | 22 | /* Define memory regions. */ 23 | MEMORY 24 | { 25 | rom (rx) : ORIGIN = 0x00004000, LENGTH = 0xC000 26 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x2000 27 | } 28 | 29 | SECTIONS { 30 | .text : { 31 | KEEP(SORT(*)(.vectors)) 32 | } >rom 33 | } 34 | 35 | /* Include the common ld script. */ 36 | INCLUDE cortex-m-generic.ld 37 | -------------------------------------------------------------------------------- /captouch/capsenseconfig.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This file contains configuration/settings for the Gecko SDK-provided 16 | // "capsense" driver at Gecko_SDK/kits/common/drivers/capsense.c. 17 | 18 | #ifndef _CAPSENSECONFIG_H_ 19 | #define _CAPSENSECONFIG_H_ 20 | 21 | #define ACMP_CAPSENSE ACMP0 22 | #define ACMP_CAPSENSE_CLKEN CMU_HFPERCLKEN0_ACMP0 23 | #define PRS_CH_CTRL_SOURCESEL_ACMP_CAPSENSE PRS_CH_CTRL_SOURCESEL_ACMP0 24 | #define PRS_CH_CTRL_SIGSEL_ACMPOUT_CAPSENSE PRS_CH_CTRL_SIGSEL_ACMP0OUT 25 | 26 | #define ACMP_CHANNELS 2 27 | 28 | #define BUTTON0_CHANNEL 0 29 | #define BUTTON1_CHANNEL 1 30 | 31 | #define CAPSENSE_CH_IN_USE { true, true } 32 | 33 | #endif // _CAPSENSECONFIG_H_ 34 | -------------------------------------------------------------------------------- /coinflip/capsenseconfig.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // This file contains configuration/settings for the Gecko SDK-provided 16 | // "capsense" driver at Gecko_SDK/kits/common/drivers/capsense.c. 17 | 18 | #ifndef _CAPSENSECONFIG_H_ 19 | #define _CAPSENSECONFIG_H_ 20 | 21 | #define ACMP_CAPSENSE ACMP0 22 | #define ACMP_CAPSENSE_CLKEN CMU_HFPERCLKEN0_ACMP0 23 | #define PRS_CH_CTRL_SOURCESEL_ACMP_CAPSENSE PRS_CH_CTRL_SOURCESEL_ACMP0 24 | #define PRS_CH_CTRL_SIGSEL_ACMPOUT_CAPSENSE PRS_CH_CTRL_SIGSEL_ACMP0OUT 25 | 26 | #define ACMP_CHANNELS 2 27 | 28 | #define BUTTON0_CHANNEL 0 29 | #define BUTTON1_CHANNEL 1 30 | 31 | #define CAPSENSE_CH_IN_USE { true, true } 32 | 33 | #endif // _CAPSENSECONFIG_H_ 34 | -------------------------------------------------------------------------------- /usb-synth/synth_core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: synth_core.h 3 | * A pretty terrible wavetablesque polyphonic synthesizer. 4 | * 5 | * Copyright (C) 2018 Seb Holzapfel 6 | * 7 | * This library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this library. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | #include "midi_events.h" 26 | 27 | /* Initialize the synth engine */ 28 | void synth_core_init(void); 29 | 30 | /* Generate some audio. Call this with a valid pointer of size `n_samples`. 31 | * `out_samples` will be populated with the next block of samples */ 32 | void synth_core_stream(uint16_t *out_samples, uint16_t n_samples); 33 | 34 | /* Tell the synth that a MIDI event occurred. */ 35 | void synth_core_decode_midi_packet(midi_usb_event_packet_t p); 36 | -------------------------------------------------------------------------------- /usb-audiostream/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | This example implements a streaming USB microphone device to demonstrate 4 | the use of the USB device stack. 5 | 6 | The microphone device will constantly stream a stereo sawtooth wave 7 | at a sample rate of 8KHz, using 16-bit PCM samples. 8 | 9 | The green LED will light when audio is being recorded. The red LED blinks constantly. 10 | 11 | # Usage 12 | 13 | Warning: only tested on a Linux host! Windows is picky about audio descriptors, 14 | so it's unlikely this will work on Windows without further work. 15 | 16 | For a simple test, fire up an ordinary sound recording program (i.e Audacity) 17 | and just record a few seconds of audio from the 'AUDIO Demo' device. 18 | 19 | When playing with different sample rates, `arecord` is nice. To list your devices: 20 | 21 | $ arecord -l 22 | 23 | To perform a recording (replace `hw:2,0` with your device as listed above): 24 | 25 | $ sudo arecord -D hw:2,0 -d 10 -f S16 -r 8000 -c 2 test.wav 26 | 27 | A useful debugging test with the above is to time how long the command takes. 28 | (just prefix it with `time`). If the command takes longer than the duration 29 | specified, the Tomu is underrunning the sample rates specified. 30 | 31 | If you really want to annoy people and feed the Tomu's audio to your 32 | speakers in real-time, try: 33 | 34 | $ sudo alsaloop -C hw:1,0 -P hw:0,0 --rate=8000 35 | 36 | The first hardware ID should be your Tomu, the second your computers' soundcard 37 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/memorymap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2012 chrysn 5 | * Copyright (C) 2015 Kuldeep Singh Dhaka 6 | * 7 | * This library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this library. If not, see . 19 | */ 20 | 21 | /** @file 22 | * 23 | * Dispatcher for the base address definitions, depending on the particular 24 | * Gecko family. 25 | * 26 | * @see efm32tg/memorymap.h 27 | * @see efm32lg/memorymap.h 28 | */ 29 | 30 | #if defined(EFM32TG) 31 | # include 32 | #elif defined(EFM32LG) 33 | # include 34 | #elif defined(EFM32HG) 35 | # include 36 | #elif defined(EFM32WG) 37 | # include 38 | #elif defined(EZR32WG) 39 | # include 40 | #else 41 | # error "efm32 family not defined." 42 | #endif 43 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/usb/hid.h: -------------------------------------------------------------------------------- 1 | /** @defgroup usb_hid_defines USB HID Type Definitions 2 | 3 | @brief Defined Constants and Types for the USB HID Type Definitions 4 | 5 | @ingroup USB_defines 6 | 7 | @version 1.0.0 8 | 9 | @author @htmlonly © @endhtmlonly 2010 10 | Gareth McMullin 11 | 12 | @date 10 March 2013 13 | 14 | LGPL License Terms @ref lgpl_license 15 | */ 16 | 17 | /* 18 | * This file is part of the libopencm3 project. 19 | * 20 | * Copyright (C) 2010 Gareth McMullin 21 | * 22 | * This library is free software: you can redistribute it and/or modify 23 | * it under the terms of the GNU Lesser General Public License as published by 24 | * the Free Software Foundation, either version 3 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This library is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU Lesser General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU Lesser General Public License 33 | * along with this library. If not, see . 34 | */ 35 | 36 | /**@{*/ 37 | 38 | #ifndef __HID_H 39 | #define __HID_H 40 | 41 | #include 42 | 43 | #define USB_CLASS_HID 3 44 | 45 | #define USB_DT_HID 0x21 46 | #define USB_DT_REPORT 0x22 47 | 48 | struct usb_hid_descriptor { 49 | uint8_t bLength; 50 | uint8_t bDescriptorType; 51 | uint16_t bcdHID; 52 | uint8_t bCountryCode; 53 | uint8_t bNumDescriptors; 54 | } __attribute__((packed)); 55 | 56 | #endif 57 | 58 | /**@}*/ 59 | 60 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/sync.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2012 Fergus Noble 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_CM3_SYNC_H 21 | #define LIBOPENCM3_CM3_SYNC_H 22 | 23 | #include "common.h" 24 | 25 | BEGIN_DECLS 26 | 27 | void __dmb(void); 28 | 29 | /* Implements synchronisation primitives as discussed in the ARM document 30 | * DHT0008A (ID081709) "ARM Synchronization Primitives" and the ARM v7-M 31 | * Architecture Reference Manual. 32 | */ 33 | 34 | /* --- Exclusive load and store instructions ------------------------------- */ 35 | 36 | /* Those are defined only on CM3 or CM4 */ 37 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 38 | 39 | uint32_t __ldrex(volatile uint32_t *addr); 40 | uint32_t __strex(uint32_t val, volatile uint32_t *addr); 41 | 42 | /* --- Convenience functions ----------------------------------------------- */ 43 | 44 | /* Here we implement some simple synchronisation primitives. */ 45 | 46 | typedef uint32_t mutex_t; 47 | 48 | #define MUTEX_UNLOCKED 0 49 | #define MUTEX_LOCKED 1 50 | 51 | void mutex_lock(mutex_t *m); 52 | uint32_t mutex_trylock(mutex_t *m); 53 | void mutex_unlock(mutex_t *m); 54 | 55 | #endif 56 | 57 | END_DECLS 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/hg/nvic.h: -------------------------------------------------------------------------------- 1 | /* This file is part of the libopencm3 project. 2 | * 3 | * It was generated by the irq2nvic_h script. 4 | */ 5 | 6 | #ifndef LIBOPENCM3_EFM32HG_NVIC_H 7 | #define LIBOPENCM3_EFM32HG_NVIC_H 8 | 9 | #include 10 | 11 | /** @defgroup CM3_nvic_defines_EFM32HG User interrupts for EFM32 Happy Gecko series 12 | @ingroup CM3_nvic_defines 13 | 14 | @{*/ 15 | 16 | #define NVIC_DMA_IRQ 0 17 | #define NVIC_GPIO_EVEN_IRQ 1 18 | #define NVIC_TIMER0_IRQ 2 19 | #define NVIC_ACMP0_IRQ 3 20 | #define NVIC_ADC0_IRQ 4 21 | #define NVIC_I2C0_IRQ 5 22 | #define NVIC_GPIO_ODD_IRQ 6 23 | #define NVIC_TIMER1_IRQ 7 24 | #define NVIC_USART1_RX_IRQ 8 25 | #define NVIC_USART1_TX_IRQ 9 26 | #define NVIC_LEUART0_IRQ 10 27 | #define NVIC_PCNT0_IRQ 11 28 | #define NVIC_RTC_IRQ 12 29 | #define NVIC_CMU_IRQ 13 30 | #define NVIC_VCMP_IRQ 14 31 | #define NVIC_MSC_IRQ 15 32 | #define NVIC_AES_IRQ 16 33 | #define NVIC_USART0_RX_IRQ 17 34 | #define NVIC_USART0_TX_IRQ 18 35 | #define NVIC_USB_IRQ 19 36 | #define NVIC_TIMER2_IRQ 20 37 | 38 | #define NVIC_IRQ_COUNT 21 39 | 40 | /**@}*/ 41 | 42 | /** @defgroup CM3_nvic_isrprototypes_EFM32HG User interrupt service routines (ISR) prototypes for EFM32 Happy Gecko series 43 | @ingroup CM3_nvic_isrprototypes 44 | 45 | @{*/ 46 | 47 | BEGIN_DECLS 48 | 49 | void dma_isr(void); 50 | void gpio_even_isr(void); 51 | void timer0_isr(void); 52 | void acmp0_isr(void); 53 | void adc0_isr(void); 54 | void i2c0_isr(void); 55 | void gpio_odd_isr(void); 56 | void timer1_isr(void); 57 | void usart1_rx_isr(void); 58 | void usart1_tx_isr(void); 59 | void leuart0_isr(void); 60 | void pcnt0_isr(void); 61 | void rtc_isr(void); 62 | void cmu_isr(void); 63 | void vcmp_isr(void); 64 | void msc_isr(void); 65 | void aes_isr(void); 66 | void usart0_rx_isr(void); 67 | void usart0_tx_isr(void); 68 | void usb_isr(void); 69 | void timer2_isr(void); 70 | 71 | END_DECLS 72 | 73 | /**@}*/ 74 | 75 | #endif /* LIBOPENCM3_EFM32HG_NVIC_H */ 76 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/common/rmu_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_EFM32_RMU_H 21 | #define LIBOPENCM3_EFM32_RMU_H 22 | 23 | #include 24 | #include 25 | 26 | #define RMU_CTRL MMIO32(RMU_BASE + 0x00) 27 | #define RMU_RSTCAUSE MMIO32(RMU_BASE + 0x04) 28 | #define RMU_CMD MMIO32(RMU_BASE + 0x08) 29 | 30 | /* RMU_CTRL */ 31 | #define RMU_CTRL_BURSTEN (1 << 1) 32 | #define RMU_CTRL_LOCKUPRDIS (1 << 0) 33 | 34 | /* RMU_RSTCAUSE */ 35 | #define RMU_RSTCAUSE_BUMODERST (1 << 15) 36 | #define RMU_RSTCAUSE_BUBODREG (1 << 14) 37 | #define RMU_RSTCAUSE_BUBODUNREG (1 << 13) 38 | #define RMU_RSTCAUSE_BUBODBUVIN (1 << 12) 39 | #define RMU_RSTCAUSE_BUBODVDDDREG (1 << 11) 40 | #define RMU_RSTCAUSE_BODAVDD1 (1 << 10) 41 | #define RMU_RSTCAUSE_BODAVDD0 (1 << 9) 42 | #define RMU_RSTCAUSE_EM4WURST (1 << 8) 43 | #define RMU_RSTCAUSE_EM4RST (1 << 7) 44 | #define RMU_RSTCAUSE_SYSREQRST (1 << 6) 45 | #define RMU_RSTCAUSE_LOCKUPRST (1 << 5) 46 | #define RMU_RSTCAUSE_WDOGRST (1 << 4) 47 | #define RMU_RSTCAUSE_EXTRST (1 << 3) 48 | #define RMU_RSTCAUSE_BODREGRST (1 << 2) 49 | #define RMU_RSTCAUSE_BODUNREGRST (1 << 1) 50 | #define RMU_RSTCAUSE_PORST (1 << 0) 51 | 52 | /* RMU_CMD */ 53 | #define RMU_CMD_RCCLR (1 << 0) 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /libopencm3/include/libopencmsis/dispatch/irqhandlers.h: -------------------------------------------------------------------------------- 1 | #if defined(STM32F0) 2 | # include 3 | #elif defined(STM32F1) 4 | # include 5 | #elif defined(STM32F2) 6 | # include 7 | #elif defined(STM32F3) 8 | # include 9 | #elif defined(STM32F4) 10 | # include 11 | #elif defined(STM32F7) 12 | # include 13 | #elif defined(STM32L0) 14 | # include 15 | #elif defined(STM32L1) 16 | # include 17 | #elif defined(STM32L4) 18 | # include 19 | 20 | #elif defined(EFM32TG) 21 | # include 22 | #elif defined(EFM32G) 23 | # include 24 | #elif defined(EFM32HG) 25 | # include 26 | #elif defined(EFM32LG) 27 | # include 28 | #elif defined(EFM32GG) 29 | # include 30 | 31 | #elif defined(LPC13XX) 32 | # include 33 | #elif defined(LPC17XX) 34 | # include 35 | #elif defined(LPC43XX_M4) 36 | # include 37 | #elif defined(LPC43XX_M0) 38 | # include 39 | 40 | #elif defined(SAM3A) 41 | # include 42 | #elif defined(SAM3N) 43 | # include 44 | #elif defined(SAM3S) 45 | # include 46 | #elif defined(SAM3U) 47 | # include 48 | #elif defined(SAM3X) 49 | # include 50 | #elif defined(SAMD) 51 | # include 52 | 53 | #elif defined(LM3S) || defined(LM4F) 54 | /* Yes, we use the same interrupt table for both LM3S and LM4F */ 55 | # include 56 | 57 | #else 58 | # warning"no chipset defined; user interrupts are not redirected" 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/hg/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * Copyright (C) 2018 Seb Holzapfel 6 | * 7 | * This library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this library. If not, see . 19 | */ 20 | 21 | #ifndef LIBOPENCM3_EFM32_USB_H 22 | #define LIBOPENCM3_EFM32_USB_H 23 | 24 | #include 25 | #include 26 | 27 | #define USB_CTRL MMIO32(USB_BASE + 0x000) 28 | #define USB_STATUS MMIO32(USB_BASE + 0x004) 29 | #define USB_IF MMIO32(USB_BASE + 0x008) 30 | #define USB_IFS MMIO32(USB_BASE + 0x00C) 31 | #define USB_IFC MMIO32(USB_BASE + 0x010) 32 | #define USB_IEN MMIO32(USB_BASE + 0x014) 33 | #define USB_ROUTE MMIO32(USB_BASE + 0x018) 34 | 35 | /* USB_CTRL */ 36 | /* Bits 31:26 - Reserved */ 37 | #define USB_CTRL_BIASPROGEM23_MASK (0x3 << 24) 38 | /* Bits 23:22 - Reserved */ 39 | #define USB_CTRL_BIASPROGEM01_MASK (0x3 << 20) 40 | /* Bits 19:18 - Reserved */ 41 | #define USB_CTRL_VREGOSEN (1 << 17) 42 | #define USB_CTRL_VREGDIS (1 << 16) 43 | /* Bits 15:10 - Reserved */ 44 | #define USB_CTRL_LEMIDLEEN (1 << 9) 45 | /* Bit 8 - Reserved */ 46 | #define USB_CTRL_LEMPHYCTRL (1 << 7) 47 | /* Bit 6 - Reserved */ 48 | #define USB_CTRL_LEMOSCCTRL_MASK (0x3 << 4) 49 | #define USB_CTRL_LEMOSCCTRL_NONE (0x0 << 4) 50 | #define USB_CTRL_LEMOSCCTRL_GATE (0x1 << 4) 51 | /* Bits 3:2 - Reserved */ 52 | #define USB_CTRL_DMPUAP (1 << 1) 53 | /* Bit 0 - Reserved */ 54 | 55 | /* USB_ROUTE */ 56 | /* Bits 31:3 - Reserved */ 57 | #define USB_ROUTE_DMPUPEN (1 << 2) 58 | /* Bit 1 - Reserved */ 59 | #define USB_ROUTE_PHYPEN (1 << 0) 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/common/rtc_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_EFM32_RTC_H 21 | #define LIBOPENCM3_EFM32_RTC_H 22 | 23 | #include 24 | #include 25 | 26 | #define RTC_CTRL (RTC_BASE + 0x000) 27 | #define RTC_CNT (RTC_BASE + 0x004) 28 | #define RTC_COMP0 (RTC_BASE + 0x008) 29 | #define RTC_COMP1 (RTC_BASE + 0x00C) 30 | #define RTC_IF (RTC_BASE + 0x010) 31 | #define RTC_IFS (RTC_BASE + 0x014) 32 | #define RTC_IFC (RTC_BASE + 0x018) 33 | #define RTC_IEN (RTC_BASE + 0x01C) 34 | #define RTC_FREEZE (RTC_BASE + 0x020) 35 | #define RTC_SYNCBUSY (RTC_BASE + 0x024) 36 | 37 | /* RTC_CTRL */ 38 | #define RTC_CTRL_COMP0TOP (1 << 2) 39 | #define RTC_CTRL_DEBUGRUN (1 << 1) 40 | #define RTC_CTRL_EN (1 << 0) 41 | 42 | /* RTC_IF */ 43 | #define RTC_IF_COMP1 (1 << 2) 44 | #define RTC_IF_COMP0 (1 << 1) 45 | #define RTC_IF_OF (1 << 0) 46 | 47 | /* RTC_IFS */ 48 | #define RTC_IFS_COMP1 (1 << 2) 49 | #define RTC_IFS_COMP0 (1 << 1) 50 | #define RTC_IFS_OF (1 << 0) 51 | 52 | /* RTC_IFC */ 53 | #define RTC_IFC_COMP1 (1 << 2) 54 | #define RTC_IFC_COMP0 (1 << 1) 55 | #define RTC_IFC_OF (1 << 0) 56 | 57 | /* RTC_IFE */ 58 | #define RTC_IFE_COMP1 (1 << 2) 59 | #define RTC_IFE_COMP0 (1 << 1) 60 | #define RTC_IFE_OF (1 << 0) 61 | 62 | /* RTC_FREEZE */ 63 | #define RTC_FREEZE_REGFREEZE (1 << 0) 64 | 65 | /* RTC_SYNCBUSY */ 66 | #define RTC_SYNCBUSY_COMP1 (1 << 2) 67 | #define RTC_SYNCBUSY_COMP0 (1 << 1) 68 | #define RTC_SYNCBUSY_CTRL (1 << 0) 69 | 70 | #endif 71 | 72 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/dispatch/nvic.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBOPENCM3_NVIC_H 2 | #error You should not be including this file directly, but 3 | #endif 4 | 5 | #if defined(STM32F0) 6 | # include 7 | #elif defined(STM32F1) 8 | # include 9 | #elif defined(STM32F2) 10 | # include 11 | #elif defined(STM32F3) 12 | # include 13 | #elif defined(STM32F4) 14 | # include 15 | #elif defined(STM32F7) 16 | # include 17 | #elif defined(STM32L0) 18 | # include 19 | #elif defined(STM32L1) 20 | # include 21 | #elif defined(STM32L4) 22 | # include 23 | 24 | #elif defined(EFM32TG) 25 | # include 26 | #elif defined(EFM32G) 27 | # include 28 | #elif defined(EFM32LG) 29 | # include 30 | #elif defined(EFM32GG) 31 | # include 32 | #elif defined(EFM32HG) 33 | # include 34 | #elif defined(EFM32WG) 35 | # include 36 | #elif defined(EZR32WG) 37 | # include 38 | 39 | #elif defined(LPC13XX) 40 | # include 41 | #elif defined(LPC17XX) 42 | # include 43 | #elif defined(LPC43XX_M4) 44 | # include 45 | #elif defined(LPC43XX_M0) 46 | # include 47 | 48 | #elif defined(SAM3A) 49 | # include 50 | #elif defined(SAM3N) 51 | # include 52 | #elif defined(SAM3S) 53 | # include 54 | #elif defined(SAM3U) 55 | # include 56 | #elif defined(SAM3X) 57 | # include 58 | #elif defined(SAM4L) 59 | # include 60 | #elif defined(SAMD) 61 | # include 62 | 63 | #elif defined(LM3S) || defined(LM4F) 64 | /* Yes, we use the same interrupt table for both LM3S and LM4F */ 65 | # include 66 | 67 | #elif defined(VF6XX) 68 | # include 69 | 70 | #else 71 | # warning"no interrupts defined for chipset; NVIC_IRQ_COUNT = 0" 72 | 73 | #define NVIC_IRQ_COUNT 0 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2012 chrysn 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /** @file 21 | * 22 | * Definitions for handling vector tables. 23 | * 24 | * This implements d0002_efm32_cortex-m3_reference_manual.pdf's figure 2.2 25 | * (from the EFM32 documentation at 26 | * http://www.energymicro.com/downloads/datasheets), and was seen analogously 27 | * in other ARM implementations' libopencm3 files. 28 | * 29 | * The structure of the vector table is implemented independently of the system 30 | * vector table starting at memory position 0x0, as it can be relocated to 31 | * other memory locations too. 32 | * 33 | * The exact size of a vector interrupt table depends on the number of 34 | * interrupts IRQ_COUNT, which is defined per family. 35 | */ 36 | 37 | #ifndef LIBOPENCM3_VECTOR_H 38 | #define LIBOPENCM3_VECTOR_H 39 | 40 | #include 41 | #include 42 | 43 | /** Type of an interrupt function. Only used to avoid hard-to-read function 44 | * pointers in the efm32_vector_table_t struct. */ 45 | typedef void (*vector_table_entry_t)(void); 46 | 47 | typedef struct { 48 | unsigned int *initial_sp_value; /**< Initial stack pointer value. */ 49 | vector_table_entry_t reset; 50 | vector_table_entry_t nmi; 51 | vector_table_entry_t hard_fault; 52 | vector_table_entry_t memory_manage_fault; /* not in CM0 */ 53 | vector_table_entry_t bus_fault; /* not in CM0 */ 54 | vector_table_entry_t usage_fault; /* not in CM0 */ 55 | vector_table_entry_t reserved_x001c[4]; 56 | vector_table_entry_t sv_call; 57 | vector_table_entry_t debug_monitor; /* not in CM0 */ 58 | vector_table_entry_t reserved_x0034; 59 | vector_table_entry_t pend_sv; 60 | vector_table_entry_t systick; 61 | vector_table_entry_t irq[NVIC_IRQ_COUNT]; 62 | } vector_table_t; 63 | 64 | /* Common symbols exported by the linker script(s): */ 65 | extern unsigned _data_loadaddr, _data, _edata, _ebss, _stack; 66 | extern vector_table_t vector_table; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/usb/dfu.h: -------------------------------------------------------------------------------- 1 | /** @defgroup usb_dfu_defines USB DFU Type Definitions 2 | 3 | @brief Defined Constants and Types for the USB DFU Type Definitions 4 | 5 | @ingroup USB_defines 6 | 7 | @version 1.0.0 8 | 9 | @author @htmlonly © @endhtmlonly 2010 10 | Gareth McMullin 11 | 12 | @date 10 March 2013 13 | 14 | LGPL License Terms @ref lgpl_license 15 | */ 16 | 17 | /* 18 | * This file is part of the libopencm3 project. 19 | * 20 | * Copyright (C) 2010 Gareth McMullin 21 | * 22 | * This library is free software: you can redistribute it and/or modify 23 | * it under the terms of the GNU Lesser General Public License as published by 24 | * the Free Software Foundation, either version 3 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This library is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU Lesser General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU Lesser General Public License 33 | * along with this library. If not, see . 34 | */ 35 | 36 | /**@{*/ 37 | 38 | #ifndef __DFU_H 39 | #define __DFU_H 40 | 41 | enum dfu_req { 42 | DFU_DETACH, 43 | DFU_DNLOAD, 44 | DFU_UPLOAD, 45 | DFU_GETSTATUS, 46 | DFU_CLRSTATUS, 47 | DFU_GETSTATE, 48 | DFU_ABORT, 49 | }; 50 | 51 | enum dfu_status { 52 | DFU_STATUS_OK, 53 | DFU_STATUS_ERR_TARGET, 54 | DFU_STATUS_ERR_FILE, 55 | DFU_STATUS_ERR_WRITE, 56 | DFU_STATUS_ERR_ERASE, 57 | DFU_STATUS_ERR_CHECK_ERASED, 58 | DFU_STATUS_ERR_PROG, 59 | DFU_STATUS_ERR_VERIFY, 60 | DFU_STATUS_ERR_ADDRESS, 61 | DFU_STATUS_ERR_NOTDONE, 62 | DFU_STATUS_ERR_FIRMWARE, 63 | DFU_STATUS_ERR_VENDOR, 64 | DFU_STATUS_ERR_USBR, 65 | DFU_STATUS_ERR_POR, 66 | DFU_STATUS_ERR_UNKNOWN, 67 | DFU_STATUS_ERR_STALLEDPKT, 68 | }; 69 | 70 | enum dfu_state { 71 | STATE_APP_IDLE, 72 | STATE_APP_DETACH, 73 | STATE_DFU_IDLE, 74 | STATE_DFU_DNLOAD_SYNC, 75 | STATE_DFU_DNBUSY, 76 | STATE_DFU_DNLOAD_IDLE, 77 | STATE_DFU_MANIFEST_SYNC, 78 | STATE_DFU_MANIFEST, 79 | STATE_DFU_MANIFEST_WAIT_RESET, 80 | STATE_DFU_UPLOAD_IDLE, 81 | STATE_DFU_ERROR, 82 | }; 83 | 84 | #define DFU_FUNCTIONAL 0x21 85 | struct usb_dfu_descriptor { 86 | uint8_t bLength; 87 | uint8_t bDescriptorType; 88 | uint8_t bmAttributes; 89 | #define USB_DFU_CAN_DOWNLOAD 0x01 90 | #define USB_DFU_CAN_UPLOAD 0x02 91 | #define USB_DFU_MANIFEST_TOLERANT 0x04 92 | #define USB_DFU_WILL_DETACH 0x08 93 | 94 | uint16_t wDetachTimeout; 95 | uint16_t wTransferSize; 96 | uint16_t bcdDFUVersion; 97 | } __attribute__((packed)); 98 | 99 | #endif 100 | 101 | /**@}*/ 102 | 103 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/common/wdog_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_EFM32_WDOG_H 21 | #define LIBOPENCM3_EFM32_WDOG_H 22 | 23 | #include 24 | #include 25 | 26 | #define WDOG_CTRL MMIO32(WDOG_BASE + 0x000) 27 | #define WDOG_CMD MMIO32(WDOG_BASE + 0x004) 28 | #define WDOG_SYNCBUSY MMIO32(WDOG_BASE + 0x008) 29 | 30 | /* WDOG_CTRL */ 31 | #define WDOG_CTRL_CLKSEL_SHIFT (12) 32 | #define WDOG_CTRL_CLKSEL_MASK (0x3 << WDOG_CTRL_CLKSEL_SHIFT) 33 | #define WDOG_CTRL_CLKSEL(v) \ 34 | (((v) << WDOG_CTRL_CLKSEL_SHIFT) & WDOG_CTRL_CLKSEL_MASK) 35 | #define WDOG_CTRL_CLKSEL_ULFRCO 0 36 | #define WDOG_CTRL_CLKSEL_LFRCO 1 37 | #define WDOG_CTRL_CLKSEL_LFXO 2 38 | 39 | #define WDOG_CTRL_PERSEL_SHIFT (8) 40 | #define WDOG_CTRL_PERSEL_MASK (0xF << WDOG_CTRL_PERSEL_SHIFT) 41 | #define WDOG_CTRL_PERSEL(v) \ 42 | (((v) << WDOG_CTRL_PERSEL_SHIFT) & WDOG_CTRL_PERSEL_MASK) 43 | #define WDOG_CTRL_PERSEL_9CYCLES 0 44 | #define WDOG_CTRL_PERSEL_17CYCLES 1 45 | #define WDOG_CTRL_PERSEL_33CYCLES 2 46 | #define WDOG_CTRL_PERSEL_65CYCLES 3 47 | #define WDOG_CTRL_PERSEL_129CYCLES 4 48 | #define WDOG_CTRL_PERSEL_257CYCLES 5 49 | #define WDOG_CTRL_PERSEL_513CYCLES 6 50 | #define WDOG_CTRL_PERSEL_1KCYCLES 7 51 | #define WDOG_CTRL_PERSEL_2KCYCLES 8 52 | #define WDOG_CTRL_PERSEL_4KCYCLES 9 53 | #define WDOG_CTRL_PERSEL_8KCYCLES 10 54 | #define WDOG_CTRL_PERSEL_16KCYCLES 11 55 | #define WDOG_CTRL_PERSEL_32KCYCLES 12 56 | #define WDOG_CTRL_PERSEL_64KCYCLES 13 57 | #define WDOG_CTRL_PERSEL_128KCYCLES 14 58 | #define WDOG_CTRL_PERSEL_256KCYCLES 15 59 | 60 | #define WDOG_CTRL_SWOSCBLOCK (1 << 6) 61 | #define WDOG_CTRL_EM4BLOCK (1 << 5) 62 | #define WDOG_CTRL_LOCK (1 << 4) 63 | #define WDOG_CTRL_EM3RUN (1 << 3) 64 | #define WDOG_CTRL_EM2RUN (1 << 2) 65 | #define WDOG_CTRL_DEBUGRUN (1 << 1) 66 | #define WDOG_CTRL_EN (1 << 0) 67 | 68 | /* WDOG_CMD */ 69 | #define WDOG_CMD_CLEAR (1 << 0) 70 | 71 | /* WDOG_SYNCBUSY */ 72 | #define WDOG_SYNCBUSY_CMD (1 << 1) 73 | #define WDOG_SYNCBUSY_CTRL (1 << 0) 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/fpb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2011 Gareth McMullin 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_CM3_FPB_H 21 | #define LIBOPENCM3_CM3_FPB_H 22 | 23 | /* Cortex-M3 Flash Patch and Breakpoint (FPB) unit */ 24 | 25 | /* Those defined only on ARMv7 and above */ 26 | #if !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) 27 | #error "Flash Patch and Breakpoint not available in CM0" 28 | #endif 29 | 30 | /* Note: We always use "FPB" as abbreviation, docs sometimes use only "FP". */ 31 | 32 | /* --- FPB registers ------------------------------------------------------- */ 33 | 34 | /* Flash Patch Control (FPB_CTRL) */ 35 | #define FPB_CTRL MMIO32(FPB_BASE + 0) 36 | 37 | /* Flash Patch Remap (FPB_REMAP) */ 38 | #define FPB_REMAP MMIO32(FPB_BASE + 4) 39 | 40 | /* Flash Patch Comparator (FPB_COMPx) */ 41 | #define FPB_COMP (&MMIO32(FPB_BASE + 8)) 42 | 43 | /* CoreSight Lock Status Register for this peripheral */ 44 | #define FPB_LSR MMIO32(FPB_BASE + 0xFB4) 45 | /* CoreSight Lock Access Register for this peripheral */ 46 | #define FPB_LAR MMIO32(FPB_BASE + 0xFB0) 47 | 48 | 49 | /* TODO: PID, CID */ 50 | 51 | /* --- FPB_CTRL values ----------------------------------------------------- */ 52 | 53 | /* Bits [31:15]: Reserved, read as zero, writes ignored */ 54 | 55 | #define FPB_CTRL_NUM_CODE2_MASK (0x7 << 12) 56 | 57 | #define FPB_CTRL_NUM_LIT_MASK (0xf << 8) 58 | 59 | #define FPB_CTRL_NUM_CODE1_MASK (0xf << 4) 60 | 61 | /* Bits [3:2]: Reserved */ 62 | 63 | #define FPB_CTRL_KEY (1 << 1) 64 | 65 | #define FPB_CTRL_ENABLE (1 << 0) 66 | 67 | /* --- FPB_REMAP values ---------------------------------------------------- */ 68 | 69 | /* TODO */ 70 | 71 | /* --- FPB_COMPx values ---------------------------------------------------- */ 72 | 73 | #define FPB_COMP_REPLACE_REMAP (0x0 << 30) 74 | #define FPB_COMP_REPLACE_BREAK_LOWER (0x1 << 30) 75 | #define FPB_COMP_REPLACE_BREAK_UPPER (0x2 << 30) 76 | #define FPB_COMP_REPLACE_BREAK_BOTH (0x3 << 30) 77 | #define FPB_COMP_REPLACE_MASK (0x3 << 30) 78 | 79 | /* Bit 29: Reserved */ 80 | 81 | /* TODO */ 82 | 83 | /* Bit 1: Reserved */ 84 | 85 | #define FPB_COMP_ENABLE (1 << 0) 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_CM3_COMMON_H 21 | #define LIBOPENCM3_CM3_COMMON_H 22 | 23 | #include 24 | #include 25 | 26 | /* This must be placed around external function declaration for C++ 27 | * support. */ 28 | #ifdef __cplusplus 29 | # define BEGIN_DECLS extern "C" { 30 | # define END_DECLS } 31 | #else 32 | # define BEGIN_DECLS 33 | # define END_DECLS 34 | #endif 35 | 36 | /* Full-featured deprecation attribute with fallback for older compilers. */ 37 | 38 | #ifdef __GNUC__ 39 | # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4) 40 | # define LIBOPENCM3_DEPRECATED(x) __attribute__((deprecated(x))) 41 | # else 42 | # define LIBOPENCM3_DEPRECATED(x) __attribute__((deprecated)) 43 | # endif 44 | #else 45 | # define LIBOPENCM3_DEPRECATED(x) 46 | #endif 47 | 48 | 49 | /* Generic memory-mapped I/O accessor functions */ 50 | #define MMIO8(addr) (*(volatile uint8_t *)(addr)) 51 | #define MMIO16(addr) (*(volatile uint16_t *)(addr)) 52 | #define MMIO32(addr) (*(volatile uint32_t *)(addr)) 53 | #define MMIO64(addr) (*(volatile uint64_t *)(addr)) 54 | 55 | /* Generic bit-band I/O accessor functions */ 56 | #define BBIO_SRAM(addr, bit) \ 57 | MMIO32((((uint32_t)addr) & 0x0FFFFF) * 32 + 0x22000000 + (bit) * 4) 58 | 59 | #define BBIO_PERIPH(addr, bit) \ 60 | MMIO32((((uint32_t)addr) & 0x0FFFFF) * 32 + 0x42000000 + (bit) * 4) 61 | 62 | /* Generic bit definition */ 63 | #define BIT0 (1<<0) 64 | #define BIT1 (1<<1) 65 | #define BIT2 (1<<2) 66 | #define BIT3 (1<<3) 67 | #define BIT4 (1<<4) 68 | #define BIT5 (1<<5) 69 | #define BIT6 (1<<6) 70 | #define BIT7 (1<<7) 71 | #define BIT8 (1<<8) 72 | #define BIT9 (1<<9) 73 | #define BIT10 (1<<10) 74 | #define BIT11 (1<<11) 75 | #define BIT12 (1<<12) 76 | #define BIT13 (1<<13) 77 | #define BIT14 (1<<14) 78 | #define BIT15 (1<<15) 79 | #define BIT16 (1<<16) 80 | #define BIT17 (1<<17) 81 | #define BIT18 (1<<18) 82 | #define BIT19 (1<<19) 83 | #define BIT20 (1<<20) 84 | #define BIT21 (1<<21) 85 | #define BIT22 (1<<22) 86 | #define BIT23 (1<<23) 87 | #define BIT24 (1<<24) 88 | #define BIT25 (1<<25) 89 | #define BIT26 (1<<26) 90 | #define BIT27 (1<<27) 91 | #define BIT28 (1<<28) 92 | #define BIT29 (1<<29) 93 | #define BIT30 (1<<30) 94 | #define BIT31 (1<<31) 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/usb/msc.h: -------------------------------------------------------------------------------- 1 | /** @defgroup usb_msc_defines USB MSC Type Definitions 2 | 3 | @brief Defined Constants and Types for the USB MSC Type Definitions 4 | 5 | @ingroup USB_defines 6 | 7 | @version 1.0.0 8 | 9 | @author @htmlonly © @endhtmlonly 2013 10 | Weston Schmidt 11 | Pavol Rusnak 12 | 13 | @date 27 June 2013 14 | 15 | LGPL License Terms @ref lgpl_license 16 | */ 17 | 18 | /* 19 | * This file is part of the libopencm3 project. 20 | * 21 | * Copyright (C) 2013 Weston Schmidt 22 | * Copyright (C) 2013 Pavol Rusnak 23 | * 24 | * This library is free software: you can redistribute it and/or modify 25 | * it under the terms of the GNU Lesser General Public License as published by 26 | * the Free Software Foundation, either version 3 of the License, or 27 | * (at your option) any later version. 28 | * 29 | * This library is distributed in the hope that it will be useful, 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 32 | * GNU Lesser General Public License for more details. 33 | * 34 | * You should have received a copy of the GNU Lesser General Public License 35 | * along with this library. If not, see . 36 | */ 37 | 38 | /**@{*/ 39 | 40 | #ifndef __MSC_H 41 | #define __MSC_H 42 | 43 | typedef struct _usbd_mass_storage usbd_mass_storage; 44 | 45 | /* Definitions of Mass Storage Class from: 46 | * 47 | * (A) "Universal Serial Bus Mass Storage Class Bulk-Only Transport 48 | * Revision 1.0" 49 | * 50 | * (B) "Universal Serial Bus Mass Storage Class Specification Overview 51 | * Revision 1.0" 52 | */ 53 | 54 | /* (A) Table 4.5: Mass Storage Device Class Code */ 55 | #define USB_CLASS_MSC 0x08 56 | 57 | /* (B) Table 2.1: Class Subclass Code */ 58 | #define USB_MSC_SUBCLASS_RBC 0x01 59 | #define USB_MSC_SUBCLASS_ATAPI 0x02 60 | #define USB_MSC_SUBCLASS_UFI 0x04 61 | #define USB_MSC_SUBCLASS_SCSI 0x06 62 | #define USB_MSC_SUBCLASS_LOCKABLE 0x07 63 | #define USB_MSC_SUBCLASS_IEEE1667 0x08 64 | 65 | /* (B) Table 3.1 Mass Storage Interface Class Control Protocol Codes */ 66 | #define USB_MSC_PROTOCOL_CBI 0x00 67 | #define USB_MSC_PROTOCOL_CBI_ALT 0x01 68 | #define USB_MSC_PROTOCOL_BBB 0x50 69 | 70 | /* (B) Table 4.1 Mass Storage Request Codes */ 71 | #define USB_MSC_REQ_CODES_ADSC 0x00 72 | #define USB_MSC_REQ_CODES_GET 0xFC 73 | #define USB_MSC_REQ_CODES_PUT 0xFD 74 | #define USB_MSC_REQ_CODES_GML 0xFE 75 | #define USB_MSC_REQ_CODES_BOMSR 0xFF 76 | 77 | /* (A) Table 3.1/3.2 Class-Specific Request Codes */ 78 | #define USB_MSC_REQ_BULK_ONLY_RESET 0xFF 79 | #define USB_MSC_REQ_GET_MAX_LUN 0xFE 80 | 81 | usbd_mass_storage *usb_msc_init(usbd_device *usbd_dev, 82 | uint8_t ep_in, uint8_t ep_in_size, 83 | uint8_t ep_out, uint8_t ep_out_size, 84 | const char *vendor_id, 85 | const char *product_id, 86 | const char *product_revision_level, 87 | const uint32_t block_count, 88 | int (*read_block)(uint32_t lba, uint8_t *copy_to), 89 | int (*write_block)(uint32_t lba, const uint8_t *copy_from)); 90 | 91 | #endif 92 | 93 | /**@}*/ 94 | -------------------------------------------------------------------------------- /usb-synth/usb_descriptors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: usb_descriptors.h 3 | * Boring header to glue some USB descriptors together. 4 | * 5 | * Copyright (C) 2018 Seb Holzapfel 6 | * 7 | * This library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this library. If not, see . 19 | */ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "mic_descriptors.h" 28 | #include "midi_descriptors.h" 29 | 30 | #define VENDOR_ID 0x1209 /* pid.code */ 31 | #define PRODUCT_ID 0x70b1 /* Assigned to Tomu project */ 32 | #define DEVICE_VER 0x0101 /* Program version */ 33 | 34 | static const struct usb_device_descriptor dev = { 35 | .bLength = USB_DT_DEVICE_SIZE, 36 | .bDescriptorType = USB_DT_DEVICE, 37 | .bcdUSB = 0x0200, /* was 0x0110 in Table B-1 example descriptor */ 38 | .bDeviceClass = 0, /* device defined at interface level */ 39 | .bDeviceSubClass = 0, 40 | .bDeviceProtocol = 0, 41 | .bMaxPacketSize0 = 64, 42 | .idVendor = VENDOR_ID, 43 | .idProduct = PRODUCT_ID, 44 | .bcdDevice = DEVICE_VER, 45 | .iManufacturer = 1, /* index to string desc */ 46 | .iProduct = 2, /* index to string desc */ 47 | .iSerialNumber = 3, /* index to string desc */ 48 | .bNumConfigurations = 1, 49 | }; 50 | 51 | uint8_t mic_streaming_iface_cur_altsetting = 0; 52 | 53 | static const struct usb_interface ifaces[] = {{ 54 | .num_altsetting = 1, 55 | .altsetting = mic_audio_control_iface, 56 | }, { 57 | .num_altsetting = 2, 58 | .cur_altsetting = &mic_streaming_iface_cur_altsetting, 59 | .altsetting = mic_audio_streaming_iface, 60 | }, { 61 | .num_altsetting = 1, 62 | .altsetting = midi_audio_control_iface, 63 | }, { 64 | .num_altsetting = 1, 65 | .altsetting = midi_streaming_iface, 66 | } }; 67 | 68 | static const struct usb_config_descriptor config = { 69 | .bLength = USB_DT_CONFIGURATION_SIZE, 70 | .bDescriptorType = USB_DT_CONFIGURATION, 71 | .wTotalLength = 0, /* can be anything, it is updated automatically 72 | when the usb code prepares the descriptor */ 73 | .bNumInterfaces = 4, /* control/stream [audio] + control/stream [midi] */ 74 | .bConfigurationValue = 1, 75 | .iConfiguration = 0, 76 | .bmAttributes = 0x80, /* bus powered */ 77 | .bMaxPower = 0x32, 78 | .interface = ifaces, 79 | }; 80 | 81 | static char usb_serial_number[25]; /* 12 bytes of desig and a \0 */ 82 | 83 | static const char * usb_strings[] = { 84 | "Tomu", 85 | "USB Synth Demo", 86 | usb_serial_number 87 | }; 88 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/memorymap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_CM3_MEMORYMAP_H 21 | #define LIBOPENCM3_CM3_MEMORYMAP_H 22 | 23 | /* --- ARM Cortex-M0, M3 and M4 specific definitions ----------------------- */ 24 | 25 | /* Private peripheral bus - Internal */ 26 | #define PPBI_BASE (0xE0000000U) 27 | 28 | /* Those defined only on ARMv7 and above */ 29 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 30 | /* ITM: Instrumentation Trace Macrocell */ 31 | #define ITM_BASE (PPBI_BASE + 0x0000) 32 | 33 | /* DWT: Data Watchpoint and Trace unit */ 34 | #define DWT_BASE (PPBI_BASE + 0x1000) 35 | 36 | /* FPB: Flash Patch and Breakpoint unit */ 37 | #define FPB_BASE (PPBI_BASE + 0x2000) 38 | #endif 39 | 40 | /* PPBI_BASE + 0x3000 (0xE000 3000 - 0xE000 DFFF): Reserved */ 41 | 42 | #define SCS_BASE (PPBI_BASE + 0xE000) 43 | 44 | /* PPBI_BASE + 0xF000 (0xE000 F000 - 0xE003 FFFF): Reserved */ 45 | 46 | /* Those defined only on ARMv7 and above */ 47 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 48 | #define TPIU_BASE (PPBI_BASE + 0x40000) 49 | #endif 50 | 51 | /* --- SCS: System Control Space --- */ 52 | 53 | /* Those defined only on ARMv7 and above */ 54 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 55 | /* ITR: Interrupt Type Register */ 56 | #define ITR_BASE (SCS_BASE + 0x0000) 57 | #endif 58 | 59 | /* SYS_TICK: System Timer */ 60 | #define SYS_TICK_BASE (SCS_BASE + 0x0010) 61 | 62 | /* NVIC: Nested Vector Interrupt Controller */ 63 | #define NVIC_BASE (SCS_BASE + 0x0100) 64 | 65 | /* SCB: System Control Block */ 66 | #define SCB_BASE (SCS_BASE + 0x0D00) 67 | 68 | /* MPU: Memory protection unit */ 69 | #define MPU_BASE (SCS_BASE + 0x0D90) 70 | 71 | /* Those defined only on CM0*/ 72 | #if defined(__ARM_ARCH_6M__) 73 | /* DEBUG: Debug control and configuration */ 74 | #define DEBUG_BASE (SCS_BASE + 0x0DF0) 75 | #endif 76 | 77 | /* Those defined only on ARMv7 and above */ 78 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 79 | /* STE: Software Trigger Interrupt Register */ 80 | #define STIR_BASE (SCS_BASE + 0x0F00) 81 | /* ID: ID space */ 82 | #define ID_BASE (SCS_BASE + 0x0FD0) 83 | #endif 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /usb-synth/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | A pretty terrible USB-MIDI synthesizer. The Tomu will enumerate as a composite MIDI device 4 | and line-in (mic) device. Sending MIDI notes to it will emit tones out the mic device. 5 | 6 | The green and red LEDs will toggle in time with the music as it is played 7 | 8 | Currently, this implementation ignores all drum tracks and redirects all instruments to sine tones. 9 | Velocity and sustain are supported, but it will cull notes if one attempts > 10 voice polyphony. 10 | 11 | The 'synth bits' are in `synth_core.c`. Notes are culled pretty inefficiently at the moment. 12 | 13 | # Usage 14 | 15 | Warning: only tested on a Linux host under ALSA! Windows is picky about audio descriptors, 16 | so it's unlikely this will work on Windows without further work. 17 | 18 | ## Capturing the output 19 | 20 | To feed the Tomu's audio to your speakers in real-time, `alsaloop` does the job: 21 | 22 | $ sudo alsaloop -C hw:1,0 -P hw:0,0 --rate=8000 23 | 24 | The first hardware ID should be your Tomu (`-C` for capture), the second (`-P` for playback) your computers' soundcard. 25 | You can figure out these hardware IDs by running `arecord -l` and `aplay -l` - for example: 26 | 27 | $ arecord -l 28 | **** List of CAPTURE Hardware Devices **** 29 | card 0: PCH [HDA Intel PCH], device 0: CX8200 Analog [CX8200 Analog] 30 | Subdevices: 0/1 31 | Subdevice #0: subdevice #0 32 | card 1: Demo [USB Synth Demo], device 0: USB Audio [USB Audio] 33 | Subdevices: 1/1 34 | Subdevice #0: subdevice #0 35 | 36 | This indicates that card 1, device 0 (i.e `hw:1,0`) is the Tomu capture device. 37 | The same procedure with `aplay -l` with give you the ID of your playback device. 38 | 39 | ## Feeding music to the Tomu 40 | 41 | Then, to play MIDI files, you can use `aplaymidi` to get the port name: 42 | 43 | $ aplaymidi -l 44 | Port Client name Port name 45 | 14:0 Midi Through Midi Through Port-0 46 | 20:0 USB Synth Demo USB Synth Demo MIDI 1 47 | 48 | Which can be passed to `aplaymidi` to play some music: 49 | 50 | $ aplaymidi --port 20:0 .mid 51 | 52 | If all goes well, you should hear a pretty terrible rendition of your MIDI file, and the LEDs will blink in time. 53 | 54 | ## Playing the Tomu as a live MIDI instrument 55 | 56 | If you're really keen and have a MIDI keyboard, you can hook that up to the MIDI port and play the thing live. 57 | Use `aconnect -l` to view all your ports: 58 | 59 | $ aconnect -i 60 | client 0: 'System' [type=kernel] 61 | 0 'Timer ' 62 | 1 'Announce ' 63 | client 14: 'Midi Through' [type=kernel] 64 | 0 'Midi Through Port-0' 65 | client 20: 'USB Synth Demo' [type=kernel,card=1] 66 | 0 'USB Synth Demo MIDI 1' 67 | client 24: 'A-Series Keyboard' [type=kernel,card=2] 68 | 0 'A-Series Keyboard Keyboard' 69 | 70 | Then, to connect your keyboard output to the Tomu, for the above `aconnect -l` output: 71 | 72 | $ aconnect 24:0 20:0 73 | 74 | Where the arguments are `: :`. 75 | 76 | ## Known issues 77 | 78 | I experienced underruns very occasionally (i.e clicks and scratches), but these 79 | seemed to disappear by killing and re-starting `alsaloop`. Your mileage may vary... 80 | -------------------------------------------------------------------------------- /libopencm3/lib/cortex-m-generic.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* 21 | * This is a generic linker script for Cortex-M targets using libopencm3. 22 | * 23 | * Memory regions MUST be defined in the ld script which includes this one! 24 | * Example: 25 | 26 | MEMORY 27 | { 28 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 256K 29 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 16K 30 | } 31 | 32 | INCLUDE cortex-m-generic.ld 33 | 34 | */ 35 | 36 | /* Enforce emmition of the vector table. */ 37 | EXTERN (vector_table) 38 | 39 | /* Define the entry point of the output file. */ 40 | ENTRY(reset_handler) 41 | 42 | /* Define sections. */ 43 | SECTIONS 44 | { 45 | .text : { 46 | *(.vectors) /* Vector table */ 47 | *(.text*) /* Program code */ 48 | . = ALIGN(4); 49 | *(.rodata*) /* Read-only data */ 50 | . = ALIGN(4); 51 | } >rom 52 | 53 | /* C++ Static constructors/destructors, also used for __attribute__ 54 | * ((constructor)) and the likes */ 55 | .preinit_array : { 56 | . = ALIGN(4); 57 | __preinit_array_start = .; 58 | KEEP (*(.preinit_array)) 59 | __preinit_array_end = .; 60 | } >rom 61 | .init_array : { 62 | . = ALIGN(4); 63 | __init_array_start = .; 64 | KEEP (*(SORT(.init_array.*))) 65 | KEEP (*(.init_array)) 66 | __init_array_end = .; 67 | } >rom 68 | .fini_array : { 69 | . = ALIGN(4); 70 | __fini_array_start = .; 71 | KEEP (*(.fini_array)) 72 | KEEP (*(SORT(.fini_array.*))) 73 | __fini_array_end = .; 74 | } >rom 75 | 76 | /* 77 | * Another section used by C++ stuff, appears when using newlib with 78 | * 64bit (long long) printf support 79 | */ 80 | .ARM.extab : { 81 | *(.ARM.extab*) 82 | } >rom 83 | .ARM.exidx : { 84 | __exidx_start = .; 85 | *(.ARM.exidx*) 86 | __exidx_end = .; 87 | } >rom 88 | 89 | . = ALIGN(4); 90 | _etext = .; 91 | 92 | .data : { 93 | _data = .; 94 | *(.data*) /* Read-write initialized data */ 95 | . = ALIGN(4); 96 | _edata = .; 97 | } >ram AT >rom 98 | _data_loadaddr = LOADADDR(.data); 99 | 100 | .bss : { 101 | *(.bss*) /* Read-write zero initialized data */ 102 | *(COMMON) 103 | . = ALIGN(4); 104 | _ebss = .; 105 | } >ram 106 | 107 | /* 108 | * The .eh_frame section appears to be used for C++ exception handling. 109 | * You may need to fix this if you're using C++. 110 | */ 111 | /DISCARD/ : { *(.eh_frame) } 112 | 113 | . = ALIGN(4); 114 | end = .; 115 | } 116 | 117 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 118 | 119 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/itm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2011 Gareth McMullin 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_CM3_ITM_H 21 | #define LIBOPENCM3_CM3_ITM_H 22 | 23 | /* Cortex-M3 Instrumentation Trace Macrocell (ITM) */ 24 | 25 | /* Those defined only on ARMv7 and above */ 26 | #if !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) 27 | #error "Instrumentation Trace Macrocell not available in CM0" 28 | #endif 29 | 30 | /* --- ITM registers ------------------------------------------------------- */ 31 | 32 | /* Stimulus Port x (ITM_STIM(x)) */ 33 | #define ITM_STIM8(n) (MMIO8(ITM_BASE + ((n)*4))) 34 | #define ITM_STIM16(n) (MMIO16(ITM_BASE + ((n)*4))) 35 | #define ITM_STIM32(n) (MMIO32(ITM_BASE + ((n)*4))) 36 | 37 | /* Trace Enable ports (ITM_TER[x]) */ 38 | #define ITM_TER (&MMIO32(ITM_BASE + 0xE00)) 39 | 40 | /* Trace Privilege (ITM_TPR) */ 41 | #define ITM_TPR MMIO32(ITM_BASE + 0xE40) 42 | 43 | /* Trace Control (ITM_TCR) */ 44 | #define ITM_TCR MMIO32(ITM_BASE + 0xE80) 45 | 46 | /* CoreSight Lock Status Register for this peripheral */ 47 | #define ITM_LSR MMIO32(ITM_BASE + 0xFB4) 48 | /* CoreSight Lock Access Register for this peripheral */ 49 | #define ITM_LAR MMIO32(ITM_BASE + 0xFB0) 50 | 51 | /* TODO: PID, CID */ 52 | 53 | /* --- ITM_STIM values ----------------------------------------------------- */ 54 | 55 | /* Bits 31:0 - Write to port FIFO for forwarding as software event packet */ 56 | /* Bits 31:1 - RAZ */ 57 | #define ITM_STIM_FIFOREADY (1 << 0) 58 | 59 | /* --- ITM_TER values ------------------------------------------------------ */ 60 | 61 | /* Bits 31:0 - Stimulus port #N is enabled with STIMENA[N] is set */ 62 | 63 | /* --- ITM_TPR values ------------------------------------------------------ */ 64 | /* 65 | * Bits 31:0 - Bit [N] of PRIVMASK controls stimulus ports 8N to 8N+7 66 | * 0: User access allowed to stimulus ports 67 | * 1: Privileged access only to stimulus ports 68 | */ 69 | 70 | /* --- ITM_TCR values ------------------------------------------------------ */ 71 | 72 | /* Bits 31:24 - Reserved */ 73 | #define ITM_TCR_BUSY (1 << 23) 74 | #define ITM_TCR_TRACE_BUS_ID_MASK (0x3f << 16) 75 | /* Bits 15:10 - Reserved */ 76 | #define ITM_TCR_TSPRESCALE_NONE (0 << 8) 77 | #define ITM_TCR_TSPRESCALE_DIV4 (1 << 8) 78 | #define ITM_TCR_TSPRESCALE_DIV16 (2 << 8) 79 | #define ITM_TCR_TSPRESCALE_DIV64 (3 << 8) 80 | #define ITM_TCR_TSPRESCALE_MASK (3 << 8) 81 | /* Bits 7:5 - Reserved */ 82 | #define ITM_TCR_SWOENA (1 << 4) 83 | #define ITM_TCR_TXENA (1 << 3) 84 | #define ITM_TCR_SYNCENA (1 << 2) 85 | #define ITM_TCR_TSENA (1 << 1) 86 | #define ITM_TCR_ITMENA (1 << 0) 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/common/wdog_common_hglg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /** @cond */ 21 | #if defined(LIBOPENCM3_WDOG_H) 22 | /** @endcond */ 23 | #ifndef LIBOPENCM3_EFM32_WDOG_COMMON_HGLG_H 24 | #define LIBOPENCM3_EFM32_WDOG_COMMON_HGLG_H 25 | 26 | #include 27 | #include 28 | 29 | #define WDOG_CTRL MMIO32(WDOG_BASE + 0x000) 30 | #define WDOG_CMD MMIO32(WDOG_BASE + 0x004) 31 | #define WDOG_SYNCBUSY MMIO32(WDOG_BASE + 0x008) 32 | 33 | /* WDOG_CTRL */ 34 | #define WDOG_CTRL_CLKSEL_SHIFT (12) 35 | #define WDOG_CTRL_CLKSEL_MASK (0x3 << WDOG_CTRL_CLKSEL_SHIFT) 36 | #define WDOG_CTRL_CLKSEL(v) \ 37 | (((v) << WDOG_CTRL_CLKSEL_SHIFT) & WDOG_CTRL_CLKSEL_MASK) 38 | #define WDOG_CTRL_CLKSEL_ULFRCO WDOG_CTRL_CLKSEL(0) 39 | #define WDOG_CTRL_CLKSEL_LFRCO WDOG_CTRL_CLKSEL(1) 40 | #define WDOG_CTRL_CLKSEL_LFXO WDOG_CTRL_CLKSEL(2) 41 | 42 | #define WDOG_CTRL_PERSEL_SHIFT (8) 43 | #define WDOG_CTRL_PERSEL_MASK (0xF << WDOG_CTRL_PERSEL_SHIFT) 44 | #define WDOG_CTRL_PERSEL(v) \ 45 | (((v) << WDOG_CTRL_PERSEL_SHIFT) & WDOG_CTRL_PERSEL_MASK) 46 | #define WDOG_CTRL_PERSEL_9CYCLES WDOG_CTRL_PERSEL(0) 47 | #define WDOG_CTRL_PERSEL_17CYCLES WDOG_CTRL_PERSEL(1) 48 | #define WDOG_CTRL_PERSEL_33CYCLES WDOG_CTRL_PERSEL(2) 49 | #define WDOG_CTRL_PERSEL_65CYCLES WDOG_CTRL_PERSEL(3) 50 | #define WDOG_CTRL_PERSEL_129CYCLES WDOG_CTRL_PERSEL(4) 51 | #define WDOG_CTRL_PERSEL_257CYCLES WDOG_CTRL_PERSEL(5) 52 | #define WDOG_CTRL_PERSEL_513CYCLES WDOG_CTRL_PERSEL(6) 53 | #define WDOG_CTRL_PERSEL_1KCYCLES WDOG_CTRL_PERSEL(7) 54 | #define WDOG_CTRL_PERSEL_2KCYCLES WDOG_CTRL_PERSEL(8) 55 | #define WDOG_CTRL_PERSEL_4KCYCLES WDOG_CTRL_PERSEL(9) 56 | #define WDOG_CTRL_PERSEL_8KCYCLES WDOG_CTRL_PERSEL(10) 57 | #define WDOG_CTRL_PERSEL_16KCYCLES WDOG_CTRL_PERSEL(11) 58 | #define WDOG_CTRL_PERSEL_32KCYCLES WDOG_CTRL_PERSEL(12) 59 | #define WDOG_CTRL_PERSEL_64KCYCLES WDOG_CTRL_PERSEL(13) 60 | #define WDOG_CTRL_PERSEL_128KCYCLES WDOG_CTRL_PERSEL(14) 61 | #define WDOG_CTRL_PERSEL_256KCYCLES WDOG_CTRL_PERSEL(15) 62 | 63 | #define WDOG_CTRL_SWOSCBLOCK (1 << 6) 64 | #define WDOG_CTRL_EM4BLOCK (1 << 5) 65 | #define WDOG_CTRL_LOCK (1 << 4) 66 | #define WDOG_CTRL_EM3RUN (1 << 3) 67 | #define WDOG_CTRL_EM2RUN (1 << 2) 68 | #define WDOG_CTRL_DEBUGRUN (1 << 1) 69 | #define WDOG_CTRL_EN (1 << 0) 70 | 71 | /* WDOG_CMD */ 72 | #define WDOG_CMD_CLEAR (1 << 0) 73 | 74 | /* WDOG_SYNCBUSY */ 75 | #define WDOG_SYNCBUSY_CMD (1 << 1) 76 | #define WDOG_SYNCBUSY_CTRL (1 << 0) 77 | 78 | #endif 79 | /** @cond */ 80 | #else 81 | #warning "wdog_common_hglg.h should not be included explicitly, only via wdog.h" 82 | #endif 83 | /** @endcond */ 84 | -------------------------------------------------------------------------------- /miniblink/miniblink.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2018 Seb Holzapfel 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /** 21 | * \addtogroup Examples 22 | * 23 | * Toggles between the Red and Green LEDs. 24 | * 25 | * Red LED controlled by PA0 26 | * Green LED controlled by PB7 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | /* Declare support for Toboot V2 */ 43 | /* To enable this program to run when you first plug in Tomu, pass 44 | * TOBOOT_CONFIG_FLAG_AUTORUN to this macro. Otherwise, leave the 45 | * configuration value at 0 to use the defaults. 46 | */ 47 | TOBOOT_CONFIGURATION(0); 48 | 49 | /* Systick interrupt frequency, Hz */ 50 | #define SYSTICK_FREQUENCY 1000 51 | 52 | /* USB (core clock) frequency of Tomu board */ 53 | #define USB_CLK_FREQUENCY 24000000 54 | 55 | #define LED_GREEN_PORT GPIOA 56 | #define LED_GREEN_PIN GPIO0 57 | #define LED_RED_PORT GPIOB 58 | #define LED_RED_PIN GPIO7 59 | 60 | volatile uint32_t system_millis = 0; 61 | 62 | void sys_tick_handler(void) { 63 | 64 | ++system_millis; 65 | 66 | /* Every 100ms, toggle the LEDs */ 67 | if(system_millis % 100 == 0) { 68 | gpio_toggle(LED_RED_PORT, LED_RED_PIN); 69 | gpio_toggle(LED_GREEN_PORT, LED_GREEN_PIN); 70 | } 71 | } 72 | 73 | int main(void) 74 | { 75 | /* Disable the watchdog that the bootloader started. */ 76 | WDOG_CTRL = 0; 77 | 78 | /* GPIO peripheral clock is necessary for us to set up the GPIO pins as outputs */ 79 | cmu_periph_clock_enable(CMU_GPIO); 80 | 81 | /* Set up both LEDs as outputs */ 82 | gpio_mode_setup(LED_RED_PORT, GPIO_MODE_WIRED_AND, LED_RED_PIN); 83 | gpio_mode_setup(LED_GREEN_PORT, GPIO_MODE_WIRED_AND, LED_GREEN_PIN); 84 | 85 | /* Set up LEDs so that they will alternate when toggled at the same time */ 86 | gpio_set(LED_RED_PORT, LED_RED_PIN); 87 | gpio_clear(LED_GREEN_PORT, LED_GREEN_PIN); 88 | 89 | /* Configure the system tick */ 90 | /* Set the CPU Core to run from the trimmed USB clock, divided by 2. 91 | * This will give the CPU Core a frequency of 24 MHz +/- 1% */ 92 | cmu_osc_on(USHFRCO); 93 | cmu_wait_for_osc_ready(USHFRCO); 94 | CMU_USBCRCTRL = CMU_USBCRCTRL_EN; 95 | CMU_CMD = CMU_CMD_HFCLKSEL(5); 96 | while (! (CMU_STATUS & CMU_STATUS_USHFRCODIV2SEL)) 97 | ; 98 | 99 | systick_set_frequency(SYSTICK_FREQUENCY, USB_CLK_FREQUENCY); 100 | systick_counter_enable(); 101 | systick_interrupt_enable(); 102 | 103 | /* Spin forever, SysTick interrupt will toggle the LEDs */ 104 | while(1); 105 | } 106 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/tpiu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2011 Gareth McMullin 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_CM3_TPIU_H 21 | #define LIBOPENCM3_CM3_TPIU_H 22 | 23 | /* Cortex-M3 Trace Port Interface Unit (TPIU) */ 24 | 25 | /* Those defined only on ARMv7 and above */ 26 | #if !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) 27 | #error "Trace Port Interface Unit not available in CM0" 28 | #endif 29 | 30 | /* --- TPIU registers ------------------------------------------------------ */ 31 | 32 | /* Supported Synchronous Port Size (TPIU_SSPSR) */ 33 | #define TPIU_SSPSR MMIO32(TPIU_BASE + 0x000) 34 | 35 | /* Current Synchronous Port Size (TPIU_CSPSR) */ 36 | #define TPIU_CSPSR MMIO32(TPIU_BASE + 0x004) 37 | 38 | /* Asynchronous Clock Prescaler (TPIU_ACPR) */ 39 | #define TPIU_ACPR MMIO32(TPIU_BASE + 0x010) 40 | 41 | /* Selected Pin Protocol (TPIU_SPPR) */ 42 | #define TPIU_SPPR MMIO32(TPIU_BASE + 0x0F0) 43 | 44 | /* Formatter and Flush Status Register (TPIU_FFSR) */ 45 | #define TPIU_FFSR MMIO32(TPIU_BASE + 0x300) 46 | 47 | /* Formatter and Flush Control Register (TPIU_FFCR) */ 48 | #define TPIU_FFCR MMIO32(TPIU_BASE + 0x304) 49 | 50 | /* (TPIU_DEVID) */ 51 | #define TPIU_DEVID MMIO32(TPIU_BASE + 0xFC8) 52 | 53 | /* CoreSight Lock Status Register for this peripheral */ 54 | #define TPIU_LSR MMIO32(TPIU_BASE + 0xFB4) 55 | /* CoreSight Lock Access Register for this peripheral */ 56 | #define TPIU_LAR MMIO32(TPIU_BASE + 0xFB0) 57 | 58 | /* TODO: PID, CID */ 59 | 60 | /* --- TPIU_ACPR values ---------------------------------------------------- */ 61 | 62 | /* Bits 31:16 - Reserved */ 63 | /* Bits 15:0 - SWO output clock = Asynchronous_Reference_Clock/(value +1) */ 64 | 65 | /* --- TPIU_SPPR values ---------------------------------------------------- */ 66 | 67 | /* Bits 31:2 - Reserved */ 68 | #define TPIU_SPPR_SYNC (0x0) 69 | #define TPIU_SPPR_ASYNC_MANCHESTER (0x1) 70 | #define TPIU_SPPR_ASYNC_NRZ (0x2) 71 | 72 | /* --- TPIU_FFSR values ---------------------------------------------------- */ 73 | 74 | /* Bits 31:4 - Reserved */ 75 | #define TPIU_FFSR_FTNONSTOP (1 << 3) 76 | #define TPIU_FFSR_TCPRESENT (1 << 2) 77 | #define TPIU_FFSR_FTSTOPPED (1 << 1) 78 | #define TPIU_FFSR_FLINPROG (1 << 0) 79 | 80 | /* --- TPIU_FFCR values ---------------------------------------------------- */ 81 | 82 | /* Bits 31:9 - Reserved */ 83 | #define TPIU_FFCR_TRIGIN (1 << 8) 84 | /* Bits 7:2 - Reserved */ 85 | #define TPIU_FFCR_ENFCONT (1 << 1) 86 | /* Bit 0 - Reserved */ 87 | 88 | /* --- TPIU_DEVID values ---------------------------------------------------- */ 89 | /* Bits 31:16 - Reserved */ 90 | /* Bits 15:12 - Implementation defined */ 91 | #define TPUI_DEVID_NRZ_SUPPORTED (1 << 11) 92 | #define TPUI_DEVID_MANCHESTER_SUPPORTED (1 << 10) 93 | /* Bit 9 - RAZ, indicated that trace data and clock are supported */ 94 | #define TPUI_DEVID_FIFO_SIZE_MASK (7 << 6) 95 | /* Bits 5:0 - Implementation defined */ 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /Makefile.common: -------------------------------------------------------------------------------- 1 | PACKAGE = $(notdir $(realpath .)) 2 | OPENCM3 ?= ../libopencm3 3 | ADD_CFLAGS = -I$(OPENCM3)/include -I../include -DEFM32HG 4 | ADD_LFLAGS = -L$(OPENCM3)/lib -lopencm3_efm32hg 5 | 6 | GIT_VERSION := $(shell git describe --tags) 7 | TRGT ?= arm-none-eabi- 8 | CC = $(TRGT)gcc 9 | CXX = $(TRGT)g++ 10 | OBJCOPY = $(TRGT)objcopy 11 | 12 | RM = rm -rf 13 | COPY = cp -a 14 | PATH_SEP = / 15 | 16 | ifeq ($(OS),Windows_NT) 17 | COPY = copy 18 | RM = del 19 | PATH_SEP = \\ 20 | endif 21 | 22 | LDSCRIPT = ../tomu-efm32hg309.ld 23 | DBG_CFLAGS = -ggdb -g -DDEBUG -Wall 24 | DBG_LFLAGS = -ggdb -g -Wall 25 | CFLAGS = $(ADD_CFLAGS) \ 26 | -Wall -Wextra \ 27 | -mcpu=cortex-m0plus -mfloat-abi=soft -mthumb \ 28 | -ffunction-sections -fdata-sections -fno-common \ 29 | -fomit-frame-pointer -Os \ 30 | -DGIT_VERSION=u\"$(GIT_VERSION)\" -std=gnu11 31 | CXXFLAGS = $(CFLAGS) -std=c++11 -fno-rtti -fno-exceptions 32 | LFLAGS = $(ADD_LFLAGS) $(CFLAGS) \ 33 | -nostartfiles \ 34 | -Wl,--gc-sections \ 35 | -Wl,--no-warn-mismatch,--script=$(LDSCRIPT),--build-id=none 36 | 37 | OBJ_DIR = .obj 38 | 39 | CSOURCES = $(wildcard *.c) 40 | CPPSOURCES = $(wildcard *.cpp) 41 | ASOURCES = $(wildcard *.S) 42 | COBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(CSOURCES:.c=.o))) 43 | CXXOBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(CPPSOURCES:.cpp=.o))) 44 | AOBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(ASOURCES:.S=.o))) 45 | OBJECTS = $(COBJS) $(CXXOBJS) $(AOBJS) 46 | VPATH = . 47 | 48 | QUIET = @ 49 | 50 | ALL = all 51 | TARGET = $(PACKAGE).elf 52 | CLEAN = clean 53 | 54 | $(ALL): $(TARGET) $(PACKAGE).bin $(PACKAGE).ihex $(PACKAGE).dfu 55 | 56 | $(OBJECTS): | $(OBJ_DIR) 57 | 58 | $(TARGET): $(OBJECTS) $(LDSCRIPT) 59 | $(QUIET) echo " LD $@" 60 | $(QUIET) $(CXX) $(OBJECTS) $(LFLAGS) -o $@ 61 | 62 | $(PACKAGE).bin: $(TARGET) 63 | $(QUIET) echo " OBJCOPY $@" 64 | $(QUIET) $(OBJCOPY) -O binary $(TARGET) $@ 65 | 66 | $(PACKAGE).dfu: $(TARGET) 67 | $(QUIET) echo " DFU $@" 68 | $(QUIET) $(COPY) $(PACKAGE).bin $@ 69 | $(QUIET) dfu-suffix -v 1209 -p 70b1 -a $@ 70 | 71 | $(PACKAGE).ihex: $(TARGET) 72 | $(QUIET) echo " IHEX $(PACKAGE).ihex" 73 | $(QUIET) $(OBJCOPY) -O ihex $(TARGET) $@ 74 | 75 | $(DEBUG): CFLAGS += $(DBG_CFLAGS) 76 | $(DEBUG): LFLAGS += $(DBG_LFLAGS) 77 | CFLAGS += $(DBG_CFLAGS) 78 | LFLAGS += $(DBG_LFLAGS) 79 | $(DEBUG): $(TARGET) 80 | 81 | $(OBJ_DIR): 82 | $(QUIET) mkdir $(OBJ_DIR) 83 | 84 | $(COBJS) : $(OBJ_DIR)/%.o : %.c Makefile 85 | $(QUIET) echo " CC $< $(notdir $@)" 86 | $(QUIET) $(CC) -c $< $(CFLAGS) -o $@ -MMD 87 | 88 | $(OBJ_DIR)/%.o: %.cpp 89 | $(QUIET) echo " CXX $< $(notdir $@)" 90 | $(QUIET) $(CXX) -c $< $(CXXFLAGS) -o $@ -MMD 91 | 92 | $(OBJ_DIR)/%.o: %.S 93 | $(QUIET) echo " AS $< $(notdir $@)" 94 | $(QUIET) $(CC) -x assembler-with-cpp -c $< $(CFLAGS) -o $@ -MMD 95 | 96 | .PHONY: clean 97 | 98 | clean: 99 | $(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))" 100 | -$(QUIET) $(RM) $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d)) 101 | $(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))" 102 | -$(QUIET) $(RM) $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.o)) 103 | $(QUIET) echo " RM $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu" 104 | -$(QUIET) $(RM) $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu 105 | 106 | include $(wildcard $(OBJ_DIR)/*.d) 107 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/common/uart_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_EFM32_UART_H 21 | #define LIBOPENCM3_EFM32_UART_H 22 | 23 | /** 24 | * USART and UART registers are equivalent except [in UART registers]: 25 | * 26 | * USART_CTRL: SYNC, CSMA, SMSDELAY, SSSEARLY, CSINV, CPOL and CPHA [1] 27 | * USART_STATUS: MASTEREN [1] 28 | * [1] Synchronous operation not available. 29 | * USART_CTRL: MSBF (transmission LSB first only) 30 | * USART_CTRL: AUTOCS (chip-select not available) 31 | * USART_CTRL: SCMODE (SmartCard mode not available) 32 | * USART_FRAME: DATABITS (limited framsize. 8-9 databits only) 33 | * USART_IRCTRL: IREN (IrDA not available) 34 | * (except DATABITS, all the above are 0) 35 | * 36 | * full text: (p495, "d0183_Rev1.10" EFM32LG-RM) 37 | * - "18.3 Functional Description", 38 | * - "18.4 Register Description" 39 | * - "18.5 Register Map" 40 | * 41 | * use USART macro's to manipulate UART registers. 42 | */ 43 | #include 44 | #include 45 | 46 | /* UART0 */ 47 | #define UART0 UART0_BASE 48 | #define UART0_CTRL USART_CTRL(UART0) 49 | #define UART0_FRAME USART_FRAME(UART0) 50 | #define UART0_TRIGCTRL USART_TRIGCTRL(UART0) 51 | #define UART0_CMD USART_CMD(UART0) 52 | #define UART0_STATUS USART_STATUS(UART0) 53 | #define UART0_CLKDIV USART_CLKDIV(UART0) 54 | #define UART0_RXDATAX USART_RXDATAX(UART0) 55 | #define UART0_RXDATA USART_RXDATA(UART0) 56 | #define UART0_RXDOUBLEX USART_RXDOUBLEX(UART0) 57 | #define UART0_RXDOUBLE USART_RXDOUBLE(UART0) 58 | #define UART0_RXDATAXP USART_RXDATAXP(UART0) 59 | #define UART0_RXDOUBLEXP USART_RXDOUBLEXP(UART0) 60 | #define UART0_TXDATAX USART_TXDATAX(UART0) 61 | #define UART0_TXDATA USART_TXDATA(UART0) 62 | #define UART0_TXDOUBLEX USART_TXDOUBLEX(UART0) 63 | #define UART0_TXDOUBLE USART_TXDOUBLE(UART0) 64 | #define UART0_IF USART_IF(UART0) 65 | #define UART0_IFS USART_IFS(UART0) 66 | #define UART0_IFC USART_IFC(UART0) 67 | #define UART0_IEN USART_IEN(UART0) 68 | #define UART0_IRCTRL USART_IRCTRL(UART0) 69 | #define UART0_ROUTE USART_ROUTE(UART0) 70 | #define UART0_INPUT USART_INPUT(UART0) 71 | #define UART0_I2SCTRL USART_I2SCTRL(UART0) 72 | 73 | /* UART1 */ 74 | #define UART1 UART1_BASE 75 | #define UART1_CTRL USART_CTRL(UART1) 76 | #define UART1_FRAME USART_FRAME(UART1) 77 | #define UART1_TRIGCTRL USART_TRIGCTRL(UART1) 78 | #define UART1_CMD USART_CMD(UART1) 79 | #define UART1_STATUS USART_STATUS(UART1) 80 | #define UART1_CLKDIV USART_CLKDIV(UART1) 81 | #define UART1_RXDATAX USART_RXDATAX(UART1) 82 | #define UART1_RXDATA USART_RXDATA(UART1) 83 | #define UART1_RXDOUBLEX USART_RXDOUBLEX(UART1) 84 | #define UART1_RXDOUBLE USART_RXDOUBLE(UART1) 85 | #define UART1_RXDATAXP USART_RXDATAXP(UART1) 86 | #define UART1_RXDOUBLEXP USART_RXDOUBLEXP(UART1) 87 | #define UART1_TXDATAX USART_TXDATAX(UART1) 88 | #define UART1_TXDATA USART_TXDATA(UART1) 89 | #define UART1_TXDOUBLEX USART_TXDOUBLEX(UART1) 90 | #define UART1_TXDOUBLE USART_TXDOUBLE(UART1) 91 | #define UART1_IF USART_IF(UART1) 92 | #define UART1_IFS USART_IFS(UART1) 93 | #define UART1_IFC USART_IFC(UART1) 94 | #define UART1_IEN USART_IEN(UART1) 95 | #define UART1_IRCTRL USART_IRCTRL(UART1) 96 | #define UART1_ROUTE USART_ROUTE(UART1) 97 | #define UART1_INPUT USART_INPUT(UART1) 98 | #define UART1_I2SCTRL USART_I2SCTRL(UART1) 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /pwm-shell/README.md: -------------------------------------------------------------------------------- 1 | # PWM Shell LED indicator 2 | 3 | ## Overview 4 | 5 | This program demonstrates using Timer PWM and interrupts to control the Tomu's green and red LEDs. 6 | A shell interface over USB serial (CDC-ACM) is implemented, based on the ACM and Opticspy demos. 7 | The interface allows setting the Tomu's LEDs to various brightness values and blink/fade patterns. 8 | Commands can be scripted externally, so the Tomu may be used as a notification light (in the spirit of "blink(1)"). 9 | 10 | The general case for LED operation is a cyclic fade ramp, from Low to ramp Up, High, ramp Down: ```__/⁻⁻⁻⁻\__``` 11 | 12 | The PWM duty cycle values for each LED are updated individually in its concomitant timer's OF interrupt. 13 | Millisecond timing is estimated based on the LED Timer's frequency (derived from clock, prescale, top value settings). 14 | This timing method can achieve > 99% accuracy, which seems acceptable for a LED indicator viewed by humans. 15 | An alternative implementation can use an additional timer or the System Tick interrupt to count milliseconds and update the LEDs. 16 | 17 | ## Usage 18 | 19 | Input format: ``[PARAMETERS] ...`` 20 | Command parameters are *case-insensitive*. 21 | Commands are parsed when the return key is sent ("Enter"). 22 | Several commands may be sent in a single line of input, separated by spaces if necessary. 23 | 24 | ## Supported commands 25 | 26 | ### H : Print help message 27 | 28 | ### T : Advance both LEDs to their next test mode 29 | * Cycles through several demo configurations. 30 | 31 | ### G,R : Configure Green/Red LED settings 32 | * Syntax: ```` 33 | * T : Set LED configuration to the next test mode (for demo purposes). 34 | * N : Min brightness, 0-100, duty cycle percentage. 35 | * X : Max brightness, 0-100, duty cycle percentage. 36 | * L : Low (Min) value duration in millisconds, positive integer. 37 | * U : Ramp up duration in millisconds, positive integer. 38 | * H : High (Max) value duration in millisconds, positive integer. 39 | * D : Ramp down duration in millisconds, positive integer. 40 | * P : Current phase, letter ``[L,U,H,D]`` or number ``[0,1,2,3]``. 41 | 42 | ### D : Disable/Enable debug printouts 43 | * Syntax: ``<0,1>`` 44 | 45 | ### E : Disable/Enable Serial Echo for the shell 46 | * Syntax: ``<0,1>`` 47 | 48 | ### P : Print current configuration of the Green/Red LED 49 | * Syntax: ``

`` 50 | 51 | ### S : Sync both LED timers. 52 | * Syntax: ``<[L,U,H,D][L,U,H,D]>`` 53 | * The first phase letter is for the Green LED, second for Red LED. 54 | * The command stops the timers, resets, sets the phases, then restarts both together. 55 | 56 | 57 | ## Example commands 58 | 59 | * Printing the configuration of the Green and Red LEDs: 60 | ``` 61 | pgpr 62 | ``` 63 | Same as: 64 | ``` 65 | PG PR 66 | ``` 67 | * Set constant 100% brightness for both LEDs: 68 | ``` 69 | gn100 gx100 rn100 rx100 gl0 gu0 gh1000 gd0 rl0 ru0 rh1000 rd0 70 | ``` 71 | * Turn off Red LED: 72 | ``` 73 | rn0rx0 74 | ``` 75 | * Set Green LED config, fade from 0 to 50 % brightness, each phase duration 1000 ms: 76 | ``` 77 | gn0 gx50 gl1000 gu1000 gh1000 gd1000 78 | ``` 79 | * Set both LEDs to blink once a second: 80 | ``` 81 | gn0 gx100 gl1000 gu0 gh1000 gd0 rn0 rx100 rl1000 ru0 rh1000 rd0 82 | ``` 83 | * Synchronize the LEDs, starting from Low phase: 84 | ``` 85 | sll 86 | ``` 87 | * Set alternating Green/Red blink, once a second: 88 | ``` 89 | gn0 gx100 gl1000 gu0 gh1000 gd0 rn0 rx100 rl1000 ru0 rh1000 rd0 slh 90 | ``` 91 | * Set alternating Green/Red fade in and out: 92 | ``` 93 | gn0 gx50 gl3500 gu1500 gh500 gd1500 rn0 rx100 rl3500 ru1500 rh500 rd1500 slu 94 | ``` 95 | 96 | ## Accessing the serial shell 97 | 98 | ### From Windows 99 | 100 | Use a terminal emulator program, such as [PuTTY](https://www.putty.org/) or [Tera Term](https://ttssh2.osdn.jp/index.html.en). 101 | 102 | ### From Linux 103 | 104 | * Use a terminal program, such as [Minicom](https://en.wikipedia.org/wiki/Minicom) or [Screen](https://en.wikipedia.org/wiki/GNU_Screen), either interactively or using a pipe. 105 | * Redirect commands to the serial device, e.g. to send the "t" (test) command: 106 | ``` 107 | echo -en “t\r” > /dev/ttyACM0 108 | ``` -------------------------------------------------------------------------------- /captouch/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: printf.h 3 | 4 | Copyright (C) 2004 Kustaa Nyholm 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | See the GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | 20 | This library is realy just two files: 'printf.h' and 'printf.c'. 21 | 22 | They provide a simple and small (+200 loc) printf functionality to 23 | be used in embedded systems. 24 | 25 | I've found them so usefull in debugging that I do not bother with a 26 | debugger at all. 27 | 28 | They are distributed in source form, so to use them, just compile them 29 | into your project. 30 | 31 | Two printf variants are provided: printf and sprintf. 32 | 33 | The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. 34 | 35 | Zero padding and field width are also supported. 36 | 37 | If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the 38 | long specifier is also 39 | supported. Note that this will pull in some long math routines (pun intended!) 40 | and thus make your executable noticably longer. 41 | 42 | The memory foot print of course depends on the target cpu, compiler and 43 | compiler options, but a rough guestimate (based on a H8S target) is about 44 | 1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space. 45 | Not too bad. Your milage may vary. By hacking the source code you can 46 | get rid of some hunred bytes, I'm sure, but personally I feel the balance of 47 | functionality and flexibility versus code size is close to optimal for 48 | many embedded systems. 49 | 50 | To use the printf you need to supply your own character output function, 51 | something like : 52 | 53 | void putc ( void* p, char c) 54 | { 55 | while (!SERIAL_PORT_EMPTY) ; 56 | SERIAL_PORT_TX_REGISTER = c; 57 | } 58 | 59 | Before you can call printf you need to initialize it to use your 60 | character output function with something like: 61 | 62 | init_printf(NULL,putc); 63 | 64 | Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc', 65 | the NULL (or any pointer) you pass into the 'init_printf' will eventually be 66 | passed to your 'putc' routine. This allows you to pass some storage space (or 67 | anything realy) to the character output function, if necessary. 68 | This is not often needed but it was implemented like that because it made 69 | implementing the sprintf function so neat (look at the source code). 70 | 71 | The code is re-entrant, except for the 'init_printf' function, so it 72 | is safe to call it from interupts too, although this may result in mixed output. 73 | If you rely on re-entrancy, take care that your 'putc' function is re-entrant! 74 | 75 | The printf and sprintf functions are actually macros that translate to 76 | 'tfp_printf' and 'tfp_sprintf'. This makes it possible 77 | to use them along with 'stdio.h' printf's in a single source file. 78 | You just need to undef the names before you include the 'stdio.h'. 79 | Note that these are not function like macros, so if you have variables 80 | or struct members with these names, things will explode in your face. 81 | Without variadic macros this is the best we can do to wrap these 82 | fucnction. If it is a problem just give up the macros and use the 83 | functions directly or rename them. 84 | 85 | For further details see source code. 86 | 87 | regs Kusti, 23.10.2004 88 | */ 89 | 90 | 91 | #ifndef __TFP_PRINTF__ 92 | #define __TFP_PRINTF__ 93 | 94 | #include 95 | #ifdef printf 96 | #undef printf 97 | #endif 98 | #define printf tfp_printf 99 | 100 | #ifdef __cplusplus 101 | extern "C" { 102 | #endif 103 | 104 | void init_printf(void* putp,void (*putf) (void*,char)); 105 | 106 | void tfp_printf(char *fmt, ...); 107 | void tfp_sprintf(char* s,const char *fmt, ...); 108 | 109 | void tfp_format(void* putp,void (*putf) (void*,char), const char *fmt, va_list va); 110 | 111 | #ifdef __cplusplus 112 | }; 113 | #endif 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /ledpulse/ledpulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Based on code: 5 | * Copyright (C) 2018 Seb Holzapfel 6 | * 7 | * Copyright (C) 2020 Marc MERLIN 8 | * 9 | * This library is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this library. If not, see . 21 | */ 22 | 23 | /** 24 | * \addtogroup Examples 25 | * 26 | * Toggles between the Red and Green LEDs. 27 | * 28 | * Red LED controlled by PA0 29 | * Green LED controlled by PB7 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | 43 | #include 44 | 45 | /* Declare support for Toboot V2 */ 46 | /* To enable this program to run when you first plug in Tomu, pass 47 | * TOBOOT_CONFIG_FLAG_AUTORUN to this macro. Otherwise, leave the 48 | * configuration value at 0 to use the defaults. 49 | */ 50 | TOBOOT_CONFIGURATION(0); 51 | 52 | /* Systick interrupt frequency, Hz */ 53 | #define SYSTICK_FREQUENCY 100000 54 | 55 | /* USB (core clock) frequency of Tomu board */ 56 | #define USB_CLK_FREQUENCY 24000000 57 | 58 | #define LED_GREEN_PORT GPIOA 59 | #define LED_GREEN_PIN GPIO0 60 | #define LED_RED_PORT GPIOB 61 | #define LED_RED_PIN GPIO7 62 | 63 | volatile uint32_t system_millis = 0; 64 | 65 | void sys_tick_handler(void) { 66 | static uint16_t tick = 0; 67 | static int8_t red_pwm_change = 4; 68 | static int8_t green_pwm_change = -10; 69 | static int16_t red_pwm = 0; 70 | static int16_t green_pwm = 1000; 71 | static bool red_on = true; 72 | static bool green_on = true; 73 | 74 | // unused for now 75 | if (tick % 10 == 0) system_millis++; 76 | 77 | if (red_on && tick >= red_pwm) { 78 | red_on = false; 79 | gpio_toggle(LED_RED_PORT, LED_RED_PIN); 80 | } 81 | if (green_on && tick >= green_pwm) { 82 | green_on = false; 83 | gpio_toggle(LED_GREEN_PORT, LED_GREEN_PIN); 84 | } 85 | 86 | if (tick++ == 1000) { 87 | tick = 0; 88 | red_pwm += red_pwm_change; 89 | green_pwm += green_pwm_change; 90 | if (red_pwm == 0 || red_pwm == 1000) red_pwm_change *= -1; 91 | if (green_pwm == 0 || green_pwm == 1000) green_pwm_change *= -1; 92 | // turn LEDs back on 93 | gpio_toggle(LED_RED_PORT, LED_RED_PIN); 94 | gpio_toggle(LED_GREEN_PORT, LED_GREEN_PIN); 95 | red_on = true; 96 | green_on = true; 97 | } 98 | } 99 | 100 | int main(void) 101 | { 102 | /* Disable the watchdog that the bootloader started. */ 103 | WDOG_CTRL = 0; 104 | 105 | /* GPIO peripheral clock is necessary for us to set up the GPIO pins as outputs */ 106 | cmu_periph_clock_enable(CMU_GPIO); 107 | 108 | /* Set up both LEDs as outputs */ 109 | gpio_mode_setup(LED_RED_PORT, GPIO_MODE_WIRED_AND, LED_RED_PIN); 110 | gpio_mode_setup(LED_GREEN_PORT, GPIO_MODE_WIRED_AND, LED_GREEN_PIN); 111 | 112 | gpio_set(LED_RED_PORT, LED_RED_PIN); 113 | gpio_set(LED_GREEN_PORT, LED_GREEN_PIN); 114 | gpio_toggle(LED_RED_PORT, LED_RED_PIN); 115 | gpio_toggle(LED_GREEN_PORT, LED_GREEN_PIN); 116 | 117 | /* Configure the system tick */ 118 | /* Set the CPU Core to run from the trimmed USB clock, divided by 2. 119 | * This will give the CPU Core a frequency of 24 MHz +/- 1% */ 120 | cmu_osc_on(USHFRCO); 121 | cmu_wait_for_osc_ready(USHFRCO); 122 | CMU_USBCRCTRL = CMU_USBCRCTRL_EN; 123 | CMU_CMD = CMU_CMD_HFCLKSEL(5); 124 | while (! (CMU_STATUS & CMU_STATUS_USHFRCODIV2SEL)) 125 | ; 126 | 127 | systick_set_frequency(SYSTICK_FREQUENCY, USB_CLK_FREQUENCY); 128 | systick_counter_enable(); 129 | systick_interrupt_enable(); 130 | 131 | /* Spin forever, SysTick interrupt will toggle the LEDs */ 132 | while(1); 133 | } 134 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/hg/memorymap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * Copyright (C) 2018 Seb Holzapfel 6 | * 7 | * This library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this library. If not, see . 19 | */ 20 | 21 | #ifndef LIBOPENCM3_EFM32_MEMORYMAP_H 22 | #define LIBOPENCM3_EFM32_MEMORYMAP_H 23 | 24 | #include 25 | 26 | #define PERIPH_BASE (0x40000000U) 27 | 28 | /* Device information */ 29 | #define DI_BASE (0x0FE08000U) 30 | 31 | /* all names are "DI_" + */ 32 | #define DI_CMU_LFRCOCTRL MMIO32(DI_BASE + 0x020) 33 | #define DI_CMU_HFRCOCTRL MMIO32(DI_BASE + 0x028) 34 | #define DI_CMU_AUXHFRCOCTRL MMIO32(DI_BASE + 0x030) 35 | #define DI_ADC0_CAL MMIO32(DI_BASE + 0x040) 36 | #define DI_ADC0_BIASPROG MMIO32(DI_BASE + 0x048) 37 | #define DI_ACMP0_CTRL MMIO32(DI_BASE + 0x050) 38 | #define DI_CMU_LCDCTRL MMIO32(DI_BASE + 0x058) 39 | #define DI_IDAC0_CAL MMIO32(DI_BASE + 0x078) 40 | #define DI_USHFRCOCTRL MMIO32(DI_BASE + 0x098) 41 | #define DI_DI_CRC MMIO16(DI_BASE + 0x1B0) 42 | #define DI_CAL_TEMP_0 MMIO8(DI_BASE + 0x1B2) 43 | #define DI_ADC0_CAL_1V25 MMIO16(DI_BASE + 0x1B4) 44 | #define DI_ADC0_CAL_2V5 MMIO16(DI_BASE + 0x1B6) 45 | #define DI_ADC0_CAL_VDD MMIO16(DI_BASE + 0x1B8) 46 | #define DI_ADC0_CAL_5VDIFF MMIO16(DI_BASE + 0x1BA) 47 | #define DI_ADC0_CAL_2XVDD MMIO16(DI_BASE + 0x1BC) 48 | #define DI_ADC0_TEMP_0_READ_1V25 MMIO16(DI_BASE + 0x1BE) 49 | #define DI_IDAC0_CAL_RANGE0 MMIO32(DI_BASE + 0x1C8) 50 | #define DI_IDAC0_CAL_RANGE1 MMIO32(DI_BASE + 0x1C9) 51 | #define DI_IDAC0_CAL_RANGE2 MMIO32(DI_BASE + 0x1CA) 52 | #define DI_IDAC0_CAL_RANGE3 MMIO32(DI_BASE + 0x1CB) 53 | #define DI_USHFRCO_COARSECAL_BAND_25 MMIO32(DI_BASE + 0x1CC) 54 | #define DI_USHFRCO_FINECAL_BAND_25 MMIO32(DI_BASE + 0x1CD) 55 | #define DI_USHFRCO_COARSECAL_BAND_48 MMIO32(DI_BASE + 0x1CE) 56 | #define DI_USHFRCO_FINECAL_BAND_48 MMIO32(DI_BASE + 0x1CF) 57 | #define DI_AUXHFRCO_CALIB_BAND_1 MMIO8(DI_BASE + 0x1D4) 58 | #define DI_AUXHFRCO_CALIB_BAND_7 MMIO8(DI_BASE + 0x1D5) 59 | #define DI_AUXHFRCO_CALIB_BAND_11 MMIO8(DI_BASE + 0x1D6) 60 | #define DI_AUXHFRCO_CALIB_BAND_14 MMIO8(DI_BASE + 0x1D7) 61 | #define DI_AUXHFRCO_CALIB_BAND_21 MMIO8(DI_BASE + 0x1D8) 62 | #define DI_HFRCO_CALIB_BAND_1 MMIO8(DI_BASE + 0x1DC) 63 | #define DI_HFRCO_CALIB_BAND_7 MMIO8(DI_BASE + 0x1DD) 64 | #define DI_HFRCO_CALIB_BAND_11 MMIO8(DI_BASE + 0x1DE) 65 | #define DI_HFRCO_CALIB_BAND_14 MMIO8(DI_BASE + 0x1DF) 66 | #define DI_HFRCO_CALIB_BAND_21 MMIO8(DI_BASE + 0x1E0) 67 | #define DI_UNIQUE_0 MMIO32(DI_BASE + 0x1F0) 68 | #define DI_UNIQUE_1 MMIO32(DI_BASE + 0x1F4) 69 | #define DI_MEM_INFO_FLASH MMIO16(DI_BASE + 0x1F8) 70 | #define DI_MEM_INFO_RAM MMIO16(DI_BASE + 0x1FA) 71 | #define DI_PART_NUMBER MMIO16(DI_BASE + 0x1FC) 72 | #define DI_PART_FAMILY MMIO8(DI_BASE + 0x1FE) 73 | #define DI_PROD_REV MMIO8(DI_BASE + 0x1FF) 74 | 75 | #define AES_BASE (PERIPH_BASE + 0xE0000) 76 | #define PRS_BASE (PERIPH_BASE + 0xCC000) 77 | #define RMU_BASE (PERIPH_BASE + 0xCA000) 78 | #define CMU_BASE (PERIPH_BASE + 0xC8000) 79 | #define EMU_BASE (PERIPH_BASE + 0xC6000) 80 | #define USB_BASE (PERIPH_BASE + 0xC4000) 81 | #define DMA_BASE (PERIPH_BASE + 0xC2000) 82 | #define MSC_BASE (PERIPH_BASE + 0xC0000) 83 | #define WDOG_BASE (PERIPH_BASE + 0x88000) 84 | #define PCNT0_BASE (PERIPH_BASE + 0x86000) 85 | #define LEUART0_BASE (PERIPH_BASE + 0x84000) 86 | #define RTC_BASE (PERIPH_BASE + 0x80000) 87 | #define TIMER2_BASE (PERIPH_BASE + 0x10800) 88 | #define TIMER1_BASE (PERIPH_BASE + 0x10400) 89 | #define TIMER0_BASE (PERIPH_BASE + 0x10000) 90 | #define USART1_BASE (PERIPH_BASE + 0x0C400) 91 | #define USART0_BASE (PERIPH_BASE + 0x0C000) 92 | #define I2C0_BASE (PERIPH_BASE + 0x0A000) 93 | #define GPIO_BASE (PERIPH_BASE + 0x06000) 94 | #define IDAC0_BASE (PERIPH_BASE + 0x04000) 95 | #define ADC0_BASE (PERIPH_BASE + 0x02000) 96 | #define ACMP0_BASE (PERIPH_BASE + 0x01000) 97 | #define VCMP_BASE (PERIPH_BASE + 0x00000) 98 | 99 | #define USB_OTG_FS_BASE (USB_BASE + 0x3C000) 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/systick.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2010 Thomas Otto 5 | * Copyright (C) 2012 Benjamin Vernoux 6 | * 7 | * This library is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this library. If not, see . 19 | */ 20 | /** @defgroup CM3_systick_defines SysTick Defines 21 | * 22 | * @brief libopencm3 Defined Constants and Types for the Cortex SysTick 23 | * 24 | * @ingroup CM3_defines 25 | * 26 | * @version 1.0.0 27 | * 28 | * @author @htmlonly © @endhtmlonly 2010 Thomas Otto 29 | * 30 | * @date 19 August 2012 31 | * 32 | * LGPL License Terms @ref lgpl_license 33 | */ 34 | 35 | /** 36 | * @note this file has been not following the register naming scheme, the 37 | * correct names defined, and the old ones stay there for compatibility with 38 | * old software (will be deprecated in the future) 39 | */ 40 | 41 | /**@{*/ 42 | 43 | #ifndef LIBOPENCM3_SYSTICK_H 44 | #define LIBOPENCM3_SYSTICK_H 45 | 46 | #include 47 | #include 48 | 49 | /* --- SYSTICK registers --------------------------------------------------- */ 50 | 51 | /* Control and status register (STK_CTRL) */ 52 | #define STK_CSR MMIO32(SYS_TICK_BASE + 0x00) 53 | 54 | /* reload value register (STK_LOAD) */ 55 | #define STK_RVR MMIO32(SYS_TICK_BASE + 0x04) 56 | 57 | /* current value register (STK_VAL) */ 58 | #define STK_CVR MMIO32(SYS_TICK_BASE + 0x08) 59 | 60 | /* calibration value register (STK_CALIB) */ 61 | #define STK_CALIB MMIO32(SYS_TICK_BASE + 0x0C) 62 | 63 | /* --- STK_CSR values ------------------------------------------------------ */ 64 | /* Bits [31:17] Reserved, must be kept cleared. */ 65 | /* COUNTFLAG: */ 66 | #define STK_CSR_COUNTFLAG (1 << 16) 67 | 68 | /* Bits [15:3] Reserved, must be kept cleared. */ 69 | /* CLKSOURCE: Clock source selection */ 70 | #define STK_CSR_CLKSOURCE_LSB 2 71 | #define STK_CSR_CLKSOURCE (1 << STK_CSR_CLKSOURCE_LSB) 72 | 73 | /** @defgroup systick_clksource Clock source selection 74 | @ingroup CM3_systick_defines 75 | 76 | @{*/ 77 | #if defined(__ARM_ARCH_6M__) 78 | #define STK_CSR_CLKSOURCE_EXT (0 << STK_CSR_CLKSOURCE_LSB) 79 | #define STK_CSR_CLKSOURCE_AHB (1 << STK_CSR_CLKSOURCE_LSB) 80 | #else 81 | #define STK_CSR_CLKSOURCE_AHB_DIV8 (0 << STK_CSR_CLKSOURCE_LSB) 82 | #define STK_CSR_CLKSOURCE_AHB (1 << STK_CSR_CLKSOURCE_LSB) 83 | #endif 84 | /**@}*/ 85 | 86 | /* TICKINT: SysTick exception request enable */ 87 | #define STK_CSR_TICKINT (1 << 1) 88 | /* ENABLE: Counter enable */ 89 | #define STK_CSR_ENABLE (1 << 0) 90 | 91 | /* --- STK_RVR values ------------------------------------------------------ */ 92 | /* Bits [31:24] Reserved, must be kept cleared. */ 93 | /* RELOAD[23:0]: RELOAD value */ 94 | #define STK_RVR_RELOAD 0x00FFFFFF 95 | 96 | 97 | /* --- STK_CVR values ------------------------------------------------------ */ 98 | /* Bits [31:24] Reserved, must be kept cleared. */ 99 | /* CURRENT[23:0]: Current counter value */ 100 | #define STK_CVR_CURRENT 0x00FFFFFF 101 | 102 | 103 | /* --- STK_CALIB values ---------------------------------------------------- */ 104 | /* NOREF: NOREF flag */ 105 | #define STK_CALIB_NOREF (1 << 31) 106 | /* SKEW: SKEW flag */ 107 | #define STK_CALIB_SKEW (1 << 30) 108 | /* Bits [29:24] Reserved, must be kept cleared. */ 109 | /* TENMS[23:0]: Calibration value */ 110 | #define STK_CALIB_TENMS 0x00FFFFFF 111 | 112 | /* --- Function Prototypes ------------------------------------------------- */ 113 | 114 | BEGIN_DECLS 115 | 116 | void systick_set_reload(uint32_t value); 117 | bool systick_set_frequency(uint32_t freq, uint32_t ahb); 118 | uint32_t systick_get_reload(void); 119 | uint32_t systick_get_value(void); 120 | void systick_set_clocksource(uint8_t clocksource); 121 | void systick_interrupt_enable(void); 122 | void systick_interrupt_disable(void); 123 | void systick_counter_enable(void); 124 | void systick_counter_disable(void); 125 | uint8_t systick_get_countflag(void); 126 | void systick_clear(void); 127 | 128 | uint32_t systick_get_calib(void); 129 | 130 | END_DECLS 131 | 132 | #endif 133 | /**@}*/ 134 | 135 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/usb/cdc.h: -------------------------------------------------------------------------------- 1 | /** @defgroup usb_cdc_defines USB CDC Type Definitions 2 | 3 | @brief Defined Constants and Types for the USB CDC Type Definitions 4 | 5 | @ingroup USB_defines 6 | 7 | @version 1.0.0 8 | 9 | @author @htmlonly © @endhtmlonly 2010 10 | Gareth McMullin 11 | 12 | @date 10 March 2013 13 | 14 | LGPL License Terms @ref lgpl_license 15 | */ 16 | 17 | /* 18 | * This file is part of the libopencm3 project. 19 | * 20 | * Copyright (C) 2010 Gareth McMullin 21 | * 22 | * This library is free software: you can redistribute it and/or modify 23 | * it under the terms of the GNU Lesser General Public License as published by 24 | * the Free Software Foundation, either version 3 of the License, or 25 | * (at your option) any later version. 26 | * 27 | * This library is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | * GNU Lesser General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU Lesser General Public License 33 | * along with this library. If not, see . 34 | */ 35 | 36 | /**@{*/ 37 | 38 | #ifndef __CDC_H 39 | #define __CDC_H 40 | 41 | /* Definitions of Communications Device Class from 42 | * "Universal Serial Bus Class Definitions for Communications Devices 43 | * Revision 1.2" 44 | */ 45 | 46 | /* Table 2: Communications Device Class Code */ 47 | #define USB_CLASS_CDC 0x02 48 | 49 | /* Table 4: Class Subclass Code */ 50 | #define USB_CDC_SUBCLASS_DLCM 0x01 51 | #define USB_CDC_SUBCLASS_ACM 0x02 52 | /* ... */ 53 | 54 | /* Table 5 Communications Interface Class Control Protocol Codes */ 55 | #define USB_CDC_PROTOCOL_NONE 0x00 56 | #define USB_CDC_PROTOCOL_AT 0x01 57 | /* ... */ 58 | 59 | /* Table 6: Data Interface Class Code */ 60 | #define USB_CLASS_DATA 0x0A 61 | 62 | /* Table 12: Type Values for the bDescriptorType Field */ 63 | #define CS_INTERFACE 0x24 64 | #define CS_ENDPOINT 0x25 65 | 66 | /* Table 13: bDescriptor SubType in Communications Class Functional 67 | * Descriptors */ 68 | #define USB_CDC_TYPE_HEADER 0x00 69 | #define USB_CDC_TYPE_CALL_MANAGEMENT 0x01 70 | #define USB_CDC_TYPE_ACM 0x02 71 | /* ... */ 72 | #define USB_CDC_TYPE_UNION 0x06 73 | /* ... */ 74 | 75 | /* Table 15: Class-Specific Descriptor Header Format */ 76 | struct usb_cdc_header_descriptor { 77 | uint8_t bFunctionLength; 78 | uint8_t bDescriptorType; 79 | uint8_t bDescriptorSubtype; 80 | uint16_t bcdCDC; 81 | } __attribute__((packed)); 82 | 83 | /* Table 16: Union Interface Functional Descriptor */ 84 | struct usb_cdc_union_descriptor { 85 | uint8_t bFunctionLength; 86 | uint8_t bDescriptorType; 87 | uint8_t bDescriptorSubtype; 88 | uint8_t bControlInterface; 89 | uint8_t bSubordinateInterface0; 90 | /* ... */ 91 | } __attribute__((packed)); 92 | 93 | 94 | /* Definitions for Abstract Control Model devices from: 95 | * "Universal Serial Bus Communications Class Subclass Specification for 96 | * PSTN Devices" 97 | */ 98 | 99 | /* Table 3: Call Management Functional Descriptor */ 100 | struct usb_cdc_call_management_descriptor { 101 | uint8_t bFunctionLength; 102 | uint8_t bDescriptorType; 103 | uint8_t bDescriptorSubtype; 104 | uint8_t bmCapabilities; 105 | uint8_t bDataInterface; 106 | } __attribute__((packed)); 107 | 108 | /* Table 4: Abstract Control Management Functional Descriptor */ 109 | struct usb_cdc_acm_descriptor { 110 | uint8_t bFunctionLength; 111 | uint8_t bDescriptorType; 112 | uint8_t bDescriptorSubtype; 113 | uint8_t bmCapabilities; 114 | } __attribute__((packed)); 115 | 116 | /* Table 13: Class-Specific Request Codes for PSTN subclasses */ 117 | /* ... */ 118 | #define USB_CDC_REQ_SET_LINE_CODING 0x20 119 | /* ... */ 120 | #define USB_CDC_REQ_SET_CONTROL_LINE_STATE 0x22 121 | /* ... */ 122 | 123 | /* Table 17: Line Coding Structure */ 124 | struct usb_cdc_line_coding { 125 | uint32_t dwDTERate; 126 | uint8_t bCharFormat; 127 | uint8_t bParityType; 128 | uint8_t bDataBits; 129 | } __attribute__((packed)); 130 | 131 | enum usb_cdc_line_coding_bCharFormat { 132 | USB_CDC_1_STOP_BITS = 0, 133 | USB_CDC_1_5_STOP_BITS = 1, 134 | USB_CDC_2_STOP_BITS = 2, 135 | }; 136 | 137 | enum usb_cdc_line_coding_bParityType { 138 | USB_CDC_NO_PARITY = 0, 139 | USB_CDC_ODD_PARITY = 1, 140 | USB_CDC_EVEN_PARITY = 2, 141 | USB_CDC_MARK_PARITY = 3, 142 | USB_CDC_SPACE_PARITY = 4, 143 | }; 144 | 145 | /* Table 30: Class-Specific Notification Codes for PSTN subclasses */ 146 | /* ... */ 147 | #define USB_CDC_NOTIFY_SERIAL_STATE 0x20 148 | /* ... */ 149 | 150 | /* Notification Structure */ 151 | struct usb_cdc_notification { 152 | uint8_t bmRequestType; 153 | uint8_t bNotification; 154 | uint16_t wValue; 155 | uint16_t wIndex; 156 | uint16_t wLength; 157 | } __attribute__((packed)); 158 | 159 | #endif 160 | 161 | /**@}*/ 162 | 163 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/mpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2013 Frantisek Burian 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /** @defgroup CM3_mpu_defines MPU Defines 21 | * 22 | * @brief libopencm3 Cortex Memory Protection Unit 23 | * 24 | * @ingroup CM3_defines 25 | * 26 | * @version 1.0.0 27 | * 28 | * LGPL License Terms @ref lgpl_license 29 | * 30 | * The MPU is available as an option in both ARMv6-M and ARMv7-M, but it has 31 | * more features in v7, particularly in the available attributes. 32 | * 33 | * For more information see the ARM Architecture reference manuals. 34 | */ 35 | /**@{*/ 36 | 37 | #ifndef LIBOPENCM3_MPU_H 38 | #define LIBOPENCM3_MPU_H 39 | 40 | #include 41 | #include 42 | 43 | /* --- SCB: Registers ------------------------------------------------------ */ 44 | /** @defgroup CM3_mpu_registers MPU Registers 45 | * @ingroup CM3_mpu_defines 46 | * 47 | *@{*/ 48 | /** MPU_TYPE is alays available, even if the MPU is not implemented */ 49 | #define MPU_TYPE MMIO32(MPU_BASE + 0x00) 50 | #define MPU_CTRL MMIO32(MPU_BASE + 0x04) 51 | #define MPU_RNR MMIO32(MPU_BASE + 0x08) 52 | #define MPU_RBAR MMIO32(MPU_BASE + 0x0C) 53 | #define MPU_RASR MMIO32(MPU_BASE + 0x10) 54 | /**@}*/ 55 | 56 | /* --- MPU values ---------------------------------------------------------- */ 57 | 58 | /** @defgroup CM3_mpu_type MPU TYPE register fields 59 | * @ingroup CM3_mpu_defines 60 | * The MPU_TYPE register is always available, even if the MPU is not implemented. 61 | * In that case, the DREGION field will read as 0. 62 | *@{*/ 63 | /** v6m/v7m only support a unified MPU (IREGION always 0) */ 64 | #define MPU_TYPE_IREGION_LSB 16 65 | #define MPU_TYPE_IREGION (0xFF << MPU_TYPE_IREGION_LSB) 66 | /** DREGION is non zero if the MPU is available */ 67 | #define MPU_TYPE_DREGION_LSB 8 68 | #define MPU_TYPE_DREGION (0xFF << MPU_TYPE_DREGION_LSB) 69 | /** v6m/v7m only support a unifed MPU (Separate always 0) */ 70 | #define MPU_TYPE_SEPARATE (1<<0) 71 | /**@}*/ 72 | 73 | /** @defgroup CM3_mpu_ctrl MPU CTRL register fields 74 | * @ingroup CM3_mpu_defines 75 | * Defines for the Control Register. 76 | *@{*/ 77 | #define MPU_CTRL_PRIVDEFENA (1<<2) 78 | #define MPU_CTRL_HFNMIENA (1<<1) 79 | #define MPU_CTRL_ENABLE (1<<0) 80 | /**@}*/ 81 | 82 | /** @defgroup CM3_mpu_rnr MPU RNR register fields 83 | * @ingroup CM3_mpu_defines 84 | * Defines for the Region Number Register. 85 | *@{*/ 86 | #define MPU_RNR_REGION_LSB 0 87 | #define MPU_RNR_REGION (0xFF << MPU_RNR_REGION_LSB) 88 | /**@}*/ 89 | 90 | /** @defgroup CM3_mpu_rbar MPU RBAR register fields 91 | * @ingroup CM3_mpu_defines 92 | * Defines for the Region Base Address Register. 93 | *@{*/ 94 | /** minimum size supported is by writing all ones to ADDR, then reading back */ 95 | #define MPU_RBAR_ADDR 0xFFFFFFE0 96 | #define MPU_RBAR_VALID (1<<4) 97 | #define MPU_RBAR_REGION_LSB 0 98 | #define MPU_RBAR_REGION (0xF << MPU_RBAR_REGION_LSB) 99 | /**@}*/ 100 | 101 | /** @defgroup CM3_mpu_rasr MPU RASR register fields 102 | * @ingroup CM3_mpu_defines 103 | * Defines for the Region Attribute and Size Register. 104 | *@{*/ 105 | #define MPU_RASR_ATTRS_LSB 16 106 | #define MPU_RASR_ATTRS (0xFFFF << MPU_RASR_ATTRS_LSB) 107 | #define MPU_RASR_SRD_LSB 8 108 | #define MPU_RASR_SRD (0xFF << MPU_RASR_SRD_LSB) 109 | #define MPU_RASR_SIZE_LSB 1 110 | #define MPU_RASR_SIZE (0x1F << MPU_RASR_SIZE_LSB) 111 | #define MPU_RASR_ENABLE (1 << 0) 112 | 113 | /** @defgroup mpu_rasr_attributes MPU RASR Attributes 114 | * @ingroup CM3_mpu_rasr 115 | * Not all attributes are available on v6m. 116 | * 117 | *@{*/ 118 | #define MPU_RASR_ATTR_XN (1 << 28) 119 | #define MPU_RASR_ATTR_AP (7 << 24) 120 | #define MPU_RASR_ATTR_AP_PNO_UNO (0 << 24) 121 | #define MPU_RASR_ATTR_AP_PRW_UNO (1 << 24) 122 | #define MPU_RASR_ATTR_AP_PRW_URO (2 << 24) 123 | #define MPU_RASR_ATTR_AP_PRW_URW (3 << 24) 124 | #define MPU_RASR_ATTR_AP_PRO_UNO (5 << 24) 125 | #define MPU_RASR_ATTR_AP_PRO_URO (6 << 24) 126 | #define MPU_RASR_ATTR_TEX (7 << 19) 127 | #define MPU_RASR_ATTR_S (1 << 18) 128 | #define MPU_RASR_ATTR_C (1 << 17) 129 | #define MPU_RASR_ATTR_B (1 << 16) 130 | #define MPU_RASR_ATTR_SCB (7 << 16) 131 | /**@}*/ 132 | /**@}*/ 133 | 134 | /* --- MPU functions ------------------------------------------------------- */ 135 | 136 | BEGIN_DECLS 137 | 138 | 139 | END_DECLS 140 | 141 | /**@}*/ 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /usb-synth/usb_synth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: usb_synth.c 3 | * A basic USB synthesizer. The device will enumerate as a composite MIDI 4 | * device and microphone device. Sending MIDI notes to it will play tones. 5 | * 6 | * 'midi_descriptors.h' from the libopencm3 MIDI example, attribution: 7 | * Copyright (C) 2014 Daniel Thompson 8 | * 9 | * Everything else: 10 | * Copyright (C) 2018 Seb Holzapfel 11 | * 12 | * This library is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU Lesser General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public License 23 | * along with this library. If not, see . 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "tomu_pins.h" 41 | #include "usb_descriptors.h" 42 | #include "usb_isochronous.h" 43 | #include "midi_events.h" 44 | #include "synth_core.h" 45 | 46 | /* Default AHB (core clock) frequency of Tomu board */ 47 | #define AHB_FREQUENCY 14000000 48 | 49 | /* libopencm3 USB datastructures */ 50 | usbd_device *g_usbd_dev = 0; 51 | uint8_t usbd_control_buffer[1024]; 52 | 53 | /* Amout of data is copied for every isochronous audio packet */ 54 | #define ISO_COPY_BUF_SZ 32 /* bytes = 16 samples = 8 stereo time units */ 55 | #define ISO_COPY_BUF_SAMPLES ISO_COPY_BUF_SZ/2 56 | 57 | static void usbaudio_iso_stream_callback(usbd_device *usbd_dev, uint8_t ep) 58 | { 59 | /* Required to use full bandwidth - see `usb_isochronous.h` */ 60 | isochronous_frame_toggle(ep); 61 | 62 | /* Create and write a new block of audio samples */ 63 | uint16_t out_samples[ISO_COPY_BUF_SAMPLES]; 64 | synth_core_stream(out_samples, ISO_COPY_BUF_SAMPLES); 65 | usbd_ep_write_packet(usbd_dev, 0x82, out_samples, ISO_COPY_BUF_SZ); 66 | } 67 | 68 | static void usbmidi_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) 69 | { 70 | (void)ep; 71 | 72 | char buf[64]; 73 | int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64); 74 | 75 | /* Check if this USB packet contains one or more MIDI packets */ 76 | if(len % 4 == 0) { 77 | for(int i = 0; i != len; i += 4) { 78 | synth_core_decode_midi_packet(*(midi_usb_event_packet_t*)(buf+i)); 79 | } 80 | } 81 | } 82 | 83 | static void usbaudio_set_config(usbd_device *usbd_dev, uint16_t wValue) 84 | { 85 | (void)wValue; 86 | 87 | usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_ISOCHRONOUS, 88 | ISO_COPY_BUF_SZ, usbaudio_iso_stream_callback); 89 | 90 | usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, 91 | usbmidi_data_rx_cb); 92 | 93 | usbd_ep_setup(usbd_dev, 0x81, USB_ENDPOINT_ATTR_BULK, 64, NULL); 94 | 95 | /* XXX: This is necessary -> but why? */ 96 | uint8_t junk[ISO_COPY_BUF_SZ] = {0}; 97 | usbd_ep_write_packet(usbd_dev, 0x82, junk, ISO_COPY_BUF_SZ); 98 | } 99 | 100 | void usb_isr(void) 101 | { 102 | usbd_poll(g_usbd_dev); 103 | } 104 | 105 | void hard_fault_handler(void) 106 | { 107 | while (1); 108 | } 109 | 110 | int main(void) 111 | { 112 | int i; 113 | 114 | /* Make sure the vector table is relocated correctly 115 | * (after the Tomu bootloader) */ 116 | SCB_VTOR = 0x4000; 117 | 118 | /* Disable the watchdog that the bootloader started. */ 119 | WDOG_CTRL = 0; 120 | 121 | /* GPIO peripheral clock is necessary for us to set 122 | * up the GPIO pins as outputs */ 123 | cmu_periph_clock_enable(CMU_GPIO); 124 | 125 | /* Set up both LEDs as outputs */ 126 | gpio_mode_setup(LED_RED_PORT, GPIO_MODE_WIRED_AND, LED_RED_PIN); 127 | gpio_mode_setup(LED_GREEN_PORT, GPIO_MODE_WIRED_AND, LED_GREEN_PIN); 128 | 129 | synth_core_init(); 130 | 131 | /* Configure the USB core & stack */ 132 | g_usbd_dev = usbd_init(&efm32hg_usb_driver, &dev, &config, 133 | usb_strings, 3, usbd_control_buffer, 134 | sizeof(usbd_control_buffer)); 135 | usbd_register_set_config_callback(g_usbd_dev, usbaudio_set_config); 136 | 137 | /* Enable USB IRQs */ 138 | nvic_enable_irq(NVIC_USB_IRQ); 139 | 140 | /* Turn on both LEDs */ 141 | gpio_clear(LED_GREEN_PORT, LED_GREEN_PIN); 142 | gpio_clear(LED_RED_PORT, LED_GREEN_PIN); 143 | 144 | while (1) { 145 | 146 | for (i = 0; i != 200000; ++i) 147 | __asm__("nop"); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/usb/dwc/otg_fs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2010 Gareth McMullin 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* 21 | * This file covers definitions for DesignWare USB OTG HS peripherals. 22 | */ 23 | 24 | #ifndef LIBOPENCM3_USB_DWC_OTG_FS_H 25 | #define LIBOPENCM3_USB_DWC_OTG_FS_H 26 | 27 | #include 28 | #include 29 | 30 | /* Memory map is required for USB_OTG_FS_BASE address */ 31 | #if defined(STM32F1) || defined(STM32F2) || defined(STM32F4) 32 | # include 33 | #elif defined(EFM32HG) 34 | # include 35 | #else 36 | # error "device family not supported by dwc/otg_fs." 37 | #endif 38 | 39 | /***********************************************************************/ 40 | 41 | /* Core Global Control and Status Registers */ 42 | #define OTG_FS_GOTGCTL MMIO32(USB_OTG_FS_BASE + OTG_GOTGCTL) 43 | #define OTG_FS_GOTGINT MMIO32(USB_OTG_FS_BASE + OTG_GOTGINT) 44 | #define OTG_FS_GAHBCFG MMIO32(USB_OTG_FS_BASE + OTG_GAHBCFG) 45 | #define OTG_FS_GUSBCFG MMIO32(USB_OTG_FS_BASE + OTG_GUSBCFG) 46 | #define OTG_FS_GRSTCTL MMIO32(USB_OTG_FS_BASE + OTG_GRSTCTL) 47 | #define OTG_FS_GINTSTS MMIO32(USB_OTG_FS_BASE + OTG_GINTSTS) 48 | #define OTG_FS_GINTMSK MMIO32(USB_OTG_FS_BASE + OTG_GINTMSK) 49 | #define OTG_FS_GRXSTSR MMIO32(USB_OTG_FS_BASE + OTG_GRXSTSR) 50 | #define OTG_FS_GRXSTSP MMIO32(USB_OTG_FS_BASE + OTG_GRXSTSP) 51 | #define OTG_FS_GRXFSIZ MMIO32(USB_OTG_FS_BASE + OTG_GRXFSIZ) 52 | #define OTG_FS_GNPTXFSIZ MMIO32(USB_OTG_FS_BASE + OTG_GNPTXFSIZ) 53 | #define OTG_FS_GNPTXSTS MMIO32(USB_OTG_FS_BASE + OTG_GNPTXSTS) 54 | #define OTG_FS_GCCFG MMIO32(USB_OTG_FS_BASE + OTG_GCCFG) 55 | #define OTG_FS_CID MMIO32(USB_OTG_FS_BASE + OTG_CID) 56 | #define OTG_FS_HPTXFSIZ MMIO32(USB_OTG_FS_BASE + OTG_HPTXFSIZ) 57 | #define OTG_FS_DIEPTXF(x) MMIO32(USB_OTG_FS_BASE + OTG_DIEPTXF(x)) 58 | 59 | 60 | /* Host-mode Control and Status Registers */ 61 | #define OTG_FS_HCFG MMIO32(USB_OTG_FS_BASE + OTG_HCFG) 62 | #define OTG_FS_HFIR MMIO32(USB_OTG_FS_BASE + OTG_HFIR) 63 | #define OTG_FS_HFNUM MMIO32(USB_OTG_FS_BASE + OTG_HFNUM) 64 | #define OTG_FS_HPTXSTS MMIO32(USB_OTG_FS_BASE + OTG_HPTXSTS) 65 | #define OTG_FS_HAINT MMIO32(USB_OTG_FS_BASE + OTG_HAINT) 66 | #define OTG_FS_HAINTMSK MMIO32(USB_OTG_FS_BASE + OTG_HAINTMSK) 67 | #define OTG_FS_HPRT MMIO32(USB_OTG_FS_BASE + OTG_HPRT) 68 | #define OTG_FS_HCCHAR(x) MMIO32(USB_OTG_FS_BASE + OTG_HCCHAR(x)) 69 | #define OTG_FS_HCINT(x) MMIO32(USB_OTG_FS_BASE + OTG_HCINT(x)) 70 | #define OTG_FS_HCINTMSK(x) MMIO32(USB_OTG_FS_BASE + OTG_HCINTMSK(x)) 71 | #define OTG_FS_HCTSIZ(x) MMIO32(USB_OTG_FS_BASE + OTG_HCTSIZ(x)) 72 | 73 | /* Device-mode Control and Status Registers */ 74 | #define OTG_FS_DCFG MMIO32(USB_OTG_FS_BASE + OTG_DCFG) 75 | #define OTG_FS_DCTL MMIO32(USB_OTG_FS_BASE + OTG_DCTL) 76 | #define OTG_FS_DSTS MMIO32(USB_OTG_FS_BASE + OTG_DSTS) 77 | #define OTG_FS_DIEPMSK MMIO32(USB_OTG_FS_BASE + OTG_DIEPMSK) 78 | #define OTG_FS_DOEPMSK MMIO32(USB_OTG_FS_BASE + OTG_DOEPMSK) 79 | #define OTG_FS_DAINT MMIO32(USB_OTG_FS_BASE + OTG_DAINT) 80 | #define OTG_FS_DAINTMSK MMIO32(USB_OTG_FS_BASE + OTG_DAINTMSK) 81 | #define OTG_FS_DVBUSDIS MMIO32(USB_OTG_FS_BASE + OTG_DVBUSDIS) 82 | #define OTG_FS_DVBUSPULSE MMIO32(USB_OTG_FS_BASE + OTG_DVBUSPULSE) 83 | #define OTG_FS_DIEPEMPMSK MMIO32(USB_OTG_FS_BASE + OTG_DIEPEMPMSK) 84 | #define OTG_FS_DIEPCTL0 MMIO32(USB_OTG_FS_BASE + OTG_DIEPCTL0) 85 | #define OTG_FS_DIEPCTL(x) MMIO32(USB_OTG_FS_BASE + OTG_DIEPCTL(x)) 86 | #define OTG_FS_DOEPCTL0 MMIO32(USB_OTG_FS_BASE + OTG_DOEPCTL0) 87 | #define OTG_FS_DOEPCTL(x) MMIO32(USB_OTG_FS_BASE + OTG_DOEPCTL(x)) 88 | #define OTG_FS_DIEPINT(x) MMIO32(USB_OTG_FS_BASE + OTG_DIEPINT(x)) 89 | #define OTG_FS_DOEPINT(x) MMIO32(USB_OTG_FS_BASE + OTG_DOEPINT(x)) 90 | #define OTG_FS_DIEPTSIZ0 MMIO32(USB_OTG_FS_BASE + OTG_DIEPTSIZ0) 91 | #define OTG_FS_DOEPTSIZ0 MMIO32(USB_OTG_FS_BASE + OTG_DOEPTSIZ0) 92 | #define OTG_FS_DIEPTSIZ(x) MMIO32(USB_OTG_FS_BASE + OTG_DIEPTSIZ(x)) 93 | #define OTG_FS_DTXFSTS(x) MMIO32(USB_OTG_FS_BASE + OTG_DTXFSTS(x)) 94 | #define OTG_FS_DOEPTSIZ(x) MMIO32(USB_OTG_FS_BASE + OTG_DOEPTSIZ(x)) 95 | 96 | /* Power and clock gating control and status register */ 97 | #define OTG_FS_PCGCCTL MMIO32(USB_OTG_FS_BASE + OTG_PCGCCTL) 98 | 99 | /* Data FIFO */ 100 | #define OTG_FS_FIFO(x) (&MMIO32(USB_OTG_FS_BASE \ 101 | + (((x) + 1) \ 102 | << 12))) 103 | 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/assert.h: -------------------------------------------------------------------------------- 1 | /** @defgroup debugging Debugging 2 | 3 | @brief Macros and functions to aid in debugging 4 | 5 | @version 1.0.0 6 | 7 | @date 25 September 2012 8 | 9 | Two preprocessor defines control the behavior of assertion check macros in 10 | this module. They allow the choice between generated code size and ease of 11 | debugging. 12 | 13 | If NDEBUG is defined, all assertion checks are disabled and macros do not 14 | generate any code. 15 | 16 | If CM3_ASSERT_VERBOSE is defined, information regarding the position of 17 | assertion checks will be stored in the binary, allowing for more 18 | informative error messages, but also significantly increased code size. As 19 | default assertion checks do not use this information it is only useful if 20 | the application linked with libopencm3 defines its own 21 | cm3_assert_failed_verbose() implementation. 22 | 23 | LGPL License Terms @ref lgpl_license 24 | */ 25 | 26 | /* 27 | * This file is part of the libopencm3 project. 28 | * 29 | * Copyright (C) 2012 Tomaz Solc 30 | * 31 | * This library is free software: you can redistribute it and/or modify 32 | * it under the terms of the GNU Lesser General Public License as published by 33 | * the Free Software Foundation, either version 3 of the License, or 34 | * (at your option) any later version. 35 | * 36 | * This library is distributed in the hope that it will be useful, 37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 39 | * GNU Lesser General Public License for more details. 40 | * 41 | * You should have received a copy of the GNU Lesser General Public License 42 | * along with this library. If not, see . 43 | */ 44 | 45 | /**@{*/ 46 | 47 | #ifndef LIBOPENCM3_CM3_ASSERT_H 48 | #define LIBOPENCM3_CM3_ASSERT_H 49 | 50 | #include 51 | 52 | #define CM3_LIKELY(expr) (__builtin_expect(!!(expr), 1)) 53 | 54 | #ifdef NDEBUG 55 | # define cm3_assert(expr) (void)0 56 | # define cm3_assert_not_reached() do { } while (1) 57 | #else 58 | # ifdef CM3_ASSERT_VERBOSE 59 | # define cm3_assert(expr) do { \ 60 | if (CM3_LIKELY(expr)) { \ 61 | (void)0; \ 62 | } else { \ 63 | cm3_assert_failed_verbose( \ 64 | __FILE__, __LINE__, \ 65 | __func__, #expr); \ 66 | } \ 67 | } while (0) 68 | # define cm3_assert_not_reached() \ 69 | cm3_assert_failed_verbose( \ 70 | __FILE__, __LINE__, \ 71 | __func__, 0) 72 | # else 73 | /** @brief Check if assertion is true. 74 | * 75 | * If NDEBUG macro is defined, this macro generates no code. Otherwise 76 | * cm3_assert_failed() or cm3_assert_failed_verbose() is called if assertion 77 | * is false. 78 | * 79 | * The purpose of this macro is to aid in debugging libopencm3 and 80 | * applications using it. It can be used for example to check if function 81 | * arguments are within expected ranges and stop execution in case an 82 | * unexpected state is reached. 83 | * 84 | * @param expr expression to check */ 85 | # define cm3_assert(expr) do { \ 86 | if (CM3_LIKELY(expr)) { \ 87 | (void)0; \ 88 | } else { \ 89 | cm3_assert_failed(); \ 90 | } \ 91 | } while (0) 92 | /** @brief Check if unreachable code is reached. 93 | * 94 | * If NDEBUG macro is defined, this macro generates code for an infinite loop. 95 | * Otherwise cm3_assert_failed() or cm3_assert_failed_verbose() is called if 96 | * the macro is ever reached. 97 | * 98 | * The purpose of this macro is to aid in debugging libopencm3 and 99 | * applications using it. It can be used for example to stop execution if an 100 | * unreachable portion of code is reached. */ 101 | # define cm3_assert_not_reached() cm3_assert_failed() 102 | # endif 103 | #endif 104 | 105 | BEGIN_DECLS 106 | 107 | /** @brief Called on a failed assertion. 108 | * 109 | * Halts execution in an infinite loop. This function never returns. 110 | * 111 | * Defined as a weak symbol, so applications can define their own 112 | * implementation. Usually, a custom implementation of this function should 113 | * report an error in some way (print a message to a debug console, display, 114 | * LED, ...) and halt execution or reboot the device. */ 115 | void cm3_assert_failed(void) __attribute__((__noreturn__)); 116 | 117 | /** @brief Called on a failed assertion with verbose messages enabled. 118 | * 119 | * Halts execution in an infinite loop. This function never returns. 120 | * 121 | * Defined as a weak symbol, so applications can define their own 122 | * implementation. Usually, a custom implementation of this function should 123 | * report an error in some way (print a message to a debug console, display, 124 | * LED, ...) and halt execution or reboot the device. 125 | * 126 | * @param file File name where the failed assertion occurred 127 | * @param line Line number where the failed assertion occurred 128 | * @param func Name of the function where the failed assertion occurred 129 | * @param assert_expr Expression that evaluated to false (can be NULL) */ 130 | void cm3_assert_failed_verbose(const char *file, int line, const char *func, 131 | const char *assert_expr) __attribute__((__noreturn__)); 132 | 133 | END_DECLS 134 | 135 | #endif 136 | 137 | /**@}*/ 138 | -------------------------------------------------------------------------------- /include/toboot.h: -------------------------------------------------------------------------------- 1 | #ifndef TOBOOT_API_H_ 2 | #define TOBOOT_API_H_ 3 | 4 | #include 5 | 6 | /// Store this configuration struct at offset 0x94 from the start 7 | /// of your binary image. 8 | /// You may set all RESERVED values to 0. as they will be calculated 9 | /// when the program is written to flash. 10 | struct toboot_configuration { 11 | /// Set to 0x907070b2 to indicate a valid configuration header. 12 | uint32_t magic; 13 | 14 | /// Reserved value. Used as a generational counter. Toboot will 15 | /// overwrite this value with a monotonically-increasing counter 16 | /// every time a new image is burned. This is used to determine 17 | /// which image is the newest. 18 | uint16_t reserved_gen; 19 | 20 | /// The starting page for your program in 1024-byte blocks. 21 | /// Toboot itself sets this to 0. If this is nonzero, then it 22 | /// must be located after the Toboot image. Toboot is currently 23 | /// under 5 kilobytes, so make sure this value is at least 6. 24 | uint8_t start; 25 | 26 | /// Configuration bitmask. See below for values. 27 | uint8_t config; 28 | 29 | /// Set to 0x18349420 to prevent the user from entering Toboot manually. 30 | /// Use this value with caution, as it can be used to lockout a Tomu. 31 | uint32_t lock_entry; 32 | 33 | /// A bitmask of sectors to erase when updating the program. Each "1" 34 | /// causes that sector to be erased, unless it's Toboot itself. Bit values 35 | /// determine flash blocks 0-31. 36 | uint32_t erase_mask_lo; 37 | 38 | /// A bitmask of sectors to erase when updating the program. Each "1" 39 | /// causes that sector to e erased. Use these two values to e.g. force 40 | /// private keys to be erased when updating. Bit values determine flash 41 | /// blocks 32-63. 42 | uint32_t erase_mask_hi; 43 | 44 | /// A hash of the entire header, minus this entry. Toboot calculates 45 | /// this when it programs the first block. A Toboot configuration 46 | /// header MUST have a valid hash in order to be considered valid. 47 | uint32_t reserved_hash; 48 | } __attribute__((packed)); 49 | 50 | /// Toboot V1.0 leaves IRQs enabled, mimicking the behavior of 51 | /// AN0042. Toboot V2.0 makes this configurable by adding a 52 | /// bit to the configuration area. 53 | #define TOBOOT_CONFIG_FLAG_ENABLE_IRQ_MASK 0x01 54 | #define TOBOOT_CONFIG_FLAG_ENABLE_IRQ_SHIFT 0 55 | #define TOBOOT_CONFIG_FLAG_ENABLE_IRQ (1 << 0) 56 | #define TOBOOT_CONFIG_FLAG_DISABLE_IRQ (0 << 0) 57 | 58 | /// When running a normal program, you won't want Toboot to run. 59 | /// However, when developing new software it is handy to have 60 | /// Toboot run at poweron. Set this flag to enter Toboot whenever 61 | /// the system has powered on for the first time. 62 | #define TOBOOT_CONFIG_FLAG_AUTORUN_MASK 0x02 63 | #define TOBOOT_CONFIG_FLAG_AUTORUN_SHIFT 1 64 | #define TOBOOT_CONFIG_FLAG_AUTORUN (1 << 1) 65 | 66 | /// When we create a fake header, this flag will be set. Otherwise, 67 | /// leave the flag cleared. 68 | #define TOBOOT_CONFIG_FAKE_MASK 0x04 69 | #define TOBOOT_CONFIG_FAKE_SHIFT 2 70 | #define TOBOOT_CONFIG_FAKE (1 << 2) 71 | 72 | /// Various magic values describing Toboot configuration headers. 73 | #define TOBOOT_V1_MAGIC 0x70B0 74 | #define TOBOOT_V1_MAGIC_MASK 0x0000ffff 75 | #define TOBOOT_V2_MAGIC 0x907070b2 76 | #define TOBOOT_V2_MAGIC_MASK 0xffffffff 77 | 78 | /// This value is used to prevent manual entry into Toboot. 79 | #define TOBOOT_LOCKOUT_MAGIC 0x18349420 80 | 81 | /// The seed value for the hash of Toboot's configuration header 82 | #define TOBOOT_HASH_SEED 0x037a5cf1 83 | 84 | /// This is the runtime part that lives at the start of RAM. 85 | /// Running programs can use this to force entry into Toboot 86 | /// during the next reboot. 87 | struct toboot_runtime { 88 | /// Set this to 0x74624346 and reboot to enter bootloader, 89 | /// even if LOCKOUT is enabled. 90 | uint32_t magic; 91 | 92 | /// Set this to 0 when your program starts. 93 | uint8_t boot_count; 94 | 95 | /// The bootloader should set this to 0x23 for Tomu. 96 | uint8_t board_model; 97 | 98 | /// Unused. 99 | uint16_t reserved; 100 | }; 101 | 102 | /// Set runtime.magic to this value and reboot to force 103 | /// entry into Toboot. 104 | #define TOBOOT_FORCE_ENTRY_MAGIC 0x74624346 105 | 106 | /// Use this macro to define a Toboot V2 configuration. If unspecified, 107 | /// your program will default to a legacy configuration, and will not have 108 | /// access to features such as autoboot. 109 | #define TOBOOT_CONFIGURATION(cfg) \ 110 | __attribute__ ((used, section(".vectors"))) \ 111 | const struct toboot_configuration __toboot_configuration = { \ 112 | .magic = TOBOOT_V2_MAGIC, \ 113 | .reserved_gen = 0, \ 114 | .start = 16, \ 115 | .config = cfg, \ 116 | .lock_entry = 0, \ 117 | .erase_mask_lo = 0, \ 118 | .erase_mask_hi = 0, \ 119 | .reserved_hash = 0, \ 120 | } 121 | 122 | #endif /* TOBOOT_API_H_ */ 123 | -------------------------------------------------------------------------------- /captouch/printf.c: -------------------------------------------------------------------------------- 1 | /* 2 | File: printf.c 3 | 4 | Copyright (C) 2004 Kustaa Nyholm 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | 20 | */ 21 | 22 | #include "printf.h" 23 | 24 | typedef void (*putcf) (void*,char); 25 | static putcf stdout_putf; 26 | static void* stdout_putp; 27 | 28 | #ifdef PRINTF_LONG_SUPPORT 29 | 30 | static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf) 31 | { 32 | int n=0; 33 | unsigned int d=1; 34 | while (num/d >= base) 35 | d*=base; 36 | while (d!=0) { 37 | int dgt = num / d; 38 | num%=d; 39 | d/=base; 40 | if (n || dgt>0|| d==0) { 41 | *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); 42 | ++n; 43 | } 44 | } 45 | *bf=0; 46 | } 47 | 48 | static void li2a (long num, char * bf) 49 | { 50 | if (num<0) { 51 | num=-num; 52 | *bf++ = '-'; 53 | } 54 | uli2a(num,10,0,bf); 55 | } 56 | 57 | #endif 58 | 59 | static void ui2a(unsigned int num, unsigned int base, int uc,char * bf) 60 | { 61 | int n=0; 62 | unsigned int d=1; 63 | while (num/d >= base) 64 | d*=base; 65 | while (d!=0) { 66 | int dgt = num / d; 67 | num%= d; 68 | d/=base; 69 | if (n || dgt>0 || d==0) { 70 | *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10); 71 | ++n; 72 | } 73 | } 74 | *bf=0; 75 | } 76 | 77 | static void i2a (int num, char * bf) 78 | { 79 | if (num<0) { 80 | num=-num; 81 | *bf++ = '-'; 82 | } 83 | ui2a(num,10,0,bf); 84 | } 85 | 86 | static int a2d(char ch) 87 | { 88 | if (ch>='0' && ch<='9') 89 | return ch-'0'; 90 | else if (ch>='a' && ch<='f') 91 | return ch-'a'+10; 92 | else if (ch>='A' && ch<='F') 93 | return ch-'A'+10; 94 | else return -1; 95 | } 96 | 97 | static char a2i(char ch, const char** src,int base,int* nump) 98 | { 99 | const char* p= *src; 100 | int num=0; 101 | int digit; 102 | while ((digit=a2d(ch))>=0) { 103 | if (digit>base) break; 104 | num=num*base+digit; 105 | ch=*p++; 106 | } 107 | *src=p; 108 | *nump=num; 109 | return ch; 110 | } 111 | 112 | static void putchw(void* putp,putcf putf,int n, char z, char* bf) 113 | { 114 | char fc=z? '0' : ' '; 115 | char ch; 116 | char* p=bf; 117 | while (*p++ && n > 0) 118 | n--; 119 | while (n-- > 0) 120 | putf(putp,fc); 121 | while ((ch= *bf++)) 122 | putf(putp,ch); 123 | } 124 | 125 | void tfp_format(void* putp,putcf putf, const char *fmt, va_list va) 126 | { 127 | char bf[12]; 128 | 129 | char ch; 130 | 131 | 132 | while ((ch=*(fmt++))) { 133 | if (ch!='%') 134 | putf(putp,ch); 135 | else { 136 | char lz=0; 137 | #ifdef PRINTF_LONG_SUPPORT 138 | char lng=0; 139 | #endif 140 | int w=0; 141 | ch=*(fmt++); 142 | if (ch=='0') { 143 | ch=*(fmt++); 144 | lz=1; 145 | } 146 | if (ch>='0' && ch<='9') { 147 | ch=a2i(ch,&fmt,10,&w); 148 | } 149 | #ifdef PRINTF_LONG_SUPPORT 150 | if (ch=='l') { 151 | ch=*(fmt++); 152 | lng=1; 153 | } 154 | #endif 155 | switch (ch) { 156 | case 0: 157 | goto abort; 158 | case 'u' : { 159 | #ifdef PRINTF_LONG_SUPPORT 160 | if (lng) 161 | uli2a(va_arg(va, unsigned long int),10,0,bf); 162 | else 163 | #endif 164 | ui2a(va_arg(va, unsigned int),10,0,bf); 165 | putchw(putp,putf,w,lz,bf); 166 | break; 167 | } 168 | case 'd' : { 169 | #ifdef PRINTF_LONG_SUPPORT 170 | if (lng) 171 | li2a(va_arg(va, unsigned long int),bf); 172 | else 173 | #endif 174 | i2a(va_arg(va, int),bf); 175 | putchw(putp,putf,w,lz,bf); 176 | break; 177 | } 178 | case 'x': case 'X' : 179 | #ifdef PRINTF_LONG_SUPPORT 180 | if (lng) 181 | uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf); 182 | else 183 | #endif 184 | ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf); 185 | putchw(putp,putf,w,lz,bf); 186 | break; 187 | case 'c' : 188 | putf(putp,(char)(va_arg(va, int))); 189 | break; 190 | case 's' : 191 | putchw(putp,putf,w,0,va_arg(va, char*)); 192 | break; 193 | case '%' : 194 | putf(putp,ch); 195 | default: 196 | break; 197 | } 198 | } 199 | } 200 | abort:; 201 | } 202 | 203 | 204 | void init_printf(void* putp,void (*putf) (void*,char)) 205 | { 206 | stdout_putf=putf; 207 | stdout_putp=putp; 208 | } 209 | 210 | void tfp_printf(char *fmt, ...) 211 | { 212 | va_list va; 213 | va_start(va,fmt); 214 | tfp_format(stdout_putp,stdout_putf,fmt,va); 215 | va_end(va); 216 | } 217 | 218 | static void putcp(void* p,char c) 219 | { 220 | *(*((char**)p))++ = c; 221 | } 222 | 223 | 224 | 225 | void tfp_sprintf(char* s,const char *fmt, ...) 226 | { 227 | va_list va; 228 | va_start(va,fmt); 229 | tfp_format(&s,putcp,fmt,va); 230 | putcp(&s,0); 231 | va_end(va); 232 | } 233 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/cm3/nvic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2010 Piotr Esden-Tempski 5 | * Copyright (C) 2012 Michael Ossmann 6 | * Copyright (C) 2012 Benjamin Vernoux 7 | * 8 | * This library is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this library. If not, see . 20 | */ 21 | /** @defgroup CM3_nvic_defines NVIC Defines 22 | * 23 | * @brief libopencm3 Cortex Nested Vectored Interrupt Controller 24 | * 25 | * @ingroup CM3_defines 26 | * 27 | * @version 1.0.0 28 | * 29 | * @author @htmlonly © @endhtmlonly 2010 Piotr Esden-Tempski 30 | * 31 | * @date 18 August 2012 32 | * 33 | * LGPL License Terms @ref lgpl_license 34 | */ 35 | /**@{*/ 36 | 37 | #ifndef LIBOPENCM3_NVIC_H 38 | #define LIBOPENCM3_NVIC_H 39 | 40 | #include 41 | #include 42 | 43 | /* --- NVIC Registers ------------------------------------------------------ */ 44 | 45 | /* ISER: Interrupt Set Enable Registers */ 46 | /* Note: 8 32bit Registers */ 47 | /* Note: Single register on CM0 */ 48 | #define NVIC_ISER(iser_id) MMIO32(NVIC_BASE + 0x00 + \ 49 | ((iser_id) * 4)) 50 | 51 | /* NVIC_BASE + 0x020 (0xE000 E120 - 0xE000 E17F): Reserved */ 52 | 53 | /* ICER: Interrupt Clear Enable Registers */ 54 | /* Note: 8 32bit Registers */ 55 | /* Note: Single register on CM0 */ 56 | #define NVIC_ICER(icer_id) MMIO32(NVIC_BASE + 0x80 + \ 57 | ((icer_id) * 4)) 58 | 59 | /* NVIC_BASE + 0x0A0 (0xE000 E1A0 - 0xE000 E1FF): Reserved */ 60 | 61 | /* ISPR: Interrupt Set Pending Registers */ 62 | /* Note: 8 32bit Registers */ 63 | /* Note: Single register on CM0 */ 64 | #define NVIC_ISPR(ispr_id) MMIO32(NVIC_BASE + 0x100 + \ 65 | ((ispr_id) * 4)) 66 | 67 | /* NVIC_BASE + 0x120 (0xE000 E220 - 0xE000 E27F): Reserved */ 68 | 69 | /* ICPR: Interrupt Clear Pending Registers */ 70 | /* Note: 8 32bit Registers */ 71 | /* Note: Single register on CM0 */ 72 | #define NVIC_ICPR(icpr_id) MMIO32(NVIC_BASE + 0x180 + \ 73 | ((icpr_id) * 4)) 74 | 75 | /* NVIC_BASE + 0x1A0 (0xE000 E2A0 - 0xE00 E2FF): Reserved */ 76 | 77 | /* Those defined only on ARMv7 and above */ 78 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 79 | /* IABR: Interrupt Active Bit Register */ 80 | /* Note: 8 32bit Registers */ 81 | #define NVIC_IABR(iabr_id) MMIO32(NVIC_BASE + 0x200 + \ 82 | ((iabr_id) * 4)) 83 | #endif 84 | 85 | /* NVIC_BASE + 0x220 (0xE000 E320 - 0xE000 E3FF): Reserved */ 86 | 87 | /* IPR: Interrupt Priority Registers */ 88 | /* Note: 240 8bit Registers */ 89 | /* Note: 32 8bit Registers on CM0 */ 90 | #define NVIC_IPR(ipr_id) MMIO8(NVIC_BASE + 0x300 + \ 91 | (ipr_id)) 92 | 93 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 94 | /* STIR: Software Trigger Interrupt Register */ 95 | #define NVIC_STIR MMIO32(STIR_BASE) 96 | #endif 97 | 98 | /* --- IRQ channel numbers-------------------------------------------------- */ 99 | 100 | /* Cortex M0, M3 and M4 System Interrupts */ 101 | /** @defgroup nvic_sysint Cortex M0/M3/M4 System Interrupts 102 | @ingroup CM3_nvic_defines 103 | 104 | IRQ numbers -3 and -6 to -9 are reserved 105 | @{*/ 106 | #define NVIC_NMI_IRQ -14 107 | #define NVIC_HARD_FAULT_IRQ -13 108 | 109 | /* Those defined only on ARMv7 and above */ 110 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 111 | #define NVIC_MEM_MANAGE_IRQ -12 112 | #define NVIC_BUS_FAULT_IRQ -11 113 | #define NVIC_USAGE_FAULT_IRQ -10 114 | #endif 115 | 116 | /* irq numbers -6 to -9 are reserved */ 117 | #define NVIC_SV_CALL_IRQ -5 118 | 119 | /* Those defined only on ARMv7 and above */ 120 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 121 | #define DEBUG_MONITOR_IRQ -4 122 | #endif 123 | 124 | /* irq number -3 reserved */ 125 | #define NVIC_PENDSV_IRQ -2 126 | #define NVIC_SYSTICK_IRQ -1 127 | /**@}*/ 128 | 129 | /* Note: User interrupts are family specific and are defined in a family 130 | * specific header file in the corresponding subfolder. 131 | */ 132 | 133 | #include 134 | 135 | /* --- NVIC functions ------------------------------------------------------ */ 136 | 137 | BEGIN_DECLS 138 | 139 | void nvic_enable_irq(uint8_t irqn); 140 | void nvic_disable_irq(uint8_t irqn); 141 | uint8_t nvic_get_pending_irq(uint8_t irqn); 142 | void nvic_set_pending_irq(uint8_t irqn); 143 | void nvic_clear_pending_irq(uint8_t irqn); 144 | uint8_t nvic_get_irq_enabled(uint8_t irqn); 145 | void nvic_set_priority(uint8_t irqn, uint8_t priority); 146 | 147 | /* Those defined only on ARMv7 and above */ 148 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 149 | uint8_t nvic_get_active_irq(uint8_t irqn); 150 | void nvic_generate_software_interrupt(uint16_t irqn); 151 | #endif 152 | 153 | void reset_handler(void); 154 | void nmi_handler(void); 155 | void hard_fault_handler(void); 156 | void sv_call_handler(void); 157 | void pend_sv_handler(void); 158 | void sys_tick_handler(void); 159 | 160 | /* Those defined only on ARMv7 and above */ 161 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 162 | void mem_manage_handler(void); 163 | void bus_fault_handler(void); 164 | void usage_fault_handler(void); 165 | void debug_monitor_handler(void); 166 | #endif 167 | 168 | END_DECLS 169 | 170 | /**@}*/ 171 | 172 | #endif 173 | -------------------------------------------------------------------------------- /usb-msc/usb-msc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2013 Weston Schmidt 5 | * Copyright (C) 2013 Pavol Rusnak 6 | * Copyright (C) 2018 Seb Holzapfel 7 | * 8 | * This library is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this library. If not, see . 20 | */ 21 | 22 | /** 23 | * \addtogroup Examples 24 | * 25 | * This example implements a USB MSC device (aka Mass Storage Controller, 26 | * aka hard disk) to demonstrate the use of the USB device stack. Any 27 | * data written to the disk will be erased when the device is reset. 28 | * 29 | * When data is recieved, it will toggle the green LED. 30 | * The red LED is toggled constantly. 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | #include "ramdisk.h" 48 | 49 | /* Default AHB (core clock) frequency of Tomu board */ 50 | #define AHB_FREQUENCY 14000000 51 | 52 | #define LED_GREEN_PORT GPIOA 53 | #define LED_GREEN_PIN GPIO0 54 | #define LED_RED_PORT GPIOB 55 | #define LED_RED_PIN GPIO7 56 | 57 | #define VENDOR_ID 0x1209 /* pid.code */ 58 | #define PRODUCT_ID 0x70b1 /* Assigned to Tomu project */ 59 | #define DEVICE_VER 0x0101 /* Program version */ 60 | 61 | usbd_device *g_usbd_dev = 0; 62 | 63 | static const struct usb_device_descriptor dev_descr = { 64 | .bLength = USB_DT_DEVICE_SIZE, 65 | .bDescriptorType = USB_DT_DEVICE, 66 | .bcdUSB = 0x0110, 67 | .bDeviceClass = 0, 68 | .bDeviceSubClass = 0, 69 | .bDeviceProtocol = 0, 70 | .bMaxPacketSize0 = 64, 71 | .idVendor = VENDOR_ID, 72 | .idProduct = PRODUCT_ID, 73 | .bcdDevice = DEVICE_VER, 74 | .iManufacturer = 1, 75 | .iProduct = 2, 76 | .iSerialNumber = 3, 77 | .bNumConfigurations = 1, 78 | }; 79 | 80 | static const struct usb_endpoint_descriptor msc_endp[] = {{ 81 | .bLength = USB_DT_ENDPOINT_SIZE, 82 | .bDescriptorType = USB_DT_ENDPOINT, 83 | .bEndpointAddress = 0x01, 84 | .bmAttributes = USB_ENDPOINT_ATTR_BULK, 85 | .wMaxPacketSize = 64, 86 | .bInterval = 0, 87 | }, { 88 | .bLength = USB_DT_ENDPOINT_SIZE, 89 | .bDescriptorType = USB_DT_ENDPOINT, 90 | .bEndpointAddress = 0x82, 91 | .bmAttributes = USB_ENDPOINT_ATTR_BULK, 92 | .wMaxPacketSize = 64, 93 | .bInterval = 0, 94 | }}; 95 | 96 | static const struct usb_interface_descriptor msc_iface[] = {{ 97 | .bLength = USB_DT_INTERFACE_SIZE, 98 | .bDescriptorType = USB_DT_INTERFACE, 99 | .bInterfaceNumber = 0, 100 | .bAlternateSetting = 0, 101 | .bNumEndpoints = 2, 102 | .bInterfaceClass = USB_CLASS_MSC, 103 | .bInterfaceSubClass = USB_MSC_SUBCLASS_SCSI, 104 | .bInterfaceProtocol = USB_MSC_PROTOCOL_BBB, 105 | .iInterface = 0, 106 | .endpoint = msc_endp, 107 | .extra = NULL, 108 | .extralen = 0 109 | }}; 110 | 111 | static const struct usb_interface ifaces[] = {{ 112 | .num_altsetting = 1, 113 | .altsetting = msc_iface, 114 | }}; 115 | 116 | static const struct usb_config_descriptor config_descr = { 117 | .bLength = USB_DT_CONFIGURATION_SIZE, 118 | .bDescriptorType = USB_DT_CONFIGURATION, 119 | .wTotalLength = 0, 120 | .bNumInterfaces = 1, 121 | .bConfigurationValue = 1, 122 | .iConfiguration = 0, 123 | .bmAttributes = 0x80, 124 | .bMaxPower = 0x32, 125 | .interface = ifaces, 126 | }; 127 | 128 | static const char *usb_strings[] = { 129 | "Tomu", 130 | "MSC Demo", 131 | "DEMO", 132 | }; 133 | 134 | void usb_isr(void) 135 | { 136 | usbd_poll(g_usbd_dev); 137 | gpio_toggle(LED_GREEN_PORT, LED_GREEN_PIN); 138 | } 139 | 140 | void hard_fault_handler(void) 141 | { 142 | while(1); 143 | } 144 | 145 | /* Buffer to be used for control requests. */ 146 | static uint8_t usbd_control_buffer[128]; 147 | 148 | int main(void) 149 | { 150 | int i; 151 | 152 | /* Make sure the vector table is relocated correctly (after the Tomu bootloader) */ 153 | SCB_VTOR = 0x4000; 154 | 155 | /* Disable the watchdog that the bootloader started. */ 156 | WDOG_CTRL = 0; 157 | 158 | /* GPIO peripheral clock is necessary for us to set up the GPIO pins as outputs */ 159 | cmu_periph_clock_enable(CMU_GPIO); 160 | 161 | /* Set up both LEDs as outputs */ 162 | gpio_mode_setup(LED_RED_PORT, GPIO_MODE_WIRED_AND, LED_RED_PIN); 163 | gpio_mode_setup(LED_GREEN_PORT, GPIO_MODE_WIRED_AND, LED_GREEN_PIN); 164 | 165 | /* Configure the USB core & stack */ 166 | g_usbd_dev = usbd_init(&efm32hg_usb_driver, &dev_descr, &config_descr, 167 | usb_strings, 3, 168 | usbd_control_buffer, sizeof(usbd_control_buffer)); 169 | 170 | 171 | ramdisk_init(); 172 | usb_msc_init(g_usbd_dev, 0x82, 64, 0x01, 64, "Tomu", "RamdiskExample", 173 | "0.00", ramdisk_blocks(), ramdisk_read, ramdisk_write); 174 | 175 | /* Enable USB IRQs */ 176 | nvic_enable_irq(NVIC_USB_IRQ); 177 | 178 | while(1) { 179 | gpio_toggle(LED_RED_PORT, LED_RED_PIN); 180 | for(i = 0; i != 500000; ++i) 181 | __asm__("nop"); 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /libopencm3/include/libopencm3/efm32/common/msc_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2015 Kuldeep Singh Dhaka 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | #ifndef LIBOPENCM3_EFM32_MSC_H 21 | #define LIBOPENCM3_EFM32_MSC_H 22 | 23 | #include 24 | #include 25 | 26 | #define MSC_CTRL MMIO32(MSC_BASE + 0x000) 27 | #define MSC_READCTRL MMIO32(MSC_BASE + 0x004) 28 | #define MSC_WRITECTRL MMIO32(MSC_BASE + 0x008) 29 | #define MSC_WRITECMD MMIO32(MSC_BASE + 0x00C) 30 | #define MSC_ADDRB MMIO32(MSC_BASE + 0x010) 31 | #define MSC_WDATA MMIO32(MSC_BASE + 0x018) 32 | #define MSC_STATUS MMIO32(MSC_BASE + 0x01C) 33 | #define MSC_IF MMIO32(MSC_BASE + 0x02C) 34 | #define MSC_IFS MMIO32(MSC_BASE + 0x030) 35 | #define MSC_IFC MMIO32(MSC_BASE + 0x034) 36 | #define MSC_IEN MMIO32(MSC_BASE + 0x038) 37 | #define MSC_LOCK MMIO32(MSC_BASE + 0x03C) 38 | #define MSC_CMD MMIO32(MSC_BASE + 0x040) 39 | #define MSC_CACHEHITS MMIO32(MSC_BASE + 0x044) 40 | #define MSC_CACHEMISSES MMIO32(MSC_BASE + 0x048) 41 | #define MSC_TIMEBASE MMIO32(MSC_BASE + 0x050) 42 | #define MSC_MASSLOCK MMIO32(MSC_BASE + 0x054) 43 | 44 | /* MSC_CTRL */ 45 | #define MSC_CTRL_BUSFAULT (1 << 0) 46 | 47 | /* MSC_READCTRL */ 48 | #define MSC_READCTRL_BUSSTRATEGY_SHIFT (16) 49 | #define MSC_READCTRL_BUSSTRATEGY_MASK \ 50 | (0x3 << MSC_READCTRL_BUSSTRATEGY_SHIFT) 51 | #define MSC_READCTRL_BUSSTRATEGY(v) \ 52 | (((v) << MSC_READCTRL_BUSSTRATEGY_SHIFT) & \ 53 | MSC_READCTRL_BUSSTRATEGY_MASK) 54 | 55 | #define MSC_READCTRL_BUSSTRATEGY_CPU MSC_READCTRL_BUSSTRATEGY(0) 56 | #define MSC_READCTRL_BUSSTRATEGY_DMA MSC_READCTRL_BUSSTRATEGY(1) 57 | #define MSC_READCTRL_BUSSTRATEGY_DMAEM1 MSC_READCTRL_BUSSTRATEGY(2) 58 | #define MSC_READCTRL_BUSSTRATEGY_NONE MSC_READCTRL_BUSSTRATEGY(3) 59 | 60 | #define MSC_READCTRL_RAMCEN (1 << 7) 61 | #define MSC_READCTRL_EBICDIS (1 << 6) 62 | #define MSC_READCTRL_ICCDIS (1 << 5) 63 | #define MSC_READCTRL_AIDIS (1 << 4) 64 | #define MSC_READCTRL_IFCDIS (1 << 3) 65 | 66 | #define MSC_READCTRL_MODE_SHIFT (0) 67 | #define MSC_READCTRL_MODE_MASK (0x7 << MSC_READCTRL_MODE_SHIFT) 68 | #define MSC_READCTRL_MODE(v) \ 69 | (((v) << MSC_READCTRL_MODE_SHIFT) & MSC_READCTRL_MODE_MASK) 70 | #define MSC_READCTRL_MODE_WS0 0 71 | #define MSC_READCTRL_MODE_WS1 1 72 | #define MSC_READCTRL_MODE_WS0SCBTP 2 73 | #define MSC_READCTRL_MODE_WS1SCBTP 3 74 | #define MSC_READCTRL_MODE_WS2 4 75 | #define MSC_READCTRL_MODE_WS2SCBTP 5 76 | 77 | /* MSC_WRITECTRL */ 78 | #define MSC_WRITECTRL_IRQERASEABORT (1 << 1) 79 | #define MSC_WRITECTRL_WREN (1 << 0) 80 | 81 | /* MSC_WRITECMD */ 82 | #define MSC_WRITECMD_CLEARWDATA (1 << 12) 83 | #define MSC_WRITECMD_ERASEMAIN0 (1 << 8) 84 | #define MSC_WRITECMD_ERASEABORT (1 << 5) 85 | #define MSC_WRITECMD_WRITETRIG (1 << 4) 86 | #define MSC_WRITECMD_WRITEONCE (1 << 3) 87 | #define MSC_WRITECMD_WRITEEND (1 << 2) 88 | #define MSC_WRITECMD_ERASEPAGE (1 << 1) 89 | #define MSC_WRITECMD_LADDRIM (1 << 0) 90 | 91 | /* MSC_STATUS */ 92 | #define MSC_STATUS_PCRUNNING (1 << 6) 93 | #define MSC_STATUS_ERASEABORTED (1 << 5) 94 | #define MSC_STATUS_WORDTIMEOUT (1 << 4) 95 | #define MSC_STATUS_WDATAREADY (1 << 3) 96 | #define MSC_STATUS_INVADDR (1 << 2) 97 | #define MSC_STATUS_LOCKED (1 << 1) 98 | #define MSC_STATUS_BUSY (1 << 0) 99 | 100 | /* MSC_IF */ 101 | #define MSC_IF_CMOF (1 << 3) 102 | #define MSC_IF_CHOF (1 << 2) 103 | #define MSC_IF_WRITE (1 << 1) 104 | #define MSC_IF_ERASE (1 << 0) 105 | 106 | /* MSC_IFS */ 107 | #define MSC_IFS_CMOF (1 << 3) 108 | #define MSC_IFS_CHOF (1 << 2) 109 | #define MSC_IFS_WRITE (1 << 1) 110 | #define MSC_IFS_ERASE (1 << 0) 111 | 112 | /* MSC_IFC */ 113 | #define MSC_IFC_CMOF (1 << 3) 114 | #define MSC_IFC_CHOF (1 << 2) 115 | #define MSC_IFC_WRITE (1 << 1) 116 | #define MSC_IFC_ERASE (1 << 0) 117 | 118 | /* MSC_*IEN */ 119 | #define MSC_IEN_CMOF (1 << 3) 120 | #define MSC_IEN_CHOF (1 << 2) 121 | #define MSC_IEN_WRITE (1 << 1) 122 | #define MSC_IEN_ERASE (1 << 0) 123 | 124 | /* MSC_LOCK */ 125 | #define MSC_LOCK_LOCKKEY_SHIFT (0) 126 | #define MSC_LOCK_LOCKKEY(v) ((v) << MSC_LOCK_LOCKKEY_SHIFT) 127 | #define MSC_LOCK_LOCKKEY_UNLOCKED MSC_LOCK_LOCKKEY(0) 128 | #define MSC_LOCK_LOCKKEY_LOCKED MSC_LOCK_LOCKKEY(1) 129 | #define MSC_LOCK_LOCKKEY_LOCK MSC_LOCK_LOCKKEY(0) 130 | #define MSC_LOCK_LOCKKEY_UNLOCK MSC_LOCK_LOCKKEY(0x1B71) 131 | 132 | /* MSC_CMD */ 133 | #define MSC_CMD_STOPPC (1 << 2) 134 | #define MSC_CMD_STARTPC (1 << 1) 135 | #define MSC_CMD_INVCACHE (1 << 0) 136 | 137 | /* MSC_TIMEBASE */ 138 | #define MSC_TIMEBASE_PERIOD (1 << 16) 139 | 140 | #define MSC_TIMEBASE_BASE_SHIFT (0) 141 | #define MSC_TIMEBASE_BASE_MASK (0x3F << MSC_TIMEBASE_BASE_SHIFT) 142 | #define MSC_TIMEBASE_BASE(v) \ 143 | (((v) << MSC_TIMEBASE_BASE_SHIFT) & MSC_TIMEBASE_BASE_MASK) 144 | 145 | /* MSC_MASSLOCK */ 146 | #define MSC_MASSLOCK_LOCKKEY_SHIFT (0) 147 | #define MSC_MASSLOCK_LOCKKEY(v) ((v) << MSC_MASSLOCK_LOCKKEY_SHIFT) 148 | #define MSC_MASSLOCK_LOCKKEY_UNLOCKED MSC_MASSLOCK_LOCKKEY(0) 149 | #define MSC_MASSLOCK_LOCKKEY_LOCKED MSC_MASSLOCK_LOCKKEY(1) 150 | #define MSC_MASSLOCK_LOCKKEY_LOCK MSC_MASSLOCK_LOCKKEY(0) 151 | #define MSC_MASSLOCK_LOCKKEY_UNLOCK MSC_MASSLOCK_LOCKKEY(0x631A) 152 | 153 | #endif 154 | 155 | -------------------------------------------------------------------------------- /libopencm3/include/libopencmsis/core_cm3.h: -------------------------------------------------------------------------------- 1 | /* big fat FIXME: this should use a consistent structure, and reference 2 | * functionality from libopencm3 instead of copypasting. 3 | * 4 | * particularly unimplemented features are FIXME'd extra 5 | * */ 6 | 7 | /* the original core_cm3.h is nonfree by arm; this provides libopencm3 variant 8 | * of the symbols efm32lib needs of CMSIS. */ 9 | 10 | #ifndef OPENCMSIS_CORECM3_H 11 | #define OPENCMSIS_CORECM3_H 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | /* needed by system_efm32.h:196, guessing */ 21 | #define __INLINE inline 22 | /* new since emlib 3.0 */ 23 | #define __STATIC_INLINE static inline 24 | 25 | /* needed around efm32tg840f32.h:229. comparing the efm32lib definitions to the 26 | * libopencm3 ones, "volatile" is all that's missing. */ 27 | #define __IO volatile 28 | #define __O volatile 29 | #define __I volatile 30 | 31 | /* -> style access for what is defined in libopencm3/stm32/f1/scb.h / 32 | * cm3/memorymap.h, as it's needed by efm32lib/inc/efm32_emu.h */ 33 | 34 | /* from cm3/scb.h */ 35 | #define SCB_SCR_SLEEPDEEP_Msk SCB_SCR_SLEEPDEEP 36 | 37 | /* structure as in, for example, 38 | * DeviceSupport/EnergyMicro/EFM32/efm32tg840f32.h, data from 39 | * libopencm3/cm3/scb.h. FIXME incomplete. */ 40 | typedef struct { 41 | __IO uint32_t CPUID; 42 | __IO uint32_t ICSR; 43 | __IO uint32_t VTOR; 44 | __IO uint32_t AIRCR; 45 | __IO uint32_t SCR; 46 | __IO uint32_t CCR; 47 | __IO uint8_t SHPR[12]; /* FIXME: how is this properly indexed? */ 48 | __IO uint32_t SHCSR; 49 | } SCB_TypeDef; 50 | #define SCB ((SCB_TypeDef *) SCB_BASE) 51 | 52 | /* needed by efm32_emu.h, guessing and taking the implementation used in 53 | * lightswitch-interrupt.c */ 54 | #define __WFI() __asm__("wfi") 55 | 56 | /* needed by efm32_cmu.h, probably it's just what gcc provides anyway */ 57 | #define __CLZ(div) __builtin_clz(div) 58 | 59 | /* needed by efm32_aes.c. __builtin_bswap32 does the same thing as the rev 60 | * instruction according to https://bugzilla.mozilla.org/show_bug.cgi?id=600106 61 | */ 62 | #define __REV(x) __builtin_bswap32(x) 63 | 64 | /* stubs for efm32_dbg.h */ 65 | typedef struct { 66 | uint32_t DHCSR; 67 | uint32_t DEMCR; /* needed by efm32tg stk trace.c */ 68 | } CoreDebug_TypeDef; 69 | /* FIXME let's just hope writes to flash are protected */ 70 | #define CoreDebug ((CoreDebug_TypeDef *) 0) 71 | #define CoreDebug_DHCSR_C_DEBUGEN_Msk 0 72 | #define CoreDebug_DEMCR_TRCENA_Msk 0 73 | 74 | /* stubs for efm32_dma */ 75 | 76 | static inline void NVIC_ClearPendingIRQ(uint8_t irqn) 77 | { 78 | nvic_clear_pending_irq(irqn); 79 | } 80 | static inline void NVIC_EnableIRQ(uint8_t irqn) 81 | { 82 | nvic_enable_irq(irqn); 83 | } 84 | static inline void NVIC_DisableIRQ(uint8_t irqn) 85 | { 86 | nvic_disable_irq(irqn); 87 | } 88 | 89 | /* stubs for efm32_int */ 90 | 91 | static inline void __enable_irq(void) 92 | { 93 | cm_enable_interrupts(); 94 | } 95 | static inline void __disable_irq(void) 96 | { 97 | cm_disable_interrupts(); 98 | } 99 | 100 | /* stubs for efm32_mpu FIXME */ 101 | 102 | #define SCB_SHCSR_MEMFAULTENA_Msk 0 103 | 104 | typedef struct { 105 | uint32_t CTRL; 106 | uint32_t RNR; 107 | uint32_t RBAR; 108 | uint32_t RASR; 109 | } MPU_TypeDef; 110 | /* FIXME struct at NULL */ 111 | #define MPU ((MPU_TypeDef *) 0) 112 | #define MPU_CTRL_ENABLE_Msk 0 113 | #define MPU_RASR_XN_Pos 0 114 | #define MPU_RASR_AP_Pos 0 115 | #define MPU_RASR_TEX_Pos 0 116 | #define MPU_RASR_S_Pos 0 117 | #define MPU_RASR_C_Pos 0 118 | #define MPU_RASR_B_Pos 0 119 | #define MPU_RASR_SRD_Pos 0 120 | #define MPU_RASR_SIZE_Pos 0 121 | #define MPU_RASR_ENABLE_Pos 0 122 | 123 | /* required for the blink example */ 124 | 125 | /* if if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ; 126 | * configures the sys ticks to 1ms, then the argument to SysTick_Config 127 | * describes how many cycles to wait between two systicks. 128 | * 129 | * the endless loop part looks like an "if it returns an error condition, 130 | * rather loop here than continue"; every other solution would involve things 131 | * that are dark magic to my understanding. 132 | * 133 | * implementation more or less copypasted from lib/stm32/systick.c, FIXME until 134 | * the generic cm3 functionality is moved out from stm32 and can be used here 135 | * easily (systick_set_reload, systick_interrupt_enable, systick_counter_enable 136 | * and systick_set_clocksource). 137 | * 138 | * modified for CMSIS style array as the powertest example needs it. 139 | * */ 140 | 141 | /* from d0002_efm32_cortex-m3_reference_manual.pdf section 4.4 */ 142 | typedef struct { 143 | uint32_t CTRL; 144 | uint32_t LOAD; 145 | uint32_t VAL; 146 | uint32_t CALIB; 147 | } SysTick_TypeDef; 148 | #define SysTick ((SysTick_TypeDef *) SYS_TICK_BASE) 149 | 150 | static inline uint32_t SysTick_Config(uint32_t n_ticks) 151 | { 152 | /* constant from systick_set_reload -- as this returns something that's 153 | * not void, this is the only possible error condition */ 154 | if (n_ticks & ~0x00FFFFFF) { 155 | return 1; 156 | } 157 | 158 | systick_set_reload(n_ticks); 159 | systick_set_clocksource(true); 160 | systick_interrupt_enable(); 161 | systick_counter_enable(); 162 | 163 | return 0; 164 | } 165 | 166 | /* stubs for efm32tg stk trace.c */ 167 | typedef struct { 168 | uint32_t LAR; 169 | uint32_t TCR; 170 | } ITM_TypeDef; 171 | /* FIXME struct at NULL */ 172 | #define ITM ((ITM_TypeDef *) 0) 173 | 174 | /* blink.h expects the isr for systicks to be named SysTick_Handler. with this, 175 | * its Systick_Handler function gets renamed to the weak symbol exported by 176 | * vector.c */ 177 | 178 | #define SysTick_Handler sys_tick_handler 179 | /* FIXME: this needs to be done for all of the 14 hard vectors */ 180 | 181 | #include 182 | 183 | #endif 184 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tomu Quickstart Guide 2 | 3 | This guide describes everything you need to set up your system to develop for [Tomu](https://tomu.im/). 4 | 5 | This quickstart guide is designed to be used on Mac, Windows, Linux, and anything else that can run GCC and Make. 6 | 7 | The [main Tomu U2F firmware](https://github.com/im-tomu/chopstx/tree/efm32/u2f) is in a different repo. 8 | 9 | ## Overview of Requirements 10 | 11 | To build and load sample code, you will need three things: 12 | 13 | 1. An [ARM toolchain](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm) 14 | 1. Make 15 | 1. dfu-utils 16 | 17 | Installation varies depending on your platform: 18 | 19 | Platform | ARM Toolchain | Make | dfu-util 20 | ---------- | -------------- | ----- | ---------- 21 | *Windows* | [GNU Arm Embedded Toolchain](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads) | [GNU Win32 Make](http://gnuwin32.sourceforge.net/packages/make.htm) | [precompiled binaries](http://dfu-util.sourceforge.net/releases/dfu-util-0.8-binaries/win32-mingw32/) 22 | *macOS* | [GNU Arm Embedded Toolchain](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads) | [Xcode](https://itunes.apple.com/us/app/xcode/id497799835) | [Homebrew](https://brew.sh/) `brew install dfu-util` 23 | *Debian/Ubuntu* | `sudo apt-get install gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib` | `sudo apt-get install make` | `sudo apt-get install dfu-util` 24 | *Fedora* | `sudo dnf install arm-none-eabi-newlib arm-none-eabi-gcc-cs-c++` | `sudo dnf install make` | `sudo dnf install dfu-util` 25 | *Arch* | `sudo pacman -S arm-none-eabi-gcc arm-none-eabi-newlib` | `sudo pacman -S make` | `sudo pacman -S dfu-util` 26 | 27 | If you don't have dfu-util (for instance a chromebook), you may be able to flash from a chrome browser with https://dfu.tomu.im/ 28 | 29 | This quickstart repo differs from the samples repo in that it has a prebuilt version of `libopencm3`, which normally requires various command line programs to compile. This cuts down on compile time, and enables building on platforms that don't have commands like grep, printf, or cat. 30 | 31 | ## Building Examples 32 | 33 | To build an example, go into the directory and type `make`. For example, `bare-minimum`. 34 | 35 | ## Loading Examples 36 | 37 | ### Upgrade toboot (if needed) 38 | Before you start, check if you have an old bootloader. On linux, it will look like this in dmesg: 39 | `Product: Tomu Bootloader` instead of `Product: Tomu Bootloader (5) v2.0-rc7` 40 | If you flash a program, you will require a recovery procedure to get the flashing bootloader 41 | back by default. 42 | You will need to go to: https://github.com/im-tomu/toboot and if you lost your bootloader, you will have to 43 | short external pads 1 and 4 before you insert tomu. 44 | After that, you'll need to flash 2 files: 45 | * "sudo dfu-util --download toboot-boosted.dfu" (flash, and then re-insert tomu) 46 | * tomu should now look like this in dmesg "Tomu Bootloader (1) v2.0-rc7" 47 | * flash a 2nd time with "sudo dfu-util -D toboot-boosted.bin" 48 | * now tomu should say "Tomu Bootloader (5) v2.0-rc7" 49 | 50 | ### Load an an example 51 | To load examples onto Tomu, ensure it is in DFU mode by verifying that the red and green LEDs are alternately blinking, and that it shows up if you run `sudo dfu-util --list`. Then, load the sample you want using `dfu-util --download project.dfu`. 52 | 53 | Note that you may need to use sudo or proper udev permissions to flash: 54 | ``` 55 | sauron [mc]$ dfu-util --download miniblink.dfu 56 | Match vendor ID from file: 1209 57 | Match product ID from file: 70b1 58 | dfu-util: Cannot open DFU device 1209:70b1 59 | dfu-util: No DFU capable USB device available 60 | 61 | sauron [mc]$ sudo dfu-util --download miniblink.dfu 62 | Match vendor ID from file: 1209 63 | Match product ID from file: 70b1 64 | Opening DFU capable USB device... 65 | ID 1209:70b1 66 | Run-time device DFU version 0101 67 | Claiming USB DFU Interface... 68 | Setting Alternate Setting #0 ... 69 | Determining device status: state = dfuIDLE, status = 0 70 | dfuIDLE, continuing 71 | DFU mode device DFU version 0101 72 | Device returned transfer size 1024 73 | Copying data from PC to DFU device 74 | Download [=========================] 100% 1164 bytes 75 | ``` 76 | 77 | ### Permissions and udev 78 | If you need to run sudo every time, on linux you can add some udev rules change permissions automatically. 79 | Write this into /etc/udev/rules.d/10-tomu.rules, then run 'udevadm trigger', and re-insert the device. 80 | ``` 81 | ACTION=="add|change", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="70b1", TAG+="uaccess" 82 | ``` 83 | 84 | ### Loading the next program, or "help, I can't load the next program" 85 | To load another program, unplug Tomu and plug it back in. If you do not get the tomu bootloader when you do so, 86 | jump back to the beginning of this section and see how to force boot into toboot and upgrade it. 87 | 88 | ## Creating a new Project 89 | 90 | To create a new project, simply copy an existing project. The [`bare-minimum`](./bare-minimum) project is a good example if you want to start from scratch. 91 | 92 | The new project's .dfu file will be based on the directory name. 93 | 94 | ## Troubleshooting Tips 95 | 96 | * The `miniblink` program, when correctly operating, looks quite similar to the bootloader's "waiting for instructions" state. You can change this by editing the `system_millis` check in the `sys_tick_handler` function to make the LEDs flash faster or slower. 97 | 98 | * Early versions of the bootloader only work with programs that have a toboot-v2.0 signature. If you load a program and get a stream of `test-in-progress` over the USB serial console instead of what you expect the program to do, you should [upgrade toboot](https://github.com/im-tomu/tomu-bootloader#installing-or-upgrading-toboot). To add a toboot-v2.0 signature, add the following near the top of the program and recompile: 99 | ``` 100 | // Make this program compatible with Toboot-V2.0 101 | #include 102 | TOBOOT_CONFIGURATION(0); 103 | ``` 104 | --------------------------------------------------------------------------------