From 4bb4ce913b0c26dd016e0de4bbd072656c79fda7 Mon Sep 17 00:00:00 2001 From: Roger Clark Date: Thu, 19 Apr 2018 18:09:09 +1000 Subject: [PATCH] Removed STM32F3 folder as it was only included as an archive, and is still available in the STM32F3 branch --- STM32F3/README.md | 45 - STM32F3/boards.txt | 62 - STM32F3/cores/maple/Arduino.h | 4 - STM32F3/cores/maple/WProgram.h | 35 - STM32F3/cores/maple/libmaple/adc.c | 52 - STM32F3/cores/maple/libmaple/bkp.c | 69 - STM32F3/cores/maple/libmaple/dac.c | 120 -- STM32F3/cores/maple/libmaple/dma.c | 82 -- STM32F3/cores/maple/libmaple/dma_private.h | 61 - STM32F3/cores/maple/libmaple/exc.S | 101 -- STM32F3/cores/maple/libmaple/exti.c | 293 ----- STM32F3/cores/maple/libmaple/exti_private.h | 34 - STM32F3/cores/maple/libmaple/flash.c | 55 - STM32F3/cores/maple/libmaple/gpio.c | 50 - STM32F3/cores/maple/libmaple/i2c.c | 52 - STM32F3/cores/maple/libmaple/i2c_private.h | 75 -- .../maple/libmaple/include/libmaple/adc.h | 319 ----- .../maple/libmaple/include/libmaple/bitband.h | 128 -- .../maple/libmaple/include/libmaple/bkp.h | 100 -- .../maple/libmaple/include/libmaple/comp.h | 46 - .../maple/libmaple/include/libmaple/dac.h | 158 --- .../maple/libmaple/include/libmaple/delay.h | 65 - .../maple/libmaple/include/libmaple/dma.h | 444 ------- .../libmaple/include/libmaple/dma_common.h | 112 -- .../maple/libmaple/include/libmaple/dsp.h | 131 -- .../maple/libmaple/include/libmaple/exti.h | 143 --- .../maple/libmaple/include/libmaple/flash.h | 106 -- .../maple/libmaple/include/libmaple/fpu.h | 56 - .../maple/libmaple/include/libmaple/fsmc.h | 340 ----- .../maple/libmaple/include/libmaple/gpio.h | 121 -- .../maple/libmaple/include/libmaple/i2c.h | 304 ----- .../libmaple/include/libmaple/i2c_common.h | 93 -- .../maple/libmaple/include/libmaple/iwdg.h | 115 -- .../libmaple/include/libmaple/libmaple.h | 48 - .../include/libmaple/libmaple_types.h | 73 -- .../maple/libmaple/include/libmaple/nvic.h | 155 --- .../maple/libmaple/include/libmaple/opamp.h | 46 - .../maple/libmaple/include/libmaple/pwr.h | 115 -- .../maple/libmaple/include/libmaple/rcc.h | 175 --- .../libmaple/include/libmaple/ring_buffer.h | 188 --- .../maple/libmaple/include/libmaple/scb.h | 214 ---- .../maple/libmaple/include/libmaple/spi.h | 487 ------- .../maple/libmaple/include/libmaple/stm32.h | 239 ---- .../maple/libmaple/include/libmaple/syscfg.h | 116 -- .../maple/libmaple/include/libmaple/systick.h | 115 -- .../maple/libmaple/include/libmaple/timer.h | 1119 ----------------- .../maple/libmaple/include/libmaple/usart.h | 464 ------- .../maple/libmaple/include/libmaple/usb.h | 176 --- .../libmaple/include/libmaple/usb_cdcacm.h | 179 --- .../maple/libmaple/include/libmaple/util.h | 111 -- STM32F3/cores/maple/libmaple/iwdg.c | 62 - STM32F3/cores/maple/libmaple/nvic.c | 103 -- STM32F3/cores/maple/libmaple/pwr.c | 41 - STM32F3/cores/maple/libmaple/rcc.c | 169 --- STM32F3/cores/maple/libmaple/rcc_private.h | 67 - STM32F3/cores/maple/libmaple/rules.mk | 53 - STM32F3/cores/maple/libmaple/spi.c | 129 -- STM32F3/cores/maple/libmaple/spi_private.h | 37 - STM32F3/cores/maple/libmaple/stm32_private.h | 45 - STM32F3/cores/maple/libmaple/stm32f3/f3_adc.c | 412 ------ STM32F3/cores/maple/libmaple/stm32f3/f3_bkp.c | 49 - .../cores/maple/libmaple/stm32f3/f3_comp.c | 61 - STM32F3/cores/maple/libmaple/stm32f3/f3_dma.c | 364 ------ .../cores/maple/libmaple/stm32f3/f3_exti.c | 40 - STM32F3/cores/maple/libmaple/stm32f3/f3_fpu.c | 57 - .../cores/maple/libmaple/stm32f3/f3_gpio.c | 169 --- STM32F3/cores/maple/libmaple/stm32f3/f3_i2c.c | 319 ----- .../cores/maple/libmaple/stm32f3/f3_opamp.c | 46 - STM32F3/cores/maple/libmaple/stm32f3/f3_rcc.c | 149 --- STM32F3/cores/maple/libmaple/stm32f3/f3_spi.c | 143 --- .../cores/maple/libmaple/stm32f3/f3_syscfg.c | 43 - .../cores/maple/libmaple/stm32f3/f3_timer.c | 147 --- .../cores/maple/libmaple/stm32f3/f3_usart.c | 210 ---- .../libmaple/stm32f3/include/series/adc.h | 696 ---------- .../libmaple/stm32f3/include/series/bkp.h | 62 - .../libmaple/stm32f3/include/series/comp.h | 119 -- .../libmaple/stm32f3/include/series/crc.h | 94 -- .../libmaple/stm32f3/include/series/dac.h | 74 -- .../libmaple/stm32f3/include/series/dma.h | 557 -------- .../libmaple/stm32f3/include/series/exti.h | 49 - .../libmaple/stm32f3/include/series/flash.h | 164 --- .../libmaple/stm32f3/include/series/fpu.h | 65 - .../libmaple/stm32f3/include/series/gpio.h | 255 ---- .../libmaple/stm32f3/include/series/i2c.h | 315 ----- .../libmaple/stm32f3/include/series/nvic.h | 153 --- .../libmaple/stm32f3/include/series/opamp.h | 123 -- .../libmaple/stm32f3/include/series/pwr.h | 52 - .../libmaple/stm32f3/include/series/rcc.h | 632 ---------- .../libmaple/stm32f3/include/series/simd.h | 109 -- .../libmaple/stm32f3/include/series/spi.h | 178 --- .../libmaple/stm32f3/include/series/stm32.h | 238 ---- .../libmaple/stm32f3/include/series/syscfg.h | 138 -- .../libmaple/stm32f3/include/series/timer.h | 123 -- .../libmaple/stm32f3/include/series/usart.h | 277 ---- STM32F3/cores/maple/libmaple/stm32f3/rules.mk | 48 - STM32F3/cores/maple/libmaple/syscfg.c | 41 - STM32F3/cores/maple/libmaple/systick.c | 88 -- STM32F3/cores/maple/libmaple/timer.c | 456 ------- STM32F3/cores/maple/libmaple/timer_private.h | 235 ---- STM32F3/cores/maple/libmaple/usart.c | 122 -- STM32F3/cores/maple/libmaple/usart_private.c | 41 - STM32F3/cores/maple/libmaple/usart_private.h | 42 - STM32F3/cores/maple/libmaple/usb/README | 63 - STM32F3/cores/maple/libmaple/usb/usb.c | 387 ------ STM32F3/cores/maple/libmaple/usb/usb_cdcacm.c | 723 ----------- .../maple/libmaple/usb/usb_lib/usb_core.c | 1013 --------------- .../maple/libmaple/usb/usb_lib/usb_core.h | 251 ---- .../maple/libmaple/usb/usb_lib/usb_def.h | 88 -- .../maple/libmaple/usb/usb_lib/usb_init.c | 64 - .../maple/libmaple/usb/usb_lib/usb_init.h | 57 - .../maple/libmaple/usb/usb_lib/usb_lib.h | 36 - .../maple/libmaple/usb/usb_lib/usb_mem.c | 73 -- .../maple/libmaple/usb/usb_lib/usb_mem.h | 40 - .../maple/libmaple/usb/usb_lib/usb_regs.c | 748 ----------- .../maple/libmaple/usb/usb_lib/usb_regs.h | 627 --------- .../maple/libmaple/usb/usb_lib/usb_type.h | 77 -- .../maple/libmaple/usb/usb_lib_globals.h | 55 - .../cores/maple/libmaple/usb/usb_reg_map.c | 88 -- .../cores/maple/libmaple/usb/usb_reg_map.h | 617 --------- STM32F3/cores/maple/libmaple/util.c | 150 --- STM32F3/cores/maple/main.cpp | 44 - STM32F3/cores/maple/wirish/HardwareSPI.cpp | 320 ----- STM32F3/cores/maple/wirish/HardwareSPI.h | 225 ---- STM32F3/cores/maple/wirish/HardwareSerial.cpp | 139 -- STM32F3/cores/maple/wirish/HardwareSerial.h | 102 -- STM32F3/cores/maple/wirish/HardwareTimer.cpp | 156 --- STM32F3/cores/maple/wirish/HardwareTimer.h | 337 ----- STM32F3/cores/maple/wirish/Print.cpp | 244 ---- STM32F3/cores/maple/wirish/Print.h | 66 - STM32F3/cores/maple/wirish/bit_constants.h | 579 --------- STM32F3/cores/maple/wirish/bits.h | 35 - STM32F3/cores/maple/wirish/boards.cpp | 215 ---- STM32F3/cores/maple/wirish/boards.h | 173 --- STM32F3/cores/maple/wirish/boards_private.h | 71 -- STM32F3/cores/maple/wirish/cxxabi-compat.cpp | 6 - STM32F3/cores/maple/wirish/ext_interrupts.cpp | 90 -- STM32F3/cores/maple/wirish/ext_interrupts.h | 128 -- STM32F3/cores/maple/wirish/io.h | 222 ---- STM32F3/cores/maple/wirish/main.cxx | 40 - STM32F3/cores/maple/wirish/pwm.cpp | 48 - STM32F3/cores/maple/wirish/pwm.h | 56 - STM32F3/cores/maple/wirish/rules.mk | 66 - .../maple/wirish/stm32f3/boards_setup.cpp | 92 -- .../wirish/stm32f3/f3_wirish_digital.cpp | 99 -- .../cores/maple/wirish/stm32f3/util_hooks.c | 45 - .../maple/wirish/stm32f3/wirish_debug.cpp | 70 -- STM32F3/cores/maple/wirish/syscalls.c | 175 --- STM32F3/cores/maple/wirish/usb_serial.cpp | 260 ---- STM32F3/cores/maple/wirish/usb_serial.h | 67 - STM32F3/cores/maple/wirish/wirish.h | 77 -- STM32F3/cores/maple/wirish/wirish_analog.cpp | 47 - STM32F3/cores/maple/wirish/wirish_debug.h | 57 - STM32F3/cores/maple/wirish/wirish_digital.cpp | 94 -- STM32F3/cores/maple/wirish/wirish_math.cpp | 49 - STM32F3/cores/maple/wirish/wirish_math.h | 151 --- STM32F3/cores/maple/wirish/wirish_shift.cpp | 37 - STM32F3/cores/maple/wirish/wirish_time.cpp | 45 - STM32F3/cores/maple/wirish/wirish_time.h | 95 -- STM32F3/cores/maple/wirish/wirish_types.h | 68 - STM32F3/examples/Blinkf3/Blinkf3.ino | 38 - .../examples/f3_buttondemo/f3_buttondemo.ino | 54 - .../f3_functionTimer/f3_functionTimer.ino | 144 --- STM32F3/examples/f3_gyrodemo/f3_gyrodemo.ino | 100 -- .../examples/f3_lsm303demo/f3_lsm303demo.ino | 111 -- .../examples/f3_ultrasonic/f3_ultrasonic.ino | 137 -- STM32F3/libraries/gyro/gyro.cpp | 337 ----- STM32F3/libraries/gyro/gyro.h | 118 -- STM32F3/libraries/gyro/l3gd20.h | 93 -- STM32F3/libraries/lsm303/lsm303.cpp | 225 ---- STM32F3/libraries/lsm303/lsm303.h | 77 -- STM32F3/libraries/lsm303/lsm303reg.h | 131 -- STM32F3/libraries/ringbuffer/ringbuffer.cpp | 320 ----- STM32F3/libraries/ringbuffer/ringbuffer.h | 155 --- STM32F3/libraries/roboter/debug.cpp | 196 --- STM32F3/libraries/roboter/debug.h | 58 - STM32F3/libraries/roboter/eeprom.cpp | 169 --- STM32F3/libraries/roboter/eeprom.h | 53 - STM32F3/libraries/roboter/functiontimer.cpp | 234 ---- STM32F3/libraries/roboter/functiontimer.h | 51 - STM32F3/libraries/roboter/motor.cpp | 259 ---- STM32F3/libraries/roboter/motor.h | 58 - STM32F3/libraries/roboter/sound.cpp | 30 - STM32F3/libraries/roboter/sound.h | 33 - STM32F3/libraries/roboter/ultraschall.cpp | 536 -------- STM32F3/libraries/roboter/ultraschall.h | 156 --- STM32F3/platform.txt | 144 --- STM32F3/variants/discovery_f3/board/board.h | 138 -- .../variants/discovery_f3/discovery_f3.cpp | 193 --- STM32F3/variants/discovery_f3/ld/common.inc | 229 ---- .../variants/discovery_f3/ld/extra_libs.inc | 7 - STM32F3/variants/discovery_f3/ld/flash.ld | 28 - STM32F3/variants/discovery_f3/ld/jtag.ld | 33 - .../variants/discovery_f3/ld/mem-flash.inc | 6 - STM32F3/variants/discovery_f3/ld/mem-jtag.inc | 6 - STM32F3/variants/discovery_f3/ld/mem-ram.inc | 6 - STM32F3/variants/discovery_f3/ld/names.inc | 78 -- STM32F3/variants/discovery_f3/ld/ram.ld | 27 - .../discovery_f3/ld/vector_symbols.inc | 98 -- STM32F3/variants/discovery_f3/stm32_isrs.S | 331 ----- .../discovery_f3/stm32_vector_table.S | 134 -- STM32F3/variants/discovery_f3/wirish/start.S | 57 - .../variants/discovery_f3/wirish/start_c.c | 95 -- 202 files changed, 31982 deletions(-) delete mode 100644 STM32F3/README.md delete mode 100644 STM32F3/boards.txt delete mode 100644 STM32F3/cores/maple/Arduino.h delete mode 100644 STM32F3/cores/maple/WProgram.h delete mode 100644 STM32F3/cores/maple/libmaple/adc.c delete mode 100644 STM32F3/cores/maple/libmaple/bkp.c delete mode 100644 STM32F3/cores/maple/libmaple/dac.c delete mode 100644 STM32F3/cores/maple/libmaple/dma.c delete mode 100644 STM32F3/cores/maple/libmaple/dma_private.h delete mode 100644 STM32F3/cores/maple/libmaple/exc.S delete mode 100644 STM32F3/cores/maple/libmaple/exti.c delete mode 100644 STM32F3/cores/maple/libmaple/exti_private.h delete mode 100644 STM32F3/cores/maple/libmaple/flash.c delete mode 100644 STM32F3/cores/maple/libmaple/gpio.c delete mode 100644 STM32F3/cores/maple/libmaple/i2c.c delete mode 100644 STM32F3/cores/maple/libmaple/i2c_private.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/adc.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/bitband.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/bkp.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/comp.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/dac.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/delay.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/dma.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/dma_common.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/dsp.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/exti.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/flash.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/fpu.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/fsmc.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/gpio.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/i2c.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/i2c_common.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/iwdg.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/libmaple.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/libmaple_types.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/nvic.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/opamp.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/pwr.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/rcc.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/ring_buffer.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/scb.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/spi.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/stm32.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/syscfg.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/systick.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/timer.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/usart.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/usb.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/usb_cdcacm.h delete mode 100644 STM32F3/cores/maple/libmaple/include/libmaple/util.h delete mode 100644 STM32F3/cores/maple/libmaple/iwdg.c delete mode 100644 STM32F3/cores/maple/libmaple/nvic.c delete mode 100644 STM32F3/cores/maple/libmaple/pwr.c delete mode 100644 STM32F3/cores/maple/libmaple/rcc.c delete mode 100644 STM32F3/cores/maple/libmaple/rcc_private.h delete mode 100644 STM32F3/cores/maple/libmaple/rules.mk delete mode 100644 STM32F3/cores/maple/libmaple/spi.c delete mode 100644 STM32F3/cores/maple/libmaple/spi_private.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32_private.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_adc.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_bkp.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_comp.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_dma.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_exti.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_fpu.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_gpio.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_i2c.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_opamp.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_rcc.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_spi.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_syscfg.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_timer.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/f3_usart.c delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/adc.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/bkp.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/comp.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/crc.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/dac.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/dma.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/exti.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/flash.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/fpu.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/gpio.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/i2c.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/nvic.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/opamp.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/pwr.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/rcc.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/simd.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/spi.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/stm32.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/syscfg.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/timer.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/include/series/usart.h delete mode 100644 STM32F3/cores/maple/libmaple/stm32f3/rules.mk delete mode 100644 STM32F3/cores/maple/libmaple/syscfg.c delete mode 100644 STM32F3/cores/maple/libmaple/systick.c delete mode 100644 STM32F3/cores/maple/libmaple/timer.c delete mode 100644 STM32F3/cores/maple/libmaple/timer_private.h delete mode 100644 STM32F3/cores/maple/libmaple/usart.c delete mode 100644 STM32F3/cores/maple/libmaple/usart_private.c delete mode 100644 STM32F3/cores/maple/libmaple/usart_private.h delete mode 100644 STM32F3/cores/maple/libmaple/usb/README delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb.c delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_cdcacm.c delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_core.c delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_core.h delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_def.h delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_init.c delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_init.h delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_lib.h delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_mem.c delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_mem.h delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_regs.c delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_regs.h delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib/usb_type.h delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_lib_globals.h delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_reg_map.c delete mode 100644 STM32F3/cores/maple/libmaple/usb/usb_reg_map.h delete mode 100644 STM32F3/cores/maple/libmaple/util.c delete mode 100644 STM32F3/cores/maple/main.cpp delete mode 100644 STM32F3/cores/maple/wirish/HardwareSPI.cpp delete mode 100644 STM32F3/cores/maple/wirish/HardwareSPI.h delete mode 100644 STM32F3/cores/maple/wirish/HardwareSerial.cpp delete mode 100644 STM32F3/cores/maple/wirish/HardwareSerial.h delete mode 100644 STM32F3/cores/maple/wirish/HardwareTimer.cpp delete mode 100644 STM32F3/cores/maple/wirish/HardwareTimer.h delete mode 100644 STM32F3/cores/maple/wirish/Print.cpp delete mode 100644 STM32F3/cores/maple/wirish/Print.h delete mode 100644 STM32F3/cores/maple/wirish/bit_constants.h delete mode 100644 STM32F3/cores/maple/wirish/bits.h delete mode 100644 STM32F3/cores/maple/wirish/boards.cpp delete mode 100644 STM32F3/cores/maple/wirish/boards.h delete mode 100644 STM32F3/cores/maple/wirish/boards_private.h delete mode 100644 STM32F3/cores/maple/wirish/cxxabi-compat.cpp delete mode 100644 STM32F3/cores/maple/wirish/ext_interrupts.cpp delete mode 100644 STM32F3/cores/maple/wirish/ext_interrupts.h delete mode 100644 STM32F3/cores/maple/wirish/io.h delete mode 100644 STM32F3/cores/maple/wirish/main.cxx delete mode 100644 STM32F3/cores/maple/wirish/pwm.cpp delete mode 100644 STM32F3/cores/maple/wirish/pwm.h delete mode 100644 STM32F3/cores/maple/wirish/rules.mk delete mode 100644 STM32F3/cores/maple/wirish/stm32f3/boards_setup.cpp delete mode 100644 STM32F3/cores/maple/wirish/stm32f3/f3_wirish_digital.cpp delete mode 100644 STM32F3/cores/maple/wirish/stm32f3/util_hooks.c delete mode 100644 STM32F3/cores/maple/wirish/stm32f3/wirish_debug.cpp delete mode 100644 STM32F3/cores/maple/wirish/syscalls.c delete mode 100644 STM32F3/cores/maple/wirish/usb_serial.cpp delete mode 100644 STM32F3/cores/maple/wirish/usb_serial.h delete mode 100644 STM32F3/cores/maple/wirish/wirish.h delete mode 100644 STM32F3/cores/maple/wirish/wirish_analog.cpp delete mode 100644 STM32F3/cores/maple/wirish/wirish_debug.h delete mode 100644 STM32F3/cores/maple/wirish/wirish_digital.cpp delete mode 100644 STM32F3/cores/maple/wirish/wirish_math.cpp delete mode 100644 STM32F3/cores/maple/wirish/wirish_math.h delete mode 100644 STM32F3/cores/maple/wirish/wirish_shift.cpp delete mode 100644 STM32F3/cores/maple/wirish/wirish_time.cpp delete mode 100644 STM32F3/cores/maple/wirish/wirish_time.h delete mode 100644 STM32F3/cores/maple/wirish/wirish_types.h delete mode 100644 STM32F3/examples/Blinkf3/Blinkf3.ino delete mode 100644 STM32F3/examples/f3_buttondemo/f3_buttondemo.ino delete mode 100644 STM32F3/examples/f3_functionTimer/f3_functionTimer.ino delete mode 100644 STM32F3/examples/f3_gyrodemo/f3_gyrodemo.ino delete mode 100644 STM32F3/examples/f3_lsm303demo/f3_lsm303demo.ino delete mode 100644 STM32F3/examples/f3_ultrasonic/f3_ultrasonic.ino delete mode 100644 STM32F3/libraries/gyro/gyro.cpp delete mode 100644 STM32F3/libraries/gyro/gyro.h delete mode 100644 STM32F3/libraries/gyro/l3gd20.h delete mode 100644 STM32F3/libraries/lsm303/lsm303.cpp delete mode 100644 STM32F3/libraries/lsm303/lsm303.h delete mode 100644 STM32F3/libraries/lsm303/lsm303reg.h delete mode 100644 STM32F3/libraries/ringbuffer/ringbuffer.cpp delete mode 100644 STM32F3/libraries/ringbuffer/ringbuffer.h delete mode 100644 STM32F3/libraries/roboter/debug.cpp delete mode 100644 STM32F3/libraries/roboter/debug.h delete mode 100644 STM32F3/libraries/roboter/eeprom.cpp delete mode 100644 STM32F3/libraries/roboter/eeprom.h delete mode 100644 STM32F3/libraries/roboter/functiontimer.cpp delete mode 100644 STM32F3/libraries/roboter/functiontimer.h delete mode 100644 STM32F3/libraries/roboter/motor.cpp delete mode 100644 STM32F3/libraries/roboter/motor.h delete mode 100644 STM32F3/libraries/roboter/sound.cpp delete mode 100644 STM32F3/libraries/roboter/sound.h delete mode 100644 STM32F3/libraries/roboter/ultraschall.cpp delete mode 100644 STM32F3/libraries/roboter/ultraschall.h delete mode 100644 STM32F3/platform.txt delete mode 100644 STM32F3/variants/discovery_f3/board/board.h delete mode 100644 STM32F3/variants/discovery_f3/discovery_f3.cpp delete mode 100644 STM32F3/variants/discovery_f3/ld/common.inc delete mode 100644 STM32F3/variants/discovery_f3/ld/extra_libs.inc delete mode 100644 STM32F3/variants/discovery_f3/ld/flash.ld delete mode 100644 STM32F3/variants/discovery_f3/ld/jtag.ld delete mode 100644 STM32F3/variants/discovery_f3/ld/mem-flash.inc delete mode 100644 STM32F3/variants/discovery_f3/ld/mem-jtag.inc delete mode 100644 STM32F3/variants/discovery_f3/ld/mem-ram.inc delete mode 100644 STM32F3/variants/discovery_f3/ld/names.inc delete mode 100644 STM32F3/variants/discovery_f3/ld/ram.ld delete mode 100644 STM32F3/variants/discovery_f3/ld/vector_symbols.inc delete mode 100644 STM32F3/variants/discovery_f3/stm32_isrs.S delete mode 100644 STM32F3/variants/discovery_f3/stm32_vector_table.S delete mode 100644 STM32F3/variants/discovery_f3/wirish/start.S delete mode 100644 STM32F3/variants/discovery_f3/wirish/start_c.c diff --git a/STM32F3/README.md b/STM32F3/README.md deleted file mode 100644 index 75cd5a4..0000000 --- a/STM32F3/README.md +++ /dev/null @@ -1,45 +0,0 @@ -STM32F3 files have been supplied by Frank-Michael Krause. - -The API is not as up to date as in the STM F103 files. -It looks like this port is as the F103 files orginally were when I started work on the project. -The API is for pre- Arduino 1.0 and doesn't include a lot of functions in the 1.0 API, and the class inheritance will -be different in a number of places, most importantly in the Serial class. -Specifically Stream.cpp / .h are not present in this port. - - - --------------------- Details from Frank-Michael ---------------------------- - -This port of libmaple for Arduino-IDE is based on the inofficial F3 branch -of libmaple found on -https://github.com/ventosus/libmaple/tree/F3 -and supports at the moment the STM32F3Discovery board with programming via ST-link. -Linker is configured for linking to flash, not to RAM - -Changes by Frank-Michael Krause (mich dot krause at web dot de): - -- renaming some stm32f3 related files because the Arduino build system copy all objects to same directory so the source file names must be different -- selected the correct startup modules and linker scripts for board variant stm32f3discovery - -Notes: - -- the pin names as noted on stm32f3discovery board (PA0, PA1, ..., PF10) can be used as pin id -- usb is untested because I haven't used it really -- There are some libraries and examples related to the STM32F3discovery board. - They are commented mostly in german only because I wrote them for use at robotic club of a secondary school - and the kids like to have the documentation in german. - - gyro: Interface library for the gyro-chip of the stm32f3discovery, setup the gyro in FIFO mode and so - requiring update calls only every < 120ms - lsm303: Interface library for Acceleration sensor of the stm32f3discovery, magnetometer not yet supported (writing this driver is currently under work by a student at school) - ringbuffer: Class impelentig a ringbuffer with functions for adding time stampes per added element, averaging functions, accessing the stored data like an array - roboter: several functionalities needed to program a robot: - - dc motor control as known from Lego NXC language - - support for HC-SR04 ultrasonic sensors driven by interrupt or blocking direct measurement - - function timers based on timer interrupt - - modul for interfacing a 24Cxx I2C eeprom chip - - - - - diff --git a/STM32F3/boards.txt b/STM32F3/boards.txt deleted file mode 100644 index 98a184d..0000000 --- a/STM32F3/boards.txt +++ /dev/null @@ -1,62 +0,0 @@ -# - -menu.opt=Optimize - -############################################################## -discovery_f3.name=STM32F3Discovery - -discovery_f3.upload.tool=stlink -discovery_f3.upload.protocol=stlink - -#discovery_f407.upload.use_1200bps_touch=false -discovery_f3.upload.file_type=bin -discovery_f3.upload.maximum_size=262144 -discovery_f3.upload.maximum_data_size=49152 - -#discovery_f3.upload.usbID=1EAF:0003 -#discovery_f3.upload.altID=1 -#discovery_f3.upload.auto_reset=true - -discovery_f3.build.mcu=cortex-m3 -discovery_f3.build.f_cpu=72000000L -discovery_f3.build.core=maple -discovery_f3.build.extra_flags=-DMCU_STM32F303VC -mthumb -DSTM32_XL_DENSITY -march=armv7-m -DSTM32F3 -DF303VC -DBOARD_discovery_f3 -discovery_f3.build.ldscript=ld/jtag.ld -discovery_f3.build.variant=discovery_f3 -discovery_f3.build.variant_system_lib=lib_f3.a -discovery_f3.build.vect=VECT_TAB_BASE -discovery_f3.build.density=STM32_XL_DENSITY -discovery_f3.build.error_led_port=GPIOE -discovery_f3.build.error_led_pin=8 -discovery_f3.build.board=STM32F3Discovery - -#-- Optimizations -discovery_f3.menu.opt.osstd=Smallest (default) -discovery_f3.menu.opt.osstd.build.flags.optimize=-Os -discovery_f3.menu.opt.osstd.build.flags.ldspecs= -discovery_f3.menu.opt.oslto=Smallest Code with LTO -discovery_f3.menu.opt.oslto.build.flags.optimize=-Os -flto -discovery_f3.menu.opt.oslto.build.flags.ldspecs=-flto -discovery_f3.menu.opt.o1std=Fast (-O1) -discovery_f3.menu.opt.o1std.build.flags.optimize=-O1 -discovery_f3.menu.opt.o1std.build.flags.ldspecs= -discovery_f3.menu.opt.o1lto=Fast (-O1) with LTO -discovery_f3.menu.opt.o1lto.build.flags.optimize=-O1 -flto -discovery_f3.menu.opt.o1lto.build.flags.ldspecs=-flto -discovery_f3.menu.opt.o2std=Faster (-O2) -discovery_f3.menu.opt.o2std.build.flags.optimize=-O2 -discovery_f3.menu.opt.o2std.build.flags.ldspecs= -discovery_f3.menu.opt.o2lto=Faster (-O2) with LTO -discovery_f3.menu.opt.o2lto.build.flags.optimize=-O2 -flto -discovery_f3.menu.opt.o2lto.build.flags.ldspecs=-flto -discovery_f3.menu.opt.o3std=Fastest (-O3) -discovery_f3.menu.opt.o3std.build.flags.optimize=-O3 -discovery_f3.menu.opt.o3std.build.flags.ldspecs= -discovery_f3.menu.opt.o3lto=Fastest (-O3) with LTO -discovery_f3.menu.opt.o3lto.build.flags.optimize=-O3 -flto -discovery_f3.menu.opt.o3lto.build.flags.ldspecs=-flto -discovery_f3.menu.opt.ogstd=Debug (-g) -discovery_f3.menu.opt.ogstd.build.flags.optimize=-Og -discovery_f3.menu.opt.ogstd.build.flags.ldspecs= -############################################################## - diff --git a/STM32F3/cores/maple/Arduino.h b/STM32F3/cores/maple/Arduino.h deleted file mode 100644 index 7278f89..0000000 --- a/STM32F3/cores/maple/Arduino.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef Arduino_h -#define Arduino_h -#include "WProgram.h" -#endif diff --git a/STM32F3/cores/maple/WProgram.h b/STM32F3/cores/maple/WProgram.h deleted file mode 100644 index b24ec2a..0000000 --- a/STM32F3/cores/maple/WProgram.h +++ /dev/null @@ -1,35 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#ifndef _WIRISH_WPROGRAM_H_ -#define _WIRISH_WPROGRAM_H_ - -#include - -void setup(); -void loop(); - -#endif diff --git a/STM32F3/cores/maple/libmaple/adc.c b/STM32F3/cores/maple/libmaple/adc.c deleted file mode 100644 index 630a8a8..0000000 --- a/STM32F3/cores/maple/libmaple/adc.c +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/adc.c - * @author Marti Bolivar , - * Perry Hung , - * F3-port by Hanspeter Portner - * @brief Analog to digital converter routines - */ - -#include -#include -#include - -/** - * @brief Initialize an ADC peripheral. - * - * Initializes the RCC clock line for the given peripheral. Resets - * ADC device registers. - * - * @param dev ADC peripheral to initialize - */ -void adc_init(const adc_dev *dev) { - rcc_clk_enable(dev->clk_id); - rcc_reset_dev(dev->clk_id); -} diff --git a/STM32F3/cores/maple/libmaple/bkp.c b/STM32F3/cores/maple/libmaple/bkp.c deleted file mode 100644 index c48440b..0000000 --- a/STM32F3/cores/maple/libmaple/bkp.c +++ /dev/null @@ -1,69 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/bkp.c - * @author F3-port by Hanspeter Portner - * @brief Backup register support (STM32F1 & STM32F3 only). - */ - -#include -#include -#include - -bkp_dev bkp = { - .regs = BKP_BASE, -}; -/** Backup device. */ -const bkp_dev *BKP = &bkp; - -void bkp_enable_writes(void) { - *bb_perip(&PWR_BASE->CR, PWR_CR_DBP_BIT) = 1; -} - -void bkp_disable_writes(void) { - *bb_perip(&PWR_BASE->CR, PWR_CR_DBP_BIT) = 0; -} - -uint16 bkp_read(uint8 reg) { - __IO uint32* dr = bkp_data_register(reg); - if (!dr) { - ASSERT(0); /* nonexistent register */ - return 0; - } - return (uint16)*dr; -} - -void bkp_write(uint8 reg, uint16 val) { - __IO uint32* dr = bkp_data_register(reg); - if (!dr) { - ASSERT(0); /* nonexistent register */ - return; - } - *dr = (uint32)val; -} - diff --git a/STM32F3/cores/maple/libmaple/dac.c b/STM32F3/cores/maple/libmaple/dac.c deleted file mode 100644 index d802d2b..0000000 --- a/STM32F3/cores/maple/libmaple/dac.c +++ /dev/null @@ -1,120 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Bryan Newbold. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/dac.c - * @brief Digital to analog converter support. - */ - -#include -#include -#include - -#if STM32_HAVE_DAC -dac_dev dac = { - .regs = DAC_BASE, -}; -const dac_dev *DAC = &dac; -#endif - -/** - * @brief Initialize the digital to analog converter - * @param dev DAC device - * @param flags Flags: - * DAC_CH1: Enable channel 1 - * DAC_CH2: Enable channel 2 - * @sideeffect May set PA4 or PA5 to INPUT_ANALOG - */ -void dac_init(const dac_dev *dev, uint32 flags) { - /* First turn on the clock */ - rcc_clk_enable(RCC_DAC); - rcc_reset_dev(RCC_DAC); - - if (flags & DAC_CH1) { - dac_enable_channel(dev, 1); - } - - if (flags & DAC_CH2) { - dac_enable_channel(dev, 2); - } -} - -/** - * @brief Write a 12-bit value to the DAC to output - * @param dev DAC device - * @param channel channel to select (1 or 2) - * @param val value to write - */ -void dac_write_channel(const dac_dev *dev, uint8 channel, uint16 val) { - switch(channel) { - case 1: - dev->regs->DHR12R1 = DAC_DHR12R1_DACC1DHR & val; - break; - case 2: - dev->regs->DHR12R2 = DAC_DHR12R2_DACC2DHR & val; - break; - } -} - -/** - * @brief Enable a DAC channel - * @param dev DAC device - * @param channel channel to enable, either 1 or 2 - * @sideeffect May change pin mode of PA4 or PA5 - */ -void dac_enable_channel(const dac_dev *dev, uint8 channel) { - /* - * Setup ANALOG mode on PA4 and PA5. This mapping is consistent - * across all supported STM32s with a DAC. - */ - switch (channel) { - case 1: - gpio_set_mode(GPIOA, 4, GPIO_MODE_ANALOG); - dev->regs->CR |= DAC_CR_EN1; - break; - case 2: - gpio_set_mode(GPIOA, 5, GPIO_MODE_ANALOG); - dev->regs->CR |= DAC_CR_EN2; - break; - } -} - -/** - * @brief Disable a DAC channel - * @param dev DAC device - * @param channel channel to disable, either 1 or 2 - */ -void dac_disable_channel(const dac_dev *dev, uint8 channel) { - switch (channel) { - case 1: - dev->regs->CR &= ~DAC_CR_EN1; - break; - case 2: - dev->regs->CR &= ~DAC_CR_EN2; - break; - } -} diff --git a/STM32F3/cores/maple/libmaple/dma.c b/STM32F3/cores/maple/libmaple/dma.c deleted file mode 100644 index 1dc875e..0000000 --- a/STM32F3/cores/maple/libmaple/dma.c +++ /dev/null @@ -1,82 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Michael Hope. - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/dma.c - * @author Marti Bolivar ; - * Original implementation by Michael Hope - * @brief Portable DMA routines. - */ - -#include -#include "dma_private.h" -#include "stm32_private.h" - -/* - * Convenience routines - */ - -/** - * @brief Initialize a DMA device. - * @param dev Device to initialize. - */ -void dma_init(dma_dev *dev) { - rcc_clk_enable(dev->clk_id); -} - -/* - * Private API - */ - -enum dma_atype _dma_addr_type(__IO void *addr) { - switch (stm32_block_purpose((void*)addr)) { - /* Notice we're treating the code block as memory here. That's - * correct for addresses in Flash and in [0x0, 0x7FFFFFF] - * (provided that those addresses are aliased to Flash, SRAM, or - * FSMC, depending on BOOT[01] and possibly SYSCFG_MEMRMP). It's - * not correct for other addresses in the code block, but those - * will (hopefully) just fail-fast with transfer or bus errors. If - * lots of people get confused, it might be worth being more - * careful here. */ - case STM32_BLOCK_CODE: /* Fall through */ - case STM32_BLOCK_SRAM: /* ... */ - case STM32_BLOCK_FSMC_1_2: /* ... */ - case STM32_BLOCK_FSMC_3_4: - return DMA_ATYPE_MEM; - case STM32_BLOCK_PERIPH: - return DMA_ATYPE_PER; - case STM32_BLOCK_FSMC_REG: /* Fall through */ - /* Is this right? I can't think of a reason to DMA into or out - * of the FSMC registers. [mbolivar] */ - case STM32_BLOCK_UNUSED: /* ... */ - case STM32_BLOCK_CORTEX_INTERNAL: /* ... */ - return DMA_ATYPE_OTHER; - default: - ASSERT(0); /* Can't happen */ - return DMA_ATYPE_OTHER; - } -} diff --git a/STM32F3/cores/maple/libmaple/dma_private.h b/STM32F3/cores/maple/libmaple/dma_private.h deleted file mode 100644 index 9338525..0000000 --- a/STM32F3/cores/maple/libmaple/dma_private.h +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -#ifndef _LIBMAPLE_DMA_PRIVATE_H_ -#define _LIBMAPLE_DMA_PRIVATE_H_ - -#include -#include - -/* - * IRQ handling - */ - -/* Wrap this in an ifdef to shut up GCC. (We provide DMA_GET_HANDLER - * in the series support files, which need dma_irq_handler().) */ -#ifdef DMA_GET_HANDLER -static __always_inline void dma_irq_handler(dma_dev *dev, dma_tube tube) { - void (*handler)(void) = DMA_GET_HANDLER(dev, tube); - if (handler) { - handler(); - dma_clear_isr_bits(dev, tube); /* in case handler doesn't */ - } -} -#endif - -/* - * Conveniences for dealing with tube sources/destinations - */ - -enum dma_atype { - DMA_ATYPE_MEM, - DMA_ATYPE_PER, - DMA_ATYPE_OTHER, -}; - -enum dma_atype _dma_addr_type(__IO void *addr); - -#endif diff --git a/STM32F3/cores/maple/libmaple/exc.S b/STM32F3/cores/maple/libmaple/exc.S deleted file mode 100644 index 7631e48..0000000 --- a/STM32F3/cores/maple/libmaple/exc.S +++ /dev/null @@ -1,101 +0,0 @@ -/* ***************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * ****************************************************************************/ - -# On an exception, push a fake stack thread mode stack frame and redirect -# thread execution to a thread mode error handler - -# From RM008: -# The SP is decremented by eight words by the completion of the stack push. -# Figure 5-1 shows the contents of the stack after an exception pre-empts the -# current program flow. -# -# Old SP--> -# xPSR -# PC -# LR -# r12 -# r3 -# r2 -# r1 -# SP--> r0 - -.text -.globl __exc_hardfault -.globl __exc_nmi -.globl __exc_hardfault -.globl __exc_memmanage -.globl __exc_busfault -.globl __exc_usagefault - -.code 16 -.thumb_func -__exc_nmi: - mov r0, #1 - b __default_exc - -.thumb_func -__exc_hardfault: - mov r0, #2 - b __default_exc - -.thumb_func -__exc_memmanage: - mov r0, #3 - b __default_exc - -.thumb_func -__exc_busfault: - mov r0, #4 - b __default_exc - -.thumb_func -__exc_usagefault: - mov r0, #5 - b __default_exc - -.thumb_func -__default_exc: - ldr r2, NVIC_CCR @ Enable returning to thread mode even if there are - mov r1 ,#1 @ pending exceptions. See flag NONEBASETHRDENA. - str r1, [r2] - cpsid i @ Disable global interrupts - ldr r2, SYSTICK_CSR @ Disable systick handler - mov r1, #0 - str r1, [r2] - ldr r1, CPSR_MASK @ Set default CPSR - push {r1} - ldr r1, TARGET_PC @ Set target pc - push {r1} - sub sp, sp, #24 @ Don't care - ldr r1, EXC_RETURN @ Return to thread mode - mov lr, r1 - bx lr @ Exception exit - -.align 4 -CPSR_MASK: .word 0x61000000 -EXC_RETURN: .word 0xFFFFFFF9 -TARGET_PC: .word __error -NVIC_CCR: .word 0xE000ED14 @ NVIC configuration control register -SYSTICK_CSR: .word 0xE000E010 @ Systick control register - diff --git a/STM32F3/cores/maple/libmaple/exti.c b/STM32F3/cores/maple/libmaple/exti.c deleted file mode 100644 index f59c0eb..0000000 --- a/STM32F3/cores/maple/libmaple/exti.c +++ /dev/null @@ -1,293 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/exti.c - * @brief External interrupt control routines - */ - -#include -#include -#include -#include - -static inline void dispatch_single_exti(uint32 exti_num); -static inline void dispatch_extis(uint32 start, uint32 stop); - -/* - * Internal state - */ - -typedef struct exti_channel { - void (*handler)(void *); - void *arg; -} exti_channel; - -static exti_channel exti_channels[] = { - { .handler = NULL, .arg = NULL }, // EXTI0 - { .handler = NULL, .arg = NULL }, // EXTI1 - { .handler = NULL, .arg = NULL }, // EXTI2 - { .handler = NULL, .arg = NULL }, // EXTI3 - { .handler = NULL, .arg = NULL }, // EXTI4 - { .handler = NULL, .arg = NULL }, // EXTI5 - { .handler = NULL, .arg = NULL }, // EXTI6 - { .handler = NULL, .arg = NULL }, // EXTI7 - { .handler = NULL, .arg = NULL }, // EXTI8 - { .handler = NULL, .arg = NULL }, // EXTI9 - { .handler = NULL, .arg = NULL }, // EXTI10 - { .handler = NULL, .arg = NULL }, // EXTI11 - { .handler = NULL, .arg = NULL }, // EXTI12 - { .handler = NULL, .arg = NULL }, // EXTI13 - { .handler = NULL, .arg = NULL }, // EXTI14 - { .handler = NULL, .arg = NULL }, // EXTI15 -}; - -/* - * Portable routines - */ - -/** - * @brief Register a handler to run upon external interrupt. - * - * This function assumes that the interrupt request corresponding to - * the given external interrupt is masked. - * - * @param num External interrupt line number. - * @param port Port to use as source input for external interrupt. - * @param handler Function handler to execute when interrupt is triggered. - * @param mode Type of transition to trigger on, one of: - * EXTI_RISING, EXTI_FALLING, EXTI_RISING_FALLING. - * @see exti_num - * @see exti_cfg - * @see voidFuncPtr - * @see exti_trigger_mode - */ -void exti_attach_interrupt(exti_num num, - exti_cfg port, - voidFuncPtr handler, - exti_trigger_mode mode) { - // Call callback version with arg being null - exti_attach_callback(num, port, (voidArgumentFuncPtr)handler, NULL, mode); -} - -/** - * @brief Register a handler with an argument to run upon external interrupt. - * - * This function assumes that the interrupt request corresponding to - * the given external interrupt is masked. - * - * @param num External interrupt line number. - * @param port Port to use as source input for external interrupt. - * @param handler Function handler to execute when interrupt is triggered. - * @param arg Argument to pass to the interrupt handler. - * @param mode Type of transition to trigger on, one of: - * EXTI_RISING, EXTI_FALLING, EXTI_RISING_FALLING. - * @see exti_num - * @see exti_cfg - * @see voidFuncPtr - * @see exti_trigger_mode - */ -void exti_attach_callback(exti_num num, - exti_cfg port, - voidArgumentFuncPtr handler, - void *arg, - exti_trigger_mode mode) { - ASSERT(handler); - - /* Register the handler */ - exti_channels[num].handler = handler; - exti_channels[num].arg = arg; - - /* Set trigger mode */ - switch (mode) { - case EXTI_RISING: - bb_peri_set_bit(&EXTI_BASE->RTSR, num, 1); - break; - case EXTI_FALLING: - bb_peri_set_bit(&EXTI_BASE->FTSR, num, 1); - break; - case EXTI_RISING_FALLING: - bb_peri_set_bit(&EXTI_BASE->RTSR, num, 1); - bb_peri_set_bit(&EXTI_BASE->FTSR, num, 1); - break; - } - - /* Use the chip-specific exti_select() to map num to port */ - exti_select(num, port); - - /* Unmask external interrupt request */ - bb_peri_set_bit(&EXTI_BASE->IMR, num, 1); - - /* Enable the interrupt line */ - switch(num) - { - case EXTI0: - nvic_irq_enable(NVIC_EXTI0); - break; - case EXTI1: - nvic_irq_enable(NVIC_EXTI1); - break; - case EXTI2: - nvic_irq_enable(NVIC_EXTI2); - break; - case EXTI3: - nvic_irq_enable(NVIC_EXTI3); - break; - case EXTI4: - nvic_irq_enable(NVIC_EXTI4); - break; - case EXTI5: - case EXTI6: - case EXTI7: - case EXTI8: - case EXTI9: - nvic_irq_enable(NVIC_EXTI_9_5); - break; - case EXTI10: - case EXTI11: - case EXTI12: - case EXTI13: - case EXTI14: - case EXTI15: - nvic_irq_enable(NVIC_EXTI_15_10); - break; - } -} - -/** - * @brief Unregister an external interrupt handler - * @param num External interrupt line to disable. - * @see exti_num - */ -void exti_detach_interrupt(exti_num num) { - /* First, mask the interrupt request */ - bb_peri_set_bit(&EXTI_BASE->IMR, num, 0); - - /* Then, clear the trigger selection registers */ - bb_peri_set_bit(&EXTI_BASE->FTSR, num, 0); - bb_peri_set_bit(&EXTI_BASE->RTSR, num, 0); - - /* Finally, unregister the user's handler */ - exti_channels[num].handler = NULL; - exti_channels[num].arg = NULL; -} - -/* - * Private routines - */ - -void exti_do_select(__IO uint32 *exti_cr, exti_num num, exti_cfg port) { - uint32 shift = 4 * (num % 4); - uint32 cr = *exti_cr; - cr &= ~(0xF << shift); - cr |= port << shift; - *exti_cr = cr; -} - -/* - * Interrupt handlers - */ - -void __irq_exti0(void) { - dispatch_single_exti(EXTI0); -} - -void __irq_exti1(void) { - dispatch_single_exti(EXTI1); -} - -void __irq_exti2(void) { - dispatch_single_exti(EXTI2); - // FIXME handle capatitive touch IRQ on F302/303 -} - -void __irq_exti3(void) { - dispatch_single_exti(EXTI3); -} - -void __irq_exti4(void) { - dispatch_single_exti(EXTI4); -} - -void __irq_exti9_5(void) { - dispatch_extis(5, 9); -} - -void __irq_exti15_10(void) { - dispatch_extis(10, 15); -} - -/* - * Auxiliary functions - */ - -/* Clear the pending bits for EXTIs whose bits are set in exti_msk. - * - * If a pending bit is cleared as the last instruction in an ISR, it - * won't actually be cleared in time and the ISR will fire again. To - * compensate, this function NOPs for 2 cycles after clearing the - * pending bits to ensure it takes effect. */ -static __always_inline void clear_pending_msk(uint32 exti_msk) { - EXTI_BASE->PR = exti_msk; - asm volatile("nop"); - asm volatile("nop"); -} - -/* This dispatch routine is for non-multiplexed EXTI lines only; i.e., - * it doesn't check EXTI_PR. */ -static __always_inline void dispatch_single_exti(uint32 exti) { - voidArgumentFuncPtr handler = exti_channels[exti].handler; - - if (!handler) { - return; - } - - handler(exti_channels[exti].arg); - clear_pending_msk(1U << exti); -} - -/* Dispatch routine for EXTIs which share an IRQ. */ -static __always_inline void dispatch_extis(uint32 start, uint32 stop) { - uint32 pr = EXTI_BASE->PR; - uint32 handled_msk = 0; - uint32 exti; - - /* Dispatch user handlers for pending EXTIs. */ - for (exti = start; exti <= stop; exti++) { - uint32 eb = (1U << exti); - if (pr & eb) { - voidArgumentFuncPtr handler = exti_channels[exti].handler; - if (handler) { - handler(exti_channels[exti].arg); - handled_msk |= eb; - } - } - } - - /* Clear the pending bits for handled EXTIs. */ - clear_pending_msk(handled_msk); -} diff --git a/STM32F3/cores/maple/libmaple/exti_private.h b/STM32F3/cores/maple/libmaple/exti_private.h deleted file mode 100644 index 221cae4..0000000 --- a/STM32F3/cores/maple/libmaple/exti_private.h +++ /dev/null @@ -1,34 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -#ifndef _LIBMAPLE_EXTI_PRIVATE_H_ -#define _LIBMAPLE_EXTI_PRIVATE_H_ - -#include - -void exti_do_select(__IO uint32 *exti_cr, exti_num num, exti_cfg port); - -#endif diff --git a/STM32F3/cores/maple/libmaple/flash.c b/STM32F3/cores/maple/libmaple/flash.c deleted file mode 100644 index c57bbbf..0000000 --- a/STM32F3/cores/maple/libmaple/flash.c +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/flash.c - * @brief Flash management functions - */ - -#include -#include - -/** - * @brief Set flash wait states - * - * Note that not all wait states are available on every MCU. See the - * Flash programming manual for your MCU for restrictions on the - * allowed value of wait_states for a given system clock (SYSCLK) - * frequency. - * - * @param wait_states number of wait states (one of - * FLASH_WAIT_STATE_0, FLASH_WAIT_STATE_1, - * ..., FLASH_WAIT_STATE_7). - */ -void flash_set_latency(uint32 wait_states) { - uint32 val = FLASH_BASE->ACR; - - val &= ~FLASH_ACR_LATENCY; - val |= wait_states; - - FLASH_BASE->ACR = val; -} diff --git a/STM32F3/cores/maple/libmaple/gpio.c b/STM32F3/cores/maple/libmaple/gpio.c deleted file mode 100644 index 6e63d2f..0000000 --- a/STM32F3/cores/maple/libmaple/gpio.c +++ /dev/null @@ -1,50 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/gpio.c - * @brief Generic STM32 GPIO support. - */ - -#include -#include - -/* - * GPIO routines - */ - -/** - * Initialize a GPIO device. - * - * Enables the clock for and resets the given device. - * - * @param dev GPIO device to initialize. - */ -void gpio_init(gpio_dev *dev) { - rcc_clk_enable(dev->clk_id); - rcc_reset_dev(dev->clk_id); -} diff --git a/STM32F3/cores/maple/libmaple/i2c.c b/STM32F3/cores/maple/libmaple/i2c.c deleted file mode 100644 index 87b96d1..0000000 --- a/STM32F3/cores/maple/libmaple/i2c.c +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/i2c.c - * @author Perry Hung , - * F3-port by Hanspeter Portner - * @brief Inter-Integrated Circuit (I2C) support. - * - * Currently, only master mode is supported. - */ - -#include "i2c_private.h" - -#include -#include -#include -#include -#include -#include - -#include - -void i2c_init(i2c_dev *dev) { - rcc_reset_dev(dev->clk_id); - rcc_clk_enable(dev->clk_id); -} diff --git a/STM32F3/cores/maple/libmaple/i2c_private.h b/STM32F3/cores/maple/libmaple/i2c_private.h deleted file mode 100644 index 4857955..0000000 --- a/STM32F3/cores/maple/libmaple/i2c_private.h +++ /dev/null @@ -1,75 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#ifndef _LIBMAPLE_I2C_PRIVATE_H_ -#define _LIBMAPLE_I2C_PRIVATE_H_ - -#include - -/* For old-style definitions (SDA/SCL on same GPIO device) */ -#define I2C_DEV_OLD(num, port, sda, scl) \ - { \ - .regs = I2C##num##_BASE, \ - .gpio_port = port, \ - .scl_port = NULL, \ - .sda_port = NULL, \ - .sda_pin = sda, \ - .scl_pin = scl, \ - .clk_id = RCC_I2C##num, \ - .ev_nvic_line = NVIC_I2C##num##_EV, \ - .er_nvic_line = NVIC_I2C##num##_ER, \ - .state = I2C_STATE_DISABLED, \ - } - -/* For new-style definitions (SDA/SCL may be on different GPIO devices) */ -#define I2C_DEV_NEW(num, sdaport, sdabit, sclport, sclbit) \ - { \ - .regs = I2C##num##_BASE, \ - .gpio_port = NULL, \ - .scl_port = sclport, \ - .scl_pin = sclbit, \ - .sda_port = sdaport, \ - .sda_pin = sdabit, \ - .clk_id = RCC_I2C##num, \ - .ev_nvic_line = NVIC_I2C##num##_EV, \ - .er_nvic_line = NVIC_I2C##num##_ER, \ - .state = I2C_STATE_DISABLED, \ - } - -void _i2c_irq_handler(i2c_dev *dev); -void _i2c_irq_error_handler(i2c_dev *dev); - -struct gpio_dev; - -static inline struct gpio_dev* scl_port(const i2c_dev *dev) { - return (dev->gpio_port == NULL) ? dev->scl_port : dev->gpio_port; -} - -static inline struct gpio_dev* sda_port(const i2c_dev *dev) { - return (dev->gpio_port == NULL) ? dev->sda_port : dev->gpio_port; -} - -#endif /* _LIBMAPLE_I2C_PRIVATE_H_ */ diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/adc.h b/STM32F3/cores/maple/libmaple/include/libmaple/adc.h deleted file mode 100644 index e2d711d..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/adc.h +++ /dev/null @@ -1,319 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/adc.h - * @author Marti Bolivar , - * Perry Hung , - * F3-port by Hanspeter Portner - * @brief Analog-to-Digital Conversion (ADC) header. - */ - -#ifndef _LIBMAPLE_ADC_H_ -#define _LIBMAPLE_ADC_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include -#include - -/** - * TODO document - */ -typedef struct adc_callback_data { - uint32 irq_flags; - void *arg; -} adc_callback_data; - -/** - * TODO document - */ -typedef struct adc_private_data { - void (*handler)(adc_callback_data*); - uint32 handler_flags; - adc_callback_data cb_data; -} adc_private_data; - -/* Pull in the series header - * - * IMPORTANT: The series header must define the following: - * - * - enum adc_extsel_event (and typedef to adc_extsel_event): One per - * external event used to trigger start of conversion of a regular - * group. If two different series support the same event as a - * trigger, they must use the same token for the enumerator for that - * event. (The value of the enumerator is of course allowed to be - * different). - * - * - enum adc_smp_rate (and typedef to adc_smp_rate): One per - * available sampling time. These must be in the form ADC_SMPR_X_Y - * for X.Y cycles (e.g. ADC_SMPR_1_5 means 1.5 cycles), or - * ADC_SMPR_X for X cycles (e.g. ADC_SMPR_3 means 3 cycles). - * - * - enum adc_prescaler (and typedef): One per available prescaler, - * suitable for adc_set_prescaler. Series which have the same - * prescaler dividers (e.g. STM32F1 and STM32F2 both divide PCLK2 by - * 2, 4, 6, or 8) must provide the same tokens as enumerators, for - * portability. - */ - -#include - -/* - * Routines - */ - -extern void adc_init(const adc_dev *dev); - -/** - * @brief Set external event select for regular group - * @param dev ADC device - * @param event Event used to trigger the start of conversion. - * @see adc_extsel_event - */ -extern void adc_set_extsel(const adc_dev *dev, adc_extsel_event event); - -/** - * @brief Set the sample rate for all channels on an ADC device. - * - * Don't call this during conversion. - * - * @param dev adc device - * @param smp_rate sample rate to set - * @see adc_smp_rate - */ -extern void adc_set_sample_rate(const adc_dev *dev, adc_smp_rate smp_rate); - -/** - * @brief Enable scan mode for an ADC. - * - * In scan mode, the ADC converts all channels in a regular or - * injected sequence. After each conversion is done, the ADC - * automatically starts converting the next channel in the sequence. - * - * Scan mode is disabled by default. - * - * @see adc_disable_scan() - */ -extern void adc_enable_scan(const adc_dev *dev); - -/** - * @brief Disable scan mode for an ADC. - * - * This is the default setting. - * - * @see adc_enable_scan() - */ -extern void adc_disable_scan(const adc_dev *dev); - -/** - * @brief Enable continuous mode for an ADC. - * - * In this mode, the ADC will automatically perform conversions - * continuously until taken out of this mode or disabled. - * - * Continuous mode is disabled by default. - * - * @see adc_disable_continuous() - */ -extern void adc_enable_continuous(const adc_dev *dev); - -/** - * @brief Disable continuous mode for an ADC. - * - * This is the default setting. - * - * @see adc_enable_continuous() - */ -extern void adc_disable_continuous(const adc_dev *dev); - -/** - * @brief Set the sequence of channels to convert. - * - * This sets the (regular) sequence of up to 16 channels to convert. - * - * @param dev ADC device - * @param channels ADC channels to convert; these can repeat and may - * be in any order. - * @param len Length of `channels', from 1 to 16. - * @see adc_start_conv() - */ -extern void adc_set_conv_seq(const adc_dev *dev, const uint8 *channels, uint8 len); - -/** - * @brief Attach an interrupt handler and enable its interrupts. - * - * This function sets `handler' as the function to be called when any - * ADC interrupts for `dev' occur. At most one ADC interrupt handler - * may be attached at any time. Subsequent calls to this function will - * overwrite any previously attached handler. - * - * When `handler' is called, its argument will point to a struct - * adc_callback_data. The .irq_flags field in this struct will be a - * logical OR of adc_interrupt_id values encoding the reason(s) for - * the call. Its .arg field will be the `arg' argument to this - * function. - * - * The interrupt bits set in the adc_callback_data's .irq_flags will - * always be a subset of those set in the `interrupt_flags' argument - * to this function. That is, interrupts not given here in the - * `interrupt_flags' argument will never cause `handler' to be - * called. This has the effect that any enabled ADC interrupts not - * specified in `interrupt_flags' will be ignored. - * - * This function additionally enables the ADC interrupts specified by - * `interrupt_flags'. - * - * @param dev ADC device whose interrupts to attach to. - * @param interrupt_flags Logical or of adc_interrupt_id values - * specifying interrupts to enable. - * @param handler Interrupt handler to call when any interrupt in - * interrupt_flags occurs. - * @param arg Value to store in .arg field of handler's callback data. - * @see enum adc_interrupt_id - * @see struct adc_callback_data - */ -extern void adc_attach_interrupt(const adc_dev *dev, uint32 interrupt_flags, - void (*handler)(adc_callback_data*), void *arg); - -/** - * @brief Disable ADC interrupts and detach interrupt handlers. - * - * This function disables all interrupts for `dev', and unsets any - * handler attached with adc_attach_interrupt(). - * - * @param dev ADC device whose handler to detach. - */ -extern void adc_detach_interrupt(const adc_dev *dev); - -/** - * @brief Enable ADC interrupts - * @param dev ADC device - * @param interrupt_flags Logical or of adc_interrupt_id values to enable. - * @see adc_disable_interrupt() - * @see adc_attach_interrupt() - */ -extern void adc_enable_interrupts(const adc_dev *dev, uint32 interrupt_flags); - -/** - * @brief Disable ADC interrupts. - * @param dev ADC device - * @param interrupt_flags Logical or of adc_interrupt_id values to disable. - * @brief adc_enable_interrupt() - */ -extern void adc_disable_interrupts(const adc_dev *dev, uint32 interrupt_flags); - -/** - * @brief Perform a single synchronous software triggered conversion on a - * channel. - * @param dev ADC device to use for reading. - * @param channel channel to convert - * @return conversion result - */ -extern uint16 adc_read(const adc_dev *dev, uint8 channel); - -/** - * @brief Set the ADC prescaler. - * - * This determines the ADC clock for all devices. - */ -extern void adc_set_prescaler(adc_prescaler pre); - -/** - * @brief Call a function on all ADC devices. - * @param fn Function to call on each ADC device. - */ -extern void adc_foreach(void (*fn)(const adc_dev*)); - -struct gpio_dev; -/** - * @brief Configure a GPIO pin for ADC conversion. - * @param dev ADC device to use for conversion (currently ignored on - * all targets). - * @param gdev GPIO device to configure. - * @param bit Bit on gdev to configure for ADC conversion. - */ -extern void adc_config_gpio(const struct adc_dev *dev, - struct gpio_dev *gdev, - uint8 bit); - -/** - * @brief Enable an ADC and configure it for single conversion mode. - * - * This function performs any initialization necessary to allow the - * ADC device to perform a single synchronous regular software - * triggered conversion, using adc_read(). - * - * @param dev Device to enable. - * @see adc_read() - */ -extern void adc_enable_single_swstart(const adc_dev* dev); - -/** - * @brief Set the regular channel sequence length. - * - * Defines the total number of conversions in the regular channel - * conversion sequence. - * - * @param dev ADC device. - * @param length Regular channel sequence length, from 1 to 16. - */ -extern void adc_set_reg_seqlen(const adc_dev *dev, uint8 length); - -/** - * @brief Enable an adc peripheral - * @param dev ADC device to enable - */ -extern void adc_enable(const adc_dev *dev); - -/** - * @brief Disable an ADC peripheral - * @param dev ADC device to disable - */ -extern void adc_disable(const adc_dev *dev); - -/** - * @brief Disable all ADC peripherals. - */ -static inline void adc_disable_all(void) { - adc_foreach(adc_disable); -} - -/* - * private - */ -extern void _adc_enable_dev_irq(const adc_dev *dev); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/bitband.h b/STM32F3/cores/maple/libmaple/include/libmaple/bitband.h deleted file mode 100644 index 6e77991..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/bitband.h +++ /dev/null @@ -1,128 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/bitband.h - * - * @brief Bit-banding utility functions - */ - -#ifndef _LIBMAPLE_BITBAND_H_ -#define _LIBMAPLE_BITBAND_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define BB_SRAM_REF 0x20000000 -#define BB_SRAM_BASE 0x22000000 -#define BB_PERI_REF 0x40000000 -#define BB_PERI_BASE 0x42000000 - -static inline volatile uint32* __bb_addr(volatile void*, - uint32, - uint32, - uint32); - -/** - * @brief Obtain a pointer to the bit-band address corresponding to a - * bit in a volatile SRAM address. - * @param address Address in the bit-banded SRAM region - * @param bit Bit in address to bit-band - */ -static inline volatile uint32* bb_sramp(volatile void *address, uint32 bit) { - return __bb_addr(address, bit, BB_SRAM_BASE, BB_SRAM_REF); -} - -/** - * @brief Get a bit from an address in the SRAM bit-band region. - * @param address Address in the SRAM bit-band region to read from - * @param bit Bit in address to read - * @return bit's value in address. - */ -static inline uint8 bb_sram_get_bit(volatile void *address, uint32 bit) { - return *bb_sramp(address, bit); -} - -/** - * @brief Set a bit in an address in the SRAM bit-band region. - * @param address Address in the SRAM bit-band region to write to - * @param bit Bit in address to write to - * @param val Value to write for bit, either 0 or 1. - */ -static inline void bb_sram_set_bit(volatile void *address, - uint32 bit, - uint8 val) { - *bb_sramp(address, bit) = val; -} - -/** - * @brief Obtain a pointer to the bit-band address corresponding to a - * bit in a peripheral address. - * @param address Address in the bit-banded peripheral region - * @param bit Bit in address to bit-band - */ -static inline volatile uint32* bb_perip(volatile void *address, uint32 bit) { - return __bb_addr(address, bit, BB_PERI_BASE, BB_PERI_REF); -} - -/** - * @brief Get a bit from an address in the peripheral bit-band region. - * @param address Address in the peripheral bit-band region to read from - * @param bit Bit in address to read - * @return bit's value in address. - */ -static inline uint8 bb_peri_get_bit(volatile void *address, uint32 bit) { - return *bb_perip(address, bit); -} - -/** - * @brief Set a bit in an address in the peripheral bit-band region. - * @param address Address in the peripheral bit-band region to write to - * @param bit Bit in address to write to - * @param val Value to write for bit, either 0 or 1. - */ -static inline void bb_peri_set_bit(volatile void *address, - uint32 bit, - uint8 val) { - *bb_perip(address, bit) = val; -} - -static inline volatile uint32* __bb_addr(volatile void *address, - uint32 bit, - uint32 bb_base, - uint32 bb_ref) { - return (volatile uint32*)(bb_base + ((uint32)address - bb_ref) * 32 + - bit * 4); -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/bkp.h b/STM32F3/cores/maple/libmaple/include/libmaple/bkp.h deleted file mode 100644 index 9b00470..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/bkp.h +++ /dev/null @@ -1,100 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/bkp.h - * @author F3-port by Hanspeter Portner - * @brief Backup register support (STM32F1 & STM32F3 only). - */ - -#ifndef _LIBMAPLE_BKP_H_ -#define _LIBMAPLE_BKP_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -/** Backup peripheral device type. */ -typedef struct bkp_dev { - bkp_reg_map *regs; /**< Register map */ -} bkp_dev; - -extern const struct bkp_dev *BKP; - -/* - * this function needs to be implemented for each series separately - */ -extern inline __IO uint32* bkp_data_register(uint8 reg); - -/** - * @brief Initialize backup interface. - * - * Enables the power and backup interface clocks, and resets the - * backup device. - */ -void bkp_init(void); - -/** - * Enable write access to the backup registers. Backup interface must - * be initialized for subsequent register writes to work. - * @see bkp_init() - */ -void bkp_enable_writes(void); - -/** - * Disable write access to the backup registers. - */ -void bkp_disable_writes(void); - -/** - * Read a value from given backup data register. - * @param reg Data register to read, from 1 to BKP_NR_DATA_REGS (10 on - * medium-density devices, 42 on high-density devices). - */ -uint16 bkp_read(uint8 reg); - -/** - * @brief Write a value to given data register. - * - * Write access to backup registers must be enabled. - * - * @param reg Data register to write, from 1 to BKP_NR_DATA_REGS (10 - * on medium-density devices, 42 on high-density devices). - * @param val Value to write into the register. - * @see bkp_enable_writes() - */ -void bkp_write(uint8 reg, uint16 val); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/comp.h b/STM32F3/cores/maple/libmaple/include/libmaple/comp.h deleted file mode 100644 index 508ba63..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/comp.h +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -/** - * @file libmaple/include/libmaple/fpu.h - * @author F3-port by Hanspeter Portner - * @brief Floating Point Unit (COMP) interace. - */ - -#ifndef _LIBMAPLE_COMP_H_ -#define _LIBMAPLE_COMP_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/dac.h b/STM32F3/cores/maple/libmaple/include/libmaple/dac.h deleted file mode 100644 index 56bfdc4..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/dac.h +++ /dev/null @@ -1,158 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * Copyright (c) 2010 Bryan Newbold. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/dac.h - * @brief Digital to analog converter support. - */ - -/* See notes/dac.txt for more info */ - -#ifndef _LIBMAPLE_DAC_H_ -#define _LIBMAPLE_DAC_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include -#include -#include - -/* - * Register map base and device pointers. - * - * The DACs are the same on all supported targets, so it's not worth - * repeating these in the series headers. - */ - -#define DAC_BASE ((struct dac_reg_map*)0x40007400) - -/** DAC device type. */ -typedef struct dac_dev { - dac_reg_map *regs; /**< Register map */ -} dac_dev; - -#if STM32_HAVE_DAC -extern const dac_dev *DAC; -#endif - -/* - * Register bit definitions - */ - -/* Control register */ - -/* Channel 1 control */ -#define DAC_CR_EN1 (1U << 0) /* Enable */ -#define DAC_CR_BOFF1 (1U << 1) /* Output buffer disable */ -#define DAC_CR_TEN1 (1U << 2) /* Trigger enable */ -#define DAC_CR_TSEL1 (0x7 << 3) /* Trigger selection */ -#define DAC_CR_WAVE1 (0x3 << 6) /* Noise/triangle wave */ -#define DAC_CR_MAMP1 (0xF << 8) /* Mask/amplitude selector */ -#define DAC_CR_DMAEN1 (1U << 12) /* DMA enable */ -/* Channel 2 control */ -#define DAC_CR_EN2 (1U << 16) /* Enable */ -#define DAC_CR_BOFF2 (1U << 17) /* Output buffer disable */ -#define DAC_CR_TEN2 (1U << 18) /* Trigger enable */ -#define DAC_CR_TSEL2 (0x7 << 19) /* Trigger selection */ -#define DAC_CR_WAVE2 (0x3 << 22) /* Noise/triangle wave */ -#define DAC_CR_MAMP2 (0xF << 24) /* Mask/amplitude selector */ -#define DAC_CR_DMAEN2 (1U << 28) /* DMA enable */ - -/* Software trigger register */ - -#define DAC_SWTRIGR_SWTRIG1 (1U << 0) /* Channel 1 software trigger */ -#define DAC_SWTRIGR_SWTRIG2 (1U << 1) /* Channel 2 software trigger */ - -/* Channel 1 12-bit right-aligned data holding register */ - -#define DAC_DHR12R1_DACC1DHR 0x00000FFF - -/* Channel 1 12-bit left-aligned data holding register */ - -#define DAC_DHR12L1_DACC1DHR 0x0000FFF0 - -/* Channel 1 8-bit left-aligned data holding register */ - -#define DAC_DHR8R1_DACC1DHR 0x000000FF - -/* Channel 2 12-bit right-aligned data holding register */ - -#define DAC_DHR12R2_DACC2DHR 0x00000FFF - -/* Channel 2 12-bit left-aligned data holding register */ - -#define DAC_DHR12L2_DACC2DHR 0x0000FFF0 - -/* Channel 2 8-bit left-aligned data holding register */ - -#define DAC_DHR8R2_DACC2DHR 0x000000FF - -/* Dual DAC 12-bit right-aligned data holding register */ - -#define DAC_DHR12RD_DACC1DHR 0x00000FFF -#define DAC_DHR12RD_DACC2DHR 0x0FFF0000 - -/* Dual DAC 12-bit left-aligned data holding register */ - -#define DAC_DHR12LD_DACC1DHR 0x0000FFF0 -#define DAC_DHR12LD_DACC2DHR 0xFFF00000 - -/* Dual DAC 8-bit left-aligned data holding register */ - -#define DAC_DHR8RD_DACC1DHR 0x000000FF -#define DAC_DHR8RD_DACC2DHR 0x0000FF00 - -/* Channel 1 data output register */ - -#define DAC_DOR1_DACC1DOR 0x00000FFF - -/* Channel 1 data output register */ - -#define DAC_DOR2_DACC2DOR 0x00000FFF - -/* - * Routines - */ - -/* We take the dev argument in these for future-proofing */ - -#define DAC_CH1 0x1 -#define DAC_CH2 0x2 -void dac_init(const dac_dev *dev, uint32 flags); - -void dac_write_channel(const dac_dev *dev, uint8 channel, uint16 val); -void dac_enable_channel(const dac_dev *dev, uint8 channel); -void dac_disable_channel(const dac_dev *dev, uint8 channel); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/delay.h b/STM32F3/cores/maple/libmaple/include/libmaple/delay.h deleted file mode 100644 index 472a208..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/delay.h +++ /dev/null @@ -1,65 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/delay.h - * @brief Delay implementation - */ - -#ifndef _LIBMAPLE_DELAY_H_ -#define _LIBMAPLE_DELAY_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -/** - * @brief Delay the given number of microseconds. - * - * @param us Number of microseconds to delay. - */ -static inline void delay_us(uint32 us) { - us *= STM32_DELAY_US_MULT; - - /* fudge for function call overhead */ - us--; - asm volatile(" mov r0, %[us] \n\t" - "1: subs r0, #1 \n\t" - " bhi 1b \n\t" - : - : [us] "r" (us) - : "r0"); -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/dma.h b/STM32F3/cores/maple/libmaple/include/libmaple/dma.h deleted file mode 100644 index 329e907..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/dma.h +++ /dev/null @@ -1,444 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Michael Hope. - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/dma.h - * - * @author Marti Bolivar ; - * Original implementation by Michael Hope - * - * @brief Direct Memory Access peripheral support - */ - -#ifndef _LIBMAPLE_DMA_H_ -#define _LIBMAPLE_DMA_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -/* provides: - * - * - An opaque dma_tube type, and predefined rvalues for each tube - * supported by the series. - * - * A "DMA tube" is a series-specific (hopefully integer) datatype - * that abstracts the conduit through which DMA-ed data flow. - * - * Examples: On STM32F1, dma_tube is just an alias for dma_channel, - * and the tube values are just DMA_CH1 (=1), DMA_CH2 (=2), etc. - * - * Note that a dma_tube doesn't have to be an enum, and its values - * don't have to be integral. They _do_ need to be cheap to pass as - * arguments, though. - * - * - struct dma_tube_reg_map (and typedef to dma_tube_reg_map). DMA - * register maps tend to be split into global registers and per-tube - * registers. It's convenient to pass around pointers to a tube's - * registers, since that makes it possible to configure or otherwise - * mess with a tube without knowing which one you're dealing with. - * - * - Base pointers to the various dma_tube_reg_maps. - * - * Examples: On STM32F1, these are DMAxCHy_BASE. You can access - * registers like DMAxCHy_BASE->CPAR, etc. - * - * - enum dma_request_src (and typedef to dma_request_src). This - * specifies the peripheral DMA request sources (e.g. USART TX DMA - * requests, etc.). - * - * - enum dma_mode_flags (and typedef to dma_mode_flags). Used in - * dma_tube_config. If two series both support the same mode flags, - * they must use the same enumerator names for those flags (the - * values of those enumerators are of course allowed to differ). - * - * - Normal stuff: dma_reg_map and base pointers, register bit - * definitions, dma_dev pointer declarations, and any other - * convenience functions useful for the series. */ -#include -/* buys us dma_dev and other necessities. */ -#include -#include - -/* - * Declarations/documentation for some of the series-provided types. - */ - -/** - * @brief (Series-dependent) DMA request sources. - * - * These specify the various pieces of peripheral functionality which - * may make DMA requests. Use them to set up a DMA transfer (see - * struct dma_tube_config, dma_tube_cfg()). - */ -enum dma_request_src; - -/** - * @brief (Series-dependent) DMA tube configuration flags. - * These specify miscellaneous bits of configuration for a DMA tube. - * @see struct dma_mode_config - */ -enum dma_cfg_flags; - -/** - * @brief (Series-dependent) DMA tube register map type. - * This allows you to access a tube's registers as a group. - * @see dma_tube_regs() - */ -struct dma_tube_reg_map; - -/* - * Convenience functions - */ - -/* Initialization */ - -void dma_init(dma_dev *dev); - -/* dma_tube configuration - * - * Use these types and functions to set up DMA transfers, handle - * interrupts, etc. The main function of interest is dma_tube_cfg(), - * which the various series implement separately. */ - -/** - * @brief Specifies a DMA tube configuration. - * - * Use one of these to set up a DMA transfer by passing it to - * dma_tube_cfg(). - * - * @see dma_tube_cfg() - * @see dma_xfer_size - */ -typedef struct dma_tube_config { - /** Source of data */ - __IO void *tube_src; - /** Source transfer size */ - dma_xfer_size tube_src_size; - - /** Destination of data */ - __IO void *tube_dst; - /** Destination transfer size */ - dma_xfer_size tube_dst_size; - - /** - * Number of data to transfer (0 to 65,535). - * - * Note that this is NOT measured in bytes; it's measured in - * number of data, which occur in multiples of tube_src_size. For - * example, if tube_src_size is DMA_SIZE_32BITS and tube_nr_xfers - * is 2, then 8 total bytes will be transferred. - */ - unsigned tube_nr_xfers; - - /** - * Target-specific configuration flags. - * - * These are an OR of series-specific enum dma_mode_flags values. - * Consult the documentation for your target for what flags you - * can use here. - * - * Typical flag examples: DMA_CFG_SRC_INC, DMA_CFG_DST_INC, - * DMA_CFG_CIRC, DMA_CFG_CMPLT_IE, etc. - */ - unsigned tube_flags; - - /** - * Currently unused. You must set this to 0 or something valid for - * your target. */ - void *target_data; - - /** - * Hardware DMA request source. - * - * This is ignored for memory-to-memory transfers. - */ - enum dma_request_src tube_req_src; -} dma_tube_config; - -#define DMA_TUBE_CFG_SUCCESS 0 -#define DMA_TUBE_CFG_EREQ 1 -#define DMA_TUBE_CFG_ENDATA 2 -#define DMA_TUBE_CFG_EDEV 3 -#define DMA_TUBE_CFG_ESRC 4 -#define DMA_TUBE_CFG_EDST 5 -#define DMA_TUBE_CFG_EDIR 6 -#define DMA_TUBE_CFG_ESIZE 7 -#define DMA_TUBE_CFG_ECFG 0xFF -/** - * @brief Configure a DMA tube. - * - * Use this function to set up a DMA transfer. The tube will be - * disabled before being reconfigured. The transfer will have low - * priority by default. You can choose another priority before the - * transfer begins using dma_set_priority(). You can manage your - * interrupt handlers for the tube using dma_attach_interrupt() and - * dma_detach_interrupt(). - * - * After calling dma_tube_cfg() and performing any other desired - * configuration, start the transfer using dma_enable(). - * - * @param dev DMA device. - * @param tube DMA tube to configure. - * @param cfg Configuration to apply to tube. - * - * @return DMA_TUBE_CFG_SUCCESS (0) on success, <0 on failure. On - * failure, returned value will be the opposite (-) of one of: - * - * - DMA_TUBE_CFG_EREQ: tube doesn't work with cfg->tube_req_src - * - DMA_TUBE_CFG_ENDATA: cfg->tube_[src,dst]_size are - * incompatible with cfg->tube_nr_xfers, or cfg->tube_nr_xfers - * is out of bounds. - * - DMA_TUBE_CFG_EDEV: dev does not support cfg - * - DMA_TUBE_CFG_ESRC: bad cfg->tube_src - * - DMA_TUBE_CFG_EDST: bad cfg->tube_dst - * - DMA_TUBE_CFG_EDIR: dev can't transfer from cfg->tube_src to - * cfg->tube_dst - * - DMA_TUBE_CFG_ESIZE: something ended up wrong due to MSIZE/PSIZE - * - DMA_TUBE_CFG_ECFG: generic "something's wrong" - * - * @sideeffect Disables tube. May alter tube's registers even when an - * error occurs. - * @see struct dma_tube_config - * @see dma_attach_interrupt() - * @see dma_detach_interrupt() - * @see dma_enable() - */ -extern int dma_tube_cfg(dma_dev *dev, dma_tube tube, dma_tube_config *cfg); - -/* Other tube configuration functions. You can use these if - * dma_tube_cfg() isn't enough, or to adjust parts of an existing tube - * configuration. */ - -/** DMA transfer priority. */ -typedef enum dma_priority { - DMA_PRIORITY_LOW = 0, /**< Low priority */ - DMA_PRIORITY_MEDIUM = 1, /**< Medium priority */ - DMA_PRIORITY_HIGH = 2, /**< High priority */ - DMA_PRIORITY_VERY_HIGH = 3, /**< Very high priority */ -} dma_priority; - -/** - * @brief Set the priority of a DMA transfer. - * - * You may not call this function while the tube is enabled. - * - * @param dev DMA device - * @param tube DMA tube - * @param priority priority to set. - */ -extern void dma_set_priority(dma_dev *dev, dma_tube tube, - dma_priority priority); - -/** - * @brief Set the number of data transfers on a DMA tube. - * - * You may not call this function while the tube is enabled. - * - * @param dev DMA device - * @param tube Tube through which the transfer will occur. - * @param num_transfers Number of DMA transactions to set. - */ -extern void dma_set_num_transfers(dma_dev *dev, dma_tube tube, - uint16 num_transfers); - -/** - * @brief Set the base memory address where data will be read from or - * written to. - * - * You must not call this function while the tube is enabled. - * - * If the DMA memory size is 16 bits, the address is automatically - * aligned to a half-word. If the DMA memory size is 32 bits, the - * address is aligned to a word. - * - * @param dev DMA Device - * @param tube Tube whose base memory address to set. - * @param address Memory base address to use. - */ -extern void dma_set_mem_addr(dma_dev *dev, dma_tube tube, __IO void *address); - -/** - * @brief Set the base peripheral address where data will be read from - * or written to. - * - * You must not call this function while the channel is enabled. - * - * If the DMA peripheral size is 16 bits, the address is automatically - * aligned to a half-word. If the DMA peripheral size is 32 bits, the - * address is aligned to a word. - * - * @param dev DMA Device - * @param tube Tube whose peripheral data register base address to set. - * @param address Peripheral memory base address to use. - */ -extern void dma_set_per_addr(dma_dev *dev, dma_tube tube, __IO void *address); - -/* Interrupt handling */ - -/** - * @brief Attach an interrupt to a DMA transfer. - * - * Interrupts are enabled using series-specific mode flags in - * dma_tube_cfg(). - * - * @param dev DMA device - * @param tube Tube to attach handler to - * @param handler Interrupt handler to call when tube interrupt fires. - * @see dma_tube_cfg() - * @see dma_get_irq_cause() - * @see dma_detach_interrupt() - */ -extern void dma_attach_interrupt(dma_dev *dev, dma_tube tube, - void (*handler)(void)); - - -/** - * @brief Detach a DMA transfer interrupt handler. - * - * After calling this function, the given tube's interrupts will be - * disabled. - * - * @param dev DMA device - * @param tube Tube whose handler to detach - * @sideeffect Clears the tube's interrupt enable bits. - * @see dma_attach_interrupt() - */ -extern void dma_detach_interrupt(dma_dev *dev, dma_tube tube); - -/* Tube enable/disable */ - -/** - * @brief Enable a DMA tube. - * - * If the tube has been properly configured, calling this function - * allows it to start serving DMA requests. - * - * @param dev DMA device - * @param tube Tube to enable - * @see dma_tube_cfg() - */ -extern void dma_enable(dma_dev *dev, dma_tube tube); - -/** - * @brief Disable a DMA channel. - * - * Calling this function makes the tube stop serving DMA requests. - * - * @param dev DMA device - * @param tube Tube to disable - */ -extern void dma_disable(dma_dev *dev, dma_tube tube); - -/** - * @brief Check if a DMA tube is enabled. - * @param dev DMA device. - * @param tube Tube to check. - * @return 0 if the tube is disabled, >0 if it is enabled. - */ -static inline uint8 dma_is_enabled(dma_dev *dev, dma_tube tube); - -/* Other conveniences */ - -/** - * @brief Obtain a pointer to an individual DMA tube's registers. - * - * Examples: - * - * - On STM32F1, dma_channel_regs(DMA1, DMA_CH1)->CCR is DMA1_BASE->CCR1. - * - * @param dev DMA device. - * @param tube DMA tube whose register map to obtain. - * @return (Series-specific) tube register map. - */ -static inline dma_tube_reg_map* dma_tube_regs(dma_dev *dev, dma_tube tube); - -/** - * Encodes the reason why a DMA interrupt was called. - * @see dma_get_irq_cause() - */ -typedef enum dma_irq_cause { - DMA_TRANSFER_COMPLETE, /**< Transfer is complete. */ - DMA_TRANSFER_HALF_COMPLETE, /**< Transfer is half complete. */ - DMA_TRANSFER_ERROR, /**< Error occurred during transfer. */ - DMA_TRANSFER_DME_ERROR, /**< - * @brief Direct mode error occurred during - * transfer. */ - DMA_TRANSFER_FIFO_ERROR, /**< FIFO error occurred during transfer. */ -} dma_irq_cause; - -/** - * @brief Discover the reason why a DMA interrupt was called. - * - * You may only call this function within an attached interrupt - * handler for the given channel. - * - * This function resets the internal DMA register state which encodes - * the cause of the interrupt; consequently, it can only be called - * once per interrupt handler invocation. - * - * @param dev DMA device - * @param tube Tube whose interrupt is being handled. - * @return Reason why the interrupt fired. - * @sideeffect Clears flags in dev's interrupt status registers. - * @see dma_attach_interrupt() - * @see dma_irq_cause - */ -extern dma_irq_cause dma_get_irq_cause(dma_dev *dev, dma_tube tube); - -/** - * @brief Get the ISR status bits for a DMA channel. - * - * The bits are returned right-aligned, in the order they appear in - * the corresponding ISR register. - * - * If you're trying to figure out why a DMA interrupt fired, you may - * find dma_get_irq_cause() more convenient. - * - * @param dev DMA device - * @param tube Tube whose ISR bits to return. - * @see dma_get_irq_cause(). - */ -static inline uint8 dma_get_isr_bits(dma_dev *dev, dma_tube tube); - -/** - * @brief Clear the ISR status bits for a given DMA tube. - * - * If you're trying to clean up after yourself in a DMA interrupt, you - * may find dma_get_irq_cause() more convenient. - * - * @param dev DMA device - * @param tube Tube whose ISR bits to clear. - * @see dma_get_irq_cause() - */ -static inline void dma_clear_isr_bits(dma_dev *dev, dma_tube tube); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/dma_common.h b/STM32F3/cores/maple/libmaple/include/libmaple/dma_common.h deleted file mode 100644 index 3765cd5..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/dma_common.h +++ /dev/null @@ -1,112 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/dma_common.h - * @author Marti Bolivar - * @brief Common DMA sub-header for and . - * - * CONTENTS UNSTABLE. The existence of this file is an implementation - * detail. Never include it directly. If you need something from - * here, include instead. - */ - -/* - * There's a fair amount of common DMA functionality needed by each - * and . This header exists in order - * to provide it to both, avoiding some hacks and circular - * dependencies. - */ - -#ifndef _LIBMAPLE_DMA_COMMON_H_ -#define _LIBMAPLE_DMA_COMMON_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include -#include - -/* - * Devices - */ - -struct dma_reg_map; - -/* Encapsulates state related to user interrupt handlers. You - * shouldn't touch these directly; use dma_attach_interrupt() and - * dma_detach_interupt() instead. */ -typedef struct dma_handler_config { - void (*handler)(void); /* User handler */ - nvic_irq_num irq_line; /* IRQ line for interrupt */ -} dma_handler_config; - -/** DMA device type */ -typedef struct dma_dev { - struct dma_reg_map *regs; /**< Register map */ - rcc_clk_id clk_id; /**< Clock ID */ - struct dma_handler_config handlers[]; /**< For internal use */ -} dma_dev; - -/** - * @brief DMA channels - * - * Notes: - * - This is also the dma_tube type for STM32F1. - * - Channel 0 is not available on all STM32 series. - * - * @see dma_tube - */ -typedef enum dma_channel { - DMA_CH0 = 0, /**< Channel 0 */ - DMA_CH1 = 1, /**< Channel 1 */ - DMA_CH2 = 2, /**< Channel 2 */ - DMA_CH3 = 3, /**< Channel 3 */ - DMA_CH4 = 4, /**< Channel 4 */ - DMA_CH5 = 5, /**< Channel 5 */ - DMA_CH6 = 6, /**< Channel 6 */ - DMA_CH7 = 7, /**< Channel 7 */ -} dma_channel; - -/** - * @brief Source and destination transfer sizes. - * Use these when initializing a struct dma_tube_config. - * @see struct dma_tube_config - * @see dma_tube_cfg - */ -typedef enum dma_xfer_size { - DMA_SIZE_8BITS = 0, /**< 8-bit transfers */ - DMA_SIZE_16BITS = 1, /**< 16-bit transfers */ - DMA_SIZE_32BITS = 2, /**< 32-bit transfers */ -} dma_xfer_size; - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/dsp.h b/STM32F3/cores/maple/libmaple/include/libmaple/dsp.h deleted file mode 100644 index 435c801..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/dsp.h +++ /dev/null @@ -1,131 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -/** - * @file libmaple/include/libmaple/dsp.h - * @author F3-port by Hanspeter Portner - * @brief Convenience macros for the digital signal processing (DSP) - * instruction set of the ARM Cortex M4 microcontroller. - */ - -#ifndef _LIBMAPLE_DSP_H_ -#define _LIBMAPLE_DSP_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#define DSP3(ID, A, B, C) \ -({ \ - uint32_t X; \ - asm volatile (ID" %[res], %[val1], %[val2], %[val3]" \ - : [res]"=r" (X) \ - : [val1]"r" (A), [val2]"r" (B), [val3]"r" (C) \ - ); \ - (uint32_t)X; \ -}) - -#define DSP2(ID, A, B) \ -({ \ - uint32_t X; \ - asm volatile (ID" %[res], %[val1], %[val2]" \ - : [res]"=r" (X) \ - : [val1]"r" (A), [val2]"r" (B) \ - );\ - (uint32_t)X; \ -}) - -#define DSP1(ID, A) \ -({ \ - uint32_t X; \ - asm volatile (ID" %[res], %[val1]" \ - : [res]"=r" (X) \ - : [val1]"r" (A) \ - ); \ - (uint32_t)X; \ -}) - -/* General data processing instructions */ -#define __rev16(A) DSP1("REV16", A) -//TODO - -/* Multiply and divide instructions */ -//TODO - -/* Saturating instructions */ -//TODO - -/* Packing and unpacking instructions */ -//TODO - -/* Bitfield instructions */ -//TODO - -/* Floating-point instructions */ -//TODO - -/* Miscellaneous instructions */ -//TODO - -/* SIMD instructions (single instruction multiple data) */ -#define __sadd16(A, B) DSP2("SADD16", A, B) -#define __shadd16(A, B) DSP2("SHADD16", A, B) -#define __ssub16(A, B) DSP2("SSUB16", A, B) -#define __shsub16(A, B) DSP2("SHSUB16", A, B) -#define __uadd16(A, B) DSP2("UADD16", A, B) -#define __uhadd16(A, B) DSP2("UHADD16", A, B) -#define __usub16(A, B) DSP2("USUB16", A, B) -#define __uhsub16(A, B) DSP2("UHSUB16", A, B) - -#define __sadd8(A, B) DSP2("SADD8", A, B) -#define __shadd8(A, B) DSP2("SHADD8", A, B) -#define __ssub8(A, B) DSP2("SSUB8", A, B) -#define __shsub8(A, B) DSP2("SHSUB8", A, B) -#define __uadd8(A, B) DSP2("UADD8", A, B) -#define __uhadd8(A, B) DSP2("UHADD8", A, B) -#define __usub8(A, B) DSP2("USUB8", A, B) -#define __uhsub8(A, B) DSP2("UHSUB8", A, B) - -#define __sasx(A, B) DSP2("SASX", A, B) -#define __ssax(A, B) DSP2("SSAX", A, B) -#define __shasx(A, B) DSP2("SHASX", A, B) -#define __shsax(A, B) DSP2("SHSAX", A, B) -#define __uasx(A, B) DSP2("UASX", A, B) -#define __usax(A, B) DSP2("USAX", A, B) -#define __uhasx(A, B) DSP2("UHASX", A, B) -#define __uhsax(A, B) DSP2("UHSAX", A, B) - -#define __usad8(A, B) DSP2("USAD8", A, B) -#define __usada8(A, B, C) DSP3("USADA8", A, B, C) - -/* MAC instructions (multiply and accumulate) */ -/* TODO */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/exti.h b/STM32F3/cores/maple/libmaple/include/libmaple/exti.h deleted file mode 100644 index 525cdc7..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/exti.h +++ /dev/null @@ -1,143 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/exti.h - * @brief External interrupt control - */ - -/* See notes/exti.txt for more info */ - -#ifndef _LIBMAPLE_EXTI_H_ -#define _LIBMAPLE_EXTI_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include /* provides EXTI_BASE */ -#include - -/* - * Register map and base pointer. - */ - -/** EXTI register map type */ -typedef struct exti_reg_map { - __IO uint32 IMR; /**< Interrupt mask register */ - __IO uint32 EMR; /**< Event mask register */ - __IO uint32 RTSR; /**< Rising trigger selection register */ - __IO uint32 FTSR; /**< Falling trigger selection register */ - __IO uint32 SWIER; /**< Software interrupt event register */ - __IO uint32 PR; /**< Pending register */ -} exti_reg_map; - -/* - * Types: exti_num, exti_cfg, exti_trigger_mode. - * - * A combination of these three specifies an external interrupt - * configuration (see exti_attach_interrupt()). - */ - -/** EXTI line. */ -typedef enum exti_num { - EXTI0, /**< EXTI line 0 */ - EXTI1, /**< EXTI line 1 */ - EXTI2, /**< EXTI line 2 */ - EXTI3, /**< EXTI line 3 */ - EXTI4, /**< EXTI line 4 */ - EXTI5, /**< EXTI line 5 */ - EXTI6, /**< EXTI line 6 */ - EXTI7, /**< EXTI line 7 */ - EXTI8, /**< EXTI line 8 */ - EXTI9, /**< EXTI line 9 */ - EXTI10, /**< EXTI line 10 */ - EXTI11, /**< EXTI line 11 */ - EXTI12, /**< EXTI line 12 */ - EXTI13, /**< EXTI line 13 */ - EXTI14, /**< EXTI line 14 */ - EXTI15, /**< EXTI line 15 */ -} exti_num; - -/** - * @brief EXTI port configuration - * - * These specify which GPIO port an external interrupt line should be - * connected to. - */ -typedef enum exti_cfg { - EXTI_PA, /**< Use PAx pin */ - EXTI_PB, /**< Use PBx pin */ - EXTI_PC, /**< Use PCx pin */ - EXTI_PD, /**< Use PDx pin */ - EXTI_PE, /**< Use PEx pin */ - EXTI_PF, /**< Use PFx pin */ - EXTI_PG, /**< Use PGx pin */ - EXTI_PH, /**< Use PHx pin */ - EXTI_PI, /**< Use PIx pin */ -} exti_cfg; - -/** External interrupt trigger mode */ -typedef enum exti_trigger_mode { - EXTI_RISING, /**< Trigger on the rising edge */ - EXTI_FALLING, /**< Trigger on the falling edge */ - EXTI_RISING_FALLING /**< Trigger on both the rising and falling edges */ -} exti_trigger_mode; - -/* - * Routines - */ - -void exti_attach_interrupt(exti_num num, - exti_cfg port, - voidFuncPtr handler, - exti_trigger_mode mode); -void exti_attach_callback(exti_num num, - exti_cfg port, - voidArgumentFuncPtr handler, - void *arg, - exti_trigger_mode mode); -void exti_detach_interrupt(exti_num num); - -/** - * @brief Set the GPIO port for an EXTI line. - * - * This is a low-level routine that most users will not - * need. exti_attach_interrupt() handles calling this function - * appropriately. - * - * @param num EXTI line - * @param port EXTI configuration for GPIO port to connect to num. - * @see exti_num - * @see exti_cfg - */ -extern void exti_select(exti_num num, exti_cfg port); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/flash.h b/STM32F3/cores/maple/libmaple/include/libmaple/flash.h deleted file mode 100644 index 943e466..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/flash.h +++ /dev/null @@ -1,106 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/flash.h - * @brief Flash support. - */ - -#ifndef _LIBMAPLE_FLASH_H_ -#define _LIBMAPLE_FLASH_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -#define FLASH_WAIT_STATE_0 0x0 -#define FLASH_WAIT_STATE_1 0x1 -#define FLASH_WAIT_STATE_2 0x2 -#define FLASH_WAIT_STATE_3 0x3 -#define FLASH_WAIT_STATE_4 0x4 -#define FLASH_WAIT_STATE_5 0x5 -#define FLASH_WAIT_STATE_6 0x6 -#define FLASH_WAIT_STATE_7 0x7 - -/* The series header must define: - * - * - FLASH_SAFE_WAIT_STATES, the smallest number of wait states that - * it is safe to use when SYSCLK is at its fastest documented rate - * and the MCU is powered at 3.3V (i.e. this doesn't consider - * overclocking or low voltage operation). - * - * - The following bit flags, for flash_enable_features(): - * - * -- FLASH_PREFETCH: prefetcher - * -- FLASH_ICACHE: instruction cache - * -- FLASH_DCACHE: data cache - * - * See that function's Doxygen for more restrictions. - */ -#include - -#ifdef __DOXYGEN__ -/** Flash register map base pointer. */ -#define FLASH_BASE -#endif - -/* - * Flash routines - */ - -void flash_set_latency(uint32 wait_states); - -/** - * @brief Enable Flash memory features - * - * If the target MCU doesn't provide a feature (e.g. instruction and - * data caches on the STM32F1), the flag will be ignored. This allows - * using these flags unconditionally, with the desired effect taking - * place on targets that support them. - * - * @param feature_flags Bitwise OR of the following: - * FLASH_PREFETCH (turns on prefetcher), - * FLASH_ICACHE (turns on instruction cache), - * FLASH_DCACHE (turns on data cache). - */ -static inline void flash_enable_features(uint32 feature_flags) { - FLASH_BASE->ACR |= feature_flags; -} - -/** - * @brief Deprecated. Use flash_enable_features(FLASH_PREFETCH) instead. - */ -static inline void flash_enable_prefetch(void) { - flash_enable_features(FLASH_PREFETCH); -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/fpu.h b/STM32F3/cores/maple/libmaple/include/libmaple/fpu.h deleted file mode 100644 index f8e2037..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/fpu.h +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -/** - * @file libmaple/include/libmaple/fpu.h - * @author F3-port by Hanspeter Portner - * @brief Floating Point Unit (FPU) interace. - */ - -#ifndef _LIBMAPLE_FPU_H_ -#define _LIBMAPLE_FPU_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/** - * @brief Enable floating point unit. - */ -void fpu_enable(void); - -/** - * @brief Disable floating point unit. - */ -void fpu_disable(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/fsmc.h b/STM32F3/cores/maple/libmaple/include/libmaple/fsmc.h deleted file mode 100644 index 9dd8a72..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/fsmc.h +++ /dev/null @@ -1,340 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Bryan Newbold. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/fsmc.h - * @brief Flexible static memory controller support. - */ - -/* - * See ../notes/fsmc.txt for more info - */ - -#ifndef _LIBMAPLE_FSMC_H_ -#define _LIBMAPLE_FSMC_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include - -#if !STM32_HAVE_FSMC -#error "FSMC is unavailable on your MCU" -#endif - -/* - * Register maps and devices - */ - -/** FSMC register map type */ -typedef struct fsmc_reg_map { - __IO uint32 BCR1; /**< SRAM/NOR-Flash chip-select control register 1 */ - __IO uint32 BTR1; /**< SRAM/NOR-Flash chip-select timing register 1 */ - __IO uint32 BCR2; /**< SRAM/NOR-Flash chip-select control register 2 */ - __IO uint32 BTR2; /**< SRAM/NOR-Flash chip-select timing register 2 */ - __IO uint32 BCR3; /**< SRAM/NOR-Flash chip-select control register 3 */ - __IO uint32 BTR3; /**< SRAM/NOR-Flash chip-select timing register 3 */ - __IO uint32 BCR4; /**< SRAM/NOR-Flash chip-select control register 4 */ - __IO uint32 BTR4; /**< SRAM/NOR-Flash chip-select timing register 4 */ - const uint8 RESERVED1[64]; /**< Reserved */ - __IO uint32 PCR2; /**< PC Card/NAND Flash control register 2 */ - __IO uint32 SR2; /**< FIFO status and interrupt register 2 */ - __IO uint32 PMEM2; /**< Common memory space timing register 2 */ - __IO uint32 PATT2; /**< Attribute memory space timing register 2 */ - const uint8 RESERVED2[4]; /**< Reserved */ - __IO uint32 ECCR2; /**< ECC result register 2 */ - const uint8 RESERVED3[2]; - __IO uint32 PCR3; /**< PC Card/NAND Flash control register 3 */ - __IO uint32 SR3; /**< FIFO status and interrupt register 3 */ - __IO uint32 PMEM3; /**< Common memory space timing register 3 */ - __IO uint32 PATT3; /**< Attribute memory space timing register 3 */ - const uint32 RESERVED4; /**< Reserved */ - __IO uint32 ECCR3; /**< ECC result register 3 */ - const uint8 RESERVED5[8]; /**< Reserved */ - __IO uint32 PCR4; /**< PC Card/NAND Flash control register 4 */ - __IO uint32 SR4; /**< FIFO status and interrupt register 4 */ - __IO uint32 PMEM4; /**< Common memory space timing register 4 */ - __IO uint32 PATT4; /**< Attribute memory space timing register 4 */ - __IO uint32 PIO4; /**< I/O space timing register 4 */ - const uint8 RESERVED6[80]; /**< Reserved */ - __IO uint32 BWTR1; /**< SRAM/NOR-Flash write timing register 1 */ - const uint32 RESERVED7; /**< Reserved */ - __IO uint32 BWTR2; /**< SRAM/NOR-Flash write timing register 2 */ - const uint32 RESERVED8; /**< Reserved */ - __IO uint32 BWTR3; /**< SRAM/NOR-Flash write timing register 3 */ - const uint32 RESERVED9; /**< Reserved */ - __IO uint32 BWTR4; /**< SRAM/NOR-Flash write timing register 4 */ -} __attribute__((packed)) fsmc_reg_map; - -#define __FSMCB 0xA0000000 - -/** FSMC register map base pointer */ -#define FSMC_BASE ((struct fsmc_reg_map*)__FSMCB) - -/** FSMC NOR/PSRAM register map type */ -typedef struct fsmc_nor_psram_reg_map { - __IO uint32 BCR; /**< Chip-select control register */ - __IO uint32 BTR; /**< Chip-select timing register */ - const uint8 RESERVED[252]; /**< Reserved */ - __IO uint32 BWTR; /**< Write timing register */ -} fsmc_nor_psram_reg_map; - -/** FSMC NOR/PSRAM base pointer 1 */ -#define FSMC_NOR_PSRAM1_BASE ((struct fsmc_nor_psram_reg_map*)__FSMCB) - -/** FSMC NOR/PSRAM base pointer 2 */ -#define FSMC_NOR_PSRAM2_BASE ((struct fsmc_nor_psram_reg_map*)(__FSMCB + 0x8)) - -/** FSMC NOR/PSRAM base pointer 3 */ -#define FSMC_NOR_PSRAM3_BASE ((struct fsmc_nor_psram_reg_map*)(__FSMCB + 0x10)) - -/** FSMC NOR/PSRAM base pointer 4 */ -#define FSMC_NOR_PSRAM4_BASE ((struct fsmc_nor_psram_reg_map*)(__FSMCB + 0x18)) - -/* - * Register bit definitions - */ - -/* NOR/PSRAM chip-select control registers */ - -#define FSMC_BCR_CBURSTRW_BIT 19 -#define FSMC_BCR_ASYNCWAIT_BIT 15 -#define FSMC_BCR_EXTMOD_BIT 14 -#define FSMC_BCR_WAITEN_BIT 13 -#define FSMC_BCR_WREN_BIT 12 -#define FSMC_BCR_WAITCFG_BIT 11 -#define FSMC_BCR_WRAPMOD_BIT 10 -#define FSMC_BCR_WAITPOL_BIT 9 -#define FSMC_BCR_BURSTEN_BIT 8 -#define FSMC_BCR_FACCEN_BIT 6 -#define FSMC_BCR_MUXEN_BIT 1 -#define FSMC_BCR_MBKEN_BIT 0 - -#define FSMC_BCR_CBURSTRW (1U << FSMC_BCR_CBURSTRW_BIT) -#define FSMC_BCR_ASYNCWAIT (1U << FSMC_BCR_ASYNCWAIT_BIT) -#define FSMC_BCR_EXTMOD (1U << FSMC_BCR_EXTMOD_BIT) -#define FSMC_BCR_WAITEN (1U << FSMC_BCR_WAITEN_BIT) -#define FSMC_BCR_WREN (1U << FSMC_BCR_WREN_BIT) -#define FSMC_BCR_WAITCFG (1U << FSMC_BCR_WAITCFG_BIT) -#define FSMC_BCR_WRAPMOD (1U << FSMC_BCR_WRAPMOD_BIT) -#define FSMC_BCR_WAITPOL (1U << FSMC_BCR_WAITPOL_BIT) -#define FSMC_BCR_BURSTEN (1U << FSMC_BCR_BURSTEN_BIT) -#define FSMC_BCR_FACCEN (1U << FSMC_BCR_FACCEN_BIT) -#define FSMC_BCR_MWID (0x3 << 4) -#define FSMC_BCR_MWID_8BITS (0x0 << 4) -#define FSMC_BCR_MWID_16BITS (0x1 << 4) -#define FSMC_BCR_MTYP (0x3 << 2) -#define FSMC_BCR_MTYP_SRAM (0x0 << 2) -#define FSMC_BCR_MTYP_PSRAM (0x1 << 2) -#define FSMC_BCR_MTYP_NOR_FLASH (0x2 << 2) -#define FSMC_BCR_MUXEN (1U << FSMC_BCR_MUXEN_BIT) -#define FSMC_BCR_MBKEN (1U << FSMC_BCR_MBKEN_BIT) - -/* SRAM/NOR-Flash chip-select timing registers */ - -#define FSMC_BTR_ACCMOD (0x3 << 28) -#define FSMC_BTR_ACCMOD_A (0x0 << 28) -#define FSMC_BTR_ACCMOD_B (0x1 << 28) -#define FSMC_BTR_ACCMOD_C (0x2 << 28) -#define FSMC_BTR_ACCMOD_D (0x3 << 28) -#define FSMC_BTR_DATLAT (0xF << 24) -#define FSMC_BTR_CLKDIV (0xF << 20) -#define FSMC_BTR_BUSTURN (0xF << 16) -#define FSMC_BTR_DATAST (0xFF << 8) -#define FSMC_BTR_ADDHLD (0xF << 4) -#define FSMC_BTR_ADDSET 0xF - -/* SRAM/NOR-Flash write timing registers */ - -#define FSMC_BWTR_ACCMOD (0x3 << 28) -#define FSMC_BWTR_ACCMOD_A (0x0 << 28) -#define FSMC_BWTR_ACCMOD_B (0x1 << 28) -#define FSMC_BWTR_ACCMOD_C (0x2 << 28) -#define FSMC_BWTR_ACCMOD_D (0x3 << 28) -#define FSMC_BWTR_DATLAT (0xF << 24) -#define FSMC_BWTR_CLKDIV (0xF << 20) -#define FSMC_BWTR_DATAST (0xFF << 8) -#define FSMC_BWTR_ADDHLD (0xF << 4) -#define FSMC_BWTR_ADDSET 0xF - -/* NAND Flash/PC Card controller registers */ - -#define FSMC_PCR_ECCEN_BIT 6 -#define FSMC_PCR_PTYP_BIT 3 -#define FSMC_PCR_PBKEN_BIT 2 -#define FSMC_PCR_PWAITEN_BIT 1 - -#define FSMC_PCR_ECCPS (0x7 << 17) -#define FSMC_PCR_ECCPS_256B (0x0 << 17) -#define FSMC_PCR_ECCPS_512B (0x1 << 17) -#define FSMC_PCR_ECCPS_1024B (0x2 << 17) -#define FSMC_PCR_ECCPS_2048B (0x3 << 17) -#define FSMC_PCR_ECCPS_4096B (0x4 << 17) -#define FSMC_PCR_ECCPS_8192B (0x5 << 17) -#define FSMC_PCR_TAR (0xF << 13) -#define FSMC_PCR_TCLR (0xF << 9) -#define FSMC_PCR_ECCEN (1U << FSMC_PCR_ECCEN_BIT) -#define FSMC_PCR_PWID (0x3 << 4) -#define FSMC_PCR_PWID_8BITS (0x0 << 4) -#define FSMC_PCR_PWID_16BITS (0x1 << 4) -#define FSMC_PCR_PTYP (1U << FSMC_PCR_PTYP_BIT) -#define FSMC_PCR_PTYP_PC_CF_PCMCIA (0x0 << FSMC_PCR_PTYP_BIT) -#define FSMC_PCR_PTYP_NAND (0x1 << FSMC_PCR_PTYP_BIT) -#define FSMC_PCR_PBKEN (1U << FSMC_PCR_PBKEN_BIT) -#define FSMC_PCR_PWAITEN (1U << FSMC_PCR_PWAITEN_BIT) - -/* FIFO status and interrupt registers */ - -#define FSMC_SR_FEMPT_BIT 6 -#define FSMC_SR_IFEN_BIT 5 -#define FSMC_SR_ILEN_BIT 4 -#define FSMC_SR_IREN_BIT 3 -#define FSMC_SR_IFS_BIT 2 -#define FSMC_SR_ILS_BIT 1 -#define FSMC_SR_IRS_BIT 0 - -#define FSMC_SR_FEMPT (1U << FSMC_SR_FEMPT_BIT) -#define FSMC_SR_IFEN (1U << FSMC_SR_IFEN_BIT) -#define FSMC_SR_ILEN (1U << FSMC_SR_ILEN_BIT) -#define FSMC_SR_IREN (1U << FSMC_SR_IREN_BIT) -#define FSMC_SR_IFS (1U << FSMC_SR_IFS_BIT) -#define FSMC_SR_ILS (1U << FSMC_SR_ILS_BIT) -#define FSMC_SR_IRS (1U << FSMC_SR_IRS_BIT) - -/* Common memory space timing registers */ - -#define FSMC_PMEM_MEMHIZ (0xFF << 24) -#define FSMC_PMEM_MEMHOLD (0xFF << 16) -#define FSMC_PMEM_MEMWAIT (0xFF << 8) -#define FSMC_PMEM_MEMSET 0xFF - -/* Attribute memory space timing registers */ - -#define FSMC_PATT_ATTHIZ (0xFF << 24) -#define FSMC_PATT_ATTHOLD (0xFF << 16) -#define FSMC_PATT_ATTWAIT (0xFF << 8) -#define FSMC_PATT_ATTSET 0xFF - -/* I/O space timing register 4 */ - -#define FSMC_PIO_IOHIZ (0xFF << 24) -#define FSMC_PIO_IOHOLD (0xFF << 16) -#define FSMC_PIO_IOWAIT (0xFF << 8) -#define FSMC_PIO_IOSET 0xFF - -/* - * Memory bank boundary addresses - */ - -/** - * @brief Void pointer to base address of FSMC memory bank 1 (NOR/PSRAM). - * - * This bank is split into 4 regions. Each region supports interfacing - * with 1 NOR Flash, SRAM, or PSRAM chip. The base addresses of these - * regions are FSMC_NOR_PSRAM_REGIONx, for x = 1, 2, 3, 4. - */ -#define FSMC_BANK1 ((void*)0x60000000) - -/** - * @brief Void pointer to base address of FSMC memory bank 1, region 1 - * (NOR/PSRAM). - */ -#define FSMC_NOR_PSRAM_REGION1 FSMC_BANK1 - -/** - * @brief Void pointer to base address of FSMC memory bank 1, region 2 - * (NOR/PSRAM). - */ -#define FSMC_NOR_PSRAM_REGION2 ((void*)0x64000000) - -/** - * @brief Void pointer to base address of FSMC memory bank 1, region 3 - * (NOR/PSRAM). - */ -#define FSMC_NOR_PSRAM_REGION3 ((void*)0x68000000) - -/** - * @brief Void pointer to base address of FSMC memory bank 1, region 4 - * (NOR/PSRAM). - */ -#define FSMC_NOR_PSRAM_REGION4 ((void*)0x6C000000) - -/** Void pointer to base address of FSMC memory bank 2 (NAND Flash). */ -#define FSMC_BANK2 ((void*)0x70000000) - -/** Void pointer to base address of FSMC memory bank 3 (NAND Flash). */ -#define FSMC_BANK3 ((void*)0x80000000) - -/** - * @brief Void pointer to base address of FSMC memory bank 4 (PC card - * devices). - */ -#define FSMC_BANK4 ((void*)0x90000000) - -/* - * SRAM/NOR Flash routines - */ - -/** - * @brief Configure FSMC GPIOs for use with SRAM. - */ -void fsmc_sram_init_gpios(void); - -/** - * Set the DATAST bits in the given NOR/PSRAM register map's - * chip-select timing register (FSMC_BTR). - * - * @param regs NOR Flash/PSRAM register map whose chip-select timing - * register to set. - * @param datast Value to use for DATAST bits. - */ -static inline void fsmc_nor_psram_set_datast(fsmc_nor_psram_reg_map *regs, - uint8 datast) { - regs->BTR &= ~FSMC_BTR_DATAST; - regs->BTR |= datast << 8; -} - -/** - * Set the ADDHLD bits in the given NOR/PSRAM register map's chip - * select timing register (FSMC_BTRx). - * - * @param regs NOR Flash/PSRAM register map whose chip-select timing - * register to set. - * @param addset Value to use for ADDSET bits. - */ -static inline void fsmc_nor_psram_set_addset(fsmc_nor_psram_reg_map *regs, - uint8 addset) { - regs->BTR &= ~FSMC_BTR_ADDSET; - regs->BTR |= addset & 0xF; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/gpio.h b/STM32F3/cores/maple/libmaple/include/libmaple/gpio.h deleted file mode 100644 index 0cc3746..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/gpio.h +++ /dev/null @@ -1,121 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -/** - * @file libmaple/include/libmaple/gpio.h - * @brief General Purpose I/O (GPIO) interace. - */ - -#ifndef _LIBMAPLE_GPIO_H_ -#define _LIBMAPLE_GPIO_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -/* - * Note: Series header must define: - * - enum gpio_pin_mode (TODO think harder about portability here) - */ -#include -#include -#include -#include - -/* - * Device type - */ - -/** GPIO device type */ -typedef struct gpio_dev { - gpio_reg_map *regs; /**< Register map */ - rcc_clk_id clk_id; /**< RCC clock information */ - /** - * @brief (Deprecated) External interrupt port. - * Instead of dev->exti_port, use gpio_exti_port(dev). - */ - exti_cfg exti_port; -} gpio_dev; - -/* - * Portable routines - */ - -void gpio_init(gpio_dev *dev); -void gpio_init_all(void); -/* TODO flags argument version? */ -void gpio_set_mode(gpio_dev *dev, uint8 pin, gpio_pin_mode mode); - -/** - * @brief Get a GPIO port's corresponding EXTI port configuration. - * @param dev GPIO port whose exti_cfg to return. - */ -static inline exti_cfg gpio_exti_port(gpio_dev *dev) { - return (exti_cfg)(EXTI_PA + (dev->clk_id - RCC_GPIOA)); -} - -/** - * Set or reset a GPIO pin. - * - * Pin must have previously been configured to output mode. - * - * @param dev GPIO device whose pin to set. - * @param pin Pin on to set or reset - * @param val If true, set the pin. If false, reset the pin. - */ -static inline void gpio_write_bit(gpio_dev *dev, uint8 pin, uint8 val) { - val = !val; /* "set" bits are lower than "reset" bits */ - dev->regs->BSRR = (1U << pin) << (16 * val); -} - -/** - * Determine whether or not a GPIO pin is set. - * - * Pin must have previously been configured to input mode. - * - * @param dev GPIO device whose pin to test. - * @param pin Pin on dev to test. - * @return True if the pin is set, false otherwise. - */ -static inline uint32 gpio_read_bit(gpio_dev *dev, uint8 pin) { - return dev->regs->IDR & (1U << pin); -} - -/** - * Toggle a pin configured as output push-pull. - * @param dev GPIO device. - * @param pin Pin on dev to toggle. - */ -static inline void gpio_toggle_bit(gpio_dev *dev, uint8 pin) { - dev->regs->ODR = dev->regs->ODR ^ (1U << pin); -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/i2c.h b/STM32F3/cores/maple/libmaple/include/libmaple/i2c.h deleted file mode 100644 index 8452c2a..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/i2c.h +++ /dev/null @@ -1,304 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/i2c.h - * @author F3-port by Hanspeter Portner - * @brief Inter-Integrated Circuit (I2C) peripheral support - * - * Currently master-only. Usage notes: - * - * - Enable an I2C device with i2c_master_enable(). - * - Initialize an array of struct i2c_msg to suit the bus - * transactions (reads/writes) you wish to perform. - * - Call i2c_master_xfer() to do the work. - */ - -#ifndef _LIBMAPLE_I2C_H_ -#define _LIBMAPLE_I2C_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Series header must provide: - * - * - uint32 _i2c_bus_clk(i2c_dev*): Clock frequency of dev's bus, in - * MHz. (This is for internal use only). - * - * - (optional) _I2C_HAVE_IRQ_FIXUP: Leave undefined, or define to 1. - * This is for internal use only. It's a hack to work around a - * silicon bug related to I2C IRQ pre-emption on some targets. If 1, - * the series header must also declare and implement a routine with - * this signature (it may also be provided as a macro): - * - * void _i2c_irq_priority_fixup(i2c_dev*) - * - * This will be called by i2c_enable_irq() before actually enabling - * I2C interrupts. - * - * - Reg. map base pointers, device pointer declarations. - */ - -#include -#include - -#include -#include -#include -#include - -/** - * @brief I2C message type - */ -typedef struct i2c_msg { - uint16 addr; /**< Address */ - -#define I2C_MSG_READ 0x1 -#define I2C_MSG_10BIT_ADDR 0x2 - /** - * Bitwise OR of: - * - I2C_MSG_READ (write is default) - * - I2C_MSG_10BIT_ADDR (7-bit is default) */ - uint16 flags; - - uint16 length; /**< Message length */ - uint16 xferred; /**< Messages transferred */ - uint8 *data; /**< Data */ -} i2c_msg; - -/* I2C enable options */ -#define I2C_FAST_MODE 0x1 // 400 khz -#define I2C_DUTY_16_9 0x2 // 16/9 duty ratio -/* Flag 0x4 is reserved; DO NOT USE. */ -#define I2C_BUS_RESET 0x8 // Perform a bus reset - -/* I2C error flags */ -#define I2C_ERROR_PROTOCOL (-1) -#define I2C_ERROR_TIMEOUT (-2) - -/* Main I2C API */ - -/** - * @brief Disable an I2C device - * - * This function disables the corresponding peripheral and marks dev's - * state as I2C_STATE_DISABLED. - * - * @param dev Device to disable. - */ -static inline void i2c_disable(i2c_dev *dev) { - dev->regs->CR1 &= ~I2C_CR1_PE; - dev->state = I2C_STATE_DISABLED; -} - -/** - * @brief Wait for an I2C event, or time out in case of error. - * @param dev I2C device - * @param state I2C_state state to wait for - * @param timeout Timeout, in milliseconds - * @return 0 if target state is reached, a negative value on error. - */ -extern int32 wait_for_state_change(i2c_dev *dev, - i2c_state state, - uint32 timeout); - -/** - * @brief Reset an I2C bus. - * - * Reset is accomplished by clocking out pulses until any hung slaves - * release SDA and SCL, then generating a START condition, then a STOP - * condition. - * - * @param dev I2C device - */ -extern void i2c_bus_reset(const i2c_dev *dev); - -/** - * @brief Initialize an I2C device as bus master - * @param dev Device to enable - * @param flags Bitwise or of the following I2C options: - * I2C_FAST_MODE: 400 khz operation, - * I2C_DUTY_16_9: 16/9 Tlow/Thigh duty cycle (only applicable for - * fast mode), - * I2C_BUS_RESET: Reset the bus and clock out any hung slaves on - * initialization, - * I2C_10BIT_ADDRESSING: Enable 10-bit addressing, - * I2C_REMAP: (deprecated, STM32F1 only) Remap I2C1 to SCL/PB8 - * SDA/PB9. - */ -extern void i2c_master_enable(i2c_dev *dev, uint32 flags); - -/** - * @brief Process an i2c transaction. - * - * Transactions are composed of one or more i2c_msg's, and may be read - * or write tranfers. Multiple i2c_msg's will generate a repeated - * start in between messages. - * - * @param dev I2C device - * @param msgs Messages to send/receive - * @param num Number of messages to send/receive - * @param timeout Bus idle timeout in milliseconds before aborting the - * transfer. 0 denotes no timeout. - * @return 0 on success, - * I2C_ERROR_PROTOCOL if there was a protocol error, - * I2C_ERROR_TIMEOUT if the transfer timed out. - */ -extern int32 i2c_master_xfer(i2c_dev *dev, - i2c_msg *msgs, - uint16 num, - uint32 timeout); - -/** - * @brief Fill data register with slave address - * @param dev I2C device - * @param addr Slave address - * @param rw Read/write bit - */ -extern void i2c_send_slave_addr(i2c_dev *dev, uint32 addr, uint32 rw); - -/* Start/stop conditions */ - -/** - * @brief Generate a start condition on the bus. - * @param dev I2C device - */ -extern void i2c_start_condition(i2c_dev *dev); - -/** - * @brief Generate a stop condition on the bus - * @param dev I2C device - */ -extern void i2c_stop_condition(i2c_dev *dev); - -/* IRQ enable/disable */ - -#ifndef _I2C_HAVE_IRQ_FIXUP -/* The series header provides this if _I2C_HAVE_IRQ_FIXUP is defined, - * but we need it either way. */ -#define _i2c_irq_priority_fixup(dev) ((void)0) -#endif - -/** - * @brief Enable one or more I2C interrupts - * @param dev I2C device - * @param irqs Bitwise or of: - * I2C_IRQ_ERROR (error interrupt), - * I2C_IRQ_EVENT (event interrupt), and - * I2C_IRQ_BUFFER (buffer interrupt). - */ -extern void i2c_enable_irq(i2c_dev *dev, uint32 irqs); - -/** - * @brief Disable one or more I2C interrupts - * @param dev I2C device - * @param irqs Bitwise or of: - * I2C_IRQ_ERROR (error interrupt), - * I2C_IRQ_EVENT (event interrupt), and - * I2C_IRQ_BUFFER (buffer interrupt). - */ -extern void i2c_disable_irq(i2c_dev *dev, uint32 irqs); - -/* ACK/NACK */ - -/** - * @brief Enable I2C acknowledgment - * @param dev I2C device - */ -extern void i2c_enable_ack(i2c_dev *dev); - -/** - * @brief Disable I2C acknowledgment - * @param dev I2C device - */ -extern void i2c_disable_ack(i2c_dev *dev); - -/* GPIO control */ - -/** - * @brief Configure device GPIOs. - * - * Configure GPIO bits dev->sda_pin and dev->scl_pin on GPIO device - * dev->gpio_port for use with I2C device dev. - * - * @param dev I2C Device - * @see i2c_release_gpios() - */ -extern void i2c_config_gpios(const i2c_dev *dev); - -/** - * @brief Release GPIOs controlling an I2C bus - * - * Releases the I2C bus controlled by dev as master, and disconnects - * GPIO bits dev->sda_pin and dev->scl_pin on GPIO device - * dev->gpio_port from I2C device dev. - * - * @param dev I2C device - * @see i2c_config_gpios() - */ -extern void i2c_master_release_bus(const i2c_dev *dev); - -/* Miscellaneous low-level routines */ - -/** - * @brief Initialize an I2C device and reset its registers to their - * default values. - * @param dev Device to initialize. - */ -void i2c_init(i2c_dev *dev); - -/** - * @brief Turn on an I2C peripheral - * @param dev Device to enable - */ -static inline void i2c_peripheral_enable(i2c_dev *dev) { - dev->regs->CR1 |= I2C_CR1_PE; -} - -/** - * @brief Turn off an I2C peripheral - * @param dev Device to turn off - */ -static inline void i2c_peripheral_disable(i2c_dev *dev) { - dev->regs->CR1 &= ~I2C_CR1_PE; -} - -/** - * @brief Fill transmit register - * @param dev I2C device - * @param byte Byte to write - */ -extern void i2c_write(i2c_dev *dev, uint8 byte); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/i2c_common.h b/STM32F3/cores/maple/libmaple/include/libmaple/i2c_common.h deleted file mode 100644 index 17cabe3..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/i2c_common.h +++ /dev/null @@ -1,93 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung (from ). - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/i2c_common.h - * @author Marti Bolivar - * @brief This file is an implementation detail - * - * CONTENTS UNSTABLE. The existence of this file is an implementation - * detail. Never include it directly. If you need something from - * here, include instead. - */ - -#ifndef _LIBMAPLE_I2C_COMMON_H_ -#define _LIBMAPLE_I2C_COMMON_H_ - -#include -#include -#include - -struct gpio_dev; -struct i2c_reg_map; -struct i2c_msg; - -/** I2C device states */ -typedef enum i2c_state { - I2C_STATE_DISABLED = 0, /**< Disabled */ - I2C_STATE_IDLE = 1, /**< Idle */ - I2C_STATE_XFER_DONE = 2, /**< Done with transfer */ - I2C_STATE_BUSY = 3, /**< Busy */ - I2C_STATE_ERROR = -1 /**< Error occurred */ -} i2c_state; - -/** - * @brief I2C device type. - */ -typedef struct i2c_dev { - struct i2c_reg_map *regs; /**< Register map */ - struct i2c_msg *msg; /**< Messages */ - uint32 error_flags; /**< Error flags, set on I2C error condition */ - volatile uint32 timestamp; /**< For internal use */ - - /** - * @brief Deprecated. Use .scl_port or .sda_port instead. - * If non-null, this will be used as SDA, SCL pins' GPIO port. If - * null, then .sda_port will be used for SDA, and .sda_port for - * SDA. */ - struct gpio_dev *gpio_port; - - /** - * @brief SDA GPIO device (but see .gpio_port). - */ - struct gpio_dev *sda_port; - - /** - * @brief SCL GPIO device (but see .gpio_port). - */ - struct gpio_dev *scl_port; - - uint16 msgs_left; /**< Messages left */ - uint8 sda_pin; /**< SDA bit on gpio_port */ - uint8 scl_pin; /**< SCL bit on gpio_port */ - rcc_clk_id clk_id; /**< RCC clock information */ - nvic_irq_num ev_nvic_line; /**< Event IRQ number */ - nvic_irq_num er_nvic_line; /**< Error IRQ number */ - volatile i2c_state state; /**< Device state */ -} i2c_dev; - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/iwdg.h b/STM32F3/cores/maple/libmaple/include/libmaple/iwdg.h deleted file mode 100644 index f999439..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/iwdg.h +++ /dev/null @@ -1,115 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Michael Hope. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/iwdg.h - * @author Michael Hope, Marti Bolivar - * @brief Independent watchdog support. - * - * To use the independent watchdog, first call iwdg_init() with the - * appropriate prescaler and IWDG counter reload values for your - * application. Afterwards, you must periodically call iwdg_feed() - * before the IWDG counter reaches 0 to reset the counter to its - * reload value. If you do not, the chip will reset. - * - * Once started, the independent watchdog cannot be turned off. - */ - -#ifndef _LIBMAPLE_IWDG_H_ -#define _LIBMAPLE_IWDG_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/* - * Register map - */ - -/** Independent watchdog register map type. */ -typedef struct iwdg_reg_map { - __IO uint32 KR; /**< Key register. */ - __IO uint32 PR; /**< Prescaler register. */ - __IO uint32 RLR; /**< Reload register. */ - __IO uint32 SR; /**< Status register */ -} iwdg_reg_map; - -/** Independent watchdog base pointer */ -#define IWDG_BASE ((struct iwdg_reg_map*)0x40003000) - -/* - * Register bit definitions - */ - -/* Key register */ - -#define IWDG_KR_UNLOCK 0x5555 -#define IWDG_KR_FEED 0xAAAA -#define IWDG_KR_START 0xCCCC - -/* Prescaler register */ - -#define IWDG_PR_DIV_4 0x0 -#define IWDG_PR_DIV_8 0x1 -#define IWDG_PR_DIV_16 0x2 -#define IWDG_PR_DIV_32 0x3 -#define IWDG_PR_DIV_64 0x4 -#define IWDG_PR_DIV_128 0x5 -#define IWDG_PR_DIV_256 0x6 - -/* Status register */ - -#define IWDG_SR_RVU_BIT 1 -#define IWDG_SR_PVU_BIT 0 - -#define IWDG_SR_RVU (1U << IWDG_SR_RVU_BIT) -#define IWDG_SR_PVU (1U << IWDG_SR_PVU_BIT) - -/** - * @brief Independent watchdog prescalers. - * - * These divide the 40 kHz IWDG clock. - */ -typedef enum iwdg_prescaler { - IWDG_PRE_4 = IWDG_PR_DIV_4, /**< Divide by 4 */ - IWDG_PRE_8 = IWDG_PR_DIV_8, /**< Divide by 8 */ - IWDG_PRE_16 = IWDG_PR_DIV_16, /**< Divide by 16 */ - IWDG_PRE_32 = IWDG_PR_DIV_32, /**< Divide by 32 */ - IWDG_PRE_64 = IWDG_PR_DIV_64, /**< Divide by 64 */ - IWDG_PRE_128 = IWDG_PR_DIV_128, /**< Divide by 128 */ - IWDG_PRE_256 = IWDG_PR_DIV_256 /**< Divide by 256 */ -} iwdg_prescaler; - -void iwdg_init(iwdg_prescaler prescaler, uint16 reload); -void iwdg_feed(void); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/libmaple.h b/STM32F3/cores/maple/libmaple/include/libmaple/libmaple.h deleted file mode 100644 index c9034d7..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/libmaple.h +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/libmaple.h - * @brief General include file for libmaple - */ - -#ifndef _LIBMAPLE_LIBMAPLE_H_ -#define _LIBMAPLE_LIBMAPLE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/libmaple_types.h b/STM32F3/cores/maple/libmaple/include/libmaple/libmaple_types.h deleted file mode 100644 index c0a989a..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/libmaple_types.h +++ /dev/null @@ -1,73 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/libmaple_types.h - * - * @brief libmaple's types, and operations on types. - */ - -#ifndef _LIBMAPLE_LIBMAPLE_TYPES_H_ -#define _LIBMAPLE_LIBMAPLE_TYPES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned int uint32; -typedef unsigned long long uint64; - -typedef signed char int8; -typedef short int16; -typedef int int32; -typedef long long int64; - -typedef void (*voidFuncPtr)(void); -typedef void (*voidArgumentFuncPtr)(void *); - -#define __IO volatile -#define __attr_flash __attribute__((section (".USER_FLASH"))) -#define __packed __attribute__((__packed__)) -#define __deprecated __attribute__((__deprecated__)) -#define __weak __attribute__((weak)) -#define __always_inline inline __attribute__((always_inline)) -#define __unused __attribute__((unused)) - -#ifndef NULL -#define NULL 0 -#endif - -#ifndef offsetof -#define offsetof(type, member) __builtin_offsetof(type, member) -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/nvic.h b/STM32F3/cores/maple/libmaple/include/libmaple/nvic.h deleted file mode 100644 index 7699604..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/nvic.h +++ /dev/null @@ -1,155 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/nvic.h - * @brief Nested vectored interrupt controller support. - * - * Basic usage: - * - * @code - * // Initialise the interrupt controller and point to the vector - * // table at the start of flash. - * nvic_init(0x08000000, 0); - * // Bind in a timer interrupt handler - * timer_attach_interrupt(TIMER_CC1_INTERRUPT, handler); - * // Optionally set the priority - * nvic_irq_set_priority(NVIC_TIMER1_CC, 5); - * // All done, enable all interrupts - * nvic_globalirq_enable(); - * @endcode - */ - -#ifndef _LIBMAPLE_NVIC_H_ -#define _LIBMAPLE_NVIC_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include - -/** NVIC register map type. */ -typedef struct nvic_reg_map { - __IO uint32 ISER[8]; /**< Interrupt Set Enable Registers */ - /** Reserved */ - uint32 RESERVED0[24]; - - __IO uint32 ICER[8]; /**< Interrupt Clear Enable Registers */ - /** Reserved */ - uint32 RESERVED1[24]; - - __IO uint32 ISPR[8]; /**< Interrupt Set Pending Registers */ - /** Reserved */ - uint32 RESERVED2[24]; - - __IO uint32 ICPR[8]; /**< Interrupt Clear Pending Registers */ - /** Reserved */ - uint32 RESERVED3[24]; - - __IO uint32 IABR[8]; /**< Interrupt Active bit Registers */ - /** Reserved */ - uint32 RESERVED4[56]; - - __IO uint8 IP[240]; /**< Interrupt Priority Registers */ - /** Reserved */ - uint32 RESERVED5[644]; - - __IO uint32 STIR; /**< Software Trigger Interrupt Registers */ -} nvic_reg_map; - -/** NVIC register map base pointer. */ -#define NVIC_BASE ((struct nvic_reg_map*)0xE000E100) - -/* - * Note: The series header must define enum nvic_irq_num, which gives - * descriptive names to the interrupts and exceptions from NMI (-14) - * to the largest interrupt available in the series, where the value - * for nonnegative enumerators corresponds to its position in the - * vector table. - * - * It also must define a static inline nvic_irq_disable_all(), which - * writes 0xFFFFFFFF to all ICE registers available in the series. (We - * place the include here to give the series header access to - * NVIC_BASE, in order to let it do so). - */ -#include - -void nvic_init(uint32 address, uint32 offset); -void nvic_set_vector_table(uint32 address, uint32 offset); -void nvic_irq_set_priority(nvic_irq_num irqn, uint8 priority); -void nvic_sys_reset(); - -/** - * Enables interrupts and configurable fault handlers (clear PRIMASK). - */ -static __always_inline void nvic_globalirq_enable() { - asm volatile("cpsie i"); -} - -/** - * Disable interrupts and configurable fault handlers (set PRIMASK). - */ -static __always_inline void nvic_globalirq_disable() { - asm volatile("cpsid i"); -} - -/** - * @brief Enable interrupt irq_num - * @param irq_num Interrupt to enable - */ -static inline void nvic_irq_enable(nvic_irq_num irq_num) { - if (irq_num < 0) { - return; - } - NVIC_BASE->ISER[irq_num / 32] = BIT(irq_num % 32); -} - -/** - * @brief Disable interrupt irq_num - * @param irq_num Interrupt to disable - */ -static inline void nvic_irq_disable(nvic_irq_num irq_num) { - if (irq_num < 0) { - return; - } - NVIC_BASE->ICER[irq_num / 32] = BIT(irq_num % 32); -} - -/** - * @brief Quickly disable all interrupts. - * - * Calling this function is significantly faster than calling - * nvic_irq_disable() in a loop. - */ -static inline void nvic_irq_disable_all(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/opamp.h b/STM32F3/cores/maple/libmaple/include/libmaple/opamp.h deleted file mode 100644 index 2a0be62..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/opamp.h +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -/** - * @file libmaple/include/libmaple/fpu.h - * @author F3-port by Hanspeter Portner - * @brief Floating Point Unit (OPAMP) interace. - */ - -#ifndef _LIBMAPLE_OPAMP_H_ -#define _LIBMAPLE_OPAMP_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/pwr.h b/STM32F3/cores/maple/libmaple/include/libmaple/pwr.h deleted file mode 100644 index 6087c9b..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/pwr.h +++ /dev/null @@ -1,115 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/pwr.h - * @brief Power control (PWR). - */ - -#ifndef _LIBMAPLE_PWR_H_ -#define _LIBMAPLE_PWR_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -/** Power interface register map. */ -typedef struct pwr_reg_map { - __IO uint32 CR; /**< Control register */ - __IO uint32 CSR; /**< Control and status register */ -} pwr_reg_map; - -/** Power peripheral register map base pointer. */ -#define PWR_BASE ((struct pwr_reg_map*)0x40007000) - -/* - * Register bit definitions - */ - -/* Control register */ - -/** Disable backup domain write protection bit */ -#define PWR_CR_DBP_BIT 8 -/** Power voltage detector enable bit */ -#define PWR_CR_PVDE_BIT 4 -/** Clear standby flag bit */ -#define PWR_CR_CSBF_BIT 3 -/** Clear wakeup flag bit */ -#define PWR_CR_CWUF_BIT 2 -/** Power down deepsleep bit */ -#define PWR_CR_PDDS_BIT 1 -/** Low-power deepsleep bit */ -#define PWR_CR_LPDS_BIT 0 - -/** Disable backup domain write protection */ -#define PWR_CR_DBP (1U << PWR_CR_DBP_BIT) -/** Power voltage detector (PVD) level selection */ -#define PWR_CR_PLS (0x7 << 5) -/** Power voltage detector enable */ -#define PWR_CR_PVDE (1U << PWR_CR_PVDE_BIT) -/** Clear standby flag */ -#define PWR_CR_CSBF (1U << PWR_CR_CSBF_BIT) -/** Clear wakeup flag */ -#define PWR_CR_CWUF (1U << PWR_CR_CWUF_BIT) -/** Power down deepsleep */ -#define PWR_CR_PDDS (1U << PWR_CR_PDDS_BIT) -/** Low-power deepsleep */ -#define PWR_CR_LPDS (1U << PWR_CR_LPDS_BIT) - -/* Control and status register */ - -/** Enable wakeup pin bit */ -#define PWR_CSR_EWUP_BIT 8 -/** PVD output bit */ -#define PWR_CSR_PVDO_BIT 2 -/** Standby flag bit */ -#define PWR_CSR_SBF_BIT 1 -/** Wakeup flag bit */ -#define PWR_CSR_WUF_BIT 0 - -/** Enable wakeup pin */ -#define PWR_CSR_EWUP (1U << PWR_CSR_EWUP_BIT) -/** PVD output */ -#define PWR_CSR_PVDO (1U << PWR_CSR_PVDO_BIT) -/** Standby flag */ -#define PWR_CSR_SBF (1U << PWR_CSR_SBF_BIT) -/** Wakeup flag */ -#define PWR_CSR_WUF (1U << PWR_CSR_WUF_BIT) - -/* - * Convenience functions - */ - -void pwr_init(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/rcc.h b/STM32F3/cores/maple/libmaple/include/libmaple/rcc.h deleted file mode 100644 index ea16803..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/rcc.h +++ /dev/null @@ -1,175 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/rcc.h - * @brief Reset and Clock Control (RCC) interface. - */ - -#ifndef _LIBMAPLE_RCC_H_ -#define _LIBMAPLE_RCC_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/* Put the SYSCLK sources before the series header is included, as it - * might need them. */ -/** - * @brief SYSCLK sources - * @see rcc_switch_sysclk() - */ -typedef enum rcc_sysclk_src { - RCC_CLKSRC_HSI = 0x0, - RCC_CLKSRC_HSE = 0x1, - RCC_CLKSRC_PLL = 0x2, -} rcc_sysclk_src; - -#include - -/* Note: Beyond the usual (registers, etc.), it's up to the series - * header to define the following types: - * - * - enum rcc_clk: Available system and secondary clock sources, - * e.g. RCC_CLK_HSE, RCC_CLK_PLL, RCC_CLK_LSE. - * - * Note that the inclusion of secondary clock sources (like LSI and - * LSE) makes enum rcc_clk different from the SYSCLK sources, which - * are defined in this header as enum rcc_sysclk_src. - * - * IMPORTANT NOTE TO IMPLEMENTORS: If you are adding support for a - * new STM32 series, see the comment near rcc_clk_reg() in - * libmaple/rcc.c for information on how to choose these values so - * that rcc_turn_on_clk() etc. will work on your series. - * - * - enum rcc_clk_id: For each available peripheral. These are widely used - * as unique IDs (TODO extricate from RCC?). Peripherals which are - * common across STM32 series should use the same token for their - * rcc_clk_id in each series header. - * - * - enum rcc_clk_domain: For each clock domain. This is returned by - * rcc_dev_clk(). For instance, each AHB and APB is a clock domain. - * - * - enum rcc_prescaler: And a suitable set of dividers for - * rcc_set_prescaler(). - * - * - enum rcc_pllsrc: For each PLL source. Same source, same token. - * - * - A target-dependent type to be pointed to by the data field in a - * struct rcc_pll_cfg. - */ - -#ifdef __DOXYGEN__ -/** RCC register map base pointer */ -#define RCC_BASE -#endif - -/* Clock prescaler management. */ - -/** - * @brief Set the divider on a peripheral prescaler - * @param prescaler prescaler to set - * @param divider prescaler divider - */ -extern void rcc_set_prescaler(rcc_prescaler prescaler, uint32 divider); - -/* SYSCLK. */ - -void rcc_switch_sysclk(rcc_sysclk_src sysclk_src); - -/* PLL configuration */ - -/** - * @brief Specifies a configuration for the main PLL. - */ -typedef struct rcc_pll_cfg { - rcc_pllsrc pllsrc; /**< PLL source */ - - /** Series-specific configuration data. */ - void *data; -} rcc_pll_cfg; - -/** - * @brief Configure the main PLL. - * - * You may only call this function while the PLL is disabled. - * - * @param pll_cfg Desired PLL configuration. The contents of this - * struct depend entirely on the target. - */ -extern void rcc_configure_pll(rcc_pll_cfg *pll_cfg); - -/* System and secondary clock sources. */ - -void rcc_turn_on_clk(rcc_clk clock); -void rcc_turn_off_clk(rcc_clk clock); -int rcc_is_clk_on(rcc_clk clock); -int rcc_is_clk_ready(rcc_clk clock); - -/* Peripheral clock lines and clock domains. */ - -/** - * @brief Turn on the clock line on a peripheral - * @param id Clock ID of the peripheral to turn on. - */ -extern void rcc_clk_enable(rcc_clk_id id); - -/** - * @brief Reset a peripheral. - * - * Caution: not all rcc_clk_id values refer to a peripheral which can - * be reset. (Only rcc_clk_ids for peripherals with bits in an RCC - * reset register can be used here.) - * - * @param id Clock ID of the peripheral to reset. - */ -extern void rcc_reset_dev(rcc_clk_id id); - -rcc_clk_domain rcc_dev_clk(rcc_clk_id id); - -/* Clock security system */ - -/** - * @brief Enable the clock security system (CSS). - */ -static inline void rcc_enable_css() { - RCC_BASE->CR |= RCC_CR_CSSON; -} - -/** - * @brief Disable the clock security system (CSS). - */ -static inline void rcc_disable_css() { - RCC_BASE->CR &= ~RCC_CR_CSSON; -} - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/ring_buffer.h b/STM32F3/cores/maple/libmaple/include/libmaple/ring_buffer.h deleted file mode 100644 index 633c29a..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/ring_buffer.h +++ /dev/null @@ -1,188 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/ring_buffer.h - * @brief Simple circular buffer - * - * This implementation is not thread-safe. In particular, none of - * these functions is guaranteed re-entrant. - */ - -#ifndef _LIBMAPLE_RING_BUFFER_H_ -#define _LIBMAPLE_RING_BUFFER_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/** - * Ring buffer type. - * - * The buffer is empty when head == tail. - * - * The buffer is full when the head is one byte in front of the tail, - * modulo buffer length. - * - * One byte is left free to distinguish empty from full. */ -typedef struct ring_buffer { - volatile uint8 *buf; /**< Buffer items are stored into */ - uint16 head; /**< Index of the next item to remove */ - uint16 tail; /**< Index where the next item will get inserted */ - uint16 size; /**< Buffer capacity minus one */ -} ring_buffer; - -/** - * Initialise a ring buffer. - * - * @param rb Instance to initialise - * - * @param size Number of items in buf. The ring buffer will always - * leave one element unoccupied, so the maximum number of - * elements it can store will be size - 1. Thus, size - * must be at least 2. - * - * @param buf Buffer to store items into - */ -static inline void rb_init(ring_buffer *rb, uint16 size, uint8 *buf) { - rb->head = 0; - rb->tail = 0; - rb->size = size - 1; - rb->buf = buf; -} - -/** - * @brief Return the number of elements stored in the ring buffer. - * @param rb Buffer whose elements to count. - */ -static inline uint16 rb_full_count(ring_buffer *rb) { - __IO ring_buffer *arb = rb; - int32 size = arb->tail - arb->head; - if (arb->tail < arb->head) { - size += arb->size + 1; - } - return (uint16)size; -} - -/** - * @brief Returns true if and only if the ring buffer is full. - * @param rb Buffer to test. - */ -static inline int rb_is_full(ring_buffer *rb) { - return (rb->tail + 1 == rb->head) || - (rb->tail == rb->size && rb->head == 0); -} - -/** - * @brief Returns true if and only if the ring buffer is empty. - * @param rb Buffer to test. - */ -static inline int rb_is_empty(ring_buffer *rb) { - return rb->head == rb->tail; -} - -/** - * Append element onto the end of a ring buffer. - * @param rb Buffer to append onto. - * @param element Value to append. - */ -static inline void rb_insert(ring_buffer *rb, uint8 element) { - rb->buf[rb->tail] = element; - rb->tail = (rb->tail == rb->size) ? 0 : rb->tail + 1; -} - -/** - * @brief Remove and return the first item from a ring buffer. - * @param rb Buffer to remove from, must contain at least one element. - */ -static inline uint8 rb_remove(ring_buffer *rb) { - uint8 ch = rb->buf[rb->head]; - rb->head = (rb->head == rb->size) ? 0 : rb->head + 1; - return ch; -} - -/** - * @brief Attempt to remove the first item from a ring buffer. - * - * If the ring buffer is nonempty, removes and returns its first item. - * If it is empty, does nothing and returns a negative value. - * - * @param rb Buffer to attempt to remove from. - */ -static inline int16 rb_safe_remove(ring_buffer *rb) { - return rb_is_empty(rb) ? -1 : rb_remove(rb); -} - -/** - * @brief Attempt to insert an element into a ring buffer. - * - * @param rb Buffer to insert into. - * @param element Value to insert into rb. - * @sideeffect If rb is not full, appends element onto buffer. - * @return If element was appended, then true; otherwise, false. */ -static inline int rb_safe_insert(ring_buffer *rb, uint8 element) { - if (rb_is_full(rb)) { - return 0; - } - rb_insert(rb, element); - return 1; -} - -/** - * @brief Append an item onto the end of a non-full ring buffer. - * - * If the buffer is full, removes its first item, then inserts the new - * element at the end. - * - * @param rb Ring buffer to insert into. - * @param element Value to insert into ring buffer. - * @return On success, returns -1. If an element was popped, returns - * the popped value. - */ -static inline int rb_push_insert(ring_buffer *rb, uint8 element) { - int ret = -1; - if (rb_is_full(rb)) { - ret = rb_remove(rb); - } - rb_insert(rb, element); - return ret; -} - -/** - * @brief Discard all items from a ring buffer. - * @param rb Ring buffer to discard all items from. - */ -static inline void rb_reset(ring_buffer *rb) { - rb->tail = rb->head; -} - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/scb.h b/STM32F3/cores/maple/libmaple/include/libmaple/scb.h deleted file mode 100644 index 0b01480..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/scb.h +++ /dev/null @@ -1,214 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011-2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/scb.h - * @brief System control block header - */ - -/* - * FIXME: STM32F2? - */ - -#ifndef _LIBMAPLE_SCB_H_ -#define _LIBMAPLE_SCB_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* - * Register map and base pointer - */ - -/** System control block register map type */ -typedef struct scb_reg_map { - __IO uint32 CPUID; /**< CPU ID Base Register */ - __IO uint32 ICSR; /**< Interrupt Control State Register */ - __IO uint32 VTOR; /**< Vector Table Offset Register */ - __IO uint32 AIRCR; /**< Application Interrupt / Reset Control Register */ - __IO uint32 SCR; /**< System Control Register */ - __IO uint32 CCR; /**< Configuration and Control Register */ - __IO uint8 SHP[12]; /**< System Handler Priority Registers - (4-7, 8-11, 12-15) */ - __IO uint32 SHCSR; /**< System Handler Control and State Register */ - __IO uint32 CFSR; /**< Configurable Fault Status Register */ - __IO uint32 HFSR; /**< Hard Fault Status Register */ - /* DFSR is not documented by ST in PM0056 (as of Revision 4), but - * there's a 4 byte hole in the SCB register map docs right where - * it belongs. Since it's specified as "always implemented" in - * the ARM v7-M ARM, I'm assuming its absence is a bug in the ST - * doc, but I haven't proven it. [mbolivar] */ - __IO uint32 DFSR; /**< Debug Fault Status Register */ - __IO uint32 MMFAR; /**< Mem Manage Address Register */ - __IO uint32 BFAR; /**< Bus Fault Address Register */ -#if 0 - /* The following registers are implementation-defined according to - * ARM v7-M, and I can't find evidence of their existence in ST's - * docs. I'm removing them. Feel free to yell at me if they do - * exist. [mbolivar] - */ - __IO uint32 AFSR; /**< Auxiliary Fault Status Register */ - __IO uint32 PFR[2]; /**< Processor Feature Register */ - __IO uint32 DFR; /**< Debug Feature Register */ - __IO uint32 AFR; /**< Auxiliary Feature Register */ - __IO uint32 MMFR[4]; /**< Memory Model Feature Register */ - __IO uint32 ISAR[5]; /**< ISA Feature Register */ -#endif -} scb_reg_map; - -/** System control block register map base pointer */ -#define SCB_BASE ((struct scb_reg_map*)0xE000ED00) - -/* - * Register bit definitions - */ - -/* No SCB_REG_FIELD_BIT macros as the relevant addresses are not in a - * bit-band region. */ - -/* CPUID base register (SCB_CPUID) */ - -#define SCB_CPUID_IMPLEMENTER (0xFF << 24) -#define SCB_CPUID_VARIANT (0xF << 20) -#define SCB_CPUID_CONSTANT (0xF << 16) -#define SCB_CPUID_PARTNO (0xFFF << 4) -#define SCB_CPUID_REVISION 0xF - -/* Interrupt control state register (SCB_ICSR) */ - -#define SCB_ICSR_NMIPENDSET (1U << 31) -#define SCB_ICSR_PENDSVSET (1U << 28) -#define SCB_ICSR_PENDSVCLR (1U << 27) -#define SCB_ICSR_PENDSTSET (1U << 26) -#define SCB_ICSR_PENDSTCLR (1U << 25) -#define SCB_ICSR_ISRPENDING (1U << 22) -#define SCB_ICSR_VECTPENDING (0x3FF << 12) -#define SCB_ICSR_RETOBASE (1U << 11) -#define SCB_ICSR_VECTACTIVE 0xFF - -/* Vector table offset register (SCB_VTOR) */ - -#define SCB_VTOR_TBLOFF (0x1FFFFF << 9) - -/* Application interrupt and reset control register (SCB_AIRCR) */ - -#define SCB_AIRCR_VECTKEYSTAT (0x5FA << 16) -#define SCB_AIRCR_VECTKEY (0x5FA << 16) -#define SCB_AIRCR_ENDIANNESS (1U << 15) -#define SCB_AIRCR_PRIGROUP (0x3 << 8) -#define SCB_AIRCR_SYSRESETREQ (1U << 2) -#define SCB_AIRCR_VECTCLRACTIVE (1U << 1) -#define SCB_AIRCR_VECTRESET (1U << 0) - -/* System control register (SCB_SCR) */ - -#define SCB_SCR_SEVONPEND (1U << 4) -#define SCB_SCR_SLEEPDEEP (1U << 2) -#define SCB_SCR_SLEEPONEXIT (1U << 1) - -/* Configuration and Control Register (SCB_CCR) */ - -#define SCB_CCR_STKALIGN (1U << 9) -#define SCB_CCR_BFHFNMIGN (1U << 8) -#define SCB_CCR_DIV_0_TRP (1U << 4) -#define SCB_CCR_UNALIGN_TRP (1U << 3) -#define SCB_CCR_USERSETMPEND (1U << 1) -#define SCB_CCR_NONBASETHRDENA (1U << 0) - -/* System handler priority registers (SCB_SHPRx) */ - -#define SCB_SHPR1_PRI6 (0xFF << 16) -#define SCB_SHPR1_PRI5 (0xFF << 8) -#define SCB_SHPR1_PRI4 0xFF - -#define SCB_SHPR2_PRI11 (0xFF << 24) - -#define SCB_SHPR3_PRI15 (0xFF << 24) -#define SCB_SHPR3_PRI14 (0xFF << 16) - -/* System Handler Control and state register (SCB_SHCSR) */ - -#define SCB_SHCSR_USGFAULTENA (1U << 18) -#define SCB_SHCSR_BUSFAULTENA (1U << 17) -#define SCB_SHCSR_MEMFAULTENA (1U << 16) -#define SCB_SHCSR_SVCALLPENDED (1U << 15) -#define SCB_SHCSR_BUSFAULTPENDED (1U << 14) -#define SCB_SHCSR_MEMFAULTPENDED (1U << 13) -#define SCB_SHCSR_USGFAULTPENDED (1U << 12) -#define SCB_SHCSR_SYSTICKACT (1U << 11) -#define SCB_SHCSR_PENDSVACT (1U << 10) -#define SCB_SHCSR_MONITORACT (1U << 8) -#define SCB_SHCSR_SVCALLACT (1U << 7) -#define SCB_SHCSR_USGFAULTACT (1U << 3) -#define SCB_SHCSR_BUSFAULTACT (1U << 1) -#define SCB_SHCSR_MEMFAULTACT (1U << 0) - -/* Configurable fault status register (SCB_CFSR) */ - -#define SCB_CFSR_DIVBYZERO (1U << 25) -#define SCB_CFSR_UNALIGNED (1U << 24) -#define SCB_CFSR_NOCP (1U << 19) -#define SCB_CFSR_INVPC (1U << 18) -#define SCB_CFSR_INVSTATE (1U << 17) -#define SCB_CFSR_UNDEFINSTR (1U << 16) -#define SCB_CFSR_BFARVALID (1U << 15) -#define SCB_CFSR_STKERR (1U << 12) -#define SCB_CFSR_UNSTKERR (1U << 11) -#define SCB_CFSR_IMPRECISERR (1U << 10) -#define SCB_CFSR_PRECISERR (1U << 9) -#define SCB_CFSR_IBUSERR (1U << 8) -#define SCB_CFSR_MMARVALID (1U << 7) -#define SCB_CFSR_MSTKERR (1U << 4) -#define SCB_CFSR_MUNSTKERR (1U << 3) -#define SCB_CFSR_DACCVIOL (1U << 1) -#define SCB_CFSR_IACCVIOL (1U << 0) - -/* Hard Fault Status Register (SCB_HFSR) */ - -#define SCB_HFSR_DEBUG_VT (1U << 31) -#define SCB_CFSR_FORCED (1U << 30) -#define SCB_CFSR_VECTTBL (1U << 1) - -/* Debug Fault Status Register */ - -/* Not specified by PM0056, but required by ARM. The bit definitions - * here are based on the names given in the ARM v7-M ARM. */ - -#define SCB_DFSR_EXTERNAL (1U << 4) -#define SCB_DFSR_VCATCH (1U << 3) -#define SCB_DFSR_DWTTRAP (1U << 2) -#define SCB_DFSR_BKPT (1U << 1) -#define SCB_DFSR_HALTED (1U << 0) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/spi.h b/STM32F3/cores/maple/libmaple/include/libmaple/spi.h deleted file mode 100644 index 5c09170..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/spi.h +++ /dev/null @@ -1,487 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/spi.h - * @author Marti Bolivar , - * F3-port by Hanspeter Portner - * @brief Serial Peripheral Interface (SPI) and Integrated - * Interchip Sound (I2S) peripheral support. - * - * I2S support is currently limited to register maps and bit definitions. - */ - -#ifndef _LIBMAPLE_SPI_H_ -#define _LIBMAPLE_SPI_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -/* - * Register maps - */ - -/** SPI register map type. */ -typedef struct spi_reg_map { - __IO uint32 CR1; /**< Control register 1 */ - __IO uint32 CR2; /**< Control register 2 */ - __IO uint32 SR; /**< Status register */ - __IO uint32 DR; /**< Data register */ - __IO uint32 CRCPR; /**< CRC polynomial register */ - __IO uint32 RXCRCR; /**< RX CRC register */ - __IO uint32 TXCRCR; /**< TX CRC register */ - __IO uint32 I2SCFGR; /**< I2S configuration register */ - __IO uint32 I2SPR; /**< I2S prescaler register */ -} spi_reg_map; - -/* - * Register bit definitions - */ - -/* Control register 1 */ - -#define SPI_CR1_BIDIMODE_BIT 15 -#define SPI_CR1_BIDIOE_BIT 14 -#define SPI_CR1_CRCEN_BIT 13 -#define SPI_CR1_CRCNEXT_BIT 12 -#define SPI_CR1_DFF_BIT 11 /* FIXME F3 incompatibility */ -#define SPI_CR1_RXONLY_BIT 10 -#define SPI_CR1_SSM_BIT 9 -#define SPI_CR1_SSI_BIT 8 -#define SPI_CR1_LSBFIRST_BIT 7 -#define SPI_CR1_SPE_BIT 6 -#define SPI_CR1_MSTR_BIT 2 -#define SPI_CR1_CPOL_BIT 1 -#define SPI_CR1_CPHA_BIT 0 - -#define SPI_CR1_BIDIMODE (1U << SPI_CR1_BIDIMODE_BIT) -#define SPI_CR1_BIDIMODE_2_LINE (0x0 << SPI_CR1_BIDIMODE_BIT) -#define SPI_CR1_BIDIMODE_1_LINE (0x1 << SPI_CR1_BIDIMODE_BIT) -#define SPI_CR1_BIDIOE (1U << SPI_CR1_BIDIOE_BIT) -#define SPI_CR1_CRCEN (1U << SPI_CR1_CRCEN_BIT) -#define SPI_CR1_CRCNEXT (1U << SPI_CR1_CRCNEXT_BIT) -#define SPI_CR1_DFF (1U << SPI_CR1_DFF_BIT) -#define SPI_CR1_DFF_8_BIT (0x0 << SPI_CR1_DFF_BIT) -#define SPI_CR1_DFF_16_BIT (0x1 << SPI_CR1_DFF_BIT) -#define SPI_CR1_RXONLY (1U << SPI_CR1_RXONLY_BIT) -#define SPI_CR1_SSM (1U << SPI_CR1_SSM_BIT) -#define SPI_CR1_SSI (1U << SPI_CR1_SSI_BIT) -#define SPI_CR1_LSBFIRST (1U << SPI_CR1_LSBFIRST_BIT) -#define SPI_CR1_SPE (1U << SPI_CR1_SPE_BIT) -#define SPI_CR1_BR (0x7 << 3) -#define SPI_CR1_BR_PCLK_DIV_2 (0x0 << 3) -#define SPI_CR1_BR_PCLK_DIV_4 (0x1 << 3) -#define SPI_CR1_BR_PCLK_DIV_8 (0x2 << 3) -#define SPI_CR1_BR_PCLK_DIV_16 (0x3 << 3) -#define SPI_CR1_BR_PCLK_DIV_32 (0x4 << 3) -#define SPI_CR1_BR_PCLK_DIV_64 (0x5 << 3) -#define SPI_CR1_BR_PCLK_DIV_128 (0x6 << 3) -#define SPI_CR1_BR_PCLK_DIV_256 (0x7 << 3) -#define SPI_CR1_MSTR (1U << SPI_CR1_MSTR_BIT) -#define SPI_CR1_CPOL (1U << SPI_CR1_CPOL_BIT) -#define SPI_CR1_CPOL_LOW (0x0 << SPI_CR1_CPOL_BIT) -#define SPI_CR1_CPOL_HIGH (0x1 << SPI_CR1_CPOL_BIT) -#define SPI_CR1_CPHA (1U << SPI_CR1_CPHA_BIT) - -/* Control register 2 */ - -#define SPI_CR2_TXEIE_BIT 7 -#define SPI_CR2_RXNEIE_BIT 6 -#define SPI_CR2_ERRIE_BIT 5 -#define SPI_CR2_SSOE_BIT 2 -#define SPI_CR2_TXDMAEN_BIT 1 -#define SPI_CR2_RXDMAEN_BIT 0 - -#define SPI_CR2_TXEIE (1U << SPI_CR2_TXEIE_BIT) -#define SPI_CR2_RXNEIE (1U << SPI_CR2_RXNEIE_BIT) -#define SPI_CR2_ERRIE (1U << SPI_CR2_ERRIE_BIT) -#define SPI_CR2_SSOE (1U << SPI_CR2_SSOE_BIT) -#define SPI_CR2_TXDMAEN (1U << SPI_CR2_TXDMAEN_BIT) -#define SPI_CR2_RXDMAEN (1U << SPI_CR2_RXDMAEN_BIT) - -/* Status register */ - -#define SPI_SR_BSY_BIT 7 -#define SPI_SR_OVR_BIT 6 -#define SPI_SR_MODF_BIT 5 -#define SPI_SR_CRCERR_BIT 4 -#define SPI_SR_UDR_BIT 3 -#define SPI_SR_CHSIDE_BIT 2 -#define SPI_SR_TXE_BIT 1 -#define SPI_SR_RXNE_BIT 0 - -#define SPI_SR_BSY (1U << SPI_SR_BSY_BIT) -#define SPI_SR_OVR (1U << SPI_SR_OVR_BIT) -#define SPI_SR_MODF (1U << SPI_SR_MODF_BIT) -#define SPI_SR_CRCERR (1U << SPI_SR_CRCERR_BIT) -#define SPI_SR_UDR (1U << SPI_SR_UDR_BIT) -#define SPI_SR_CHSIDE (1U << SPI_SR_CHSIDE_BIT) -#define SPI_SR_CHSIDE_LEFT (0x0 << SPI_SR_CHSIDE_BIT) -#define SPI_SR_CHSIDE_RIGHT (0x1 << SPI_SR_CHSIDE_BIT) -#define SPI_SR_TXE (1U << SPI_SR_TXE_BIT) -#define SPI_SR_RXNE (1U << SPI_SR_RXNE_BIT) - -/* I2S configuration register */ - -#define SPI_I2SCFGR_I2SMOD_BIT 11 -#define SPI_I2SCFGR_I2SE_BIT 10 -#define SPI_I2SCFGR_PCMSYNC_BIT 7 -#define SPI_I2SCFGR_CKPOL_BIT 3 -#define SPI_I2SCFGR_CHLEN_BIT 0 - -#define SPI_I2SCFGR_I2SMOD (1U << SPI_I2SCFGR_I2SMOD_BIT) -#define SPI_I2SCFGR_I2SMOD_SPI (0x0 << SPI_I2SCFGR_I2SMOD_BIT) -#define SPI_I2SCFGR_I2SMOD_I2S (0x1 << SPI_I2SCFGR_I2SMOD_BIT) -#define SPI_I2SCFGR_I2SE (1U << SPI_I2SCFGR_I2SE_BIT) -#define SPI_I2SCFGR_I2SCFG (0x3 << 8) -#define SPI_I2SCFGR_I2SCFG_SLAVE_TX (0x0 << 8) -#define SPI_I2SCFGR_I2SCFG_SLAVE_RX (0x1 << 8) -#define SPI_I2SCFGR_I2SCFG_MASTER_TX (0x2 << 8) -#define SPI_I2SCFGR_I2SCFG_MASTER_RX (0x3 << 8) -#define SPI_I2SCFGR_PCMSYNC (1U << SPI_I2SCFGR_PCMSYNC_BIT) -#define SPI_I2SCFGR_PCMSYNC_SHORT (0x0 << SPI_I2SCFGR_PCMSYNC_BIT) -#define SPI_I2SCFGR_PCMSYNC_LONG (0x1 << SPI_I2SCFGR_PCMSYNC_BIT) -#define SPI_I2SCFGR_I2SSTD (0x3 << 4) -#define SPI_I2SCFGR_I2SSTD_PHILLIPS (0x0 << 4) -#define SPI_I2SCFGR_I2SSTD_MSB (0x1 << 4) -#define SPI_I2SCFGR_I2SSTD_LSB (0x2 << 4) -#define SPI_I2SCFGR_I2SSTD_PCM (0x3 << 4) -#define SPI_I2SCFGR_CKPOL (1U << SPI_I2SCFGR_CKPOL_BIT) -#define SPI_I2SCFGR_CKPOL_LOW (0x0 << SPI_I2SCFGR_CKPOL_BIT) -#define SPI_I2SCFGR_CKPOL_HIGH (0x1 << SPI_I2SCFGR_CKPOL_BIT) -#define SPI_I2SCFGR_DATLEN (0x3 << 1) -#define SPI_I2SCFGR_DATLEN_16_BIT (0x0 << 1) -#define SPI_I2SCFGR_DATLEN_24_BIT (0x1 << 1) -#define SPI_I2SCFGR_DATLEN_32_BIT (0x2 << 1) -#define SPI_I2SCFGR_CHLEN (1U << SPI_I2SCFGR_CHLEN_BIT) -#define SPI_I2SCFGR_CHLEN_16_BIT (0x0 << SPI_I2SCFGR_CHLEN_BIT) -#define SPI_I2SCFGR_CHLEN_32_BIT (0x1 << SPI_I2SCFGR_CHLEN_BIT) - -/* I2S prescaler register */ - -#define SPI_I2SPR_MCKOE_BIT 9 -#define SPI_I2SPR_ODD_BIT 8 - -#define SPI_I2SPR_MCKOE (1U << SPI_I2SPR_MCKOE_BIT) -#define SPI_I2SPR_ODD (1U << SPI_I2SPR_ODD_BIT) -#define SPI_I2SPR_I2SDIV 0xFF - -/* - * Devices - */ - -/** SPI device type */ -typedef struct spi_dev { - spi_reg_map *regs; /**< Register map */ - rcc_clk_id clk_id; /**< RCC clock information */ - nvic_irq_num irq_num; /**< NVIC interrupt number */ -} spi_dev; - -/* - * SPI Convenience functions - */ - -void spi_init(spi_dev *dev); - -struct gpio_dev; -/** - * @brief Configure GPIO bit modes for use as a SPI port's pins. - * - * @param dev SPI device - * @param as_master If true, configure as bus master; otherwise, as slave. - * @param nss_dev NSS pin's GPIO device - * @param nss_bit NSS pin's GPIO bit on nss_dev - * @param comm_dev SCK, MISO, MOSI pins' GPIO device - * @param sck_bit SCK pin's GPIO bit on comm_dev - * @param miso_bit MISO pin's GPIO bit on comm_dev - * @param mosi_bit MOSI pin's GPIO bit on comm_dev - */ -extern void spi_config_gpios(spi_dev *dev, - uint8 as_master, - struct gpio_dev *nss_dev, - uint8 nss_bit, - struct gpio_dev *comm_dev, - uint8 sck_bit, - uint8 miso_bit, - uint8 mosi_bit); - -/** - * @brief SPI mode configuration. - * - * A SPI mode determines a combination of the idle state of the clock - * line (the clock polarity, or "CPOL"), and which clock edge triggers - * data capture (the clock phase, or "CPHA"). - */ -typedef enum spi_mode { - /** Clock idles low, data captured on rising edge (first transition) */ - SPI_MODE_LOW_RISING = 0, - /** Clock idles low, data captured on falling edge (second transition) */ - SPI_MODE_LOW_FALLING = 1, - /** Clock idles high, data captured on falling edge (first transition) */ - SPI_MODE_HIGH_FALLING = 2, - /** Clock idles high, data captured on rising edge (second transition) */ - SPI_MODE_HIGH_RISING = 3, - - SPI_MODE_0 = SPI_MODE_LOW_RISING, /**< Same as SPI_MODE_LOW_RISING */ - SPI_MODE_1 = SPI_MODE_LOW_FALLING, /**< Same as SPI_MODE_LOW_FALLING */ - SPI_MODE_2 = SPI_MODE_HIGH_FALLING, /**< Same as SPI_MODE_HIGH_FALLING */ - SPI_MODE_3 = SPI_MODE_HIGH_RISING, /**< Same as SPI_MODE_HIGH_RISING */ -} spi_mode; - -/** - * @brief SPI baud rate configuration, as a divisor of f_PCLK, the - * PCLK clock frequency. - */ -typedef enum spi_baud_rate { - SPI_BAUD_PCLK_DIV_2 = SPI_CR1_BR_PCLK_DIV_2, /**< f_PCLK/2 */ - SPI_BAUD_PCLK_DIV_4 = SPI_CR1_BR_PCLK_DIV_4, /**< f_PCLK/4 */ - SPI_BAUD_PCLK_DIV_8 = SPI_CR1_BR_PCLK_DIV_8, /**< f_PCLK/8 */ - SPI_BAUD_PCLK_DIV_16 = SPI_CR1_BR_PCLK_DIV_16, /**< f_PCLK/16 */ - SPI_BAUD_PCLK_DIV_32 = SPI_CR1_BR_PCLK_DIV_32, /**< f_PCLK/32 */ - SPI_BAUD_PCLK_DIV_64 = SPI_CR1_BR_PCLK_DIV_64, /**< f_PCLK/64 */ - SPI_BAUD_PCLK_DIV_128 = SPI_CR1_BR_PCLK_DIV_128, /**< f_PCLK/128 */ - SPI_BAUD_PCLK_DIV_256 = SPI_CR1_BR_PCLK_DIV_256, /**< f_PCLK/256 */ -} spi_baud_rate; - -/** - * @brief SPI initialization flags. - * @see spi_master_enable() - * @see spi_slave_enable() - */ -typedef enum spi_cfg_flag { - SPI_BIDIMODE = SPI_CR1_BIDIMODE, /**< Bidirectional mode enable */ - SPI_BIDIOE = SPI_CR1_BIDIOE, /**< Output enable in bidirectional - mode */ - SPI_CRCEN = SPI_CR1_CRCEN, /**< Cyclic redundancy check (CRC) - enable */ - SPI_DFF_8_BIT = SPI_CR1_DFF_8_BIT, /**< 8-bit data frame format (this is - the default) */ - SPI_DFF_16_BIT = SPI_CR1_DFF_16_BIT, /**< 16-bit data frame format */ - SPI_RX_ONLY = SPI_CR1_RXONLY, /**< Receive only */ - SPI_SW_SLAVE = SPI_CR1_SSM, /**< Software slave management */ - SPI_SOFT_SS = SPI_CR1_SSI, /**< Software (internal) slave - select. This flag only has an - effect when used in combination - with SPI_SW_SLAVE. */ - SPI_FRAME_LSB = SPI_CR1_LSBFIRST, /**< LSB-first (little-endian) frame - format */ - SPI_FRAME_MSB = 0, /**< MSB-first (big-endian) frame - format (this is the default) */ -} spi_cfg_flag; - -void spi_master_enable(spi_dev *dev, - spi_baud_rate baud, - spi_mode mode, - uint32 flags); - -void spi_slave_enable(spi_dev *dev, - spi_mode mode, - uint32 flags); - -uint32 spi_tx(spi_dev *dev, const void *buf, uint32 len); - -/** - * @brief Call a function on each SPI port - * @param fn Function to call. - */ -extern void spi_foreach(void (*fn)(spi_dev*)); - -void spi_peripheral_enable(spi_dev *dev); -void spi_peripheral_disable(spi_dev *dev); - -void spi_tx_dma_enable(spi_dev *dev); -void spi_tx_dma_disable(spi_dev *dev); - -void spi_rx_dma_enable(spi_dev *dev); -void spi_rx_dma_disable(spi_dev *dev); - -/** - * @brief Determine if a SPI peripheral is enabled. - * @param dev SPI device - * @return True, if and only if dev's peripheral is enabled. - */ -static inline uint8 spi_is_enabled(spi_dev *dev) { - return dev->regs->CR1 & SPI_CR1_SPE_BIT; -} - -/** - * @brief Disable all SPI peripherals - */ -static inline void spi_peripheral_disable_all(void) { - spi_foreach(spi_peripheral_disable); -} - -/** Available SPI interrupts */ -typedef enum spi_interrupt { - SPI_TXE_INTERRUPT = SPI_CR2_TXEIE, /**< TX buffer empty interrupt */ - SPI_RXNE_INTERRUPT = SPI_CR2_RXNEIE, /**< RX buffer not empty interrupt */ - SPI_ERR_INTERRUPT = SPI_CR2_ERRIE /**< - * Error interrupt (CRC, overrun, - * and mode fault errors for SPI; - * underrun, overrun errors for I2S) - */ -} spi_interrupt; - -/** - * @brief Mask for all spi_interrupt values - * @see spi_interrupt - */ -#define SPI_INTERRUPTS_ALL (SPI_TXE_INTERRUPT | \ - SPI_RXNE_INTERRUPT | \ - SPI_ERR_INTERRUPT) - -/** - * @brief Enable SPI interrupt requests - * @param dev SPI device - * @param interrupt_flags Bitwise OR of spi_interrupt values to enable - * @see spi_interrupt - */ -static inline void spi_irq_enable(spi_dev *dev, uint32 interrupt_flags) { - dev->regs->CR2 |= interrupt_flags; - nvic_irq_enable(dev->irq_num); -} - -/** - * @brief Disable SPI interrupt requests - * @param dev SPI device - * @param interrupt_flags Bitwise OR of spi_interrupt values to disable - * @see spi_interrupt - */ -static inline void spi_irq_disable(spi_dev *dev, uint32 interrupt_flags) { - dev->regs->CR2 &= ~interrupt_flags; -} - -/** - * @brief Get the data frame format flags with which a SPI port is - * configured. - * @param dev SPI device whose data frame format to get. - * @return SPI_DFF_8_BIT, if dev has an 8-bit data frame format. - * Otherwise, SPI_DFF_16_BIT. - */ -static inline spi_cfg_flag spi_dff(spi_dev *dev) { - return ((dev->regs->CR1 & SPI_CR1_DFF) == SPI_CR1_DFF_8_BIT ? - SPI_DFF_8_BIT : - SPI_DFF_16_BIT); -} - -/** - * @brief Determine whether the device's peripheral receive (RX) - * register is empty. - * @param dev SPI device - * @return true, iff dev's RX register is empty. - */ -static inline uint8 spi_is_rx_nonempty(spi_dev *dev) { - return dev->regs->SR & SPI_SR_RXNE; -} - -/** - * @brief Retrieve the contents of the device's peripheral receive - * (RX) register. - * - * You may only call this function when the RX register is nonempty. - * Calling this function clears the contents of the RX register. - * - * @param dev SPI device - * @return Contents of dev's peripheral RX register - * @see spi_is_rx_reg_nonempty() - */ -extern uint16 spi_rx_reg(spi_dev *dev); - -/** - * @brief Determine whether the device's peripheral transmit (TX) - * register is empty. - * @param dev SPI device - * @return true, iff dev's TX register is empty. - */ -static inline uint8 spi_is_tx_empty(spi_dev *dev) { - return dev->regs->SR & SPI_SR_TXE; -} - -/** - * @brief Nonblocking SPI transmit. - * @param dev SPI port to use for transmission - * @param buf Buffer to transmit. The sizeof buf's elements are - * inferred from dev's data frame format (i.e., are - * correctly treated as 8-bit or 16-bit quantities). - * @param len Maximum number of elements to transmit. - * @return Number of elements transmitted. - */ -extern uint32 spi_tx(spi_dev *dev, const void *buf, uint32 len); - -/** - * @brief Load a value into the device's peripheral transmit (TX) register. - * - * You may only call this function when the TX register is empty. - * Calling this function loads val into the peripheral's TX register. - * If the device is properly configured, this will initiate a - * transmission, the completion of which will cause the TX register to - * be empty again. - * - * @param dev SPI device - * @param val Value to load into the TX register. If the SPI data - * frame format is 8 bit, the value must be right-aligned. - * @see spi_is_tx_reg_empty() - * @see spi_init() - * @see spi_master_enable() - * @see spi_slave_enable() - */ -static inline void spi_tx_reg(spi_dev *dev, uint16 val) { - dev->regs->DR = val; /* FIXME F3 incompatibility */ -} - -/** - * @brief Determine whether the device's peripheral busy (SPI_SR_BSY) - * flag is set. - * @param dev SPI device - * @return true, iff dev's BSY flag is set. - */ -static inline uint8 spi_is_busy(spi_dev *dev) { - return dev->regs->SR & SPI_SR_BSY; -} - -/* - * SPI auxiliary routines - */ - -extern void spi_reconfigure(spi_dev *dev, uint32 cr1_config); - -/* - * I2S convenience functions (TODO) - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/stm32.h b/STM32F3/cores/maple/libmaple/include/libmaple/stm32.h deleted file mode 100644 index f7ced23..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/stm32.h +++ /dev/null @@ -1,239 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010, 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/stm32.h - * @brief STM32 chip header - * - * This header supplies various chip-specific values for the current - * build target. It's useful both to abstract away hardware details - * (e.g. through use of STM32_NR_INTERRUPTS) and to decide what to do - * when you want something nonportable (e.g. by checking - * STM32_MCU_SERIES). - */ - -#ifndef _LIBMAPLE_STM32_H_ -#define _LIBMAPLE_STM32_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * STM32 series identifiers. - * - * Don't make these into an enum; the preprocessor needs them. - */ - -/** STM32F1 series. */ -#define STM32_SERIES_F1 0 -/** STM32F2 series. */ -#define STM32_SERIES_F2 1 -/** STM32L1 series. */ -#define STM32_SERIES_L1 2 -/** STM32F3 series. */ -#define STM32_SERIES_F3 3 -/** STM32F4 series. */ -#define STM32_SERIES_F4 4 - -/* The series header is responsible for defining: - * - * - Everything in the following __DOXYGEN__ conditional block. - * - * - STM32_HAVE_FSMC: 1 if the MCU has the FSMC peripheral, and 0 - * otherwise. - * - * - STM32_HAVE_USB: 1 if the MCU has a USB peripheral, and 0 - * otherwise. - */ -#include - -/* Ensure the series header isn't broken. */ -#if (!defined(STM32_PCLK1) || \ - !defined(STM32_PCLK2) || \ - !defined(STM32_MCU_SERIES) || \ - !defined(STM32_NR_INTERRUPTS) || \ - !defined(STM32_NR_GPIO_PORTS) || \ - !defined(STM32_TIMER_MASK) || \ - !defined(STM32_DELAY_US_MULT) || \ - !defined(STM32_SRAM_END) || \ - !defined(STM32_HAVE_DAC) || \ - !defined(STM32_HAVE_FSMC) || \ - !defined(STM32_HAVE_USB)) -#error "Bad STM32F1 configuration. Check header for your MCU." -#endif - -/* - * Derived macros - */ - -/* FIXME [0.0.13] add this to ReST API page */ -/** - * @brief Statically determine whether a timer is present. - * - * Given a constant timer number n (starting from 1), this macro has a - * nonzero value exactly when TIMERn is available. - */ -#define STM32_HAVE_TIMER(n) (STM32_TIMER_MASK & (1 << (n))) - -/* - * Doxygen for functionality provided by series header. - */ - -#ifdef __DOXYGEN__ - -/* - * Clock configuration. - * - * These defines depend upon how the MCU is configured. Because of - * the potential for a mismatch between them and the actual clock - * configuration, keep their number to a minimum. - */ - -/** - * @brief APB1 clock speed, in Hz. - */ -#define STM32_PCLK1 - -/** - * @brief APB2 clock speed, in Hz. - */ -#define STM32_PCLK2 - -/** @brief Deprecated. Use STM32_PCLK1 instead. */ -#define PCLK1 -/** @brief Deprecated. Use STM32_PCLK2 instead. */ -#define PCLK2 - -/* - * Series- and MCU-specific values. - */ - -/** - * @brief STM32 series value for the MCU being targeted. - * - * At time of writing, allowed values are: STM32_SERIES_F1, - * STM32_SERIES_F2. This set of values will expand as libmaple adds - * support for more STM32 series MCUs. - */ -#define STM32_MCU_SERIES - -/** - * @brief Number of interrupts in the vector table. - * - * This does not include Cortex-M interrupts (NMI, HardFault, etc.). - */ -#define STM32_NR_INTERRUPTS - -/** - * Number of GPIO ports. - */ -#define STM32_NR_GPIO_PORTS - -/* FIXME [0.0.13] add this to ReST API page */ -/** - * @brief Bitmask of timers available on the MCU. - * - * That is, if TIMERn is available, then STM32_TIMER_MASK & (1 << n) - * will be nonzero. For example, a nonzero value of "STM32_TIMER_MASK - * & 0x2" means TIMER1 is available. - * - * A bitmask is necessary as some STM32 MCUs have "holes" in the range - * of available timers. - */ -#define STM32_TIMER_MASK - -/** - * @brief Multiplier to convert microseconds into loop iterations - * in delay_us(). - * - * @see delay_us() - */ -#define STM32_DELAY_US_MULT - -/** - * @brief Pointer to end of built-in SRAM. - * - * Points to the address which is 1 byte past the last valid - * SRAM address. - */ -#define STM32_SRAM_END - -/** - * @brief 1 if the target MCU has a DAC, and 0 otherwise. - */ -#define STM32_HAVE_DAC - -/** - * @brief 1 if the target MCU has the FSMC peripheral, and 0 otherwise. - * - * Note that the feature set of the FSMC peripheral is restricted on - * some MCUs. - */ -#define STM32_HAVE_FSMC - -/** - * @brief 1 if the target MCU has a USB peripheral, and 0 otherwise. - * - * Note that a variety of USB peripherals are available across the - * different series, with widely varying feature sets and programming - * interfaces. This macro will be 1 if any such peripheral is present. - */ -#define STM32_HAVE_USB - -#endif /* __DOXYGEN__ */ - -/* - * The following are for backwards compatibility only. - */ - -/* PCLK1 and PCLK2 are for backwards compatibility only; don't use in - * new code. */ -#ifndef PCLK1 -#define PCLK1 STM32_PCLK1 -#endif -#if PCLK1 != STM32_PCLK1 -#error "PCLK1 (which is deprecated) differs from STM32_PCLK1." -#endif -#ifndef PCLK2 -#define PCLK2 STM32_PCLK2 -#endif -#if PCLK2 != STM32_PCLK2 -#error "PCLK2 (which is deprecated) differs from STM32_PCLK2." -#endif - -/** @brief Deprecated. Use STM32_NR_INTERRUPTS instead. */ -#define NR_INTERRUPTS STM32_NR_INTERRUPTS -/** @brief Deprecated. Use STM32_NR_GPIO_PORTS instead. */ -#define NR_GPIO_PORTS STM32_NR_GPIO_PORTS -/** @brief Deprecated. Use STM32_DELAY_US_MULT instead. */ -#define DELAY_US_MULT STM32_DELAY_US_MULT - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/syscfg.h b/STM32F3/cores/maple/libmaple/include/libmaple/syscfg.h deleted file mode 100644 index b8c901f..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/syscfg.h +++ /dev/null @@ -1,116 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/syscfg.h - * @author F3-port by Hanspeter Portner - * @brief System configuration controller (SYSCFG) - * - * Availability: STM32F2, STM32F3, STM32F4. - */ - -#ifndef _LIBMAPLE_SYSCFG_H_ -#define _LIBMAPLE_SYSCFG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -/* External interrupt configuration register 1 */ - -#define SYSCFG_EXTICR1_EXTI0 0xF -#define SYSCFG_EXTICR1_EXTI1 0xF0 -#define SYSCFG_EXTICR1_EXTI2 0xF00 -#define SYSCFG_EXTICR1_EXTI3 0xF000 - -/* External interrupt configuration register 2 */ - -#define SYSCFG_EXTICR2_EXTI4 0xF -#define SYSCFG_EXTICR2_EXTI5 0xF0 -#define SYSCFG_EXTICR2_EXTI6 0xF00 -#define SYSCFG_EXTICR2_EXTI7 0xF000 - -/* External interrupt configuration register 3 */ - -#define SYSCFG_EXTICR3_EXTI8 0xF -#define SYSCFG_EXTICR3_EXTI9 0xF0 -#define SYSCFG_EXTICR3_EXTI10 0xF00 -#define SYSCFG_EXTICR3_EXTI11 0xF000 - -/* External interrupt configuration register 4 */ - -#define SYSCFG_EXTICR4_EXTI12 0xF -#define SYSCFG_EXTICR4_EXTI13 0xF0 -#define SYSCFG_EXTICR4_EXTI14 0xF00 -#define SYSCFG_EXTICR4_EXTI15 0xF000 - -/* - * Routines - */ - -/** - * @brief Initialize the SYSCFG peripheral. - */ -void syscfg_init(void); - -/** - * @brief System memory mode - * These values specify what memory to map to address 0x00000000. - * @see syscfg_set_mem_mode - */ -typedef enum syscfg_mem_mode { - /** Main flash memory is mapped at 0x0. */ - SYSCFG_MEM_MODE_FLASH = 0x0, - /** System flash (i.e. ST's baked-in bootloader) is mapped at 0x0. */ - SYSCFG_MEM_MODE_SYSTEM_FLASH = 0x1, - /** FSMC bank 1 (NOR/PSRAM 1 and 2) is mapped at 0x0. */ - SYSCFG_MEM_MODE_FSMC_BANK_1 = 0x2, - /** Embedded SRAM (i.e., not backup SRAM) is mapped at 0x0. */ - SYSCFG_MEM_MODE_SRAM = 0x3, -} syscfg_mem_mode; - - -/** - * @brief Set the memory to be mapped at address 0x00000000. - * - * This function can be used to override the BOOT pin - * configuration. Some restrictions apply; see your chip's reference - * manual for the details. - * - * @param mode Mode to set - * @see syscfg_mem_mode - */ -void syscfg_set_mem_mode(syscfg_mem_mode); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/systick.h b/STM32F3/cores/maple/libmaple/include/libmaple/systick.h deleted file mode 100644 index 815a1c3..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/systick.h +++ /dev/null @@ -1,115 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/systick.h - * @brief System timer definitions - */ - -#ifndef _LIBMAPLE_SYSTICK_H_ -#define _LIBMAPLE_SYSTICK_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include - -/** SysTick register map type */ -typedef struct systick_reg_map { - __IO uint32 CSR; /**< Control and status register */ - __IO uint32 RVR; /**< Reload value register */ - __IO uint32 CNT; /**< Current value register ("count") */ - __IO uint32 CVR; /**< Calibration value register */ -} systick_reg_map; - -/** SysTick register map base pointer */ -#define SYSTICK_BASE ((struct systick_reg_map*)0xE000E010) - -/* - * Register bit definitions. - */ - -/* Control and status register */ - -#define SYSTICK_CSR_COUNTFLAG BIT(16) -#define SYSTICK_CSR_CLKSOURCE BIT(2) -#define SYSTICK_CSR_CLKSOURCE_EXTERNAL 0 -#define SYSTICK_CSR_CLKSOURCE_CORE BIT(2) -#define SYSTICK_CSR_TICKINT BIT(1) -#define SYSTICK_CSR_TICKINT_PEND BIT(1) -#define SYSTICK_CSR_TICKINT_NO_PEND 0 -#define SYSTICK_CSR_ENABLE BIT(0) -#define SYSTICK_CSR_ENABLE_MULTISHOT BIT(0) -#define SYSTICK_CSR_ENABLE_DISABLED 0 - -/* Calibration value register */ - -#define SYSTICK_CVR_NOREF BIT(31) -#define SYSTICK_CVR_SKEW BIT(30) -#define SYSTICK_CVR_TENMS 0xFFFFFF - -/** System elapsed time, in milliseconds */ -extern volatile uint32 systick_uptime_millis; - -/** - * @brief Returns the system uptime, in milliseconds. - */ -static inline uint32 systick_uptime(void) { - return systick_uptime_millis; -} - - -void systick_init(uint32 reload_val); -void systick_disable(); -void systick_enable(); - -/** - * @brief Returns the current value of the SysTick counter. - */ -static inline uint32 systick_get_count(void) { - return SYSTICK_BASE->CNT; -} - -/** - * @brief Check for underflow. - * - * This function returns 1 if the SysTick timer has counted to 0 since - * the last time it was called. However, any reads of any part of the - * SysTick Control and Status Register SYSTICK_BASE->CSR will - * interfere with this functionality. See the ARM Cortex M3 Technical - * Reference Manual for more details (e.g. Table 8-3 in revision r1p1). - */ -static inline uint32 systick_check_underflow(void) { - return SYSTICK_BASE->CSR & SYSTICK_CSR_COUNTFLAG; -} - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/timer.h b/STM32F3/cores/maple/libmaple/include/libmaple/timer.h deleted file mode 100644 index 51a5623..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/timer.h +++ /dev/null @@ -1,1119 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/timer.h - * @author Marti Bolivar - * @brief Timer interface. - */ - -#ifndef _LIBMAPLE_TIMER_H_ -#define _LIBMAPLE_TIMER_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include -#include -#include -#include - -/* - * Register maps - */ - -/** Advanced control timer register map type */ -typedef struct timer_adv_reg_map { - __IO uint32 CR1; /**< Control register 1 */ - __IO uint32 CR2; /**< Control register 2 */ - __IO uint32 SMCR; /**< Slave mode control register */ - __IO uint32 DIER; /**< DMA/interrupt enable register */ - __IO uint32 SR; /**< Status register */ - __IO uint32 EGR; /**< Event generation register */ - __IO uint32 CCMR1; /**< Capture/compare mode register 1 */ - __IO uint32 CCMR2; /**< Capture/compare mode register 2 */ - __IO uint32 CCER; /**< Capture/compare enable register */ - __IO uint32 CNT; /**< Counter */ - __IO uint32 PSC; /**< Prescaler */ - __IO uint32 ARR; /**< Auto-reload register */ - __IO uint32 RCR; /**< Repetition counter register */ - __IO uint32 CCR1; /**< Capture/compare register 1 */ - __IO uint32 CCR2; /**< Capture/compare register 2 */ - __IO uint32 CCR3; /**< Capture/compare register 3 */ - __IO uint32 CCR4; /**< Capture/compare register 4 */ - __IO uint32 BDTR; /**< Break and dead-time register */ - __IO uint32 DCR; /**< DMA control register */ - __IO uint32 DMAR; /**< DMA address for full transfer */ -} timer_adv_reg_map; - -/* General purpose timer register map type: intentionally omitted. - * - * General purpose timers differ slightly across series, so leave it - * up to the series header to define struct timer_gen_reg_map. */ - -/** Basic timer register map type */ -typedef struct timer_bas_reg_map { - __IO uint32 CR1; /**< Control register 1 */ - __IO uint32 CR2; /**< Control register 2 */ - const uint32 RESERVED1; /**< Reserved */ - __IO uint32 DIER; /**< DMA/interrupt enable register */ - __IO uint32 SR; /**< Status register */ - __IO uint32 EGR; /**< Event generation register */ - const uint32 RESERVED2; /**< Reserved */ - const uint32 RESERVED3; /**< Reserved */ - const uint32 RESERVED4; /**< Reserved */ - __IO uint32 CNT; /**< Counter */ - __IO uint32 PSC; /**< Prescaler */ - __IO uint32 ARR; /**< Auto-reload register */ -} timer_bas_reg_map; - -/* - * Timer devices - */ - -/** - * @brief Timer register map type. - * - * Just holds a pointer to the correct type of register map, based on - * the timer's type. - */ -typedef union timer_reg_map { - timer_adv_reg_map *adv; /**< Advanced register map */ - timer_gen_reg_map *gen; /**< General purpose register map */ - timer_bas_reg_map *bas; /**< Basic register map */ -} timer_reg_map; - -/** - * @brief Timer type - * - * Type marker for timer_dev. - * - * @see timer_dev - */ -typedef enum timer_type { - TIMER_ADVANCED, /**< Advanced type */ - TIMER_GENERAL, /**< General purpose type */ - TIMER_BASIC, /**< Basic type */ -} timer_type; - -/** Timer device type */ -typedef struct timer_dev { - timer_reg_map regs; /**< Register map */ - rcc_clk_id clk_id; /**< RCC clock information */ - timer_type type; /**< Timer's type */ - voidFuncPtr handlers[]; /**< - * Don't touch these. Use these instead: - * @see timer_attach_interrupt() - * @see timer_detach_interrupt() */ -} timer_dev; - -#if STM32_HAVE_TIMER(1) -extern timer_dev *TIMER1; -#endif -#if STM32_HAVE_TIMER(2) -extern timer_dev *TIMER2; -#endif -#if STM32_HAVE_TIMER(3) -extern timer_dev *TIMER3; -#endif -#if STM32_HAVE_TIMER(4) -extern timer_dev *TIMER4; -#endif -#if STM32_HAVE_TIMER(5) -extern timer_dev *TIMER5; -#endif -#if STM32_HAVE_TIMER(6) -extern timer_dev *TIMER6; -#endif -#if STM32_HAVE_TIMER(7) -extern timer_dev *TIMER7; -#endif -#if STM32_HAVE_TIMER(8) -extern timer_dev *TIMER8; -#endif -#if STM32_HAVE_TIMER(9) -extern timer_dev *TIMER9; -#endif -#if STM32_HAVE_TIMER(10) -extern timer_dev *TIMER10; -#endif -#if STM32_HAVE_TIMER(11) -extern timer_dev *TIMER11; -#endif -#if STM32_HAVE_TIMER(12) -extern timer_dev *TIMER12; -#endif -#if STM32_HAVE_TIMER(13) -extern timer_dev *TIMER13; -#endif -#if STM32_HAVE_TIMER(14) -extern timer_dev *TIMER14; -#endif -#if STM32_HAVE_TIMER(15) -extern timer_dev *TIMER15; -#endif -#if STM32_HAVE_TIMER(16) -extern timer_dev *TIMER16; -#endif -#if STM32_HAVE_TIMER(17) -extern timer_dev *TIMER17; -#endif - -/* - * Register bit definitions - */ - -/* Control register 1 (CR1) */ - -#define TIMER_CR1_ARPE_BIT 7 -#define TIMER_CR1_DIR_BIT 4 -#define TIMER_CR1_OPM_BIT 3 -#define TIMER_CR1_URS_BIT 2 -#define TIMER_CR1_UDIS_BIT 1 -#define TIMER_CR1_CEN_BIT 0 - -#define TIMER_CR1_CKD (0x3 << 8) -#define TIMER_CR1_CKD_1TCKINT (0x0 << 8) -#define TIMER_CR1_CKD_2TCKINT (0x1 << 8) -#define TIMER_CR1_CKD_4TICKINT (0x2 << 8) -#define TIMER_CR1_ARPE (1U << TIMER_CR1_ARPE_BIT) -#define TIMER_CR1_CKD_CMS (0x3 << 5) -#define TIMER_CR1_CKD_CMS_EDGE (0x0 << 5) -#define TIMER_CR1_CKD_CMS_CENTER1 (0x1 << 5) -#define TIMER_CR1_CKD_CMS_CENTER2 (0x2 << 5) -#define TIMER_CR1_CKD_CMS_CENTER3 (0x3 << 5) -#define TIMER_CR1_DIR (1U << TIMER_CR1_DIR_BIT) -#define TIMER_CR1_OPM (1U << TIMER_CR1_OPM_BIT) -#define TIMER_CR1_URS (1U << TIMER_CR1_URS_BIT) -#define TIMER_CR1_UDIS (1U << TIMER_CR1_UDIS_BIT) -#define TIMER_CR1_CEN (1U << TIMER_CR1_CEN_BIT) - -/* Control register 2 (CR2) */ - -#define TIMER_CR2_OIS4_BIT 14 -#define TIMER_CR2_OIS3N_BIT 13 -#define TIMER_CR2_OIS3_BIT 12 -#define TIMER_CR2_OIS2N_BIT 11 -#define TIMER_CR2_OIS2_BIT 10 -#define TIMER_CR2_OIS1N_BIT 9 -#define TIMER_CR2_OIS1_BIT 8 -#define TIMER_CR2_TI1S_BIT 7 -#define TIMER_CR2_CCDS_BIT 3 -#define TIMER_CR2_CCUS_BIT 2 -#define TIMER_CR2_CCPC_BIT 0 - -#define TIMER_CR2_OIS4 (1U << TIMER_CR2_OIS4_BIT) -#define TIMER_CR2_OIS3N (1U << TIMER_CR2_OIS3N_BIT) -#define TIMER_CR2_OIS3 (1U << TIMER_CR2_OIS3_BIT) -#define TIMER_CR2_OIS2N (1U << TIMER_CR2_OIS2N_BIT) -#define TIMER_CR2_OIS2 (1U << TIMER_CR2_OIS2_BIT) -#define TIMER_CR2_OIS1N (1U << TIMER_CR2_OIS1N_BIT) -#define TIMER_CR2_OIS1 (1U << TIMER_CR2_OIS1_BIT) -#define TIMER_CR2_TI1S (1U << TIMER_CR2_TI1S_BIT) -#define TIMER_CR2_MMS (0x7 << 4) -#define TIMER_CR2_MMS_RESET (0x0 << 4) -#define TIMER_CR2_MMS_ENABLE (0x1 << 4) -#define TIMER_CR2_MMS_UPDATE (0x2 << 4) -#define TIMER_CR2_MMS_COMPARE_PULSE (0x3 << 4) -#define TIMER_CR2_MMS_COMPARE_OC1REF (0x4 << 4) -#define TIMER_CR2_MMS_COMPARE_OC2REF (0x5 << 4) -#define TIMER_CR2_MMS_COMPARE_OC3REF (0x6 << 4) -#define TIMER_CR2_MMS_COMPARE_OC4REF (0x7 << 4) -#define TIMER_CR2_CCDS (1U << TIMER_CR2_CCDS_BIT) -#define TIMER_CR2_CCUS (1U << TIMER_CR2_CCUS_BIT) -#define TIMER_CR2_CCPC (1U << TIMER_CR2_CCPC_BIT) - -/* Slave mode control register (SMCR) */ - -#define TIMER_SMCR_ETP_BIT 15 -#define TIMER_SMCR_ECE_BIT 14 -#define TIMER_SMCR_MSM_BIT 7 - -#define TIMER_SMCR_ETP (1U << TIMER_SMCR_ETP_BIT) -#define TIMER_SMCR_ECE (1U << TIMER_SMCR_ECE_BIT) -#define TIMER_SMCR_ETPS (0x3 << 12) -#define TIMER_SMCR_ETPS_OFF (0x0 << 12) -#define TIMER_SMCR_ETPS_DIV2 (0x1 << 12) -#define TIMER_SMCR_ETPS_DIV4 (0x2 << 12) -#define TIMER_SMCR_ETPS_DIV8 (0x3 << 12) -#define TIMER_SMCR_ETF (0xF << 12) -#define TIMER_SMCR_MSM (1U << TIMER_SMCR_MSM_BIT) -#define TIMER_SMCR_TS (0x3 << 4) -#define TIMER_SMCR_TS_ITR0 (0x0 << 4) -#define TIMER_SMCR_TS_ITR1 (0x1 << 4) -#define TIMER_SMCR_TS_ITR2 (0x2 << 4) -#define TIMER_SMCR_TS_ITR3 (0x3 << 4) -#define TIMER_SMCR_TS_TI1F_ED (0x4 << 4) -#define TIMER_SMCR_TS_TI1FP1 (0x5 << 4) -#define TIMER_SMCR_TS_TI2FP2 (0x6 << 4) -#define TIMER_SMCR_TS_ETRF (0x7 << 4) -#define TIMER_SMCR_SMS 0x3 -#define TIMER_SMCR_SMS_DISABLED 0x0 -#define TIMER_SMCR_SMS_ENCODER1 0x1 -#define TIMER_SMCR_SMS_ENCODER2 0x2 -#define TIMER_SMCR_SMS_ENCODER3 0x3 -#define TIMER_SMCR_SMS_RESET 0x4 -#define TIMER_SMCR_SMS_GATED 0x5 -#define TIMER_SMCR_SMS_TRIGGER 0x6 -#define TIMER_SMCR_SMS_EXTERNAL 0x7 - -/* DMA/Interrupt enable register (DIER) */ - -#define TIMER_DIER_TDE_BIT 14 -#define TIMER_DIER_COMDE_BIT 13 -#define TIMER_DIER_CC4DE_BIT 12 -#define TIMER_DIER_CC3DE_BIT 11 -#define TIMER_DIER_CC2DE_BIT 10 -#define TIMER_DIER_CC1DE_BIT 9 -#define TIMER_DIER_UDE_BIT 8 -#define TIMER_DIER_BIE_BIT 7 -#define TIMER_DIER_TIE_BIT 6 -#define TIMER_DIER_COMIE_BIT 5 -#define TIMER_DIER_CC4IE_BIT 4 -#define TIMER_DIER_CC3IE_BIT 3 -#define TIMER_DIER_CC2IE_BIT 2 -#define TIMER_DIER_CC1IE_BIT 1 -#define TIMER_DIER_UIE_BIT 0 - -#define TIMER_DIER_TDE (1U << TIMER_DIER_TDE_BIT) -#define TIMER_DIER_COMDE (1U << TIMER_DIER_COMDE_BIT) -#define TIMER_DIER_CC4DE (1U << TIMER_DIER_CC4DE_BIT) -#define TIMER_DIER_CC3DE (1U << TIMER_DIER_CC3DE_BIT) -#define TIMER_DIER_CC2DE (1U << TIMER_DIER_CC2DE_BIT) -#define TIMER_DIER_CC1DE (1U << TIMER_DIER_CC1DE_BIT) -#define TIMER_DIER_UDE (1U << TIMER_DIER_UDE_BIT) -#define TIMER_DIER_BIE (1U << TIMER_DIER_BIE_BIT) -#define TIMER_DIER_TIE (1U << TIMER_DIER_TIE_BIT) -#define TIMER_DIER_COMIE (1U << TIMER_DIER_COMIE_BIT) -#define TIMER_DIER_CC4IE (1U << TIMER_DIER_CC4IE_BIT) -#define TIMER_DIER_CC3IE (1U << TIMER_DIER_CC3IE_BIT) -#define TIMER_DIER_CC2IE (1U << TIMER_DIER_CC2IE_BIT) -#define TIMER_DIER_CC1IE (1U << TIMER_DIER_CC1IE_BIT) -#define TIMER_DIER_UIE (1U << TIMER_DIER_UIE_BIT) - -/* Status register (SR) */ - -#define TIMER_SR_CC4OF_BIT 12 -#define TIMER_SR_CC3OF_BIT 11 -#define TIMER_SR_CC2OF_BIT 10 -#define TIMER_SR_CC1OF_BIT 9 -#define TIMER_SR_BIF_BIT 7 -#define TIMER_SR_TIF_BIT 6 -#define TIMER_SR_COMIF_BIT 5 -#define TIMER_SR_CC4IF_BIT 4 -#define TIMER_SR_CC3IF_BIT 3 -#define TIMER_SR_CC2IF_BIT 2 -#define TIMER_SR_CC1IF_BIT 1 -#define TIMER_SR_UIF_BIT 0 - -#define TIMER_SR_CC4OF (1U << TIMER_SR_CC4OF_BIT) -#define TIMER_SR_CC3OF (1U << TIMER_SR_CC3OF_BIT) -#define TIMER_SR_CC2OF (1U << TIMER_SR_CC2OF_BIT) -#define TIMER_SR_CC1OF (1U << TIMER_SR_CC1OF_BIT) -#define TIMER_SR_BIF (1U << TIMER_SR_BIF_BIT) -#define TIMER_SR_TIF (1U << TIMER_SR_TIF_BIT) -#define TIMER_SR_COMIF (1U << TIMER_SR_COMIF_BIT) -#define TIMER_SR_CC4IF (1U << TIMER_SR_CC4IF_BIT) -#define TIMER_SR_CC3IF (1U << TIMER_SR_CC3IF_BIT) -#define TIMER_SR_CC2IF (1U << TIMER_SR_CC2IF_BIT) -#define TIMER_SR_CC1IF (1U << TIMER_SR_CC1IF_BIT) -#define TIMER_SR_UIF (1U << TIMER_SR_UIF_BIT) - -/* Event generation register (EGR) */ - -#define TIMER_EGR_BG_BIT 7 -#define TIMER_EGR_TG_BIT 6 -#define TIMER_EGR_COMG_BIT 5 -#define TIMER_EGR_CC4G_BIT 4 -#define TIMER_EGR_CC3G_BIT 3 -#define TIMER_EGR_CC2G_BIT 2 -#define TIMER_EGR_CC1G_BIT 1 -#define TIMER_EGR_UG_BIT 0 - -#define TIMER_EGR_BG (1U << TIMER_EGR_BG_BIT) -#define TIMER_EGR_TG (1U << TIMER_EGR_TG_BIT) -#define TIMER_EGR_COMG (1U << TIMER_EGR_COMG_BIT) -#define TIMER_EGR_CC4G (1U << TIMER_EGR_CC4G_BIT) -#define TIMER_EGR_CC3G (1U << TIMER_EGR_CC3G_BIT) -#define TIMER_EGR_CC2G (1U << TIMER_EGR_CC2G_BIT) -#define TIMER_EGR_CC1G (1U << TIMER_EGR_CC1G_BIT) -#define TIMER_EGR_UG (1U << TIMER_EGR_UG_BIT) - -/* Capture/compare mode registers, common values */ - -#define TIMER_CCMR_CCS_OUTPUT 0x0 -#define TIMER_CCMR_CCS_INPUT_TI1 0x1 -#define TIMER_CCMR_CCS_INPUT_TI2 0x2 -#define TIMER_CCMR_CCS_INPUT_TRC 0x3 - -/* Capture/compare mode register 1 (CCMR1) */ - -#define TIMER_CCMR1_OC2CE_BIT 15 -#define TIMER_CCMR1_OC2PE_BIT 11 -#define TIMER_CCMR1_OC2FE_BIT 10 -#define TIMER_CCMR1_OC1CE_BIT 7 -#define TIMER_CCMR1_OC1PE_BIT 3 -#define TIMER_CCMR1_OC1FE_BIT 2 - -#define TIMER_CCMR1_OC2CE (1U << TIMER_CCMR1_OC2CE_BIT) -#define TIMER_CCMR1_OC2M (0x3 << 12) -#define TIMER_CCMR1_IC2F (0xF << 12) -#define TIMER_CCMR1_OC2PE (1U << TIMER_CCMR1_OC2PE_BIT) -#define TIMER_CCMR1_OC2FE (1U << TIMER_CCMR1_OC2FE_BIT) -#define TIMER_CCMR1_IC2PSC (0x3 << 10) -#define TIMER_CCMR1_CC2S (0x3 << 8) -#define TIMER_CCMR1_CC2S_OUTPUT (TIMER_CCMR_CCS_OUTPUT << 8) -#define TIMER_CCMR1_CC2S_INPUT_TI1 (TIMER_CCMR_CCS_INPUT_TI1 << 8) -#define TIMER_CCMR1_CC2S_INPUT_TI2 (TIMER_CCMR_CCS_INPUT_TI2 << 8) -#define TIMER_CCMR1_CC2S_INPUT_TRC (TIMER_CCMR_CCS_INPUT_TRC << 8) -#define TIMER_CCMR1_OC1CE (1U << TIMER_CCMR1_OC1CE_BIT) -#define TIMER_CCMR1_OC1M (0x3 << 4) -#define TIMER_CCMR1_IC1F (0xF << 4) -#define TIMER_CCMR1_OC1PE (1U << TIMER_CCMR1_OC1PE_BIT) -#define TIMER_CCMR1_OC1FE (1U << TIMER_CCMR1_OC1FE_BIT) -#define TIMER_CCMR1_IC1PSC (0x3 << 2) -#define TIMER_CCMR1_CC1S 0x3 -#define TIMER_CCMR1_CC1S_OUTPUT TIMER_CCMR_CCS_OUTPUT -#define TIMER_CCMR1_CC1S_INPUT_TI1 TIMER_CCMR_CCS_INPUT_TI1 -#define TIMER_CCMR1_CC1S_INPUT_TI2 TIMER_CCMR_CCS_INPUT_TI2 -#define TIMER_CCMR1_CC1S_INPUT_TRC TIMER_CCMR_CCS_INPUT_TRC - -/* Capture/compare mode register 2 (CCMR2) */ - -#define TIMER_CCMR2_OC4CE_BIT 15 -#define TIMER_CCMR2_OC4PE_BIT 11 -#define TIMER_CCMR2_OC4FE_BIT 10 -#define TIMER_CCMR2_OC3CE_BIT 7 -#define TIMER_CCMR2_OC3PE_BIT 3 -#define TIMER_CCMR2_OC3FE_BIT 2 - -#define TIMER_CCMR2_OC4CE (1U << TIMER_CCMR2_OC4CE_BIT) -#define TIMER_CCMR2_OC4M (0x3 << 12) -#define TIMER_CCMR2_IC4F (0xF << 12) -#define TIMER_CCMR2_OC4PE (1U << TIMER_CCMR2_OC4PE_BIT) -#define TIMER_CCMR2_OC4FE (1U << TIMER_CCMR2_OC4FE_BIT) -#define TIMER_CCMR2_IC4PSC (0x3 << 10) -#define TIMER_CCMR2_CC4S (0x3 << 8) -#define TIMER_CCMR2_CC4S_OUTPUT (TIMER_CCMR_CCS_OUTPUT << 8) -#define TIMER_CCMR2_CC4S_INPUT_TI1 (TIMER_CCMR_CCS_INPUT_TI1 << 8) -#define TIMER_CCMR2_CC4S_INPUT_TI2 (TIMER_CCMR_CCS_INPUT_TI2 << 8) -#define TIMER_CCMR2_CC4S_INPUT_TRC (TIMER_CCMR_CCS_INPUT_TRC << 8) -#define TIMER_CCMR2_OC3CE (1U << TIMER_CCMR2_OC3CE_BIT) -#define TIMER_CCMR2_OC3M (0x3 << 4) -#define TIMER_CCMR2_IC3F (0xF << 4) -#define TIMER_CCMR2_OC3PE (1U << TIMER_CCMR2_OC3PE_BIT) -#define TIMER_CCMR2_OC3FE (1U << TIMER_CCMR2_OC3FE_BIT) -#define TIMER_CCMR2_IC3PSC (0x3 << 2) -#define TIMER_CCMR2_CC3S 0x3 -#define TIMER_CCMR2_CC3S_OUTPUT TIMER_CCMR_CCS_OUTPUT -#define TIMER_CCMR2_CC3S_INPUT_TI1 TIMER_CCMR_CCS_INPUT_TI1 -#define TIMER_CCMR2_CC3S_INPUT_TI2 TIMER_CCMR_CCS_INPUT_TI2 -#define TIMER_CCMR2_CC3S_INPUT_TRC TIMER_CCMR_CCS_INPUT_TRC - -/* Capture/compare enable register (CCER) */ - -#define TIMER_CCER_CC4P_BIT 13 -#define TIMER_CCER_CC4E_BIT 12 -#define TIMER_CCER_CC3NP_BIT 11 -#define TIMER_CCER_CC3NE_BIT 10 -#define TIMER_CCER_CC3P_BIT 9 -#define TIMER_CCER_CC3E_BIT 8 -#define TIMER_CCER_CC2NP_BIT 7 -#define TIMER_CCER_CC2NE_BIT 6 -#define TIMER_CCER_CC2P_BIT 5 -#define TIMER_CCER_CC2E_BIT 4 -#define TIMER_CCER_CC1NP_BIT 3 -#define TIMER_CCER_CC1NE_BIT 2 -#define TIMER_CCER_CC1P_BIT 1 -#define TIMER_CCER_CC1E_BIT 0 - -#define TIMER_CCER_CC4P (1U << TIMER_CCER_CC4P_BIT) -#define TIMER_CCER_CC4E (1U << TIMER_CCER_CC4E_BIT) -#define TIMER_CCER_CC3NP (1U << TIMER_CCER_CC3NP_BIT) -#define TIMER_CCER_CC3NE (1U << TIMER_CCER_CC3NE_BIT) -#define TIMER_CCER_CC3P (1U << TIMER_CCER_CC3P_BIT) -#define TIMER_CCER_CC3E (1U << TIMER_CCER_CC3E_BIT) -#define TIMER_CCER_CC2NP (1U << TIMER_CCER_CC2NP_BIT) -#define TIMER_CCER_CC2NE (1U << TIMER_CCER_CC2NE_BIT) -#define TIMER_CCER_CC2P (1U << TIMER_CCER_CC2P_BIT) -#define TIMER_CCER_CC2E (1U << TIMER_CCER_CC2E_BIT) -#define TIMER_CCER_CC1NP (1U << TIMER_CCER_CC1NP_BIT) -#define TIMER_CCER_CC1NE (1U << TIMER_CCER_CC1NE_BIT) -#define TIMER_CCER_CC1P (1U << TIMER_CCER_CC1P_BIT) -#define TIMER_CCER_CC1E (1U << TIMER_CCER_CC1E_BIT) - -/* Break and dead-time register (BDTR) */ - -#define TIMER_BDTR_MOE_BIT 15 -#define TIMER_BDTR_AOE_BIT 14 -#define TIMER_BDTR_BKP_BIT 13 -#define TIMER_BDTR_BKE_BIT 12 -#define TIMER_BDTR_OSSR_BIT 11 -#define TIMER_BDTR_OSSI_BIT 10 - -#define TIMER_BDTR_MOE (1U << TIMER_BDTR_MOE_BIT) -#define TIMER_BDTR_AOE (1U << TIMER_BDTR_AOE_BIT) -#define TIMER_BDTR_BKP (1U << TIMER_BDTR_BKP_BIT) -#define TIMER_BDTR_BKE (1U << TIMER_BDTR_BKE_BIT) -#define TIMER_BDTR_OSSR (1U << TIMER_BDTR_OSSR_BIT) -#define TIMER_BDTR_OSSI (1U << TIMER_BDTR_OSSI_BIT) -#define TIMER_BDTR_LOCK (0x3 << 8) -#define TIMER_BDTR_LOCK_OFF (0x0 << 8) -#define TIMER_BDTR_LOCK_LEVEL1 (0x1 << 8) -#define TIMER_BDTR_LOCK_LEVEL2 (0x2 << 8) -#define TIMER_BDTR_LOCK_LEVEL3 (0x3 << 8) -#define TIMER_BDTR_DTG 0xFF - -/* DMA control register (DCR) */ - -#define TIMER_DCR_DBL (0x1F << 8) -#define TIMER_DCR_DBL_1_XFER (0x0 << 8) -#define TIMER_DCR_DBL_2_XFER (0x1 << 8) -#define TIMER_DCR_DBL_3_XFER (0x2 << 8) -#define TIMER_DCR_DBL_4_XFER (0x3 << 8) -#define TIMER_DCR_DBL_5_XFER (0x4 << 8) -#define TIMER_DCR_DBL_6_XFER (0x5 << 8) -#define TIMER_DCR_DBL_7_XFER (0x6 << 8) -#define TIMER_DCR_DBL_8_XFER (0x7 << 8) -#define TIMER_DCR_DBL_9_XFER (0x8 << 8) -#define TIMER_DCR_DBL_10_XFER (0x9 << 8) -#define TIMER_DCR_DBL_11_XFER (0xA << 8) -#define TIMER_DCR_DBL_12_XFER (0xB << 8) -#define TIMER_DCR_DBL_13_XFER (0xC << 8) -#define TIMER_DCR_DBL_14_XFER (0xD << 8) -#define TIMER_DCR_DBL_15_XFER (0xE << 8) -#define TIMER_DCR_DBL_16_XFER (0xF << 8) -#define TIMER_DCR_DBL_17_XFER (0x10 << 8) -#define TIMER_DCR_DBL_18_XFER (0x11 << 8) -#define TIMER_DCR_DBA 0x1F -#define TIMER_DCR_DBA_CR1 0x0 -#define TIMER_DCR_DBA_CR2 0x1 -#define TIMER_DCR_DBA_SMCR 0x2 -#define TIMER_DCR_DBA_DIER 0x3 -#define TIMER_DCR_DBA_SR 0x4 -#define TIMER_DCR_DBA_EGR 0x5 -#define TIMER_DCR_DBA_CCMR1 0x6 -#define TIMER_DCR_DBA_CCMR2 0x7 -#define TIMER_DCR_DBA_CCER 0x8 -#define TIMER_DCR_DBA_CNT 0x9 -#define TIMER_DCR_DBA_PSC 0xA -#define TIMER_DCR_DBA_ARR 0xB -#define TIMER_DCR_DBA_RCR 0xC -#define TIMER_DCR_DBA_CCR1 0xD -#define TIMER_DCR_DBA_CCR2 0xE -#define TIMER_DCR_DBA_CCR3 0xF -#define TIMER_DCR_DBA_CCR4 0x10 -#define TIMER_DCR_DBA_BDTR 0x11 -#define TIMER_DCR_DBA_DCR 0x12 -#define TIMER_DCR_DBA_DMAR 0x13 - -/* - * Convenience routines - */ - -/** - * @brief Used to configure the behavior of a timer channel. - * - * Be careful: not all timers can be configured in every mode. - */ -typedef enum timer_mode { - /** - * The timer stops counting, channel interrupts are detached, and - * no state changes are output. */ - TIMER_DISABLED, - - /** PWM output. */ - TIMER_PWM, - - /* TIMER_PWM_CENTER_ALIGNED, TODO: Center-aligned PWM output mode. */ - - /** - * The timer counts from 0 to its reload value repeatedly; every - * time the counter value reaches one of the channel compare - * values, the corresponding interrupt is fired. */ - TIMER_OUTPUT_COMPARE, - - /* TIMER_INPUT_CAPTURE, TODO: In this mode, the timer can measure the - * pulse lengths of input signals */ - /* TIMER_ONE_PULSE, TODO: In this mode, the timer can generate a single - * pulse on a GPIO pin for a specified amount of - * time. */ -} timer_mode; - -/** Timer channel numbers */ -typedef enum timer_channel { - TIMER_CH1 = 1, /**< Channel 1 */ - TIMER_CH2 = 2, /**< Channel 2 */ - TIMER_CH3 = 3, /**< Channel 3 */ - TIMER_CH4 = 4 /**< Channel 4 */ -} timer_channel; - -/* - * Note: Don't require timer_channel arguments! We want to be able to say - * - * for (int channel = 1; channel <= 4; channel++) { - * ... - * } - * - * without the compiler yelling at us. - */ - -void timer_init(timer_dev *dev); -void timer_disable(timer_dev *dev); -void timer_set_mode(timer_dev *dev, uint8 channel, timer_mode mode); -void timer_foreach(void (*fn)(timer_dev*)); -int timer_has_cc_channel(timer_dev *dev, uint8 channel); - -/** - * @brief Timer interrupt number. - * - * Not all timers support all of these values. All timers support - * TIMER_UPDATE_INTERRUPT. "General purpose" timers can be a special - * nuisance in this regard, as they individually support different - * subsets of the available interupts. Consult your target's reference - * manual for the details. - */ -typedef enum timer_interrupt_id { - TIMER_UPDATE_INTERRUPT, /**< Update interrupt. */ - TIMER_CC1_INTERRUPT, /**< Capture/compare 1 interrupt. */ - TIMER_CC2_INTERRUPT, /**< Capture/compare 2 interrupt. */ - TIMER_CC3_INTERRUPT, /**< Capture/compare 3 interrupt. */ - TIMER_CC4_INTERRUPT, /**< Capture/compare 4 interrupt. */ - TIMER_COM_INTERRUPT, /**< COM interrupt. */ - TIMER_TRG_INTERRUPT, /**< Trigger interrupt. */ - TIMER_BREAK_INTERRUPT, /**< Break interrupt. */ -} timer_interrupt_id; - -void timer_attach_interrupt(timer_dev *dev, - uint8 interrupt, - voidFuncPtr handler); -void timer_detach_interrupt(timer_dev *dev, uint8 interrupt); - -/** - * Initialize all timer devices on the chip. - */ -static inline void timer_init_all(void) { - timer_foreach(timer_init); -} - -/** - * Disables all timers on the device. - */ -static inline void timer_disable_all(void) { - timer_foreach(timer_disable); -} - -/** - * @brief Stop a timer's counter from changing. - * - * Does not affect the timer's mode or other settings. - * - * @param dev Device whose counter to pause. - */ -static inline void timer_pause(timer_dev *dev) { - *bb_perip(&(dev->regs).bas->CR1, TIMER_CR1_CEN_BIT) = 0; -} - -/** - * @brief Start a timer's counter. - * - * Does not affect the timer's mode or other settings. - * - * @param dev Device whose counter to resume - */ -static inline void timer_resume(timer_dev *dev) { - *bb_perip(&(dev->regs).bas->CR1, TIMER_CR1_CEN_BIT) = 1; -} - -/** - * @brief Returns the timer's counter value. - * - * This value is likely to be inaccurate if the counter is running - * with a low prescaler. - * - * @param dev Timer whose counter to return - */ -static inline uint16 timer_get_count(timer_dev *dev) { - return (uint16)(dev->regs).bas->CNT; -} - -/** - * @brief Sets the counter value for the given timer. - * @param dev Timer whose counter to set - * @param value New counter value - */ -static inline void timer_set_count(timer_dev *dev, uint16 value) { - (dev->regs).bas->CNT = value; -} - -/** - * @brief Returns the given timer's prescaler. - * - * Note that if the timer's prescaler is set (e.g. via - * timer_set_prescaler() or accessing a TIMx_PSC register), the value - * returned by this function will reflect the new setting, but the - * timer's counter will only reflect the new prescaler at the next - * update event. - * - * @param dev Timer whose prescaler to return - * @see timer_generate_update() - */ -static inline uint16 timer_get_prescaler(timer_dev *dev) { - return (uint16)(dev->regs).bas->PSC; -} - -/** - * @brief Set a timer's prescale value. - * - * Divides the input clock by (PSC+1). The new value will not take - * effect until the next update event. - * - * @param dev Timer whose prescaler to set - * @param psc New prescaler value - * @see timer_generate_update() - */ -static inline void timer_set_prescaler(timer_dev *dev, uint16 psc) { - (dev->regs).bas->PSC = psc; -} - -/** - * @brief Returns a timer's reload value. - * @param dev Timer whose reload value to return - */ -static inline uint16 timer_get_reload(timer_dev *dev) { - return (uint16)(dev->regs).bas->ARR; -} - -/** - * @brief Set a timer's reload value. - * @param dev Timer whose reload value to set - * @param arr New reload value to use. Takes effect at next update event. - * @see timer_generate_update() - */ -static inline void timer_set_reload(timer_dev *dev, uint16 arr) { - (dev->regs).bas->ARR = arr; -} - -/** - * @brief Get the compare value for the given timer channel. - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param channel Channel whose compare value to get. - */ -static inline uint16 timer_get_compare(timer_dev *dev, uint8 channel) { - __IO uint32 *ccr = &(dev->regs).gen->CCR1 + (channel - 1); - return *ccr; -} - -/** - * @brief Set the compare value for the given timer channel. - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param channel Channel whose compare value to set. - * @param value New compare value. - */ -static inline void timer_set_compare(timer_dev *dev, - uint8 channel, - uint16 value) { - __IO uint32 *ccr = &(dev->regs).gen->CCR1 + (channel - 1); - *ccr = value; -} - -/** - * @brief Generate an update event for the given timer. - * - * Normally, this will cause the prescaler and auto-reload values in - * the PSC and ARR registers to take immediate effect. However, this - * function will do nothing if the UDIS bit is set in the timer's CR1 - * register (UDIS is cleared by default). - * - * @param dev Timer device to generate an update for. - */ -static inline void timer_generate_update(timer_dev *dev) { - *bb_perip(&(dev->regs).bas->EGR, TIMER_EGR_UG_BIT) = 1; -} - -/** - * @brief Enable a timer's trigger DMA request - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL - */ -static inline void timer_dma_enable_trg_req(timer_dev *dev) { - *bb_perip(&(dev->regs).gen->DIER, TIMER_DIER_TDE_BIT) = 1; -} - -/** - * @brief Disable a timer's trigger DMA request - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL - */ -static inline void timer_dma_disable_trg_req(timer_dev *dev) { - *bb_perip(&(dev->regs).gen->DIER, TIMER_DIER_TDE_BIT) = 0; -} - -/** - * @brief Enable a timer channel's DMA request. - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL - * @param channel Channel whose DMA request to enable. - */ -static inline void timer_dma_enable_req(timer_dev *dev, uint8 channel) { - *bb_perip(&(dev->regs).gen->DIER, channel + 8) = 1; -} - -/** - * @brief Disable a timer channel's DMA request. - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param channel Channel whose DMA request to disable. - */ -static inline void timer_dma_disable_req(timer_dev *dev, uint8 channel) { - *bb_perip(&(dev->regs).gen->DIER, channel + 8) = 0; -} - -/** - * @brief Enable a timer interrupt. - * @param dev Timer device. - * @param interrupt Interrupt number to enable; this may be any - * timer_interrupt_id value appropriate for the timer. - * @see timer_interrupt_id - * @see timer_channel - */ -static inline void timer_enable_irq(timer_dev *dev, uint8 interrupt) { - *bb_perip(&(dev->regs).adv->DIER, interrupt) = 1; -} - -/** - * @brief Disable a timer interrupt. - * @param dev Timer device. - * @param interrupt Interrupt number to disable; this may be any - * timer_interrupt_id value appropriate for the timer. - * @see timer_interrupt_id - * @see timer_channel - */ -static inline void timer_disable_irq(timer_dev *dev, uint8 interrupt) { - *bb_perip(&(dev->regs).adv->DIER, interrupt) = 0; -} - -/** - * @brief Enable a timer channel's capture/compare signal. - * - * If the channel is configured as output, the corresponding output - * compare signal will be output on the corresponding output pin. If - * the channel is configured as input, enables capture of the counter - * value into the input capture/compare register. - * - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param channel Channel to enable, from 1 to 4. - */ -static inline void timer_cc_enable(timer_dev *dev, uint8 channel) { - *bb_perip(&(dev->regs).gen->CCER, 4 * (channel - 1)) = 1; -} - -/** - * @brief Disable a timer channel's output compare or input capture signal. - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param channel Channel to disable, from 1 to 4. - * @see timer_cc_enable() - */ -static inline void timer_cc_disable(timer_dev *dev, uint8 channel) { - *bb_perip(&(dev->regs).gen->CCER, 4 * (channel - 1)) = 0; -} - -/** - * @brief Get a channel's capture/compare output polarity - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param channel Channel whose capture/compare output polarity to get. - * @return Polarity, either 0 or 1. - * @see timer_cc_set_polarity() - */ -static inline uint8 timer_cc_get_pol(timer_dev *dev, uint8 channel) { - return *bb_perip(&(dev->regs).gen->CCER, 4 * (channel - 1) + 1); -} - -/** - * @brief Set a timer channel's capture/compare output polarity. - * - * If the timer channel is configured as output: polarity == 0 means - * the output channel will be active high; polarity == 1 means active - * low. - * - * If the timer channel is configured as input: polarity == 0 means - * capture is done on the rising edge of ICn; when used as an external - * trigger, ICn is non-inverted. polarity == 1 means capture is done - * on the falling edge of ICn; when used as an external trigger, ICn - * is inverted. - * - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param channel Channel whose capture/compare output polarity to set. - * @param pol New polarity, 0 or 1. - */ -static inline void timer_cc_set_pol(timer_dev *dev, uint8 channel, uint8 pol) { - *bb_perip(&(dev->regs).gen->CCER, 4 * (channel - 1) + 1) = pol; -} - -/** - * @brief Get a timer's DMA burst length. - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @return Number of transfers per read or write to timer DMA register, - * from 1 to 18. - */ -static inline uint8 timer_dma_get_burst_len(timer_dev *dev) { - uint32 dbl = ((dev->regs).gen->DCR & TIMER_DCR_DBL) >> 8; - return dbl + 1; /* 0 means 1 transfer, etc. */ -} - -/** - * @brief Set a timer's DMA burst length. - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param length DMA burst length; i.e., number of DMA transfers per - * read/write to timer DMA register, from 1 to 18. - */ -static inline void timer_dma_set_burst_len(timer_dev *dev, uint8 length) { - uint32 tmp = (dev->regs).gen->DCR; - tmp &= ~TIMER_DCR_DBL; - tmp |= (length - 1) << 8; - (dev->regs).gen->DCR = tmp; -} - -/** - * @brief Timer DMA base address. - * - * Defines the base address for DMA transfers. - */ -typedef enum timer_dma_base_addr { - /** Base is control register 1 */ - TIMER_DMA_BASE_CR1 = TIMER_DCR_DBA_CR1, - /** Base is control register 2 */ - TIMER_DMA_BASE_CR2 = TIMER_DCR_DBA_CR2, - /** Base is slave mode control register */ - TIMER_DMA_BASE_SMCR = TIMER_DCR_DBA_SMCR, - /** Base is DMA interrupt enable register */ - TIMER_DMA_BASE_DIER = TIMER_DCR_DBA_DIER, - /** Base is status register */ - TIMER_DMA_BASE_SR = TIMER_DCR_DBA_SR, - /** Base is event generation register */ - TIMER_DMA_BASE_EGR = TIMER_DCR_DBA_EGR, - /** Base is capture/compare mode register 1 */ - TIMER_DMA_BASE_CCMR1 = TIMER_DCR_DBA_CCMR1, - /** Base is capture/compare mode register 2 */ - TIMER_DMA_BASE_CCMR2 = TIMER_DCR_DBA_CCMR2, - /** Base is capture/compare enable register */ - TIMER_DMA_BASE_CCER = TIMER_DCR_DBA_CCER, - /** Base is counter */ - TIMER_DMA_BASE_CNT = TIMER_DCR_DBA_CNT, - /** Base is prescaler */ - TIMER_DMA_BASE_PSC = TIMER_DCR_DBA_PSC, - /** Base is auto-reload register */ - TIMER_DMA_BASE_ARR = TIMER_DCR_DBA_ARR, - /** Base is repetition counter register */ - TIMER_DMA_BASE_RCR = TIMER_DCR_DBA_RCR, - /** Base is capture/compare register 1 */ - TIMER_DMA_BASE_CCR1 = TIMER_DCR_DBA_CCR1, - /** Base is capture/compare register 2 */ - TIMER_DMA_BASE_CCR2 = TIMER_DCR_DBA_CCR2, - /** Base is capture/compare register 3 */ - TIMER_DMA_BASE_CCR3 = TIMER_DCR_DBA_CCR3, - /** Base is capture/compare register 4 */ - TIMER_DMA_BASE_CCR4 = TIMER_DCR_DBA_CCR4, - /** Base is break and dead-time register */ - TIMER_DMA_BASE_BDTR = TIMER_DCR_DBA_BDTR, - /** Base is DMA control register */ - TIMER_DMA_BASE_DCR = TIMER_DCR_DBA_DCR, - /** Base is DMA address for full transfer */ - TIMER_DMA_BASE_DMAR = TIMER_DCR_DBA_DMAR, -} timer_dma_base_addr; - -/** - * @brief Get the timer's DMA base address. - * - * Some restrictions apply; see the reference manual for your chip. - * - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @return DMA base address - */ -static inline timer_dma_base_addr timer_dma_get_base_addr(timer_dev *dev) { - uint32 dcr = (dev->regs).gen->DCR; - return (timer_dma_base_addr)(dcr & TIMER_DCR_DBA); -} - -/** - * @brief Set the timer's DMA base address. - * - * Some restrictions apply; see the reference manual for your chip. - * - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param dma_base DMA base address. - */ -static inline void timer_dma_set_base_addr(timer_dev *dev, - timer_dma_base_addr dma_base) { - uint32 tmp = (dev->regs).gen->DCR; - tmp &= ~TIMER_DCR_DBA; - tmp |= dma_base; - (dev->regs).gen->DCR = tmp; -} - -/** - * Timer output compare modes. - */ -typedef enum timer_oc_mode { - /** - * Frozen: comparison between output compare register and counter - * has no effect on the outputs. */ - TIMER_OC_MODE_FROZEN = 0 << 4, - /** - * OCxREF signal is forced high when the count matches the channel - * capture/compare register. */ - TIMER_OC_MODE_ACTIVE_ON_MATCH = 1 << 4, - /** - * OCxREF signal is forced low when the counter matches the - * channel capture/compare register. */ - TIMER_OC_MODE_INACTIVE_ON_MATCH = 2 << 4, - /** - * OCxREF toggles when counter matches the channel capture/compare - * register. */ - TIMER_OC_MODE_TOGGLE = 3 << 4, - /** OCxREF is forced low. */ - TIMER_OC_MODE_FORCE_INACTIVE = 4 << 4, - /** OCxREF is forced high. */ - TIMER_OC_MODE_FORCE_ACTIVE = 5 << 4, - /** - * PWM mode 1. In upcounting, channel is active as long as count - * is less than channel capture/compare register, else inactive. - * In downcounting, channel is inactive as long as count exceeds - * capture/compare register, else active. */ - TIMER_OC_MODE_PWM_1 = 6 << 4, - /** - * PWM mode 2. In upcounting, channel is inactive as long as count - * is less than capture/compare register, else active. In - * downcounting, channel is active as long as count exceeds - * capture/compare register, else inactive. */ - TIMER_OC_MODE_PWM_2 = 7 << 4, -} timer_oc_mode; - -/** - * Timer output compare mode flags. - * @see timer_oc_set_mode() - */ -typedef enum timer_oc_mode_flags { - TIMER_OC_CE = 1U << 7, /**< Output compare clear enable. */ - TIMER_OC_PE = 1U << 3, /**< Output compare preload enable. */ - TIMER_OC_FE = 1U << 2, /**< Output compare fast enable. */ -} timer_oc_mode_flags; - -/** - * @brief Configure a channel's output compare mode. - * - * @param dev Timer device, must have type TIMER_ADVANCED or TIMER_GENERAL. - * @param channel Channel to configure in output compare mode. - * @param mode Timer mode to set. - * @param flags OR of timer_oc_mode_flags. - * @see timer_oc_mode - * @see timer_oc_mode_flags - */ -static inline void timer_oc_set_mode(timer_dev *dev, - uint8 channel, - timer_oc_mode mode, - uint8 flags) { - /* channel == 1,2 -> CCMR1; channel == 3,4 -> CCMR2 */ - __IO uint32 *ccmr = &(dev->regs).gen->CCMR1 + (((channel - 1) >> 1) & 1); - /* channel == 1,3 -> shift = 0, channel == 2,4 -> shift = 8 */ - uint8 shift = 8 * (1 - (channel & 1)); - - uint32 tmp = *ccmr; - tmp &= ~(0xFF << shift); - tmp |= (mode | flags | TIMER_CCMR_CCS_OUTPUT) << shift; - *ccmr = tmp; -} - -/* - * Old, erroneous bit definitions from previous releases, kept for - * backwards compatibility: - */ - -/** Deprecated. Use TIMER_CCMR1_CC4S_OUTPUT instead. */ -#define TIMER_CCMR1_CC4S_OUTPUT TIMER_CCMR2_CC4S_OUTPUT -/** Deprecated. Use TIMER_CCMR1_CC4S_INPUT_TI1 instead. */ -#define TIMER_CCMR1_CC4S_INPUT_TI1 TIMER_CCMR2_CC4S_INPUT_TI1 -/** Deprecated. Use TIMER_CCMR1_CC4S_INPUT_TI2 instead. */ -#define TIMER_CCMR1_CC4S_INPUT_TI2 TIMER_CCMR2_CC4S_INPUT_TI2 -/** Deprecated. Use TIMER_CCMR1_CC4S_INPUT_TRC instead. */ -#define TIMER_CCMR1_CC4S_INPUT_TRC TIMER_CCMR2_CC4S_INPUT_TRC -/** Deprecated. Use TIMER_CCMR2_IC4F instead. */ -#define TIMER_CCMR2_IC2F TIMER_CCMR2_IC4F -/** Deprecated. Use TIMER_CCMR2_IC4PSC instead. */ -#define TIMER_CCMR2_IC2PSC TIMER_CCMR2_IC4PSC -/** Deprecated. Use TIMER_CCMR2_IC3F instead. */ -#define TIMER_CCMR2_IC1F TIMER_CCMR2_IC3F -/** Deprecated. Use TIMER_CCMR2_IC3PSC instead. */ -#define TIMER_CCMR2_IC1PSC TIMER_CCMR2_IC3PSC -/** Deprecated. Use TIMER_CCMR1_CC3S_OUTPUT instead. */ -#define TIMER_CCMR1_CC3S_OUTPUT TIMER_CCMR2_CC3S_OUTPUT -/** Deprecated. Use TIMER_CCMR1_CC3S_INPUT_TI1 instead. */ -#define TIMER_CCMR1_CC3S_INPUT_TI1 TIMER_CCMR2_CC3S_INPUT_TI1 -/** Deprecated. Use TIMER_CCMR1_CC3S_INPUT_TI2 instead. */ -#define TIMER_CCMR1_CC3S_INPUT_TI2 TIMER_CCMR2_CC3S_INPUT_TI2 -/** Deprecated. Use TIMER_CCMR1_CC3S_INPUT_TRC instead. */ -#define TIMER_CCMR1_CC3S_INPUT_TRC TIMER_CCMR2_CC3S_INPUT_TRC - -/** Deprecated. Use TIMER_DCR_DBL_1_XFER instead. */ -#define TIMER_DCR_DBL_1BYTE TIMER_DCR_DBL_1_XFER -/** Deprecated. Use TIMER_DCR_DBL_2_XFER instead. */ -#define TIMER_DCR_DBL_2BYTE TIMER_DCR_DBL_2_XFER -/** Deprecated. Use TIMER_DCR_DBL_3_XFER instead. */ -#define TIMER_DCR_DBL_3BYTE TIMER_DCR_DBL_3_XFER -/** Deprecated. Use TIMER_DCR_DBL_4_XFER instead. */ -#define TIMER_DCR_DBL_4BYTE TIMER_DCR_DBL_4_XFER -/** Deprecated. Use TIMER_DCR_DBL_5_XFER instead. */ -#define TIMER_DCR_DBL_5BYTE TIMER_DCR_DBL_5_XFER -/** Deprecated. Use TIMER_DCR_DBL_6_XFER instead. */ -#define TIMER_DCR_DBL_6BYTE TIMER_DCR_DBL_6_XFER -/** Deprecated. Use TIMER_DCR_DBL_7_XFER instead. */ -#define TIMER_DCR_DBL_7BYTE TIMER_DCR_DBL_7_XFER -/** Deprecated. Use TIMER_DCR_DBL_8_XFER instead. */ -#define TIMER_DCR_DBL_8BYTE TIMER_DCR_DBL_8_XFER -/** Deprecated. Use TIMER_DCR_DBL_9_XFER instead. */ -#define TIMER_DCR_DBL_9BYTE TIMER_DCR_DBL_9_XFER -/** Deprecated. Use TIMER_DCR_DBL_10_XFER instead. */ -#define TIMER_DCR_DBL_10BYTE TIMER_DCR_DBL_10_XFER -/** Deprecated. Use TIMER_DCR_DBL_11_XFER instead. */ -#define TIMER_DCR_DBL_11BYTE TIMER_DCR_DBL_11_XFER -/** Deprecated. Use TIMER_DCR_DBL_12_XFER instead. */ -#define TIMER_DCR_DBL_12BYTE TIMER_DCR_DBL_12_XFER -/** Deprecated. Use TIMER_DCR_DBL_13_XFER instead. */ -#define TIMER_DCR_DBL_13BYTE TIMER_DCR_DBL_13_XFER -/** Deprecated. Use TIMER_DCR_DBL_14_XFER instead. */ -#define TIMER_DCR_DBL_14BYTE TIMER_DCR_DBL_14_XFER -/** Deprecated. Use TIMER_DCR_DBL_15_XFER instead. */ -#define TIMER_DCR_DBL_15BYTE TIMER_DCR_DBL_15_XFER -/** Deprecated. Use TIMER_DCR_DBL_16_XFER instead. */ -#define TIMER_DCR_DBL_16BYTE TIMER_DCR_DBL_16_XFER -/** Deprecated. Use TIMER_DCR_DBL_17_XFER instead. */ -#define TIMER_DCR_DBL_17BYTE TIMER_DCR_DBL_17_XFER -/** Deprecated. Use TIMER_DCR_DBL_18_XFER instead. */ -#define TIMER_DCR_DBL_18BYTE TIMER_DCR_DBL_18_XFER - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/usart.h b/STM32F3/cores/maple/libmaple/include/libmaple/usart.h deleted file mode 100644 index 82b1b7d..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/usart.h +++ /dev/null @@ -1,464 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/usart.h - * @author Marti Bolivar , - * Perry Hung , - * F3-port by Hanspeter Portner - * @brief USART definitions and prototypes - */ - -#ifndef _LIBMAPLE_USART_H_ -#define _LIBMAPLE_USART_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include -#include -#include -#include -#include - -/* - * Register bit definitions - */ - -/* Status register */ - -/** Line break detection bit */ -#define USART_SR_LBD_BIT 8 -/** Transmit data register empty bit */ -#define USART_SR_TXE_BIT 7 -/** Transmission complete bit */ -#define USART_SR_TC_BIT 6 -/** Read data register not empty bit */ -#define USART_SR_RXNE_BIT 5 -/** IDLE line detected bit */ -#define USART_SR_IDLE_BIT 4 -/** Overrun error bit */ -#define USART_SR_ORE_BIT 3 -/** Noise error bit */ -#define USART_SR_NE_BIT 2 -/** - * @brief Synonym for USART_SR_NE_BIT. - * - * Some series (e.g. STM32F2) use "NF" for "noise flag" instead of the - * original "NE" for "noise error". The meaning of the bit is - * unchanged, but the NF flag can be disabled when the line is - * noise-free. - * - * @see USART_SR_NE_BIT - */ -#define USART_SR_NF_BIT USART_SR_NE_BIT -/** Framing error bit */ -#define USART_SR_FE_BIT 1 -/** Parity error bit */ -#define USART_SR_PE_BIT 0 - -/** Line break detected mask */ -#define USART_SR_LBD BIT(USART_SR_LBD_BIT) -/** Transmit data register empty mask */ -#define USART_SR_TXE BIT(USART_SR_TXE_BIT) -/** Transmission complete mask */ -#define USART_SR_TC BIT(USART_SR_TC_BIT) -/** Read data register not empty mask */ -#define USART_SR_RXNE BIT(USART_SR_RXNE_BIT) -/** IDLE line detected mask */ -#define USART_SR_IDLE BIT(USART_SR_IDLE_BIT) -/** Overrun error mask */ -#define USART_SR_ORE BIT(USART_SR_ORE_BIT) -/** Noise error mask */ -#define USART_SR_NE BIT(USART_SR_NE_BIT) -/** - * @brief Synonym for USART_SR_NE. - * @see USART_SR_NF_BIT - */ -#define USART_SR_NF USART_SR_NE -/** Framing error mask */ -#define USART_SR_FE BIT(USART_SR_FE_BIT) -/** Parity error mask */ -#define USART_SR_PE BIT(USART_SR_PE_BIT) - -/* Data register */ - -/** Data register data value mask */ -#define USART_DR_DR 0xFF - -/* Baud rate register */ - -/** Mantissa of USARTDIV mask */ -#define USART_BRR_DIV_MANTISSA (0xFFF << 4) -/** Fraction of USARTDIV mask */ -#define USART_BRR_DIV_FRACTION 0xF - -/* Control register 1 */ - -/** Word length bit */ -#define USART_CR1_M_BIT 12 -/** Wakeup method bit */ -#define USART_CR1_WAKE_BIT 11 -/** Parity control enable bit */ -#define USART_CR1_PCE_BIT 10 -/** Parity selection bit */ -#define USART_CR1_PS_BIT 9 -/** Parity error interrupt enable bit */ -#define USART_CR1_PEIE_BIT 8 -/** Transmit data regsiter not empty interrupt enable bit */ -#define USART_CR1_TXEIE_BIT 7 -/** Transmission complete interrupt enable bit */ -#define USART_CR1_TCIE_BIT 6 -/** RXNE interrupt enable bit */ -#define USART_CR1_RXNEIE_BIT 5 -/** IDLE interrupt enable bit */ -#define USART_CR1_IDLEIE_BIT 4 -/** Transmitter enable bit */ -#define USART_CR1_TE_BIT 3 -/** Receiver enable bit */ -#define USART_CR1_RE_BIT 2 - -/** Word length mask */ -#define USART_CR1_M BIT(USART_CR1_M_BIT) -/** Word length: 1 start bit, 8 data bits, n stop bit */ -#define USART_CR1_M_8N1 (0 << USART_CR1_M_BIT) -/** Word length: 1 start bit, 9 data bits, n stop bit */ -#define USART_CR1_M_9N1 (1 << USART_CR1_M_BIT) -/** Wakeup method mask */ -#define USART_CR1_WAKE BIT(USART_CR1_WAKE_BIT) -/** Wakeup on idle line */ -#define USART_CR1_WAKE_IDLE (0 << USART_CR1_WAKE_BIT) -/** Wakeup on address mark */ -#define USART_CR1_WAKE_ADDR (1 << USART_CR1_WAKE_BIT) -/** Parity control enable mask */ -#define USART_CR1_PCE BIT(USART_CR1_PCE_BIT) -/** Parity selection mask */ -#define USART_CR1_PS BIT(USART_CR1_PS_BIT) -/** Parity selection: even parity */ -#define USART_CR1_PS_EVEN (0 << USART_CR1_PS_BIT) -/** Parity selection: odd parity */ -#define USART_CR1_PS_ODD (1 << USART_CR1_PS_BIT) -/** Parity error interrupt enable mask */ -#define USART_CR1_PEIE BIT(USART_CR1_PEIE_BIT) -/** Transmit data register empty interrupt enable mask */ -#define USART_CR1_TXEIE BIT(USART_CR1_TXEIE_BIT) -/** Transmission complete interrupt enable mask */ -#define USART_CR1_TCIE BIT(USART_CR1_TCIE_BIT) -/** RXNE interrupt enable mask */ -#define USART_CR1_RXNEIE BIT(USART_CR1_RXNEIE_BIT) -/** IDLE line interrupt enable mask */ -#define USART_CR1_IDLEIE BIT(USART_CR1_IDLEIE_BIT) -/** Transmitter enable mask */ -#define USART_CR1_TE BIT(USART_CR1_TE_BIT) -/** Receiver enable mask */ -#define USART_CR1_RE BIT(USART_CR1_RE_BIT) - -/* Control register 2 */ - -/** LIN mode enable bit */ -#define USART_CR2_LINEN_BIT 14 -/** Clock enable bit */ -#define USART_CR2_CLKEN_BIT 11 -/** Clock polarity bit */ -#define USART_CR2_CPOL_BIT 10 -/** Clock phase bit */ -#define USART_CR2_CPHA_BIT 9 -/** Last bit clock pulse bit */ -#define USART_CR2_LBCL_BIT 8 -/** LIN break detection interrupt enable bit */ -#define USART_CR2_LBDIE_BIT 6 -/** LIN break detection length bit */ -#define USART_CR2_LBDL_BIT 5 - -/** LIN mode enable mask */ -#define USART_CR2_LINEN BIT(USART_CR2_LINEN_BIT) -/** STOP bits mask */ -#define USART_CR2_STOP (0x3 << 12) -/** STOP bits: 1 stop bit */ -#define USART_CR2_STOP_BITS_1 (0x0 << 12) -/** - * @brief STOP bits: 0.5 stop bits - * Not available on UART4, UART5. */ -#define USART_CR2_STOP_BITS_POINT_5 (0x1 << 12) -/** STOP bits: 2 stop bits */ -#define USART_CR2_STOP_BITS_2 (0x2 << 12) -/** - * @brief STOP bits: 1.5 stop bits - * Not available on UART4, UART5. */ -#define USART_CR2_STOP_BITS_1_POINT_5 (0x3 << 12) -/** - * @brief Clock enable. - * Not available on UART4, UART5 */ -#define USART_CR2_CLKEN BIT(USART_CR2_CLKEN_BIT) -/** - * @brief Clock polarity mask. - * Not available on UART4, UART5 */ -#define USART_CR2_CPOL BIT(USART_CR2_CPOL_BIT) -/** Clock polarity: low */ -#define USART_CR2_CPOL_LOW (0x0 << USART_CR2_CLKEN_BIT) -/** Clock polarity: high */ -#define USART_CR2_CPOL_HIGH (0x1 << USART_CR2_CLKEN_BIT) -/** - * @brief Clock phase mask. - * Not available on UART4, UART5 */ -#define USART_CR2_CPHA BIT(USART_CR2_CPHA_BIT) -/** - * @brief Clock phase: first - * First clock transition is the first data capture edge. */ -#define USART_CR2_CPHA_FIRST (0x0 << USART_CR2_CPHA_BIT) -/** - * @brief Clock phase: second - * Second clock transition is the first data capture edge. */ -#define USART_CR2_CPHA_SECOND (0x1 << USART_CR2_CPHA_BIT) -/** - * @brief Last bit clock pulse mask. - * - * When set, the last bit transmitted causes a clock pulse in - * synchronous mode. - * - * Not available on UART4, UART5 */ -#define USART_CR2_LBCL BIT(USART_CR2_LBCL_BIT) -/** LIN break detection interrupt enable mask. */ -#define USART_CR2_LBDIE BIT(USART_CR2_LBDIE_BIT) -/** LIN break detection length. */ -#define USART_CR2_LBDL BIT(USART_CR2_LBDL_BIT) -/** LIN break detection length: 10 bits */ -#define USART_CR2_LBDL_10_BIT (0 << USART_CR2_LBDL_BIT) -/** LIN break detection length: 11 bits */ -#define USART_CR2_LBDL_11_BIT (1 << USART_CR2_LBDL_BIT) - -/* Control register 3 */ - -/** Clear to send interrupt enable bit */ -#define USART_CR3_CTSIE_BIT 10 -/** Clear to send enable bit */ -#define USART_CR3_CTSE_BIT 9 -/** Ready to send enable bit */ -#define USART_CR3_RTSE_BIT 8 -/** DMA enable transmitter bit */ -#define USART_CR3_DMAT_BIT 7 -/** DMA enable receiver bit */ -#define USART_CR3_DMAR_BIT 6 -/** Smartcard mode enable bit */ -#define USART_CR3_SCEN_BIT 5 -/** Smartcard NACK enable bit */ -#define USART_CR3_NACK_BIT 4 -/** Half-duplex selection bit */ -#define USART_CR3_HDSEL_BIT 3 -/** IrDA low power bit */ -#define USART_CR3_IRLP_BIT 2 -/** IrDA mode enable bit */ -#define USART_CR3_IREN_BIT 1 -/** Error interrupt enable bit */ -#define USART_CR3_EIE_BIT 0 - -/** - * @brief Clear to send interrupt enable - * Not available on UART4, UART5. */ -#define USART_CR3_CTSIE BIT(USART_CR3_CTSIE_BIT) -/** - * @brief Clear to send enable - * Not available on UART4, UART5. */ -#define USART_CR3_CTSE BIT(USART_CR3_CTSE_BIT) -/** - * @brief Ready to send enable - * Not available on UART4, UART5. */ -#define USART_CR3_RTSE BIT(USART_CR3_RTSE_BIT) -/** - * @brief DMA enable transmitter - * Not available on UART5. */ -#define USART_CR3_DMAT BIT(USART_CR3_DMAT_BIT) -/** - * @brief DMA enable receiver - * Not available on UART5. */ -#define USART_CR3_DMAR BIT(USART_CR3_DMAR_BIT) -/** - * @brief Smartcard mode enable - * Not available on UART4, UART5. */ -#define USART_CR3_SCEN BIT(USART_CR3_SCEN_BIT) -/** - * @brief Smartcard NACK enable - * Not available on UART4, UART5. */ -#define USART_CR3_NACK BIT(USART_CR3_NACK_BIT) -/** - * @brief Half-duplex selection - * When set, single-wire half duplex mode is selected. - */ -#define USART_CR3_HDSEL BIT(USART_CR3_HDSEL_BIT) -/** IrDA low power mode */ -#define USART_CR3_IRLP BIT(USART_CR3_IRLP_BIT) -/** IrDA mode: normal */ -#define USART_CR3_IRLP_NORMAL (0U << USART_CR3_IRLP_BIT) -/** IrDA mode: low power */ -#define USART_CR3_IRLP_LOW_POWER (1U << USART_CR3_IRLP_BIT) -/** IrDA mode enable */ -#define USART_CR3_IREN BIT(USART_CR3_IREN_BIT) -/** Error interrupt enable */ -#define USART_CR3_EIE BIT(USART_CR3_EIE_BIT) - -/* Guard time and prescaler register */ - -/** - * @brief Guard time value mask - * Used in Smartcard mode. Not available on UART4, UART5. */ -#define USART_GTPR_GT (0xFF << 8) -/** - * @brief Prescaler value mask - * Restrictions on this value apply, depending on the USART mode. Not - * available on UART4, UART5. */ -#define USART_GTPR_PSC 0xFF - -/* - * Devices - */ - -#ifndef USART_RX_BUF_SIZE -#define USART_RX_BUF_SIZE 64 -#endif - -/** USART device type */ -typedef struct usart_dev { - usart_reg_map *regs; /**< Register map */ - ring_buffer *rb; /**< RX ring buffer */ - uint32 max_baud; /**< @brief Deprecated. - * Maximum baud rate. */ - uint8 rx_buf[USART_RX_BUF_SIZE]; /**< @brief Deprecated. - * Actual RX buffer used by rb. - * This field will be removed in - * a future release. */ - rcc_clk_id clk_id; /**< RCC clock information */ - nvic_irq_num irq_num; /**< USART NVIC interrupt */ -} usart_dev; - -void usart_init(usart_dev *dev); - -struct gpio_dev; /* forward declaration */ -/* FIXME [PRE 0.0.13] decide if flags are necessary */ -/** - * @brief Configure GPIOs for use as USART TX/RX. - * @param udev USART device to use - * @param rx_dev RX pin gpio_dev - * @param rx RX pin bit on rx_dev - * @param tx_dev TX pin gpio_dev - * @param tx TX pin bit on tx_dev - * @param flags Currently ignored - */ -extern void usart_config_gpios_async(usart_dev *udev, - struct gpio_dev *rx_dev, uint8 rx, - struct gpio_dev *tx_dev, uint8 tx, - unsigned flags); - -#define USART_USE_PCLK 0 -void usart_set_baud_rate(usart_dev *dev, uint32 clock_speed, uint32 baud); - -void usart_enable(usart_dev *dev); -void usart_disable(usart_dev *dev); -void usart_foreach(void (*fn)(usart_dev *dev)); -/** - * @brief Nonblocking USART transmit - * @param dev Serial port to transmit over - * @param buf Buffer to transmit - * @param len Maximum number of bytes to transmit - * @return Number of bytes transmitted - */ -uint32 usart_tx(usart_dev *dev, const uint8 *buf, uint32 len); -uint32 usart_rx(usart_dev *dev, uint8 *buf, uint32 len); -void usart_putudec(usart_dev *dev, uint32 val); - -/** - * @brief Disable all serial ports. - */ -static inline void usart_disable_all(void) { - usart_foreach(usart_disable); -} - -/** - * @brief Transmit one character on a serial port. - * - * This function blocks until the character has been successfully - * transmitted. - * - * @param dev Serial port to send on. - * @param byte Byte to transmit. - */ -static inline void usart_putc(usart_dev* dev, uint8 byte) { - while (!usart_tx(dev, &byte, 1)) - ; -} - -/** - * @brief Transmit a character string on a serial port. - * - * This function blocks until str is completely transmitted. - * - * @param dev Serial port to send on - * @param str String to send - */ -static inline void usart_putstr(usart_dev *dev, const char* str) { - uint32 i = 0; - while (str[i] != '\0') { - usart_putc(dev, str[i++]); - } -} - -/** - * @brief Read one character from a serial port. - * - * It's not safe to call this function if the serial port has no data - * available. - * - * @param dev Serial port to read from - * @return byte read - * @see usart_data_available() - */ -static inline uint8 usart_getc(usart_dev *dev) { - return rb_remove(dev->rb); -} - -/** - * @brief Return the amount of data available in a serial port's RX buffer. - * @param dev Serial port to check - * @return Number of bytes in dev's RX buffer. - */ -static inline uint32 usart_data_available(usart_dev *dev) { - return rb_full_count(dev->rb); -} - -/** - * @brief Discard the contents of a serial port's RX buffer. - * @param dev Serial port whose buffer to empty. - */ -static inline void usart_reset_rx(usart_dev *dev) { - rb_reset(dev->rb); -} - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/usb.h b/STM32F3/cores/maple/libmaple/include/libmaple/usb.h deleted file mode 100644 index ea24030..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/usb.h +++ /dev/null @@ -1,176 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010, 2011, 2012 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/* - * NOTE: This API is _unstable_ and will change drastically over time. - */ - -#ifndef _LIBMAPLE_USB_H_ -#define _LIBMAPLE_USB_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -/* - * Descriptors and other paraphernalia - */ - -/* Descriptor types */ - -#define USB_DESCRIPTOR_TYPE_DEVICE 0x01 -#define USB_DESCRIPTOR_TYPE_CONFIGURATION 0x02 -#define USB_DESCRIPTOR_TYPE_STRING 0x03 -#define USB_DESCRIPTOR_TYPE_INTERFACE 0x04 -#define USB_DESCRIPTOR_TYPE_ENDPOINT 0x05 - -/* Descriptor structs and declaration helpers */ - -#define USB_DESCRIPTOR_STRING_LEN(x) (2 + (x << 1)) - -#define USB_DESCRIPTOR_STRING(len) \ - struct { \ - uint8 bLength; \ - uint8 bDescriptorType; \ - uint16 bString[len]; \ - } __packed - -typedef struct usb_descriptor_device { - uint8 bLength; - uint8 bDescriptorType; - uint16 bcdUSB; - uint8 bDeviceClass; - uint8 bDeviceSubClass; - uint8 bDeviceProtocol; - uint8 bMaxPacketSize0; - uint16 idVendor; - uint16 idProduct; - uint16 bcdDevice; - uint8 iManufacturer; - uint8 iProduct; - uint8 iSerialNumber; - uint8 bNumConfigurations; -} __packed usb_descriptor_device; - -typedef struct usb_descriptor_config_header { - uint8 bLength; - uint8 bDescriptorType; - uint16 wTotalLength; - uint8 bNumInterfaces; - uint8 bConfigurationValue; - uint8 iConfiguration; - uint8 bmAttributes; - uint8 bMaxPower; -} __packed usb_descriptor_config_header; - -typedef struct usb_descriptor_interface { - uint8 bLength; - uint8 bDescriptorType; - uint8 bInterfaceNumber; - uint8 bAlternateSetting; - uint8 bNumEndpoints; - uint8 bInterfaceClass; - uint8 bInterfaceSubClass; - uint8 bInterfaceProtocol; - uint8 iInterface; -} __packed usb_descriptor_interface; - -typedef struct usb_descriptor_endpoint { - uint8 bLength; - uint8 bDescriptorType; - uint8 bEndpointAddress; - uint8 bmAttributes; - uint16 wMaxPacketSize; - uint8 bInterval; -} __packed usb_descriptor_endpoint; - -typedef struct usb_descriptor_string { - uint8 bLength; - uint8 bDescriptorType; - uint8 bString[]; -} usb_descriptor_string; - -/* Common values that go inside descriptors */ - -#define USB_CONFIG_ATTR_BUSPOWERED 0b10000000 -#define USB_CONFIG_ATTR_SELF_POWERED 0b11000000 - -#define USB_EP_TYPE_INTERRUPT 0x03 -#define USB_EP_TYPE_BULK 0x02 - -#define USB_DESCRIPTOR_ENDPOINT_IN 0x80 -#define USB_DESCRIPTOR_ENDPOINT_OUT 0x00 - -/* - * USB module core - */ - -#ifndef USB_ISR_MSK -/* Handle CTRM, WKUPM, SUSPM, ERRM, SOFM, ESOFM, RESETM */ -#define USB_ISR_MSK 0xBF00 -#endif - -typedef enum usb_dev_state { - USB_UNCONNECTED, - USB_ATTACHED, - USB_POWERED, - USB_SUSPENDED, - USB_ADDRESSED, - USB_CONFIGURED -} usb_dev_state; - -/* Encapsulates global state formerly handled by usb_lib/ */ -typedef struct usblib_dev { - uint32 irq_mask; - void (**ep_int_in)(void); - void (**ep_int_out)(void); - usb_dev_state state; - usb_dev_state prevState; - rcc_clk_id clk_id; -} usblib_dev; - -extern usblib_dev *USBLIB; - -void usb_init_usblib(usblib_dev *dev, - void (**ep_int_in)(void), - void (**ep_int_out)(void)); - -static inline uint8 usb_is_connected(usblib_dev *dev) { - return dev->state != USB_UNCONNECTED; -} - -static inline uint8 usb_is_configured(usblib_dev *dev) { - return dev->state == USB_CONFIGURED; -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/usb_cdcacm.h b/STM32F3/cores/maple/libmaple/include/libmaple/usb_cdcacm.h deleted file mode 100644 index 5fe832c..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/usb_cdcacm.h +++ /dev/null @@ -1,179 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/usb_cdcacm.h - * @brief USB CDC ACM (virtual serial terminal) support - * - * IMPORTANT: this API is unstable, and may change without notice. - */ - -#ifndef _LIBMAPLE_USB_CDCACM_H_ -#define _LIBMAPLE_USB_CDCACM_H_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * CDC ACM Requests - */ - -#define USB_CDCACM_SET_LINE_CODING 0x20 -#define USB_CDCACM_GET_LINE_CODING 0x21 -#define USB_CDCACM_SET_COMM_FEATURE 0x02 -#define USB_CDCACM_SET_CONTROL_LINE_STATE 0x22 -#define USB_CDCACM_CONTROL_LINE_DTR (0x01) -#define USB_CDCACM_CONTROL_LINE_RTS (0x02) - -/* - * Descriptors, etc. - */ - -#define CDC_FUNCTIONAL_DESCRIPTOR_SIZE(DataSize) (3 + DataSize) -#define CDC_FUNCTIONAL_DESCRIPTOR(DataSize) \ - struct { \ - uint8 bLength; \ - uint8 bDescriptorType; \ - uint8 SubType; \ - uint8 Data[DataSize]; \ - } __packed - -#define USB_DEVICE_CLASS_CDC 0x02 -#define USB_DEVICE_SUBCLASS_CDC 0x00 -#define USB_INTERFACE_CLASS_CDC 0x02 -#define USB_INTERFACE_SUBCLASS_CDC_ACM 0x02 -#define USB_INTERFACE_CLASS_DIC 0x0A - -/* - * Endpoint configuration - */ - -#define USB_CDCACM_CTRL_ENDP 0 -#define USB_CDCACM_CTRL_RX_ADDR 0x40 -#define USB_CDCACM_CTRL_TX_ADDR 0x80 -#define USB_CDCACM_CTRL_EPSIZE 0x40 - -#define USB_CDCACM_TX_ENDP 1 -#define USB_CDCACM_TX_ADDR 0xC0 -#define USB_CDCACM_TX_EPSIZE 0x40 - -#define USB_CDCACM_MANAGEMENT_ENDP 2 -#define USB_CDCACM_MANAGEMENT_ADDR 0x100 -#define USB_CDCACM_MANAGEMENT_EPSIZE 0x40 - -#define USB_CDCACM_RX_ENDP 3 -#define USB_CDCACM_RX_ADDR 0x110 -#define USB_CDCACM_RX_EPSIZE 0x40 - -#ifndef __cplusplus -#define USB_CDCACM_DECLARE_DEV_DESC(vid, pid) \ - { \ - .bLength = sizeof(usb_descriptor_device), \ - .bDescriptorType = USB_DESCRIPTOR_TYPE_DEVICE, \ - .bcdUSB = 0x0200, \ - .bDeviceClass = USB_DEVICE_CLASS_CDC, \ - .bDeviceSubClass = USB_DEVICE_SUBCLASS_CDC, \ - .bDeviceProtocol = 0x00, \ - .bMaxPacketSize0 = 0x40, \ - .idVendor = vid, \ - .idProduct = pid, \ - .bcdDevice = 0x0200, \ - .iManufacturer = 0x01, \ - .iProduct = 0x02, \ - .iSerialNumber = 0x00, \ - .bNumConfigurations = 0x01, \ - } -#endif - -/* - * CDC ACM interface - */ - -void usb_cdcacm_enable(gpio_dev*, uint8); -void usb_cdcacm_disable(gpio_dev*, uint8); - -void usb_cdcacm_putc(char ch); -uint32 usb_cdcacm_tx(const uint8* buf, uint32 len); -uint32 usb_cdcacm_rx(uint8* buf, uint32 len); -uint32 usb_cdcacm_peek(uint8* buf, uint32 len); - -uint32 usb_cdcacm_data_available(void); /* in RX buffer */ -uint16 usb_cdcacm_get_pending(void); -uint8 usb_cdcacm_is_transmitting(void); - -uint8 usb_cdcacm_get_dtr(void); -uint8 usb_cdcacm_get_rts(void); - -typedef struct usb_cdcacm_line_coding { - uint32 dwDTERate; /* Baud rate */ - -#define USB_CDCACM_STOP_BITS_1 0 -#define USB_CDCACM_STOP_BITS_1_5 1 -#define USB_CDCACM_STOP_BITS_2 2 - uint8 bCharFormat; /* Stop bits */ - -#define USB_CDCACM_PARITY_NONE 0 -#define USB_CDCACM_PARITY_ODD 1 -#define USB_CDCACM_PARITY_EVEN 2 -#define USB_CDCACM_PARITY_MARK 3 -#define USB_CDCACM_PARITY_SPACE 4 - uint8 bParityType; /* Parity type */ - - uint8 bDataBits; /* Data bits: 5, 6, 7, 8, or 16 */ -} __packed usb_cdcacm_line_coding; - -/* Retrieve a copy of the current line coding structure. */ -void usb_cdcacm_get_line_coding(usb_cdcacm_line_coding*); - -/* Line coding conveniences. */ -int usb_cdcacm_get_baud(void); /* dwDTERate */ -int usb_cdcacm_get_stop_bits(void); /* bCharFormat */ -int usb_cdcacm_get_parity(void); /* bParityType */ -int usb_cdcacm_get_n_data_bits(void); /* bDataBits */ - -/* - * Hack: hooks for bootloader reset signalling - */ - -#define USB_CDCACM_HOOK_RX 0x1 -#define USB_CDCACM_HOOK_IFACE_SETUP 0x2 - -void usb_cdcacm_set_hooks(unsigned hook_flags, void (*hook)(unsigned, void*)); - -static __always_inline void usb_cdcacm_remove_hooks(unsigned hook_flags) { - usb_cdcacm_set_hooks(hook_flags, 0); -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/include/libmaple/util.h b/STM32F3/cores/maple/libmaple/include/libmaple/util.h deleted file mode 100644 index 5a70348..0000000 --- a/STM32F3/cores/maple/libmaple/include/libmaple/util.h +++ /dev/null @@ -1,111 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/include/libmaple/util.h - * @brief Miscellaneous utility macros and procedures. - */ - -#ifndef _LIBMAPLE_UTIL_H_ -#define _LIBMAPLE_UTIL_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/* - * Bit manipulation - */ - -/** 1UL shifted left by 'shift' */ -#define BIT(shift) (1UL << (shift)) -/** 'Mask' shifted left by 'shift' */ -#define BIT_MASK_SHIFT(mask, shift) ((mask) << (shift)) -/** Bits m to n of x */ -#define GET_BITS(x, m, n) ((((uint32)x) << (31 - (n))) >> ((31 - (n)) + (m))) -/** True iff v is a power of two (1, 2, 4, 8, ...) */ -#define IS_POWER_OF_TWO(v) ((v) && !((v) & ((v) - 1))) - -/* - * Failure routines - */ - -void __error(void); -void _fail(const char*, int, const char*); -void throb(void); - -/* - * Asserts and debug levels - */ - -#define DEBUG_NONE 0 -#define DEBUG_FAULT 1 -#define DEBUG_ALL 2 - -/** - * \def DEBUG_LEVEL - * - * Controls the level of assertion checking. - * - * The higher the debug level, the more assertions will be compiled - * in. This increases the amount of debugging information, but slows - * down (and increases the size of) the binary. - * - * The debug levels, from lowest to highest, are DEBUG_NONE, - * DEBUG_FAULT, and DEBUG_ALL. The default level is DEBUG_ALL. - */ - -#ifndef DEBUG_LEVEL -#define DEBUG_LEVEL DEBUG_ALL -#endif - -#if DEBUG_LEVEL >= DEBUG_ALL -#define ASSERT(exp) \ - if (exp) { \ - } else { \ - _fail(__FILE__, __LINE__, #exp); \ - } -#else -#define ASSERT(exp) (void)((0)) -#endif - -#if DEBUG_LEVEL >= DEBUG_FAULT -#define ASSERT_FAULT(exp) \ - if (exp) { \ - } else { \ - _fail(__FILE__, __LINE__, #exp); \ - } -#else -#define ASSERT_FAULT(exp) (void)((0)) -#endif - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/iwdg.c b/STM32F3/cores/maple/libmaple/iwdg.c deleted file mode 100644 index 2456235..0000000 --- a/STM32F3/cores/maple/libmaple/iwdg.c +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Michael Hope. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/iwdg.c - * @brief Independent watchdog (IWDG) support - */ - -#include - -/** - * @brief Initialise and start the watchdog - * - * The prescaler and reload set the timeout. For example, a prescaler - * of IWDG_PRE_32 divides the 40 kHz clock by 32 and gives roughly 1 - * ms per reload. - * - * @param prescaler Prescaler for the 40 kHz IWDG clock. - * @param reload Independent watchdog counter reload value. - */ -void iwdg_init(iwdg_prescaler prescaler, uint16 reload) { - IWDG_BASE->KR = IWDG_KR_UNLOCK; - IWDG_BASE->PR = prescaler; - IWDG_BASE->RLR = reload; - - /* Start things off */ - IWDG_BASE->KR = IWDG_KR_START; - iwdg_feed(); -} - -/** - * @brief Reset the IWDG counter. - * - * Calling this function will cause the IWDG counter to be reset to - * its reload value. - */ -void iwdg_feed(void) { - IWDG_BASE->KR = IWDG_KR_FEED; -} diff --git a/STM32F3/cores/maple/libmaple/nvic.c b/STM32F3/cores/maple/libmaple/nvic.c deleted file mode 100644 index 149e780..0000000 --- a/STM32F3/cores/maple/libmaple/nvic.c +++ /dev/null @@ -1,103 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/nvic.c - * @brief Nested vector interrupt controller support. - */ - -#include -#include -#include - -/** - * @brief Set interrupt priority for an interrupt line - * - * Note: The STM32 only implements 4 bits of priority, ignoring the - * lower 4 bits. This means there are only 16 levels of priority. - * Bits[3:0] read as zero and ignore writes. - * - * @param irqn device to set - * @param priority Priority to set, 0 being highest priority and 15 - * being lowest. - */ -void nvic_irq_set_priority(nvic_irq_num irqn, uint8 priority) { - if (irqn < 0) { - /* This interrupt is in the system handler block */ - SCB_BASE->SHP[((uint32)irqn & 0xF) - 4] = (priority & 0xF) << 4; - } else { - NVIC_BASE->IP[irqn] = (priority & 0xF) << 4; - } -} - -/** - * @brief Initialize the NVIC, setting interrupts to a default priority. - */ -void nvic_init(uint32 address, uint32 offset) { - uint32 i; - - nvic_set_vector_table(address, offset); - - /* - * Lower priority level for all peripheral interrupts to lowest - * possible. - */ - for (i = 0; i < STM32_NR_INTERRUPTS; i++) { - nvic_irq_set_priority((nvic_irq_num)i, 0xF); - } - - /* Lower systick interrupt priority to lowest level */ - nvic_irq_set_priority(NVIC_SYSTICK, 0xF); -} - -/** - * @brief Set the vector table base address. - * - * For stand-alone products, the vector table base address is normally - * the start of Flash (0x08000000). - * - * @param address Vector table base address. - * @param offset Offset from address. Some restrictions apply to the - * use of nonzero offsets; see the ARM Cortex M3 - * Technical Reference Manual. - */ -void nvic_set_vector_table(uint32 address, uint32 offset) { - SCB_BASE->VTOR = address | (offset & 0x1FFFFF80); -} - -/** - * @brief Force a system reset. - * - * Resets all major system components, excluding debug. - */ -void nvic_sys_reset() { - uint32 prigroup = SCB_BASE->AIRCR & SCB_AIRCR_PRIGROUP; - SCB_BASE->AIRCR = SCB_AIRCR_VECTKEY | SCB_AIRCR_SYSRESETREQ | prigroup; - asm volatile("dsb"); - while (1) - ; -} diff --git a/STM32F3/cores/maple/libmaple/pwr.c b/STM32F3/cores/maple/libmaple/pwr.c deleted file mode 100644 index 3cf170f..0000000 --- a/STM32F3/cores/maple/libmaple/pwr.c +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/pwr.c - * @brief Power control (PWR) support. - */ - -#include -#include - -/** - * Enables the power interface clock, and resets the power device. - */ -void pwr_init(void) { - rcc_clk_enable(RCC_PWR); - rcc_reset_dev(RCC_PWR); -} diff --git a/STM32F3/cores/maple/libmaple/rcc.c b/STM32F3/cores/maple/libmaple/rcc.c deleted file mode 100644 index aba87c0..0000000 --- a/STM32F3/cores/maple/libmaple/rcc.c +++ /dev/null @@ -1,169 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/rcc.c - * @brief Portable RCC routines. - */ - -#include - -#include "rcc_private.h" - -/** - * @brief Get a peripheral's clock domain - * @param id Clock ID of the peripheral whose clock domain to return - * @return Clock source for the given clock ID - */ -rcc_clk_domain rcc_dev_clk(rcc_clk_id id) { - return rcc_dev_table[id].clk_domain; -} - -/** - * @brief Switch the clock used as the source of the system clock. - * - * After switching the source, this function blocks until the new - * clock source is in use. - * - * @param sysclk_src New system clock source. - * @see rcc_sysclk_src - */ -void rcc_switch_sysclk(rcc_sysclk_src sysclk_src) { - uint32 cfgr = RCC_BASE->CFGR; - cfgr &= ~RCC_CFGR_SW; - cfgr |= sysclk_src; - - /* Switch SYSCLK source. */ - RCC_BASE->CFGR = cfgr; - - /* Wait for new source to come into use. */ - while ((RCC_BASE->CFGR & RCC_CFGR_SWS) != (sysclk_src << 2)) - ; -} - -/* - * Turning clocks off and on, querying their status. - */ - -/* IMPORTANT NOTE FOR IMPLEMENTORS: - * - * libmaple assumes that enum rcc_clk enumerators are two-byte - * values, stored in a uint16, in the following way: - * - * - The high-order byte is the byte offset (from RCC_BASE) of the register - * to touch when turning on or off the given clock. - * - * - The low-order byte is the bit in that register that turns the - * clock on or off. - * - * Example for STM32F1: Turning on the high-speed external clock (HSE) - * involves setting HSEON, bit 16, of RCC_CR. The high-order byte is - * then offsetof(struct rcc_reg_map, CR) = 0, and the low-order byte - * is 16. - * - * The corresponding value of RCC_CLK_HSE is thus (0 << 8) | 16 = 16. - * - * On all known STM32 series, this encoding has the property that - * adding one to the low byte also gives the bit to check to determine - * if the clock is ready. For example, on STM32F1, RCC_CR_HSERDY is - * bit 17. If that's not the case on your series, rcc_is_clk_ready() - * won't work for you. */ - -/* Returns the RCC register which controls the clock source. */ -static inline __IO uint32* rcc_clk_reg(rcc_clk clock) { - return (__IO uint32*)((__IO uint8*)RCC_BASE + (clock >> 8)); -} - -/* Returns a mask in rcc_clk_reg(clock) to be used for turning the - * clock on and off */ -static inline uint32 rcc_clk_on_mask(rcc_clk clock) { - return 1 << (clock & 0xFF); -} - -/* Returns a mask in rcc_clk_reg(clock) to be used when checking the - * readiness of the clock. */ -static inline uint32 rcc_clk_ready_mask(rcc_clk clock) { - return rcc_clk_on_mask(clock) << 1; -} - -/** - * @brief Turn on a clock source. - * - * After this routine exits, callers should ensure that the clock - * source is ready by waiting until rcc_is_clk_ready(clock) returns - * true. - * - * @param clock Clock to turn on. - * @see rcc_turn_off_clk() - * @see rcc_is_clk_ready() - */ -void rcc_turn_on_clk(rcc_clk clock) { - *rcc_clk_reg(clock) |= rcc_clk_on_mask(clock); -} - -/** - * @brief Turn off a clock source. - * - * In certain configurations, certain clock sources cannot be safely - * turned off. (For example, the main PLL on STM32F1 devices cannot be - * turned off if it has been selected as the SYSCLK source). Consult - * the reference material for your MCU to ensure it is safe to call - * this function. - * - * @param clock Clock to turn off. - * @see rcc_turn_on_clk() - * @see rcc_is_clk_ready() - */ -void rcc_turn_off_clk(rcc_clk clock) { - *rcc_clk_reg(clock) &= ~rcc_clk_on_mask(clock); -} - -/** - * @brief Check if a clock is on. - * @param clock Clock to check. - * @return 1 if the clock is on, 0 if the clock is off. - */ -int rcc_is_clk_on(rcc_clk clock) { - return !!(*rcc_clk_reg(clock) & rcc_clk_on_mask(clock)); -} - -/** - * @brief Check if a clock source is ready. - * - * In general, it is not safe to rely on a clock source unless this - * function returns nonzero. Also note that this function may return - * nonzero for a short period of time after a clock has been turned - * off. Consult the reference material for your MCU for more details. - * - * @param clock Clock whose readiness to check for. - * @return Nonzero if the clock is ready, zero otherwise. - * @see rcc_turn_on_clk() - * @see rcc_turn_off_clk() - */ -int rcc_is_clk_ready(rcc_clk clock) { - return (int)(*rcc_clk_reg(clock) & rcc_clk_ready_mask(clock)); -} diff --git a/STM32F3/cores/maple/libmaple/rcc_private.h b/STM32F3/cores/maple/libmaple/rcc_private.h deleted file mode 100644 index b20a2c5..0000000 --- a/STM32F3/cores/maple/libmaple/rcc_private.h +++ /dev/null @@ -1,67 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/* - * RCC private header. - */ - -#ifndef _LIBMAPLE_PRIVATE_RCC_H_ -#define _LIBMAPLE_PRIVATE_RCC_H_ - -#include - -struct rcc_dev_info { - const rcc_clk_domain clk_domain; - const uint8 line_num; -}; - -extern const struct rcc_dev_info rcc_dev_table[]; - -static inline void rcc_do_clk_enable(__IO uint32** enable_regs, - rcc_clk_id id) { - __IO uint32 *enable_reg = enable_regs[rcc_dev_clk(id)]; - uint8 line_num = rcc_dev_table[id].line_num; - bb_peri_set_bit(enable_reg, line_num, 1); -} - -static inline void rcc_do_reset_dev(__IO uint32** reset_regs, - rcc_clk_id id) { - __IO uint32 *reset_reg = reset_regs[rcc_dev_clk(id)]; - uint8 line_num = rcc_dev_table[id].line_num; - bb_peri_set_bit(reset_reg, line_num, 1); - bb_peri_set_bit(reset_reg, line_num, 0); -} - -static inline void rcc_do_set_prescaler(const uint32 *masks, - rcc_prescaler prescaler, - uint32 divider) { - uint32 cfgr = RCC_BASE->CFGR; - cfgr &= ~masks[prescaler]; - cfgr |= divider; - RCC_BASE->CFGR = cfgr; -} - -#endif diff --git a/STM32F3/cores/maple/libmaple/rules.mk b/STM32F3/cores/maple/libmaple/rules.mk deleted file mode 100644 index 0b541ed..0000000 --- a/STM32F3/cores/maple/libmaple/rules.mk +++ /dev/null @@ -1,53 +0,0 @@ -# Standard things -sp := $(sp).x -dirstack_$(sp) := $(d) -d := $(dir) -BUILDDIRS += $(BUILD_PATH)/$(d) - -LIBMAPLE_INCLUDES := -I$(LIBMAPLE_PATH)/include -I$(LIBMAPLE_MODULE_SERIES)/include -LIBMAPLE_PRIVATE_INCLUDES := -I$(LIBMAPLE_PATH) - -# Local flags -CFLAGS_$(d) = $(LIBMAPLE_PRIVATE_INCLUDES) $(LIBMAPLE_INCLUDES) -Wall -Werror - -# Local rules and targets -cSRCS_$(d) := adc.c -cSRCS_$(d) += dac.c -cSRCS_$(d) += dma.c -cSRCS_$(d) += exti.c -cSRCS_$(d) += flash.c -cSRCS_$(d) += gpio.c -cSRCS_$(d) += iwdg.c -cSRCS_$(d) += nvic.c -cSRCS_$(d) += pwr.c -cSRCS_$(d) += rcc.c -cSRCS_$(d) += spi.c -cSRCS_$(d) += systick.c -ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),stm32f2 stm32f3)) # SYSCFG peripheral available only on F2, F3 -cSRCS_$(d) += syscfg.c -endif -cSRCS_$(d) += timer.c -cSRCS_$(d) += usart.c -cSRCS_$(d) += usart_private.c -cSRCS_$(d) += util.c -sSRCS_$(d) := exc.S -ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),stm32f1 stm32f3)) # TODO port I2C to F2 -cSRCS_$(d) += i2c.c -cSRCS_$(d) += bkp.c -endif - -cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%) -sFILES_$(d) := $(sSRCS_$(d):%=$(d)/%) - -OBJS_$(d) := $(cFILES_$(d):%.c=$(BUILD_PATH)/%.o) $(sFILES_$(d):%.S=$(BUILD_PATH)/%.o) -DEPS_$(d) := $(OBJS_$(d):%.o=%.d) - -$(OBJS_$(d)): TGT_CFLAGS := $(CFLAGS_$(d)) -$(OBJS_$(d)): TGT_ASFLAGS := - -TGT_BIN += $(OBJS_$(d)) - -# Standard things --include $(DEPS_$(d)) -d := $(dirstack_$(sp)) -sp := $(basename $(sp)) diff --git a/STM32F3/cores/maple/libmaple/spi.c b/STM32F3/cores/maple/libmaple/spi.c deleted file mode 100644 index ec008d4..0000000 --- a/STM32F3/cores/maple/libmaple/spi.c +++ /dev/null @@ -1,129 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/spi.c - * @author Marti Bolivar - * @brief Serial Peripheral Interface (SPI) support. - * Currently, there is no Integrated Interchip Sound (I2S) support. - */ - -#include -#include - -/* - * SPI convenience routines - */ - -/** - * @brief Initialize and reset a SPI device. - * @param dev Device to initialize and reset. - */ -void spi_init(spi_dev *dev) { - rcc_clk_enable(dev->clk_id); - rcc_reset_dev(dev->clk_id); -} - -/** - * @brief Configure and enable a SPI device as bus master. - * - * The device's peripheral will be disabled before being reconfigured. - * - * @param dev Device to configure as bus master - * @param baud Bus baud rate - * @param mode SPI mode - * @param flags Logical OR of spi_cfg_flag values. - * @see spi_cfg_flag - */ -void spi_master_enable(spi_dev *dev, - spi_baud_rate baud, - spi_mode mode, - uint32 flags) { - spi_reconfigure(dev, baud | flags | SPI_CR1_MSTR | mode); -} - -/** - * @brief Configure and enable a SPI device as a bus slave. - * - * The device's peripheral will be disabled before being reconfigured. - * - * @param dev Device to configure as a bus slave - * @param mode SPI mode - * @param flags Logical OR of spi_cfg_flag values. - * @see spi_cfg_flag - */ -void spi_slave_enable(spi_dev *dev, spi_mode mode, uint32 flags) { - spi_reconfigure(dev, flags | mode); -} - -/** - * @brief Enable a SPI peripheral - * @param dev Device to enable - */ -void spi_peripheral_enable(spi_dev *dev) { - bb_peri_set_bit(&dev->regs->CR1, SPI_CR1_SPE_BIT, 1); -} - -/** - * @brief Disable a SPI peripheral - * @param dev Device to disable - */ -void spi_peripheral_disable(spi_dev *dev) { - bb_peri_set_bit(&dev->regs->CR1, SPI_CR1_SPE_BIT, 0); -} - -/** - * @brief Enable DMA requests whenever the transmit buffer is empty - * @param dev SPI device on which to enable TX DMA requests - */ -void spi_tx_dma_enable(spi_dev *dev) { - bb_peri_set_bit(&dev->regs->CR2, SPI_CR2_TXDMAEN_BIT, 1); -} - -/** - * @brief Disable DMA requests whenever the transmit buffer is empty - * @param dev SPI device on which to disable TX DMA requests - */ -void spi_tx_dma_disable(spi_dev *dev) { - bb_peri_set_bit(&dev->regs->CR2, SPI_CR2_TXDMAEN_BIT, 0); -} - -/** - * @brief Enable DMA requests whenever the receive buffer is empty - * @param dev SPI device on which to enable RX DMA requests - */ -void spi_rx_dma_enable(spi_dev *dev) { - bb_peri_set_bit(&dev->regs->CR2, SPI_CR2_RXDMAEN_BIT, 1); -} - -/** - * @brief Disable DMA requests whenever the receive buffer is empty - * @param dev SPI device on which to disable RX DMA requests - */ -void spi_rx_dma_disable(spi_dev *dev) { - bb_peri_set_bit(&dev->regs->CR2, SPI_CR2_RXDMAEN_BIT, 0); -} diff --git a/STM32F3/cores/maple/libmaple/spi_private.h b/STM32F3/cores/maple/libmaple/spi_private.h deleted file mode 100644 index f0e0bd1..0000000 --- a/STM32F3/cores/maple/libmaple/spi_private.h +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#ifndef _LIBMAPLE_SPI_PRIVATE_H_ -#define _LIBMAPLE_SPI_PRIVATE_H_ - -#define SPI_DEV(num) \ - { \ - .regs = SPI##num##_BASE, \ - .clk_id = RCC_SPI##num, \ - .irq_num = NVIC_SPI##num, \ - } - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32_private.h b/STM32F3/cores/maple/libmaple/stm32_private.h deleted file mode 100644 index 427417a..0000000 --- a/STM32F3/cores/maple/libmaple/stm32_private.h +++ /dev/null @@ -1,45 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -#ifndef _LIBMAPLE_STM32_PRIVATE_H_ -#define _LIBMAPLE_STM32_PRIVATE_H_ - -typedef enum stm32_mem_block_purpose { - STM32_BLOCK_CODE, - STM32_BLOCK_SRAM, - STM32_BLOCK_PERIPH, - STM32_BLOCK_FSMC_1_2, - STM32_BLOCK_FSMC_3_4, - STM32_BLOCK_FSMC_REG, - STM32_BLOCK_UNUSED, - STM32_BLOCK_CORTEX_INTERNAL, -} stm32_mem_block_purpose; - -static inline stm32_mem_block_purpose stm32_block_purpose(void *addr) { - return (stm32_mem_block_purpose)((unsigned)addr >> 29); -} - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_adc.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_adc.c deleted file mode 100644 index 23a3b96..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_adc.c +++ /dev/null @@ -1,412 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/adc.c - * @author Marti Bolivar , - * Perry Hung , - * F3-port by Hanspeter Portner - * @brief STM32F3 ADC support. - */ - -#include -#include -#include - -/* - * Devices - */ - -static adc_private_data adc1_priv; -static adc_dev adc1 = { - .regs = ADC1_BASE, - .clk_id = RCC_ADC12, - .priv = &adc1_priv -}; -/** ADC1 device. */ -const adc_dev *ADC1 = &adc1; - -static adc_private_data adc2_priv; -static adc_dev adc2 = { - .regs = ADC2_BASE, - .clk_id = RCC_ADC12, - .priv = &adc2_priv -}; -/** ADC2 device. */ -const adc_dev *ADC2 = &adc2; - -#if STM32_F3_LINE == STM32_F3_LINE_303 -static adc_private_data adc3_priv; -static adc_dev adc3 = { - .regs = ADC3_BASE, - .clk_id = RCC_ADC34, - .priv = &adc3_priv -}; -/** ADC3 device. */ -const adc_dev *ADC3 = &adc3; - -static adc_private_data adc4_priv; -static adc_dev adc4 = { - .regs = ADC4_BASE, - .clk_id = RCC_ADC34, - .priv = &adc4_priv -}; -/** ADC4 device. */ -const adc_dev *ADC4 = &adc4; -#endif - -/* - * STM32F3 routines - */ - -static inline void adc_check_regular_notongoing(const adc_dev *dev) { - adc_reg_map *regs = dev->regs; - if(regs->CR & ADC_CR_ADSTART) /* check for ongoing regular channel conversion */ - { - regs->CR |= ADC_CR_ADSTP; /* stop regular channel conversion */ - while(regs->CR & ADC_CR_ADSTP) - ; /* wait for conversion to stop */ - } -} - -static inline void adc_check_injected_notongoing(const adc_dev *dev) { - adc_reg_map *regs = dev->regs; - if(regs->CR & ADC_CR_JADSTART) /* check for ongoing injected channel conversion */ - { - regs->CR |= ADC_CR_JADSTP; /* stop injected channel conversion */ - while(regs->CR & ADC_CR_JADSTP) - ; /* wait for conversion to stop */ - } -} - -void adc_set_extsel(const adc_dev *dev, adc_extsel_event event) { - adc_check_regular_notongoing(dev); - - uint32 cfgr = dev->regs->CFGR; - cfgr &= ~ADC_CFGR_EXTSEL; - cfgr |= event; - dev->regs->CFGR = cfgr; -} - -void adc_set_resolution(const adc_dev *dev, adc_resolution res) { - adc_check_regular_notongoing(dev); - adc_check_injected_notongoing(dev); - - uint32 cfgr = dev->regs->CFGR; - cfgr &= ~ADC_CFGR_RES; - cfgr |= res; - dev->regs->CFGR = cfgr; -} - -void adc_set_sample_rate(const adc_dev *dev, adc_smp_rate smp_rate) { - adc_check_regular_notongoing(dev); - adc_check_injected_notongoing(dev); - - uint32 adc_smpr1_val = 0, adc_smpr2_val = 0; - int i; - - for(i = 0; i < 9; i++) { - /* ADC_SMPR1 determines sample time for channels [1,9] */ - adc_smpr1_val |= smp_rate << (i * 3 + 3); - /* ADC_SMPR2 determines sample time for channels [10,18] */ - adc_smpr2_val |= smp_rate << (i * 3); - } - - dev->regs->SMPR1 = adc_smpr1_val; - dev->regs->SMPR2 = adc_smpr2_val; -} - -void adc_enable_scan(const adc_dev *dev) { - /* FIXME nonexistent in F3 series */ -} - -void adc_disable_scan(const adc_dev *dev) { - /* FIXME nonexistent in F3 series*/ -} - -void adc_enable_continuous(const adc_dev *dev) { - bb_peri_set_bit(&dev->regs->CFGR, ADC_CFGR_CONT_BIT, 1); -} - -void adc_disable_continuous(const adc_dev *dev) { - bb_peri_set_bit(&dev->regs->CFGR, ADC_CFGR_CONT_BIT, 0); -} - -#define BITS_PER_SQ 6 -#define SQs_PER_SQR 5 -void adc_set_conv_seq(const adc_dev *dev, const uint8 *channels, uint8 len) { - ASSERT( (0 < len) && (len <= 16) ); - uint8 i; - uint32 val = 0; - uint8 lshift; - __IO uint32 *sqr = &dev->regs->SQR1; - - for (i=0; iregs; - - adc_set_conv_seq(dev, &channel, 1); - - regs->CR |= ADC_CR_ADSTART; /* start conversion */ - while (!(regs->ISR & ADC_ISR_EOC)) - ; /* wait until done */ - - return (uint16)(regs->DR & ADC_DR_RDATA); -} - -void adc_attach_interrupt(const adc_dev *dev, uint32 interrupt_flags, - void (*handler)(adc_callback_data*), void *arg) { - adc_private_data *priv = dev->priv; - priv->handler = handler; - priv->handler_flags = interrupt_flags; - priv->cb_data.arg = arg; - adc_enable_interrupts(dev, interrupt_flags); -} - -void adc_detach_interrupt(const adc_dev *dev) { - adc_private_data *priv; - adc_disable_interrupts(dev, ADC_ALL_INTERRUPTS); - priv = dev->priv; - priv->handler = NULL; - priv->handler_flags = 0; -} - -void adc_enable_interrupts(const adc_dev *dev, uint32 interrupt_flags) { - uint32 ier = dev->regs->IER; - ier |= interrupt_flags; - dev->regs->IER = ier; - _adc_enable_dev_irq(dev); -} - -void adc_disable_interrupts(const adc_dev *dev, uint32 interrupt_flags) { - /* Don't use nvic_irq_disable()! IRQs are shared among ADCs. */ - uint32 ier = dev->regs->IER; - ier &= ~interrupt_flags; - dev->regs->IER = ier; -} - -void adc_calibrate(const adc_dev *dev) { - adc_reg_map *regs = dev->regs; - - if( (regs->CR & ADC_CR_ADVREGEN) != ADC_CR_ADVREGEN_ENABLE) - adc_regulator_enable(dev); /* ensure that voltage regulator is enabled */ - - if(regs->CR & ADC_CR_ADEN) - adc_disable(dev); /* ensure that ADC is disabled */ - - regs->CR &= ~ADC_CR_ADCALDIF; /* calibrate in single-ended mode */ - regs->CR |= ADC_CR_ADCAL; /* start calibration */ - while (regs->CR & ADC_CR_ADCAL) - ; /* wait until done */ - - regs->CR |= ADC_CR_ADCALDIF; /* calibrate in differential mode */ - regs->CR |= ADC_CR_ADCAL; /* start calibration */ - while (regs->CR & ADC_CR_ADCAL) - ; /* wait until done */ -} - -void adc_set_exttrig(const adc_dev *dev, adc_exttrig_mode mode) { - adc_reg_map *regs = dev->regs; - regs->CFGR &= ~ADC_CFGR_EXTEN; - regs->CFGR |= mode; -} - -void adc_set_prescaler(adc_prescaler pre) { - if (pre & 0x10) { /* PLL is used as clock source */ - ADC12_BASE->CCR &= ~ADC_CCR_CKMODE; -#if STM32_F3_LINE == STM32_F3_LINE_303 - ADC34_BASE->CCR &= ~ADC_CCR_CKMODE; -#endif - - uint32 cfgr2 = RCC_BASE->CFGR2; - - cfgr2 &= ~RCC_CFGR2_ADC12PRES; // clear register - cfgr2 |= (uint32)pre << RCC_CFGR2_ADC12PRES_SHIFT; // set register - -#if STM32_F3_LINE == STM32_F3_LINE_303 - cfgr2 &= ~RCC_CFGR2_ADC34PRES; // clear register - cfgr2 |= (uint32)pre << RCC_CFGR2_ADC34PRES_SHIFT; // set register -#endif - - RCC_BASE->CFGR2 = cfgr2; - } else { /* AHB bus is used as clock source */ - /* FIXME does not work with current wirish booting routine */ - uint32 tmp; - - tmp = ADC12_BASE->CCR; - tmp &= ~ADC_CCR_CKMODE; - tmp |= pre << ADC_CCR_CKMODE_SHIFT; - ADC12_BASE->CCR = tmp; - -#if STM32_F3_LINE == STM32_F3_LINE_303 - tmp = ADC34_BASE->CCR; - tmp &= ~ADC_CCR_CKMODE; - tmp |= pre << ADC_CCR_CKMODE_SHIFT; - ADC34_BASE->CCR = tmp; -#endif - } -} - -void adc_foreach(void (*fn)(const adc_dev*)) { - fn(ADC1); - fn(ADC2); -#if STM32_F3_LINE == STM32_F3_LINE_303 - fn(ADC3); - fn(ADC4); -#endif -} - -void adc_config_gpio(const adc_dev *ignored, gpio_dev *gdev, uint8 bit) { - gpio_set_modef(gdev, bit, GPIO_MODE_ANALOG, GPIO_MODEF_PUPD_NONE); -} - -void adc_enable_single_swstart(const adc_dev *dev) { - int check_dev_adc = dev == ADC1; -#if STM32_F3_LINE == STM32_F3_LINE_303 - check_dev_adc = (check_dev_adc || dev == ADC3); -#endif - if (check_dev_adc) - adc_init(dev); /* FIXME hack needed for wirish, as master and slave ADC share the same reset register */ - adc_set_exttrig(dev, ADC_EXTTRIG_MODE_SOFTWARE); - adc_regulator_enable(dev); - adc_calibrate(dev); - adc_enable(dev); -} - -void adc_set_reg_seqlen(const adc_dev *dev, uint8 length) { - adc_check_regular_notongoing(dev); - - uint32 tmp = dev->regs->SQR1; - tmp &= ~ADC_SQR1_L; - tmp |= (length - 1) & ADC_SQR1_L; - dev->regs->SQR1 = tmp; -} - -void adc_enable(const adc_dev *dev) { - adc_reg_map *regs = dev->regs; - - while( (regs->CR & ADC_CR_ADVREGEN) != ADC_CR_ADVREGEN_ENABLE) - adc_regulator_enable(dev); /* ensure that voltage regulator is enabled */ - - regs->CR |= ADC_CR_ADEN; /* enable ADC */ - while (!(regs->ISR & ADC_ISR_ADRDY)) - ; /* wait until ADC is ready */ -} - -void adc_disable(const adc_dev *dev) { - adc_reg_map *regs = dev->regs; - - adc_check_regular_notongoing(dev); - adc_check_injected_notongoing(dev); - - regs->CR |= ADC_CR_ADDIS; /* disable ADC */ - while(regs->CR & ADC_CR_ADEN) - ; /* wait until ADC is effectively disabled */ -} - -void adc_regulator_enable(const adc_dev *dev) { - adc_reg_map *regs = dev->regs; - - regs->CR &= ~ADC_CR_ADVREGEN; - regs->CR |= ADC_CR_ADVREGEN_ENABLE; - - delay_us(10); /* 10us are worst case */ -} - -void adc_regulator_disable(const adc_dev *dev) { - adc_reg_map *regs = dev->regs; - - regs->CR &= ~ADC_CR_ADVREGEN; - regs->CR |= ADC_CR_ADVREGEN_DISABLE; -} - -/* - * Private API - */ - -void _adc_enable_dev_irq(const adc_dev *dev) { - if ( (dev == ADC1) || (dev == ADC2) ) - nvic_irq_enable(NVIC_ADC1_2); -#if STM32_F3_LINE == STM32_F3_LINE_303 - else { - if (dev == ADC3) - nvic_irq_enable(NVIC_ADC3); - else // dev == ADC4 - nvic_irq_enable(NVIC_ADC4); - } -#endif -} - -/* IRQ handler for adc_attach_interrupt() */ -static __always_inline void adc_irq(const adc_dev *dev) { - adc_private_data *priv = dev->priv; - uint32 irq_flags = dev->regs->ISR & priv->handler_flags; - - if (!irq_flags) { - /* The user isn't interested in this IRQ. */ - return; - } else if (priv->handler) { - priv->cb_data.irq_flags = irq_flags; - priv->handler(&priv->cb_data); - } -} - -/* - * IRQ handlers for adc_attach_interrupt() - */ -/* -void __irq_adc1_2(void) { - adc_irq(ADC1); - adc_irq(ADC2); -} - -#if STM32_F3_LINE == STM32_F3_LINE_303 -void __irq_adc3(void) { - adc_irq(ADC3); -} - -void __irq_adc4(void) { - adc_irq(ADC4); -} -#endif -*/ diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_bkp.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_bkp.c deleted file mode 100644 index 5ce70ae..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_bkp.c +++ /dev/null @@ -1,49 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/bkp.c - * @author F3-port by Hanspeter Portner - * @brief STM32F3 backup register support. - */ - -#include -#include -#include - -void bkp_init(void) { - /* Don't call pwr_init(), or you'll reset the device. We just - * need the clock. */ - rcc_clk_enable(RCC_PWR); -} - -inline __IO uint32* bkp_data_register(uint8 reg) { - if (reg < 1 || reg > BKP_NR_DATA_REGS) - return NULL; - else - return (uint32*)BKP_BASE + (reg-1); // regs are accessed from 1-16 -} diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_comp.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_comp.c deleted file mode 100644 index 527be71..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_comp.c +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/comp.c - * @author F3-port by Hanspeter Portner - * @brief STM32F3 Comparator support. - */ - -#include - -/* - * Devices - */ - -static comp_dev comp1 = { .regs = COMP1_BASE }; const comp_dev *COMP1 = &comp1; -static comp_dev comp2 = { .regs = COMP2_BASE }; const comp_dev *COMP2 = &comp2; -static comp_dev comp3 = { .regs = COMP3_BASE }; const comp_dev *COMP3 = &comp3; -static comp_dev comp4 = { .regs = COMP4_BASE }; const comp_dev *COMP4 = &comp4; -static comp_dev comp5 = { .regs = COMP5_BASE }; const comp_dev *COMP5 = &comp5; -static comp_dev comp6 = { .regs = COMP6_BASE }; const comp_dev *COMP6 = &comp6; -static comp_dev comp7 = { .regs = COMP7_BASE }; const comp_dev *COMP7 = &comp7; - -void __irq_comp123(void) { - //TODO -} - -void __irq_com456(void) { - //TODO -} - -void __irq_comp7(void) { - //TODO -} - -/* TODO - * actually implement me ;-) - */ diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_dma.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_dma.c deleted file mode 100644 index 10ba37f..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_dma.c +++ /dev/null @@ -1,364 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Michael Hope. - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/dma.c - * @author Marti Bolivar , - * Original implementation by Michael Hope, - * F3-port by Hanspeter Portner - * @brief STM32F3 DMA support. - */ - -#include -#include - -/* Hack to ensure inlining in dma_irq_handler() */ -#define DMA_GET_HANDLER(dev, tube) (dev->handlers[tube - 1].handler) -#include "dma_private.h" - -/* - * Devices - */ - -static dma_dev dma1 = { - .regs = DMA1_BASE, - .clk_id = RCC_DMA1, - .handlers = {{ .handler = NULL, .irq_line = NVIC_DMA_CH1 }, - { .handler = NULL, .irq_line = NVIC_DMA_CH2 }, - { .handler = NULL, .irq_line = NVIC_DMA_CH3 }, - { .handler = NULL, .irq_line = NVIC_DMA_CH4 }, - { .handler = NULL, .irq_line = NVIC_DMA_CH5 }, - { .handler = NULL, .irq_line = NVIC_DMA_CH6 }, - { .handler = NULL, .irq_line = NVIC_DMA_CH7 }}, -}; -/** STM32F3 DMA1 device */ -dma_dev *DMA1 = &dma1; - -static dma_dev dma2 = { - .regs = DMA2_BASE, - .clk_id = RCC_DMA2, - .handlers = {{ .handler = NULL, .irq_line = NVIC_DMA2_CH1 }, - { .handler = NULL, .irq_line = NVIC_DMA2_CH2 }, - { .handler = NULL, .irq_line = NVIC_DMA2_CH3 }, - { .handler = NULL, .irq_line = NVIC_DMA2_CH4 }, - { .handler = NULL, .irq_line = NVIC_DMA2_CH5 }}, -}; -/** STM32F3 DMA2 device */ -dma_dev *DMA2 = &dma2; - -/* - * Auxiliary routines - */ - -/* Can channel serve cfg->tube_req_src? */ -static int cfg_req_ok(dma_channel channel, dma_tube_config *cfg) { - return (cfg->tube_req_src & 0x7) == channel; -} - -/* Can dev serve cfg->tube_req_src? */ -static int cfg_dev_ok(dma_dev *dev, dma_tube_config *cfg) { - return (rcc_clk_id)(cfg->tube_req_src >> 3) == dev->clk_id; -} - -/* Is addr acceptable for use as DMA src/dst? */ -static int cfg_mem_ok(__IO void *addr) { - enum dma_atype atype = _dma_addr_type(addr); - return atype == DMA_ATYPE_MEM || atype == DMA_ATYPE_PER; -} - -/* Is the direction implied by src->dst supported? */ -static int cfg_dir_ok(dma_tube_config *cfg) { - /* We can't do peripheral->peripheral transfers. */ - return ((_dma_addr_type(cfg->tube_src) == DMA_ATYPE_MEM) || - (_dma_addr_type(cfg->tube_dst) == DMA_ATYPE_MEM)); -} - -static int preconfig_check(dma_dev *dev, dma_channel channel, - dma_tube_config *cfg) { - if (!cfg_req_ok(channel, cfg)) { - return -DMA_TUBE_CFG_EREQ; - } - if (cfg->tube_nr_xfers > 65535) { - return -DMA_TUBE_CFG_ENDATA; - } - if (!cfg_dev_ok(dev, cfg)) { - return -DMA_TUBE_CFG_EDEV; - } - if (!cfg_mem_ok(cfg->tube_src)) { - return -DMA_TUBE_CFG_ESRC; - } - if (!cfg_mem_ok(cfg->tube_dst)) { - return -DMA_TUBE_CFG_EDST; - } - if (!cfg_dir_ok(cfg)) { - return -DMA_TUBE_CFG_EDIR; - } - return DMA_TUBE_CFG_SUCCESS; -} - -static inline void set_ccr(dma_tube_reg_map *chregs, - dma_xfer_size msize, int minc, - dma_xfer_size psize, int pinc, - uint32 other_flags) { - chregs->CCR = ((msize << 10) | (psize << 8) | - (minc ? DMA_CCR_MINC : 0) | (pinc ? DMA_CCR_PINC : 0) | - other_flags); -} - -static inline uint32 cfg_ccr_flags(unsigned tube_flags) { - /* DMA_CFG_SRC_INC and DMA_CFG_DST_INC are special */ - return tube_flags & ~(DMA_CFG_SRC_INC | DMA_CFG_DST_INC); -} - -/* Configure chregs according to cfg, where cfg->tube_dst is peripheral. */ -static int config_to_per(dma_tube_reg_map *chregs, dma_tube_config *cfg) { - /* Check that ->tube_src is memory (if it's anything else, we - * shouldn't have been called). */ - ASSERT(_dma_addr_type(cfg->tube_src) == DMA_ATYPE_MEM); - - set_ccr(chregs, - cfg->tube_src_size, cfg->tube_flags & DMA_CFG_SRC_INC, - cfg->tube_dst_size, cfg->tube_flags & DMA_CFG_DST_INC, - (cfg_ccr_flags(cfg->tube_flags) | DMA_CCR_DIR_FROM_MEM)); - chregs->CNDTR = cfg->tube_nr_xfers; - chregs->CMAR = (uint32)cfg->tube_src; - chregs->CPAR = (uint32)cfg->tube_dst; - return DMA_TUBE_CFG_SUCCESS; -} - -/* Configure chregs according to cfg, where cfg->tube_dst is memory. */ -static int config_to_mem(dma_tube_reg_map *chregs, dma_tube_config *cfg) { - uint32 mem2mem; - - if ((_dma_addr_type(cfg->tube_src) == DMA_ATYPE_MEM) && - (cfg->tube_flags & DMA_CFG_CIRC)) { - /* Can't do mem-to-mem and circular mode */ - return -DMA_TUBE_CFG_ECFG; - } - - mem2mem = (_dma_addr_type(cfg->tube_src) == DMA_ATYPE_MEM ? - DMA_CCR_MEM2MEM : 0); - set_ccr(chregs, - cfg->tube_dst_size, cfg->tube_flags & DMA_CFG_DST_INC, - cfg->tube_src_size, cfg->tube_flags & DMA_CFG_SRC_INC, - (cfg_ccr_flags(cfg->tube_flags) | - DMA_CCR_DIR_FROM_PER | - mem2mem)); - chregs->CNDTR = cfg->tube_nr_xfers; - chregs->CMAR = (uint32)cfg->tube_dst; - chregs->CPAR = (uint32)cfg->tube_src; - return DMA_TUBE_CFG_SUCCESS; -} - -/* - * Routines - */ - -int dma_tube_cfg(dma_dev *dev, dma_channel channel, dma_tube_config *cfg) { - dma_tube_reg_map *chregs; - int ret = preconfig_check(dev, channel, cfg); - - if (ret < 0) { - return ret; - } - - dma_disable(dev, channel); /* Must disable before reconfiguring */ - dma_clear_isr_bits(dev, channel); /* For sanity and consistency - * with STM32F2. */ - - chregs = dma_tube_regs(dev, channel); - switch (_dma_addr_type(cfg->tube_dst)) { - case DMA_ATYPE_PER: - ret = config_to_per(chregs, cfg); - break; - case DMA_ATYPE_MEM: - ret = config_to_mem(chregs, cfg); - break; - default: - /* Can't happen */ - ASSERT(0); - return -DMA_TUBE_CFG_ECFG; - } - if (ret < 0) { - return ret; - } - chregs->CNDTR = cfg->tube_nr_xfers; - return DMA_TUBE_CFG_SUCCESS; -} - -void dma_set_priority(dma_dev *dev, - dma_channel channel, - dma_priority priority) { - dma_channel_reg_map *channel_regs; - uint32 ccr; - - ASSERT_FAULT(!dma_is_channel_enabled(dev, channel)); - - channel_regs = dma_channel_regs(dev, channel); - ccr = channel_regs->CCR; - ccr &= ~DMA_CCR_PL; - ccr |= (priority << 12); - channel_regs->CCR = ccr; -} - -void dma_set_num_transfers(dma_dev *dev, - dma_channel channel, - uint16 num_transfers) { - dma_channel_reg_map *channel_regs; - - ASSERT_FAULT(!dma_is_channel_enabled(dev, channel)); - - channel_regs = dma_channel_regs(dev, channel); - channel_regs->CNDTR = num_transfers; -} - -void dma_attach_interrupt(dma_dev *dev, dma_channel channel, - void (*handler)(void)) { - DMA_GET_HANDLER(dev, channel) = handler; - nvic_irq_enable(dev->handlers[channel - 1].irq_line); -} - -void dma_detach_interrupt(dma_dev *dev, dma_channel channel) { - /* Don't use nvic_irq_disable()! Think about DMA2 channels 4 and 5. */ - dma_channel_regs(dev, channel)->CCR &= ~0xF; - DMA_GET_HANDLER(dev, channel) = NULL; -} - -void dma_enable(dma_dev *dev, dma_channel channel) { - dma_channel_reg_map *chan_regs = dma_channel_regs(dev, channel); - bb_peri_set_bit(&chan_regs->CCR, DMA_CCR_EN_BIT, 1); -} - -void dma_disable(dma_dev *dev, dma_channel channel) { - dma_channel_reg_map *chan_regs = dma_channel_regs(dev, channel); - bb_peri_set_bit(&chan_regs->CCR, DMA_CCR_EN_BIT, 0); -} - -dma_irq_cause dma_get_irq_cause(dma_dev *dev, dma_channel channel) { - /* Grab and clear the ISR bits. */ - uint8 status_bits = dma_get_isr_bits(dev, channel); - dma_clear_isr_bits(dev, channel); - - /* If the channel global interrupt flag is cleared, then - * something's very wrong. */ - ASSERT(status_bits & 0x1); - /* If GIF is set, then some other flag should be set, barring - * something unexpected (e.g. the user making an unforeseen IFCR - * write). */ - ASSERT(status_bits != 0x1); - - /* ISR flags get set even if the corresponding interrupt enable - * bits in the channel's configuration register are cleared, so we - * can't use a switch here. - * - * Don't change the order of these if statements. */ - if (status_bits & 0x8) { - return DMA_TRANSFER_ERROR; - } else if (status_bits & 0x2) { - return DMA_TRANSFER_COMPLETE; - } else if (status_bits & 0x4) { - return DMA_TRANSFER_HALF_COMPLETE; - } - - /* If we get here, one of our assumptions has been violated, but - * the debug level is too low for the above ASSERTs() to have had - * any effect. In order to fail fast, mimic the DMA controller's - * behavior when an error occurs. */ - dma_disable(dev, channel); - return DMA_TRANSFER_ERROR; -} - -void dma_set_mem_addr(dma_dev *dev, dma_channel channel, __IO void *addr) { - dma_channel_reg_map *chan_regs; - - ASSERT_FAULT(!dma_is_channel_enabled(dev, channel)); - - chan_regs = dma_channel_regs(dev, channel); - chan_regs->CMAR = (uint32)addr; -} - -void dma_set_per_addr(dma_dev *dev, dma_channel channel, __IO void *addr) { - dma_channel_reg_map *chan_regs; - - ASSERT_FAULT(!dma_is_channel_enabled(dev, channel)); - - chan_regs = dma_channel_regs(dev, channel); - chan_regs->CPAR = (uint32)addr; -} - -/* - * IRQ handlers - */ - -void __irq_dma1_ch1(void) { - dma_irq_handler(DMA1, DMA_CH1); -} - -void __irq_dma1_ch2(void) { - dma_irq_handler(DMA1, DMA_CH2); -} - -void __irq_dma1_ch3(void) { - dma_irq_handler(DMA1, DMA_CH3); -} - -void __irq_dma1_ch4(void) { - dma_irq_handler(DMA1, DMA_CH4); -} - -void __irq_dma1_ch5(void) { - dma_irq_handler(DMA1, DMA_CH5); -} - -void __irq_dma1_ch6(void) { - dma_irq_handler(DMA1, DMA_CH6); -} - -void __irq_dma1_ch7(void) { - dma_irq_handler(DMA1, DMA_CH7); -} - -void __irq_dma2_ch1(void) { - dma_irq_handler(DMA2, DMA_CH1); -} - -void __irq_dma2_ch2(void) { - dma_irq_handler(DMA2, DMA_CH2); -} - -void __irq_dma2_ch3(void) { - dma_irq_handler(DMA2, DMA_CH3); -} - -void __irq_dma2_ch4(void) { - dma_irq_handler(DMA2, DMA_CH4); -} - -void __irq_dma2_ch5(void) { - dma_irq_handler(DMA2, DMA_CH5); -} diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_exti.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_exti.c deleted file mode 100644 index 44f0057..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_exti.c +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -/** - * @file libmaple/stm32f3/exti.c - * @author F3-port by Hanspeter Portner - * @brief STM32F3 EXTI. - */ - -#include -#include -#include "exti_private.h" - -void exti_select(exti_num num, exti_cfg cfg) { - exti_do_select(&SYSCFG_BASE->EXTICR[num / 4], num, cfg); -} diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_fpu.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_fpu.c deleted file mode 100644 index 7ea5277..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_fpu.c +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/fpu.c - * @author F3-port by Hanspeter Portner - * @brief STM32F3 FPU. - */ - -#include - -void fpu_enable(void) { - /* - * set coprocessor access control registers - */ - asm("\tLDR.W R0, =0xE000ED88\n" - "\tLDR R1, [R0]\n" - "\tORR R1, R1, #(0xF << 20)\n" - "\tSTR R1, [R0]\n" - "\tDSB\n" - "\tISB"); -} - -void fpu_disable(void) { - /* - * clear coprocessor access control registers - */ - asm("\tLDR.W R0, =0xE000ED88\n" - "\tLDR R1, [R0]\n" - "\tORR R1, R1, #(0x0 << 20)\n" - "\tSTR R1, [R0]\n" - "\tDSB\n" - "\tISB"); -} diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_gpio.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_gpio.c deleted file mode 100644 index 7ca982a..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_gpio.c +++ /dev/null @@ -1,169 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/gpio.c - * @author F3-port by Hanspeter Portner - * @brief STM32F3 GPIO. - */ - -#include -#include -#include - -/* - * GPIO devices - */ - -gpio_dev gpioa = { - .regs = GPIOA_BASE, - .clk_id = RCC_GPIOA, - .exti_port = EXTI_PA, -}; -/** GPIO port A device. */ -gpio_dev* const GPIOA = &gpioa; - -gpio_dev gpiob = { - .regs = GPIOB_BASE, - .clk_id = RCC_GPIOB, - .exti_port = EXTI_PB, -}; -/** GPIO port B device. */ -gpio_dev* const GPIOB = &gpiob; - -gpio_dev gpioc = { - .regs = GPIOC_BASE, - .clk_id = RCC_GPIOC, - .exti_port = EXTI_PC, -}; -/** GPIO port C device. */ -gpio_dev* const GPIOC = &gpioc; - -gpio_dev gpiod = { - .regs = GPIOD_BASE, - .clk_id = RCC_GPIOD, - .exti_port = EXTI_PD, -}; -/** GPIO port D device. */ -gpio_dev* const GPIOD = &gpiod; - -gpio_dev gpioe = { - .regs = GPIOE_BASE, - .clk_id = RCC_GPIOE, - .exti_port = EXTI_PE, -}; -/** GPIO port E device. */ -gpio_dev* const GPIOE = &gpioe; - -gpio_dev gpiof = { - .regs = GPIOF_BASE, - .clk_id = RCC_GPIOF, - .exti_port = EXTI_PF, -}; -/** GPIO port F device. */ -gpio_dev* const GPIOF = &gpiof; - -/* - * GPIO routines - */ - -/** - * Initialize and reset all available GPIO devices. - */ -void gpio_init_all(void) { - gpio_init(GPIOA); - gpio_init(GPIOB); - gpio_init(GPIOC); - gpio_init(GPIOD); - gpio_init(GPIOE); - gpio_init(GPIOF); -} - -/** - * @brief Set the mode of a GPIO pin. - * @param dev GPIO device. - * @param bit Bit on dev whose mode to set, 0--15. - * @param mode Mode to set the pin to. - * @param flags Flags to modify basic mode configuration - */ -void gpio_set_modef(gpio_dev *dev, - uint8 bit, - gpio_pin_mode mode, - unsigned flags) { - gpio_reg_map *regs = dev->regs; - unsigned shift = bit * 2; - uint32 tmp; - - /* Mode */ - tmp = regs->MODER; - tmp &= ~(0x3 << shift); - tmp |= mode << shift; - regs->MODER = tmp; - - /* Output type */ - bb_peri_set_bit(®s->OTYPER, bit, flags & 0x1); - - /* Speed */ - tmp = regs->OSPEEDR; - tmp &= ~(0x3 << shift); - tmp |= ((flags >> 1) & 0x3) << shift; - regs->OSPEEDR = tmp; - - /* Pull-up/pull-down */ - tmp = regs->PUPDR; - tmp &= ~(0x3 << shift); - tmp |= ((flags >> 3) & 0x3) << shift; - regs->PUPDR = tmp; -} - -/** - * @brief Set a pin's alternate function. - * - * The pin must have its mode set to GPIO_MODE_AF for this to take - * effect. - * - * @param dev Device whose pin to configure. - * @param bit Pin whose alternate function to set. - * @param af Alternate function to use for pin. - * @see gpio_set_modef() - */ -void gpio_set_af(gpio_dev *dev, uint8 bit, gpio_af af) { - __IO uint32 *afr; - unsigned shift; - uint32 tmp; - if (bit >= 8) { - afr = &dev->regs->AFRH; - shift = 4 * (bit - 8); - } else{ - afr = &dev->regs->AFRL; - shift = 4 * bit; - } - tmp = *afr; - tmp &= ~(0xF << shift); - tmp |= (af << shift); - *afr = tmp; -} diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_i2c.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_i2c.c deleted file mode 100644 index 2412987..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_i2c.c +++ /dev/null @@ -1,319 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/i2c.c - * @author F3-port by Hanspeter Portner - * @brief STM32F3 I2C support - */ - -#include "i2c_private.h" -#include -#include - -/* - * Devices - */ - -/* on GPIO_AF_4 (PA14,PA15) (PB7,PB6) (PB9,PB8)*/ -static i2c_dev i2c1 = I2C_DEV_OLD(1, &gpiob, 7, 6); -/** STM32F3 I2C device 1 */ -i2c_dev* const I2C1 = &i2c1; - -/* on GPIO_AF_4 (PA10,PA9) (PF0,PF1) (PF0,PF6)*/ -static i2c_dev i2c2 = I2C_DEV_OLD(2, &gpioa, 10, 9); -/** STM32F3 I2C device 2 */ -i2c_dev* const I2C2 = &i2c2; - -/* - * Routines - */ - -void i2c_config_gpios(const i2c_dev *dev) { - gpio_set_modef(sda_port(dev), dev->sda_pin, GPIO_MODE_AF, GPIO_MODEF_TYPE_OD); - gpio_set_modef(scl_port(dev), dev->scl_pin, GPIO_MODE_AF, GPIO_MODEF_TYPE_OD); - - gpio_set_af(sda_port(dev), dev->sda_pin, GPIO_AF_4); - gpio_set_af(scl_port(dev), dev->scl_pin, GPIO_AF_4); -} - -void i2c_master_release_bus(const i2c_dev *dev) { - gpio_write_bit(scl_port(dev), dev->scl_pin, 1); /* TODO check this */ - gpio_write_bit(sda_port(dev), dev->sda_pin, 1); - - i2c_config_gpios(dev); -} - -int32 wait_for_state_change(i2c_dev *dev, - i2c_state state, - uint32 timeout) { - //FIXME not yet used on F3 - return 1; -} - -void i2c_bus_reset(const i2c_dev *dev) { - //FIXME not yet used on F3 -} - -void _i2c_software_reset(i2c_dev *dev) { - dev->regs->CR1 &= ~I2C_CR1_PE; - while(dev->regs->CR1 & I2C_CR1_PE) - ; - dev->regs->CR1 |= I2C_CR1_PE; -} - -void i2c_master_enable(i2c_dev *dev, uint32 flags) { - /* Bring the peripheral down for configuration */ - i2c_peripheral_disable(dev); - - /* Reset the bus when requested so */ - if (flags & I2C_BUS_RESET) - i2c_bus_reset(dev); - - /* Turn on the clock and set GPIO modes */ - i2c_init(dev); - i2c_config_gpios(dev); - - /* Configure analog and digital filters */ - /* TODO ANFOFF, DNF */ - - /* Configure the clock and rise time */ - dev->regs->TIMINGR = I2C_TIMING_10_kHz; - - /* Configure NOSTRETCH behaviour */ - /* TODO NOSTRETCH */ - - /* Enable all interrupts */ /* FIXME not yet used on F3 */ - //nvic_irq_enable(dev->ev_nvic_line); - //nvic_irq_enable(dev->er_nvic_line); - //i2c_enable_irq(dev, 0xFE); /* All interrupts */ - - /* Make it go! */ - i2c_peripheral_enable(dev); - - dev->state = I2C_STATE_IDLE; -} - -static void _i2c_master_xmit(i2c_dev *dev, i2c_msg *msg) { - uint32 cr2; - uint32 isr; - uint16 remaining = msg->length; - msg->xferred = 0; - uint8 *ptr = msg->data; /* pointer to data buffer */ - - while (remaining > 0) { - uint32 reload = remaining > 0xFF ? I2C_CR2_RELOAD : 0U; - uint16 size = remaining >= 0xFF ? 0xFF : remaining & 0xFF; - uint32 nbytes = size << I2C_CR2_NBYTES_SHIFT; - - cr2 = dev->regs->CR2; - cr2 &= ~(I2C_CR2_RELOAD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN); - cr2 |= reload | nbytes; - dev->regs->CR2 = cr2; - - if (msg->xferred == 0) /* first loop iteration? */ - dev->regs->CR2 |= I2C_CR2_START; /* generate START condition */ - - while (ptr < msg->data + msg->xferred + size) { - while ( !( (isr = dev->regs->ISR) & (I2C_ISR_NACKF | I2C_ISR_TXIS) ) ) - ; /* wait until ready for the next byte or NACK*/ - - if (isr & I2C_ISR_TXIS) - dev->regs->TXDR = *ptr++; /* byte to send */ - else { /* NACKF */ - dev->regs->ICR |= I2C_ICR_NACKCF; /* clear NACK flag */ - dev->regs->CR2 |= I2C_CR2_STOP; /* generate STOP condition */ - return; /* STOP condition is automatically generated */ - } - } - - if (reload) - while ( !(dev->regs->ISR & I2C_ISR_TCR) ) - ; /* wait for transmission reload complete */ - - remaining -= size; - msg->xferred += size; - } - - while ( !(dev->regs->ISR & I2C_ISR_TC) ) - ; /* wait for transmission complete */ - - dev->regs->CR2 |= I2C_CR2_STOP; /* generate STOP condition */ - - while ( !(dev->regs->ISR & I2C_ISR_STOPF) ) - ; /* wait for STOP flag */ - - dev->regs->ICR |= I2C_ICR_STOPCF; /* clear STOP flag */ -} - -static void _i2c_master_recv(i2c_dev *dev, i2c_msg *msg) { - uint32 cr2; - uint16 remaining = msg->length; - msg->xferred = 0; - uint8 *ptr = msg->data; /* pointer to data buffer */ - - while (remaining > 0) { - uint32 reload = remaining > 0xFF ? I2C_CR2_RELOAD : 0U; - uint16 size = remaining >= 0xFF ? 0xFF : remaining & 0xFF; - uint32 nbytes = size << I2C_CR2_NBYTES_SHIFT; - - cr2 = dev->regs->CR2; - cr2 &= ~(I2C_CR2_RELOAD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN); - cr2 |= reload | nbytes | I2C_CR2_RD_WRN; - dev->regs->CR2 = cr2; - - if (msg->xferred == 0) /* first loop iteration? */ - dev->regs->CR2 |= I2C_CR2_START; /* generate START condition */ - - while (ptr < msg->data + msg->xferred + size) { - while ( !(dev->regs->ISR & I2C_ISR_RXNE) ) - ; /* wait for next byte */ - - *ptr++ = dev->regs->RXDR & I2C_RXDR_RXDATA; /* read byte */ - } - - if (reload) - while ( !(dev->regs->ISR & I2C_ISR_TCR) ) - ; /* wait for transmission reload complete */ - - remaining -= size; - msg->xferred += size; - } - - while ( !(dev->regs->ISR & I2C_ISR_TC)) - ; /* wait for transmission complete */ - - dev->regs->CR2 |= I2C_CR2_STOP; /* generate STOP condition */ - - while ( !(dev->regs->ISR & I2C_ISR_STOPF) ) - ; /* wait for STOP flag */ - - dev->regs->ICR |= I2C_ICR_STOPCF; /* clear STOP flag */ -} - -int32 i2c_master_xfer(i2c_dev *dev, - i2c_msg *msgs, - uint16 num, - uint32 timeout) { - i2c_msg *msg; - - ASSERT(dev->state == I2C_STATE_IDLE); - - dev->msg = msgs; - dev->msgs_left = num; - dev->timestamp = systick_uptime(); /* FIXME implement handling of timeout */ - dev->state = I2C_STATE_BUSY; - - /* loop over messages */ - for (msg = dev->msg; dev->msgs_left; dev->msgs_left--, msg++) { - /* set slave address and direction*/ - uint32 addr = msg->flags & I2C_MSG_10BIT_ADDR - ? I2C_CR2_ADD10 | (msg->addr << I2C_CR2_SADD_10_BIT_SHIFT) - : msg->addr << I2C_CR2_SADD_7_BIT_SHIFT; - uint32 rd = msg->flags & I2C_MSG_READ ? I2C_CR2_RD_WRN : 0U; - uint32 cr2 = dev->regs->CR2; - cr2 &= ~(I2C_CR2_HEAD10R | I2C_CR2_ADD10 | I2C_CR2_SADD_10_BIT | I2C_CR2_RD_WRN); - cr2 |= rd | addr; - dev->regs->CR2 = cr2; - - if (rd) - _i2c_master_recv(dev, msg); - else - _i2c_master_xmit(dev, msg); - } - - dev->state = I2C_STATE_IDLE; - - return 0; /* FIXME implement error handling*/ -} - -void i2c_start_condition(i2c_dev *dev) { - dev->regs->CR2 |= I2C_CR2_START; /* generate START condition */ -} - -void i2c_stop_condition(i2c_dev *dev) { - dev->regs->CR2 |= I2C_CR2_STOP; /* generate STOP condition */ - - while ( !(dev->regs->ISR & I2C_ISR_STOPF) ) - ; /* wait for STOP flag */ - - dev->regs->ICR |= I2C_ICR_STOPCF; /* clear STOP flag */ -} - -void i2c_enable_irq(i2c_dev *dev, uint32 irqs) { - dev->regs->CR1 |= irqs; -} - -void i2c_disable_irq(i2c_dev *dev, uint32 irqs) { - dev->regs->CR1 &= ~irqs; -} - -/* ACK/NACK */ -void i2c_enable_ack(i2c_dev *dev) { - //FIXME nonexistant on F3 -} - -void i2c_disable_ack(i2c_dev *dev) { - //FIXME nonexistant on F3 -} - -void i2c_write(i2c_dev *dev, uint8 byte) { - //FIXME proper handling of ISR - dev->regs->TXDR = byte; -} - -uint8 i2c_read(i2c_dev *dev) { - //FIXME proper handling of ISR - return dev->regs->RXDR & I2C_RXDR_RXDATA; -} - -void _i2c_irq_handler(i2c_dev *dev) { - //FIXME not yet used on F3 -} - -void _i2c_irq_error_handler(i2c_dev *dev) { - //FIXME not yet used on F3 -} - -/* - * IRQ handlers - */ - -void __irq_i2c1_ev(void) { - _i2c_irq_handler(I2C1); -} - -void __irq_i2c2_ev(void) { - _i2c_irq_handler(I2C2); -} - -void __irq_i2c1_er(void) { - _i2c_irq_error_handler(I2C1); -} - -void __irq_i2c2_er(void) { - _i2c_irq_error_handler(I2C2); -} diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_opamp.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_opamp.c deleted file mode 100644 index c6ec0d5..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_opamp.c +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/opamp.c - * @author F3-port by Hanspeter Portner - * @brief STM32F3 OpAmp support. - */ - -#include - -/* - * Devices - */ - -static opamp_dev opamp1 = { .regs = OPAMP1_BASE }; const opamp_dev *OPAMP1 = &opamp1; -static opamp_dev opamp2 = { .regs = OPAMP2_BASE }; const opamp_dev *OPAMP2 = &opamp2; -static opamp_dev opamp3 = { .regs = OPAMP3_BASE }; const opamp_dev *OPAMP3 = &opamp3; -static opamp_dev opamp4 = { .regs = OPAMP4_BASE }; const opamp_dev *OPAMP4 = &opamp4; - -/* TODO - * actually implement me ;-) - */ diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_rcc.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_rcc.c deleted file mode 100644 index 5ebe2ad..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_rcc.c +++ /dev/null @@ -1,149 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/rcc.c - * @author F3-port by Hanspeter Portner - * @brief STM32F3 RCC. - */ - -#include -#include -#include - -#include "rcc_private.h" - -#define APB1 RCC_APB1 -#define APB2 RCC_APB2 -#define AHB RCC_AHB - -/* Device descriptor table, maps rcc_clk_id onto bus and enable/reset - * register bit numbers. */ -const struct rcc_dev_info rcc_dev_table[] = { - [RCC_GPIOA] = { .clk_domain = AHB, .line_num = RCC_AHBENR_IOPAEN_BIT }, - [RCC_GPIOB] = { .clk_domain = AHB, .line_num = RCC_AHBENR_IOPBEN_BIT }, - [RCC_GPIOC] = { .clk_domain = AHB, .line_num = RCC_AHBENR_IOPCEN_BIT }, - [RCC_GPIOD] = { .clk_domain = AHB, .line_num = RCC_AHBENR_IOPDEN_BIT }, - [RCC_GPIOE] = { .clk_domain = AHB, .line_num = RCC_AHBENR_IOPEEN_BIT }, - [RCC_GPIOF] = { .clk_domain = AHB, .line_num = RCC_AHBENR_IOPFEN_BIT }, - - [RCC_ADC12] = { .clk_domain = AHB, .line_num = RCC_AHBENR_ADC12EN_BIT}, -#if STM32_F3_LINE == STM32_F3_LINE_303 - [RCC_ADC34] = { .clk_domain = AHB, .line_num = RCC_AHBENR_ADC34EN_BIT }, -#endif - - [RCC_DAC] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_DACEN_BIT }, - - [RCC_DMA1] = { .clk_domain = AHB, .line_num = RCC_AHBENR_DMA1EN_BIT }, - [RCC_DMA2] = { .clk_domain = AHB, .line_num = RCC_AHBENR_DMA2EN_BIT }, - - [RCC_I2C1] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_I2C1EN_BIT }, - [RCC_I2C2] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_I2C2EN_BIT }, - - [RCC_SPI1] = { .clk_domain = APB2, .line_num = RCC_APB2ENR_SPI1EN_BIT }, - [RCC_SPI2] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_SPI2EN_BIT }, - [RCC_SPI3] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_SPI3EN_BIT }, - - [RCC_USART1] = { .clk_domain = APB2, .line_num = RCC_APB2ENR_USART1EN_BIT }, - [RCC_USART2] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_USART2EN_BIT }, - [RCC_USART3] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_USART3EN_BIT }, -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) - [RCC_UART4] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_UART4EN_BIT }, - [RCC_UART5] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_UART5EN_BIT }, -#endif - - [RCC_TIMER1] = { .clk_domain = APB2, .line_num = RCC_APB2ENR_TIM1EN_BIT }, - [RCC_TIMER2] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_TIM2EN_BIT }, - [RCC_TIMER3] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_TIM3EN_BIT }, - [RCC_TIMER4] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_TIM4EN_BIT }, - [RCC_TIMER6] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_TIM6EN_BIT }, -#if STM32_F3_LINE == STM32_F3_LINE_303 - [RCC_TIMER7] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_TIM7EN_BIT }, - [RCC_TIMER8] = { .clk_domain = APB2, .line_num = RCC_APB2ENR_TIM8EN_BIT }, -#endif - [RCC_TIMER15] = { .clk_domain = APB2, .line_num = RCC_APB2ENR_TIM15EN_BIT }, - [RCC_TIMER16] = { .clk_domain = APB2, .line_num = RCC_APB2ENR_TIM16EN_BIT }, - [RCC_TIMER17] = { .clk_domain = APB2, .line_num = RCC_APB2ENR_TIM17EN_BIT }, - - [RCC_SYSCFG] = { .clk_domain = APB2, .line_num = RCC_APB2ENR_SYSCFGEN_BIT }, - [RCC_PWR] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_PWREN_BIT }, - [RCC_CRC] = { .clk_domain = AHB, .line_num = RCC_AHBENR_CRCEN_BIT }, - [RCC_FLITF] = { .clk_domain = AHB, .line_num = RCC_AHBENR_FLITFEN_BIT }, - [RCC_SRAM] = { .clk_domain = AHB, .line_num = RCC_AHBENR_SRAMEN_BIT }, - [RCC_USB] = { .clk_domain = APB1, .line_num = RCC_APB1ENR_USBEN_BIT }, -}; - -/* pll_cfg->data must point to a valid struct stm32f3_rcc_pll_data. */ -void rcc_configure_pll(rcc_pll_cfg *pll_cfg) { - stm32f3_rcc_pll_data *data = pll_cfg->data; - rcc_pll_multiplier pll_mul = data->pll_mul; - rcc_prediv_divider pclk_prediv = data->pclk_prediv; //TODO use this!!! - uint32 cfgr; - uint32 cfgr2; - - /* Check that the PLL is disabled. */ - ASSERT_FAULT(!rcc_is_clk_on(RCC_CLK_PLL)); - - cfgr2 = RCC_BASE->CFGR2; - cfgr2 &= ~(RCC_CFGR2_PREDIV); - cfgr2 |= pclk_prediv; - RCC_BASE->CFGR2 = cfgr2; - - cfgr = RCC_BASE->CFGR; - cfgr &= ~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL); - cfgr |= pll_cfg->pllsrc | pll_mul; - RCC_BASE->CFGR = cfgr; -} - -void rcc_clk_enable(rcc_clk_id id) { - static __IO uint32* enable_regs[] = { - [APB1] = &RCC_BASE->APB1ENR, - [APB2] = &RCC_BASE->APB2ENR, - [AHB] = &RCC_BASE->AHBENR, - }; - rcc_do_clk_enable(enable_regs, id); -} - -void rcc_reset_dev(rcc_clk_id id) { - static __IO uint32* reset_regs[] = { - [APB1] = &RCC_BASE->APB1RSTR, - [APB2] = &RCC_BASE->APB2RSTR, - [AHB] = &RCC_BASE->AHBRSTR, - }; - rcc_do_reset_dev(reset_regs, id); -} - -void rcc_set_prescaler(rcc_prescaler prescaler, uint32 divider) { - static const uint32 masks[] = { - [RCC_PRESCALER_AHB] = RCC_CFGR_HPRE, - [RCC_PRESCALER_APB1] = RCC_CFGR_PPRE1, - [RCC_PRESCALER_APB2] = RCC_CFGR_PPRE2, - [RCC_PRESCALER_USB] = RCC_CFGR_USBPRE, - }; - rcc_do_set_prescaler(masks, prescaler, divider); -} diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_spi.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_spi.c deleted file mode 100644 index d5c38a0..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_spi.c +++ /dev/null @@ -1,143 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/spi.c - * @author Marti Bolivar , - * F3-port by Hanspeter Portner - * @brief STM32F3 SPI/I2S. - */ - -#include -#include -#include "spi_private.h" - -/* - * Devices - */ - -static spi_dev spi1 = SPI_DEV(1); -static spi_dev spi2 = SPI_DEV(2); -static spi_dev spi3 = SPI_DEV(3); - -spi_dev *SPI1 = &spi1; -spi_dev *SPI2 = &spi2; -spi_dev *SPI3 = &spi3; - -/* - * Routines - */ - -void spi_config_gpios(spi_dev *dev, - uint8 as_master, - gpio_dev *nss_dev, - uint8 nss_bit, - gpio_dev *comm_dev, - uint8 sck_bit, - uint8 miso_bit, - uint8 mosi_bit) { - gpio_set_modef(nss_dev, nss_bit, GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - gpio_set_modef(comm_dev, sck_bit, GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - gpio_set_modef(comm_dev, miso_bit, GPIO_MODE_AF, GPIO_MODEF_PUPD_NONE); - gpio_set_modef(comm_dev, mosi_bit, GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - - if ( (dev == SPI1) || (dev == SPI2) ) - { - gpio_set_af(nss_dev, nss_bit, GPIO_AF_5); - gpio_set_af(comm_dev, sck_bit, GPIO_AF_5); - gpio_set_af(comm_dev, miso_bit, GPIO_AF_5); - gpio_set_af(comm_dev, mosi_bit, GPIO_AF_5); - } - else if (dev == SPI3) - { - gpio_set_af(nss_dev, nss_bit, GPIO_AF_6); - gpio_set_af(comm_dev, sck_bit, GPIO_AF_6); - gpio_set_af(comm_dev, miso_bit, GPIO_AF_6); - gpio_set_af(comm_dev, mosi_bit, GPIO_AF_6); - } -} - -void spi_foreach(void (*fn)(spi_dev*)) { - fn(SPI1); - fn(SPI2); - fn(SPI3); -} - -void spi_data_size(struct spi_dev *dev, spi_ds ds) { - uint8 byte_frame = ds <= SPI_DATA_SIZE_8_BIT; - uint32 cr2 = dev->regs->CR2; - cr2 &= ~(SPI_CR2_DS | SPI_CR2_FRXTH); - cr2 |= ds; - if (byte_frame) - cr2 |= SPI_CR2_FRXTH; - dev->regs->CR2 = cr2; -} - -/* - * SPI auxiliary routines - */ -void spi_reconfigure(spi_dev *dev, uint32 cr1_config) { - spi_irq_disable(dev, SPI_INTERRUPTS_ALL); - spi_peripheral_disable(dev); - - uint8 byte_frame = (dev->regs->CR2 & SPI_CR2_DS) <= SPI_DATA_SIZE_8_BIT; - uint32 cr2 = dev->regs->CR2; - cr2 &= ~SPI_CR2_FRXTH; - if (byte_frame) - cr2 |= SPI_CR2_FRXTH; - dev->regs->CR2 = cr2; - - dev->regs->CR1 = cr1_config; - spi_peripheral_enable(dev); -} - -uint16 spi_rx_reg(spi_dev *dev) { - uint8 byte_frame = (dev->regs->CR2 & SPI_CR2_DS) <= SPI_DATA_SIZE_8_BIT; - if (byte_frame) { - __IO uint8 *dr8 = (__IO uint8 *)&dev->regs->DR; /* we need to access as byte */ - return (uint16)*dr8; - } else { - __IO uint16 *dr16 = (__IO uint16 *)&dev->regs->DR; /* we need to access as half-word */ - return (uint16)*dr16; - } -} - -uint32 spi_tx(spi_dev *dev, const void *buf, uint32 len) { - uint32 txed = 0; - uint8 byte_frame = (dev->regs->CR2 & SPI_CR2_DS) <= SPI_DATA_SIZE_8_BIT; - while (spi_is_tx_empty(dev) && (txed < len)) { - if (byte_frame) { - __IO uint8 *dr8 = (__IO uint8 *)&dev->regs->DR; /* we need to access as byte */ - *dr8 = ((const uint8 *)buf)[txed++]; - } else { - __IO uint16 *dr16 = (__IO uint16 *)&dev->regs->DR; /* we need to access as half-word */ - *dr16 = ((const uint16 *)buf)[txed++]; - } - } - return txed; -} diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_syscfg.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_syscfg.c deleted file mode 100644 index 9421b2d..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_syscfg.c +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/syscfg.c - * @author F3-port by Hanspeter Portner - * @brief SYSCFG routines. - */ - -#include -#include -#include - -void syscfg_set_mem_mode(syscfg_mem_mode mode) { - uint32 memrmp = SYSCFG_BASE->CFGR1; - memrmp &= ~SYSCFG_CFGR1_MEM_MODE; - memrmp |= (uint32)mode; - SYSCFG_BASE->CFGR1 = memrmp; -} diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_timer.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_timer.c deleted file mode 100644 index 08b9063..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_timer.c +++ /dev/null @@ -1,147 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/timer.c - * @author Marti Bolivar , - * F3-port by Hanspeter Portner - * @brief STM32F3 timer. - */ - -#include -#include -#include -#include "timer_private.h" - -/** - * @brief Get the GPIO alternate function corresponding to a timer. - * - * For example, if dev is TIMER1, this function returns - * GPIO_AF_TIM_1_2. This is useful for e.g. using gpio_set_af() to set - * a pin's alternate function to a timer. - * - * @param dev Timer device, must not be TIMER6 or TIMER7. - * @return gpio_af corresponding to dev - * @see gpio_set_af - * @see gpio_af - */ - /* FIXME this has to be inline with the PIN_MAP, but some timers are accessible on different alternate function lanes based on the used pin... */ -gpio_af timer_get_af(timer_dev *dev) { - rcc_clk_id clk_id = dev->clk_id; - /* Timers 6 and 7 don't have any capture/compare, so they can't do - * PWM (and in fact have no AF values). */ - ASSERT(clk_id != RCC_TIMER6 && clk_id != RCC_TIMER7); - switch(dev->clk_id) { - case RCC_TIMER1: - return GPIO_AF_6; - case RCC_TIMER2: // fall-through - case RCC_TIMER3: // fall-through - case RCC_TIMER4: - return GPIO_AF_2; - case RCC_TIMER8: - return GPIO_AF_4; - case RCC_TIMER15: - return GPIO_AF_3; - case RCC_TIMER16: // fall-through - case RCC_TIMER17: - return GPIO_AF_1; - default: - ASSERT(0); // Can't happen - return (gpio_af)-1; - } -} - -/* - * IRQ handlers - * - * Defer to the timer_private dispatch API. - * - * FIXME: The names of these handlers are inaccurate since XL-density - * devices came out. Update these to match the STM32F3 names, maybe - * using some weak symbol magic to preserve backwards compatibility if - * possible. Once that's done, we can just move the IRQ handlers into - * the top-level libmaple/timer.c, and there will be no need for this - * file. - */ - -void __irq_tim1_brk_tim15(void) { - dispatch_adv_brk(TIMER1); - dispatch_tim_9_12(TIMER15); -} - -void __irq_tim1_up_tim16(void) { - dispatch_adv_up(TIMER1); - dispatch_tim_10_11_13_14(TIMER16); -} - -void __irq_tim1_trg_com_tim17(void) { - dispatch_adv_trg_com(TIMER1); - dispatch_tim_10_11_13_14(TIMER17); -} - -void __irq_tim1_cc(void) { - dispatch_adv_cc(TIMER1); -} - -void __irq_tim2(void) { - dispatch_general(TIMER2); -} - -void __irq_tim3(void) { - dispatch_general(TIMER3); -} - -void __irq_tim4(void) { - dispatch_general(TIMER4); -} - -void __irq_tim6_dacunder(void) { - dispatch_basic(TIMER6); - /* FIXME handle DAC12 underrun */ -} - -#if STM32_F3_LINE == STM32_F3_LINE_303 -void __irq_tim7(void) { - dispatch_basic(TIMER7); -} - -void __irq_tim8_brk(void) { - dispatch_adv_brk(TIMER8); -} - -void __irq_tim8_up(void) { - dispatch_adv_up(TIMER8); -} - -void __irq_tim8_trg_com(void) { - dispatch_adv_trg_com(TIMER8); -} - -void __irq_tim8_cc(void) { - dispatch_adv_cc(TIMER8); -} -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/f3_usart.c b/STM32F3/cores/maple/libmaple/stm32f3/f3_usart.c deleted file mode 100644 index 4d466b3..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/f3_usart.c +++ /dev/null @@ -1,210 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/usart.c - * @author F3-port by Hanspeter Portner - * @brief STM32F3 USART. - */ - -#include -#include -#include -#include "usart_private.h" - -/* - * Devices - */ - -static ring_buffer usart1_rb; -static usart_dev usart1 = { - .regs = USART1_BASE, - .rb = &usart1_rb, - .max_baud = 4500000UL, - .clk_id = RCC_USART1, - .irq_num = NVIC_USART1, -}; -/** USART1 device */ -usart_dev *USART1 = &usart1; - -static ring_buffer usart2_rb; -static usart_dev usart2 = { - .regs = USART2_BASE, - .rb = &usart2_rb, - .max_baud = 2250000UL, - .clk_id = RCC_USART2, - .irq_num = NVIC_USART2, -}; -/** USART2 device */ -usart_dev *USART2 = &usart2; - -static ring_buffer usart3_rb; -static usart_dev usart3 = { - .regs = USART3_BASE, - .rb = &usart3_rb, - .max_baud = 2250000UL, - .clk_id = RCC_USART3, - .irq_num = NVIC_USART3, -}; -/** USART3 device */ -usart_dev *USART3 = &usart3; - -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) -static ring_buffer uart4_rb; -static usart_dev uart4 = { - .regs = UART4_BASE, - .rb = &uart4_rb, - .max_baud = 2250000UL, - .clk_id = RCC_UART4, - .irq_num = NVIC_UART4, -}; -/** UART4 device */ -usart_dev *UART4 = &uart4; - -static ring_buffer uart5_rb; -static usart_dev uart5 = { - .regs = UART5_BASE, - .rb = &uart5_rb, - .max_baud = 2250000UL, - .clk_id = RCC_UART5, - .irq_num = NVIC_UART5, -}; -/** UART5 device */ -usart_dev *UART5 = &uart5; -#endif - -/* - * Routines - */ - -void usart_config_gpios_async(usart_dev *udev, - gpio_dev *rx_dev, uint8 rx, - gpio_dev *tx_dev, uint8 tx, - unsigned flags) { - gpio_af af = usart_get_af(udev); - gpio_set_modef(rx_dev, rx, GPIO_MODE_AF, GPIO_MODEF_PUPD_NONE); - //gpio_set_modef(tx_dev, tx, GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - gpio_set_modef(tx_dev, tx, GPIO_MODE_AF, GPIO_MODEF_TYPE_OD); - gpio_set_af(rx_dev, rx, af); - gpio_set_af(tx_dev, tx, af); -} - -void usart_set_baud_rate(usart_dev *dev, uint32 clock_speed, uint32 baud) { - /* Figure out the clock speed, if the user doesn't give one. */ - if (clock_speed == 0) { - clock_speed = _usart_clock_freq(dev); - } - ASSERT(clock_speed); - - uint32 divider = clock_speed / baud; - uint32 tmpreg = clock_speed % baud; - /* round divider : if fractional part i greater than 0.5 increment divider */ - if (tmpreg >= baud / 2) - divider++; - dev->regs->BRR = (uint16)divider; -} - -uint32 usart_tx(usart_dev *dev, const uint8 *buf, uint32 len) { - usart_reg_map *regs = dev->regs; - uint32 txed = 0; - while ((regs->SR & USART_SR_TXE) && (txed < len)) { - regs->TDR = buf[txed++] & USART_TDR_TDR; - } - return txed; -} - -/** - * @brief Call a function on each USART. - * @param fn Function to call. - */ -void usart_foreach(void (*fn)(usart_dev*)) { - fn(USART1); - fn(USART2); - fn(USART3); -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) - fn(UART4); - fn(UART5); -#endif -} - -/** - * @brief Get GPIO alternate function mode for a USART. - * @param dev USART whose gpio_af to get. - * @return gpio_af corresponding to dev. - */ -gpio_af usart_get_af(usart_dev *dev) { - switch (dev->clk_id) { - case RCC_USART1: - case RCC_USART2: - case RCC_USART3: - return GPIO_AF_7; -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) - case RCC_UART4: - case RCC_UART5: - return GPIO_AF_5; -#endif - default: - ASSERT(0); /* Can't happen */ - return (gpio_af)-1; - } -} - -/* - * Interrupt handlers. - */ - -static __always_inline void usart_irq(ring_buffer *rb, usart_reg_map *regs) { -#ifdef USART_SAFE_INSERT - /* If the buffer is full and the user defines USART_SAFE_INSERT, - * ignore new bytes. */ - rb_safe_insert(rb, regs->RDR & USART_RDR_RDR); -#else - /* By default, push bytes around in the ring buffer. */ - rb_push_insert(rb, regs->RDR & USART_RDR_RDR); -#endif -} - -void __irq_usart1(void) { - usart_irq(&usart1_rb, USART1_BASE); -} - -void __irq_usart2(void) { - usart_irq(&usart2_rb, USART2_BASE); -} - -void __irq_usart3(void) { - usart_irq(&usart3_rb, USART3_BASE); -} - -#ifdef STM32_HIGH_DENSITY -void __irq_uart4(void) { - usart_irq(&uart4_rb, UART4_BASE); -} - -void __irq_uart5(void) { - usart_irq(&uart5_rb, UART5_BASE); -} -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/adc.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/adc.h deleted file mode 100644 index 8f4edde..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/adc.h +++ /dev/null @@ -1,696 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/adc.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 ADC support. - */ - -#ifndef _LIBMAPLE_STM32F3_ADC_H_ -#define _LIBMAPLE_STM32F3_ADC_H_ - -#include -#include -#include /* For the prescalers */ - -/* - * Register map - */ - -/* - * ADC individual register map type. - */ -typedef struct adc_reg_map { - __IO uint32 ISR; /**< */ - __IO uint32 IER; /**< */ - __IO uint32 CR; /**< */ - __IO uint32 CFGR; /**< */ - uint32 reserved1; - __IO uint32 SMPR1; /**< */ - __IO uint32 SMPR2; /**< */ - uint32 reserved2; - __IO uint32 TR1; /**< */ - __IO uint32 TR2; /**< */ - __IO uint32 TR3; /**< */ - uint32 reserved3; - __IO uint32 SQR1; /**< */ - __IO uint32 SQR2; /**< */ - __IO uint32 SQR3; /**< */ - __IO uint32 SQR4; /**< */ - __IO uint32 DR; /**< */ - uint32 reserved4 [2]; - __IO uint32 JSQR; /**< */ - uint32 reserved5 [4]; - __IO uint32 OFR1; /**< */ - __IO uint32 OFR2; /**< */ - __IO uint32 OFR3; /**< */ - __IO uint32 OFR4; /**< */ - uint32 reserved6 [4]; - __IO uint32 JDR1; /**< */ - __IO uint32 JDR2; /**< */ - __IO uint32 JDR3; /**< */ - __IO uint32 JDR4; /**< */ - uint32 reserved7 [4]; - __IO uint32 AWD2CR; /**< */ - __IO uint32 AWD3CR; /**< */ - uint32 reserved8 [2]; - __IO uint32 DIFSEL; /**< */ - __IO uint32 CALFACT; /**< */ -} adc_reg_map; - -/* - * ADC master and slave common register map type. - */ -typedef struct adc_common_reg_map { - __IO uint32 CSR; /**< */ - uint32 reserved; - __IO uint32 CCR; /**< */ - __IO uint32 CDR; /**< */ -} adc_common_reg_map; - -/** ADC device type. */ -typedef struct adc_dev { - adc_reg_map *regs; /**< Register map */ - rcc_clk_id clk_id; /**< RCC clock information */ - adc_private_data *priv; /**< ADC private data */ -} adc_dev; - -/* - * Devices - */ - -extern const struct adc_dev *ADC1; /* master */ -extern const struct adc_dev *ADC2; /* slave */ -#if STM32_F3_LINE == STM32_F3_LINE_303 -extern const struct adc_dev *ADC3; /* master */ -extern const struct adc_dev *ADC4; /* slave */ -#endif - -/* - * Register map base pointers - */ - -/** STM32F3 ADC1 individual register map base pointer. */ -#define ADC1_BASE ((struct adc_reg_map*)0x50000000) -/** STM32F3 ADC2 individual register map base pointer. */ -#define ADC2_BASE ((struct adc_reg_map*)0x50000100) -/** STM32F3 ADC1/ADC2 common register map base pointer. */ -#define ADC12_BASE ((struct adc_common_reg_map*)0x50000300) -#if STM32_F3_LINE == STM32_F3_LINE_303 -/** STM32F3 ADC3 individual register map base pointer. */ -#define ADC3_BASE ((struct adc_reg_map*)0x50000400) -/** STM32F3 ADC4 individual register map base pointer. */ -#define ADC4_BASE ((struct adc_reg_map*)0x50000500) -/** STM32F3 ADC3/ADC4 common register map base pointer. */ -#define ADC34_BASE ((struct adc_common_reg_map*)0x50000700) -#endif - -/* - * Register bit definitions - */ - -/* Interrupt and status register */ -#define ADC_ISR_JQOVF_BIT 10 -#define ADC_ISR_AWD3_BIT 9 -#define ADC_ISR_AWD2_BIT 8 -#define ADC_ISR_AWD1_BIT 7 -#define ADC_ISR_JEOS_BIT 6 -#define ADC_ISR_JEOC_BIT 5 -#define ADC_ISR_OVR_BIT 4 -#define ADC_ISR_EOS_BIT 3 -#define ADC_ISR_EOC_BIT 2 -#define ADC_ISR_EOSMP_BIT 1 -#define ADC_ISR_ADRDY_BIT 0 - -#define ADC_ISR_JQOVF (1U << ADC_ISR_JQOVF_BIT) -#define ADC_ISR_AWD3 (1U << ADC_ISR_AWD3_BIT) -#define ADC_ISR_AWD2 (1U << ADC_ISR_AWD2_BIT) -#define ADC_ISR_AWD1 (1U << ADC_ISR_AWD1_BIT) -#define ADC_ISR_JEOS (1U << ADC_ISR_JEOS_BIT) -#define ADC_ISR_JEOC (1U << ADC_ISR_JEOC_BIT) -#define ADC_ISR_OVR (1U << ADC_ISR_OVR_BIT) -#define ADC_ISR_EOS (1U << ADC_ISR_EOS_BIT) -#define ADC_ISR_EOC (1U << ADC_ISR_EOC_BIT) -#define ADC_ISR_EOSMP (1U << ADC_ISR_EOSMP_BIT) -#define ADC_ISR_ADRDY (1U << ADC_ISR_ADRDY_BIT) - -/* FIXME make an enum out of this */ -#define ADC_WATCHDOG_1_INTERRUPT ADC_ISR_AWD1 -#define ADC_WATCHDOG_2_INTERRUPT ADC_ISR_AWD2 -#define ADC_WATCHDOG_3_INTERRUPT ADC_ISR_AWD3 -#define ADC_CONV_INTERRUPT ADC_ISR_EOC -#define ADC_INJ_CONV_INTERRUPT ADC_ISR_JEOC -#define ADC_OVERRUN_INTERRUPT ADC_ISR_OVR -#define ADC_ALL_INTERRUPTS (ADC_CONV_INTERRUPT | ADC_WATCHDOG_1_INTERRUPT | ADC_WATCHDOG_2_INTERRUPT | ADC_WATCHDOG_3_INTERRUPT | ADC_INJ_CONV_INTERRUPT | ADC_OVERRUN_INTERRUPT) - -/* Interrupt enable register */ -#define ADC_IER_JQOVF_BIT 10 -#define ADC_IER_AWD3_BIT 9 -#define ADC_IER_AWD2_BIT 8 -#define ADC_IER_AWD1_BIT 7 -#define ADC_IER_JEOS_BIT 6 -#define ADC_IER_JEOC_BIT 5 -#define ADC_IER_OVR_BIT 4 -#define ADC_IER_EOS_BIT 3 -#define ADC_IER_EOC_BIT 2 -#define ADC_IER_EOSMP_BIT 1 -#define ADC_IER_ADRDY_BIT 0 - -#define ADC_IER_JQOVF (1U << ADC_IER_JQOVF_BIT) -#define ADC_IER_AWD3 (1U << ADC_IER_AWD3_BIT) -#define ADC_IER_AWD2 (1U << ADC_IER_AWD2_BIT) -#define ADC_IER_AWD1 (1U << ADC_IER_AWD1_BIT) -#define ADC_IER_JEOS (1U << ADC_IER_JEOS_BIT) -#define ADC_IER_JEOC (1U << ADC_IER_JEOC_BIT) -#define ADC_IER_OVR (1U << ADC_IER_OVR_BIT) -#define ADC_IER_EOS (1U << ADC_IER_EOS_BIT) -#define ADC_IER_EOC (1U << ADC_IER_EOC_BIT) -#define ADC_IER_EOSMP (1U << ADC_IER_EOSMP_BIT) -#define ADC_IER_ADRDY (1U << ADC_IER_ADRDY_BIT) - -/* Control register */ -#define ADC_CR_ADCAL_BIT 31 -#define ADC_CR_ADCALDIF_BIT 30 -#define ADC_CR_ADVREGEN_SHIFT 28 -#define ADC_CR_JADSTP_BIT 5 -#define ADC_CR_ADSTP_BIT 4 -#define ADC_CR_JADSTART_BIT 3 -#define ADC_CR_ADSTART_BIT 2 -#define ADC_CR_ADDIS_BIT 1 -#define ADC_CR_ADEN_BIT 0 - -#define ADC_CR_ADCAL (1U << ADC_CR_ADCAL_BIT) -#define ADC_CR_ADCALDIF (1U << ADC_CR_ADCALDIF_BIT) -#define ADC_CR_ADVREGEN (0x3 << ADC_CR_ADVREGEN_SHIFT) -#define ADC_CR_ADVREGEN_ENABLE (0x1 << ADC_CR_ADVREGEN_SHIFT) -#define ADC_CR_ADVREGEN_DISABLE (0x2 << ADC_CR_ADVREGEN_SHIFT) -#define ADC_CR_JADSTP (1U << ADC_CR_JADSTP_BIT) -#define ADC_CR_ADSTP (1U << ADC_CR_ADSTP_BIT) -#define ADC_CR_JADSTART (1U << ADC_CR_JADSTART_BIT) -#define ADC_CR_ADSTART (1U << ADC_CR_ADSTART_BIT) -#define ADC_CR_ADDIS (1U << ADC_CR_ADDIS_BIT) -#define ADC_CR_ADEN (1U << ADC_CR_ADEN_BIT) - -/* Configuration register */ -#define ADC_CFGR_AWD1CH_SHIFT 26 -#define ADC_CFGR_JAUTO_BIT 25 -#define ADC_CFGR_JAWD1EN_BIT 24 -#define ADC_CFGR_AWD1EN_BIT 23 -#define ADC_CFGR_AWD1SGL_BIT 22 -#define ADC_CFGR_JQM_BIT 21 -#define ADC_CFGR_JDISCEN_BIT 20 -#define ADC_CFGR_JDISCNUM_SHIFT 17 -#define ADC_CFGR_DISCEN_BIT 16 -#define ADC_CFGR_AUTDLY_BIT 14 -#define ADC_CFGR_CONT_BIT 13 -#define ADC_CFGR_OVRMOD_BIT 12 -#define ADC_CFGR_EXTEN_SHIFT 10 -#define ADC_CFGR_EXTSEL_SHIFT 6 -#define ADC_CFGR_ALIGN_BIT 5 -#define ADC_CFGR_RES_SHIFT 3 -#define ADC_CFGR_DMACFG_BIT 1 -#define ADC_CFGR_DMAEN_BIT 0 - -#define ADC_CFGR_AWD1CH (0x1F << ADC_CFGR_AWD1CH_SHIFT) -#define ADC_CFGR_JAUTO (1U << ADC_CFGR_JAUTO_BIT) -#define ADC_CFGR_JAWD1EN (1U << ADC_CFGR_JAWD1EN_BIT) -#define ADC_CFGR_AWD1EN (1U << ADC_CFGR_AWD1EN_BIT) -#define ADC_CFGR_AWD1SGL (1U << ADC_CFGR_AWD1SGL_BIT) -#define ADC_CFGR_JQM (1U << ADC_CFGR_JQM_BIT) -#define ADC_CFGR_JDISCEN (1U << ADC_CFGR_JDISCEN_BIT) -#define ADC_CFGR_JDISCNUM (0x7 << ADC_CFGR_JDISCNUM_SHIFT) -#define ADC_CFGR_DISCEN (1U << ADC_CFGR_DISCEN_BIT) -#define ADC_CFGR_AUTODLY (1U << ADC_CFGR_AUTODLY_BIT) -#define ADC_CFGR_CONT (1U << ADC_CFGR_CONT_BIT) -#define ADC_CFGR_OVRMOD (1U << ADC_CFGR_OVRMOD_BIT) -#define ADC_CFGR_EXTEN (0x3 << ADC_CFGR_EXTEN_SHIFT) -#define ADC_CFGR_EXTSEL (0xF << ADC_CFGR_EXTSEL_SHIFT) -#define ADC_CFGR_ALIGN (1U << ADC_CFGR_ALIGN_BIT) -#define ADC_CFGR_RES (0x3 << ADC_CFGR_RES_SHIFT) -#define ADC_CFGR_DMACFG (1U << ADC_CFGR_DMACFG_BIT) -#define ADC_CFGR_DMAEN (1U << ADC_CFGR_DMAEN_BIT) - -/* Sample time register 1 */ -#define ADC_SMPR1_SMP9 (0x7 << 27) -#define ADC_SMPR1_SMP8 (0x7 << 24) -#define ADC_SMPR1_SMP7 (0x7 << 21) -#define ADC_SMPR1_SMP6 (0x7 << 18) -#define ADC_SMPR1_SMP5 (0x7 << 15) -#define ADC_SMPR1_SMP4 (0x7 << 12) -#define ADC_SMPR1_SMP3 (0x7 << 9) -#define ADC_SMPR1_SMP2 (0x7 << 6) -#define ADC_SMPR1_SMP1 (0x7 << 3) - -/* Sample time register 2 */ -#define ADC_SMPR2_SMP18 (0x7 << 24) -#define ADC_SMPR2_SMP17 (0x7 << 21) -#define ADC_SMPR2_SMP16 (0x7 << 18) -#define ADC_SMPR2_SMP15 (0x7 << 15) -#define ADC_SMPR2_SMP14 (0x7 << 12) -#define ADC_SMPR2_SMP13 (0x7 << 9) -#define ADC_SMPR2_SMP12 (0x7 << 6) -#define ADC_SMPR2_SMP11 (0x7 << 3) -#define ADC_SMPR2_SMP10 0x7 - -/* Analog watchdog 1 threshold register */ -#define ADC_TR1_HT1 (0xFFF << 16) /* 12bit watchdog */ -#define ADC_TR1_LT1 0xFFF - -/* Analog watchdog 2 threshold register */ -#define ADC_TR2_HT2 (0xFF << 16) /* 8bit watchdog */ -#define ADC_TR2_LT2 0xFF - -/* Analog watchdog 3 threshold register */ -#define ADC_TR3_HT3 (0xFF << 16) /* 8bit watchdog */ -#define ADC_TR3_LT3 0xFF - -/* Regular sequence register 1 */ -#define ADC_SQR1_SQ4 (0x1F << 24) -#define ADC_SQR1_SQ3 (0x1F << 18) -#define ADC_SQR1_SQ2 (0x1F << 12) -#define ADC_SQR1_SQ1 (0x1F << 6) -#define ADC_SQR1_L 0xF - -/* Regular sequence register 2 */ -#define ADC_SQR2_SQ9 (0x1F << 24) -#define ADC_SQR2_SQ8 (0x1F << 18) -#define ADC_SQR2_SQ7 (0x1F << 12) -#define ADC_SQR2_SQ6 (0x1F << 6) -#define ADC_SQR2_SQ5 0x1F - -/* Regular sequence register 3 */ -#define ADC_SQR3_SQ14 (0x1F << 24) -#define ADC_SQR3_SQ13 (0x1F << 18) -#define ADC_SQR3_SQ12 (0x1F << 12) -#define ADC_SQR3_SQ11 (0x1F << 6) -#define ADC_SQR3_SQ10 0x1F - -/* Regular sequence register 4 */ -#define ADC_SQR4_SQ16 (0x1F << 6) -#define ADC_SQR4_SQ15 0x1F - -/* Regular data register */ -#define ADC_DR_RDATA 0xFFFF - -/* Injected sequence register */ -#define ADC_JSQR_JEXTEN_SHIFT 6 -#define ADC_JSQR_JEXTSEL_SHIFT 2 - -#define ADC_JSQR_SQ4 (0x1F << 26) -#define ADC_JSQR_SQ3 (0x1F << 20) -#define ADC_JSQR_SQ2 (0x1F << 14) -#define ADC_JSQR_SQ1 (0x1F << 8) -#define ADC_JSQR_JEXTEN (0x3 << ADC_JSQR_JEXTEN_SHIFT) -#define ADC_JSQR_JEXTSEL (0xF << ADC_JSQR_JEXTSEL_SHIFT) -#define ADC_JSQR_JL 0x3 - -/* Offset register 1 */ -#define ADC_OFR1_OFFSET1EN_BIT 31 - -#define ADC_OFR1_OFFSET1ENT (1U << ADC_OFR1_OFFSET1EN_BIT) -#define ADC_OFR1_OFFSET1_CH (0x1F << 26) -#define ADC_OFR1_OFFSET1 0xFFF - -/* Offset register 2 */ -#define ADC_OFR2_OFFSET2EN_BIT 31 - -#define ADC_OFR2_OFFSET2EN (1U << ADC_OFR2_OFFSET2EN_BIT) -#define ADC_OFR2_OFFSET2_CH (0x1F << 26) -#define ADC_OFR2_OFFSET2 0xFFF - -/* Offset register 3 */ -#define ADC_OFR3_OFFSET3EN_BIT 31 - -#define ADC_OFR3_OFFSET3EN (1U << ADC_OFR3_OFFSET3EN_BIT) -#define ADC_OFR3_OFFSET3_CH (0x1F << 26) -#define ADC_OFR3_OFFSET3 0xFFF - -/* Offset register 4 */ -#define ADC_OFR4_OFFSET4EN_BIT 31 - -#define ADC_OFR4_OFFSET4EN (1U << ADC_OFR4_OFFSET4EN_BIT) -#define ADC_OFR4_OFFSET4_CH (0x1F << 26) -#define ADC_OFR4_OFFSET4 0xFFF - -/* Injected data register 1 */ -#define ADC_JDR1_JDATA1 0xFFFF - -/* Injected data register 2 */ -#define ADC_JDR2_JDATA2 0xFFFF - -/* Injected data register 3 */ -#define ADC_JDR3_JDATA3 0xFFFF - -/* Injected data register 4 */ -#define ADC_JDR4_JDATA4 0xFFFF - -/* Analog watchdog 2 configuration register */ -#define ADC_AWD2CR_AWD2CH (0x1FFFF << 1) - -/* Analog watchdog 3 configuration register */ -#define ADC_AWD3CR_AWD3CH (0x1FFFF << 1) - -/* Differential mode selection register */ -#define ADC_DIFSEL_DIFSEL (0x1FFFF << 1) - -/* Calibration factors */ -#define ADC_CALFACT_CALFACT_D (0x7F << 16) -#define ADC_CALFACT_CALFACT_S 0x7F - -/* Common status register */ -#define ADC_CSR_JQOVF_SLV_BIT 26 -#define ADC_CSR_AWD3_SLV_BIT 25 -#define ADC_CSR_AWD2_SLV_BIT 24 -#define ADC_CSR_AWD1_SLV_BIT 23 -#define ADC_CSR_JEOS_SLV_BIT 22 -#define ADC_CSR_JEOC_SLV_BIT 21 -#define ADC_CSR_OVR_SLV_BIT 20 -#define ADC_CSR_EOS_SLV_BIT 19 -#define ADC_CSR_EOC_SLV_BIT 18 -#define ADC_CSR_EOSMP_SLV_BIT 17 -#define ADC_CSR_ADRDY_SLV_BIT 16 - -#define ADC_CSR_JQOVF_MST_BIT 10 -#define ADC_CSR_AWD3_MST_BIT 9 -#define ADC_CSR_AWD2_MST_BIT 8 -#define ADC_CSR_AWD1_MST_BIT 7 -#define ADC_CSR_JEOS_MST_BIT 6 -#define ADC_CSR_JEOC_MST_BIT 5 -#define ADC_CSR_OVR_MST_BIT 4 -#define ADC_CSR_EOS_MST_BIT 3 -#define ADC_CSR_EOC_MST_BIT 2 -#define ADC_CSR_EOSMP_MST_BIT 1 -#define ADC_CSR_ADRDY_MST_BIT 0 - -#define ADC_CSR_JQOVF_SLV (1U << ADC_CSR_JQOVF_SLV_BIT) -#define ADC_CSR_AWD3_SLV (1U << ADC_CSR_AWD3_SLV_BIT) -#define ADC_CSR_AWD2_SLV (1U << ADC_CSR_AWD2_SLV_BIT) -#define ADC_CSR_AWD1_SLV (1U << ADC_CSR_AWD1_SLV_BIT) -#define ADC_CSR_JEOS_SLV (1U << ADC_CSR_JEOS_SLV_BIT) -#define ADC_CSR_JEOC_SLV (1U << ADC_CSR_JEOC_SLV_BIT) -#define ADC_CSR_OVR_SLV (1U << ADC_CSR_OVR_SLV_BIT) -#define ADC_CSR_EOS_SLV (1U << ADC_CSR_EOS_SLV_BIT) -#define ADC_CSR_EOC_SLV (1U << ADC_CSR_EOC_SLV_BIT) -#define ADC_CSR_EOSMP_SLV (1U << ADC_CSR_EOS_MP_SLV_BIT) -#define ADC_CSR_ADRDY_SLV (1U << ADC_CSR_ADRDY_SLV_BIT) - -#define ADC_CSR_JQOVF_MST (1U << ADC_CSR_JQOVF_MST_BIT) -#define ADC_CSR_AWD3_MST (1U << ADC_CSR_AWD3_MST_BIT) -#define ADC_CSR_AWD2_MST (1U << ADC_CSR_AWD2_MST_BIT) -#define ADC_CSR_AWD1_MST (1U << ADC_CSR_AWD1_MST_BIT) -#define ADC_CSR_JEOS_MST (1U << ADC_CSR_JEOS_MST_BIT) -#define ADC_CSR_JEOC_MST (1U << ADC_CSR_JEOC_MST_BIT) -#define ADC_CSR_OVR_MST (1U << ADC_CSR_OVR_MST_BIT) -#define ADC_CSR_EOS_MST (1U << ADC_CSR_EOS_MST_BIT) -#define ADC_CSR_EOC_MST (1U << ADC_CSR_EOC_MST_BIT) -#define ADC_CSR_EOSMP_MST (1U << ADC_CSR_EOS_MP_MST_BIT) -#define ADC_CSR_ADRDY_MST (1U << ADC_CSR_ADRDY_MST_BIT) - -/* Common control register */ -#define ADC_CCR_VBATEN_BIT 24 -#define ADC_CCR_TSEN_BIT 23 -#define ADC_CCR_VREFEN_BIT 22 -#define ADC_CCR_CKMODE_SHIFT 16 -#define ADC_CCR_MDMA_SHIFT 14 -#define ADC_CCR_DMACFG_BIT 13 -#define ADC_CCR_DELAY_SHIFT 8 -#define ADC_CCR_DUAL_SHIFT 0 - -#define ADC_CCR_VBATEN (1U << ADC_CCR_VBATEN_BIT) -#define ADC_CCR_TSEN (1U << ADC_CCR_TSEN_BIT) -#define ADC_CCR_VREFEN (1U << ADC_CCR_VREFEN_BIT) -#define ADC_CCR_CKMODE (0x3 << ADC_CCR_CKMODE_SHIFT) -#define ADC_CCR_MDMA (0x3 << ADC_CCR_MDMA_SHIFT) -#define ADC_CCR_DMACFG (1U << ADC_CCR_DMACFG_BIT) -#define ADC_CCR_DELAY (0xF << ADC_CCR_DELAY_SHIFT) -#define ADC_CCR_DUAL 0X1F - -/* Common regular data register for dual mode */ -#define ADC_CDR_RDATA_SLV (0xFFFF << 16) -#define ADC_CDR_RDATA_MST 0xFFFF - -/* - * Other types - */ - -/** - * @brief STM32F3 external event selectors for regular group - * conversion. - * - * For ease of use, each event selector is given along with the ADCs - * it's available on, along with any other availability restrictions. - * - * @see adc_set_extsel() - */ -typedef enum adc_extsel_event { - /* ADC1 (master) and ADC2 (slave) regular channels */ - ADC12_EXT_EV_TIM1_CC1 = 0x0 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM1_CC2 = 0x1 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM1_CC3 = 0x2 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM2_CC2 = 0x3 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM3_TRGO = 0x4 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM4_CC4 = 0x5 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_EXTI_11 = 0x6 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM8_TRGO = 0x7 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM8_TRGO2 = 0x8 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM1_TRGO = 0x9 << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM1_TRGO2 = 0xA << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM2_TRGO = 0xB << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM4_TRGO = 0xC << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM6_TRGO = 0xD << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM15_TRGO = 0xE << ADC_CFGR_EXTSEL_SHIFT, - ADC12_EXT_EV_TIM3_CC4 = 0xF << ADC_CFGR_EXTSEL_SHIFT, - - /* ADC1 (master) and ADC2 (slave) injected channels */ - ADC12_JEXT_EV_TIM1_TRGO = 0x0 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM1_CC4 = 0x1 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM2_TRGO = 0x2 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM2_CC1 = 0x3 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM3_CC4 = 0x4 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM4_TRGO = 0x5 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_EXTI_15 = 0x6 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM8_CC4 = 0x7 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM1_TRGO2 = 0x8 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM8_TRGO = 0x9 << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM8_TRGO2 = 0xA << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM3_CC3 = 0xB << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM3_TRGO = 0xC << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM3_CC1 = 0xD << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM6_TRGO = 0xE << ADC_JSQR_JEXTSEL_SHIFT, - ADC12_JEXT_EV_TIM15_TRGO = 0xF << ADC_JSQR_JEXTSEL_SHIFT, - - /* ADC3 (master) and ADC4 (slave) injected channels */ - ADC34_EXT_EV_TIM3_CC1 = 0x0 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM3_CC3 = 0x1 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM1_cc3 = 0x2 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM8_CC1 = 0x3 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM8_TRGO = 0x4 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_EXTI_2 = 0x5 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM4_CC1 = 0x6 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM2_TRGO = 0x7 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM8_TRGO2 = 0x8 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM1_TRGO = 0x9 << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM1_TRGO2 = 0xA << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM3_TRGO = 0xB << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM4_TRGO = 0xC << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM7_TRGO = 0xD << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM15_TRGO = 0xE << ADC_CFGR_EXTSEL_SHIFT, - ADC34_EXT_EV_TIM2_CC1 = 0xF << ADC_CFGR_EXTSEL_SHIFT, - - /* ADC3 (master) and ADC4 (slave) injected channels */ - ADC34_JEXT_EV_TIM1_TRGO = 0x0 << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM1_CC4 = 0x1 << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM4_CC3 = 0x2 << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM8_CC2 = 0x3 << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM8_CC4 = 0x4 << ADC_JSQR_JEXTSEL_SHIFT, - /* ADC34_JEXT_EV_TIM4_CC3 = 0x5 << ADC_JSQR_JEXTSEL_SHIFT, */ /* FIXME duplicate or typo in manual? */ - ADC34_JEXT_EV_TIM4_CC4 = 0x6 << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM4_TRGO = 0x7 << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM1_TRGO2 = 0x8 << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM8_TRGO = 0x9 << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM8_TRGO2 = 0xA << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM1_CC3 = 0xB << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM3_TRGO = 0xC << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM2_TRGO = 0xD << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM7_TRGO = 0xE << ADC_JSQR_JEXTSEL_SHIFT, - ADC34_JEXT_EV_TIM15_TRGO = 0xF << ADC_JSQR_JEXTSEL_SHIFT, -} adc_extsel_event; - -/** - * @brief STM32F3 ADC trigger mode. - * - * These control the trigger mode of the ADC, which can be set to: - * Software trigger, hardware trigger on rising, falling or both edges. - */ -typedef enum adc_exttrig_mode { - ADC_EXTTRIG_MODE_SOFTWARE = 0x0 << ADC_CFGR_EXTEN_SHIFT, /**< .. */ - ADC_EXTTRIG_MODE_HARDWARE_RISING = 0x1 << ADC_CFGR_EXTEN_SHIFT, /**< .. */ - ADC_EXTTRIG_MODE_HARDWARE_FALLING = 0x2 << ADC_CFGR_EXTEN_SHIFT, /**< .. */ - ADC_EXTTRIG_MODE_HARDWARE_BOTH = 0x3 << ADC_CFGR_EXTEN_SHIFT, /**< .. */ -} adc_exttrig_mode; - -/** - * @brief STM32F3 ADC resolution. - * - * These control the ADC resolution, which can be set to: - * 6, 8, 10 or 12 bit. - */ -typedef enum adc_resolution { - ADC_RESOLUTION_12_BIT = 0x0 << ADC_CFGR_RES_SHIFT, /**< .. */ - ADC_RESOLUTION_10_BIT = 0x1 << ADC_CFGR_RES_SHIFT, /**< .. */ - ADC_RESOLUTION_8_BIT = 0x2 << ADC_CFGR_RES_SHIFT, /**< .. */ - ADC_RESOLUTION_6_BIT = 0x3 << ADC_CFGR_RES_SHIFT, /**< .. */ -} adc_resolution; - -/** - * @brief STM32F3 sample times, in ADC clock cycles. - * - * These control the amount of time spent sampling the input voltage. - */ -typedef enum adc_smp_rate { - ADC_SMPR_1_5 = 0x0, /**< 1.5 ADC cycles */ - ADC_SMPR_2_5 = 0x1, /**< 2.5 ADC cycles */ - ADC_SMPR_4_5 = 0x2, /**< 4.5 ADC cycles */ - ADC_SMPR_7_5 = 0x3, /**< 7.5 ADC cycles */ - ADC_SMPR_19_5 = 0x4, /**< 19.5 ADC cycles */ - ADC_SMPR_61_5 = 0x5, /**< 61.5 ADC cycles */ - ADC_SMPR_181_5 = 0x6, /**< 181.5 ADC cycles */ - ADC_SMPR_601_5 = 0x7, /**< 601.5 ADC cycles */ -} adc_smp_rate; - -/* - * FIXME SHIFT - */ - -/** - * @brief STM32F3 ADC clock mode. - */ -typedef enum adc_clock_mode { - ADC_CLOCK_MODE_ASYNCHRONOUS = 0x0, /**< . */ - ADC_CLOCK_MODE_SYNCHRONOUS_DIV_1 = 0x1, /**< . */ - ADC_CLOCK_MODE_SYNCHRONOUS_DIV_2 = 0x2, /**< . */ - ADC_CLOCK_MODE_SYNCHRONOUS_DIV_4 = 0x3, /**< . */ -} adc_clock_mode; - -/** - * @brief STM32F3 ADC DMA mode. - */ -typedef enum adc_dma_mode { - ADC_MDMA_MODE_DISABLE = (0x0 << ADC_CCR_MDMA_SHIFT), /**< . */ - ADC_MDMA_MODE_ENABLE_12_10_BIT = (0x2 << ADC_CCR_MDMA_SHIFT), /**< . */ - ADC_MDMA_MODE_ENABLE_8_6_BIT = (0x3 << ADC_CCR_MDMA_SHIFT), /**< . */ -} adc_dma_mode; - -/** - * @brief STM32F3 ADC mode. - */ -typedef enum adc_mode { - ADC_MODE_INDEPENDENT = 0x0, /**< . */ - ADC_MODE_DUAL_REGULAR_INJECTED = 0x1, /**< . */ - ADC_MODE_DUAL_REGULAR_ALTERNATE_TRIGGER = 0x2, /**< . */ - ADC_MODE_DUAL_INJECTED_ONLY = 0x5, /**< . */ - ADC_MODE_DUAL_REGULAR_ONLY = 0x6, /**< . */ - ADC_MODE_DUAL_INTERLEAVED_ONLY = 0x7, /**< . */ - ADC_MODE_DUAL_ALTERNATE_TRIGGER_ONLY = 0x9, /**< . */ -} adc_mode; - -/** - * @brief STM32F3 ADC prescalers, as divisors of PCLK2. - */ -typedef enum adc_prescaler { - /** ADC clock disabled, AHB clock enabled */ - ADC_PRE_AHBCLK_DIV_1 = ADC_CLOCK_MODE_SYNCHRONOUS_DIV_1, - ADC_PRE_AHBCLK_DIV_2 = ADC_CLOCK_MODE_SYNCHRONOUS_DIV_2, - ADC_PRE_AHBCLK_DIV_4 = ADC_CLOCK_MODE_SYNCHRONOUS_DIV_4, - - /** ADC clock enabled, AHB clock disabled */ - ADC_PRE_PCLK_DIV_1 = RCC_ADCPRE_PCLK_DIV_1, /** PCLK divided by 1 */ - ADC_PRE_PCLK_DIV_2 = RCC_ADCPRE_PCLK_DIV_2, /** PCLK divided by 2 */ - ADC_PRE_PCLK_DIV_4 = RCC_ADCPRE_PCLK_DIV_4, /** PCLK divided by 4 */ - ADC_PRE_PCLK_DIV_6 = RCC_ADCPRE_PCLK_DIV_6, /** PCLK divided by 6 */ - ADC_PRE_PCLK_DIV_8 = RCC_ADCPRE_PCLK_DIV_8, /** PCLK divided by 8 */ - ADC_PRE_PCLK_DIV_10 = RCC_ADCPRE_PCLK_DIV_10, /** PCLK divided by 10 */ - ADC_PRE_PCLK_DIV_12 = RCC_ADCPRE_PCLK_DIV_12, /** PCLK divided by 12 */ - ADC_PRE_PCLK_DIV_16 = RCC_ADCPRE_PCLK_DIV_16, /** PCLK divided by 16 */ - ADC_PRE_PCLK_DIV_32 = RCC_ADCPRE_PCLK_DIV_32, /** PCLK divided by 32 */ - ADC_PRE_PCLK_DIV_64 = RCC_ADCPRE_PCLK_DIV_64, /** PCLK divided by 64 */ - ADC_PRE_PCLK_DIV_128 = RCC_ADCPRE_PCLK_DIV_128, /** PCLK divided by 128 */ - ADC_PRE_PCLK_DIV_256 = RCC_ADCPRE_PCLK_DIV_256, /** PCLK divided by 256 */ -} adc_prescaler; - -/* - * Routines - */ - -/** - * @brief Calibrate an ADC peripheral - * - * Availability: STM32F1, STM32F3. - * - * @param dev adc device - */ -void adc_calibrate(const adc_dev *dev); - -/** - * @brief Set external trigger conversion mode event for regular channels - * - * Availability: STM32F1, STM32F3. - * - * @param dev ADC device - * @param mode external trigger disabled, on rising edge, on falling edge or on both - */ -void adc_set_exttrig(const adc_dev *dev, adc_exttrig_mode mode); - -/** - * @brief Set ADC resolution of an ADC peripheral - * - * Availability: STM32F3. - * - * @param dev adc device - * @param resolution ADC resolution (6, 8, 10 or 12 bit) - */ -void adc_set_resolution(const adc_dev *dev, adc_resolution res); - -/** - * @brief Enable the voltage regulatr of an ADC peripheral - * - * Availability: STM32F3. - * - * @param dev adc device - */ -void adc_regulator_enable(const adc_dev *dev); - -/** - * @brief Disable the voltage regulatr of an ADC peripheral - * - * Availability: STM32F3. - * - * @param dev adc device - */ -void adc_regulator_disable(const adc_dev *dev); - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/bkp.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/bkp.h deleted file mode 100644 index 21ab1c1..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/bkp.h +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/bkp.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 backup register support. - */ - -#ifndef _LIBMAPLE_STM32F3_BKP_H_ -#define _LIBMAPLE_STM32F3_BKP_H_ - -#define BKP_NR_DATA_REGS 16 - -/** Backup peripheral register map type. */ -typedef struct bkp_reg_map { - __IO uint32 DR0; ///< Data register 0 - __IO uint32 DR1; ///< Data register 1 - __IO uint32 DR2; ///< Data register 2 - __IO uint32 DR3; ///< Data register 3 - __IO uint32 DR4; ///< Data register 4 - __IO uint32 DR5; ///< Data register 5 - __IO uint32 DR6; ///< Data register 6 - __IO uint32 DR7; ///< Data register 7 - __IO uint32 DR8; ///< Data register 8 - __IO uint32 DR9; ///< Data register 9 - __IO uint32 DR10; ///< Data register 10 - __IO uint32 DR11; ///< Data register 11 - __IO uint32 DR12; ///< Data register 12 - __IO uint32 DR13; ///< Data register 13 - __IO uint32 DR14; ///< Data register 14 - __IO uint32 DR15; ///< Data register 15 -} bkp_reg_map; - -/** Backup peripheral register map base pointer. */ -#define BKP_BASE ((struct bkp_reg_map*)0x40002850) //is part of RTC memory map - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/comp.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/comp.h deleted file mode 100644 index 161f439..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/comp.h +++ /dev/null @@ -1,119 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/comp.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 Comparator support. - */ - -#ifndef _LIBMAPLE_STM32F3_COMP_H_ -#define _LIBMAPLE_STM32F3_COMP_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/* - * Register map - */ - -/* - * COMP individual register map type. - */ -typedef struct comp_reg_map { - __IO uint32 CSR; /**< */ -} comp_reg_map; - -/** COMP device type. */ -typedef struct comp_dev { - comp_reg_map *regs; /**< Register map */ -} comp_dev; - -/* - * Devices - */ - -extern const struct comp_dev *COMP1; /* comparator 1 */ -extern const struct comp_dev *COMP2; /* comparator 2 */ -extern const struct comp_dev *COMP3; /* comparator 3 */ -extern const struct comp_dev *COMP4; /* comparator 4 */ -extern const struct comp_dev *COMP5; /* comparator 5 */ -extern const struct comp_dev *COMP6; /* comparator 6 */ -extern const struct comp_dev *COMP7; /* comparator 7 */ - -/* - * Register map base pointers - */ - -#define COMP1_BASE ((struct comp_reg_map*)0x4001001C) -#define COMP2_BASE ((struct comp_reg_map*)0x40010020) -#define COMP3_BASE ((struct comp_reg_map*)0x40010024) -#define COMP4_BASE ((struct comp_reg_map*)0x40010028) -#define COMP5_BASE ((struct comp_reg_map*)0x4001002C) -#define COMP6_BASE ((struct comp_reg_map*)0x40010030) -#define COMP7_BASE ((struct comp_reg_map*)0x40010034) - -/* - * Register bit definitions - */ - -/* Control and status register */ -#define COMP_CSR_LOCK_BIT 31 -#define COMP_CSR_OUT_BIT 30 -#define COMP_CSR_BLANKING_SHIFT 18 -#define COMP_CSR_HIST_SHIFT 16 -#define COMP_CSR_POL_BIT 15 -#define COMP_CSR_OUTSEL_SHIFT 10 -#define COMP_CSR_WINMODE_BIT 9 -#define COMP_CSR_INPSEL_BIT 7 -#define COMP_CSR_INMSEL_SHIFT 4 -#define COMP_CSR_MODE_SHIFT 2 -#define COMP_CSR_EN_BIT 0 - -#define COMP_CSR_LOCK (1U << COMP_CSR_LOCK_BIT) -#define COMP_CSR_OUT (1U << COMP_CSR_OUT_BIT) -#define COMP_CSR_BLANKING (0x7 << COMP_CSR_BLANKING_SHIFT) -#define COMP_CSR_HIST (0x3 << COMP_CSR_HIST_SHIFT) -#define COMP_CSR_POL (1U << COMP_CSR_POL_BIT) -#define COMP_CSR_OUTSEL (0xF << COMP_CSR_OUTSEL_SHIFT) -#define COMP_CSR_WINMODE (0xF << COMP_CSR_WINMODE_SHIFT) -#define COMP_CSR_INPSEL (1U << COMP_CSR_INPSEL_BIT) -#define COMP_CSR_INMSEL (0x7 << COMP_CSR_INMSEL_SHIFT) -#define COMP_CSR_MODE (0x3 << COMP_CSR_MODE_SHIFT) -#define COMP_CSR_EN (1U << COMP_CSR_EN_BIT) - -/* TODO - * actually implement me ;-) - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/crc.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/crc.h deleted file mode 100644 index fa10aa4..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/crc.h +++ /dev/null @@ -1,94 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/crc.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 Cylic Redundancy Check (CRC) support. - */ - -#ifndef _LIBMAPLE_STM32F3_CRC_H_ -#define _LIBMAPLE_STM32F3_CRC_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -/* - * Register maps - */ - -/** CRC register map type */ -typedef struct crc_reg_map { - __IO uint32 DR; /**< Data register */ - __IO uint32 IDR; /**< Independent data register */ - __IO uint32 CR; /**< Control register */ - uint32 reserved; - __IO uint32 INIT; /**< Initial data register */ - __IO uint32 POL; /**< Polynomial register */ -} crc_reg_map; - -/* - * Register map base pointers - */ - -/** CRC register map base pointer */ -#define CRC_BASE ((struct crc_reg_map*)0x40013800) //TODO - -/* - * Register bit definitions - */ - -/* Data register */ -#define CRC_DR_DATA 0xFFFFFFFF - -/* Independent data register */ -#define CRC_IDR_DATA 0xFF - -/* Control register */ -#define CRC_CR_REV_OUT_BIT 7 -#define CRC_CR_REV_IN_SHIFT 5 -#define CRC_CR_POLYSIZE_SHIFT 3 -#define CRC_CR_RESET_BIT 0 - -#define CRC_CR_REV_OUT (1U << CRC_CR_REV_OUT_BIT) -#define CRC_CR_REV_IN (0x3 << CRC_CR_REV_IN_SHIFT) -#define CRC_CR_POLYSIZE (0x3 << CRC_CR_POLYSIZE_SHIFT) -#define CRC_CR_RESET (1U << CRC_CR_RESET_BIT) - -/* Initial data register */ -#define CRC_INIT_DATA 0xFFFFFFFF - -/* Polynomial register */ -#define CRC_POL_DATA 0xFFFFFFFF - -/* TODO add some routines */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/dac.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/dac.h deleted file mode 100644 index 890e34c..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/dac.h +++ /dev/null @@ -1,74 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/dac.h - * @brief STM32F3 DAC support - */ - -#ifndef _LIBMAPLE_STM32F3_DAC_H_ -#define _LIBMAPLE_STM32F3_DAC_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/** STM32F3 DAC register map type. */ -typedef struct dac_reg_map { - __IO uint32 CR; /**< Control register */ - __IO uint32 SWTRIGR; /**< Software trigger register */ - __IO uint32 DHR12R1; /**< Channel 1 12-bit right-aligned data - holding register */ - __IO uint32 DHR12L1; /**< Channel 1 12-bit left-aligned data - holding register */ - __IO uint32 DHR8R1; /**< Channel 1 8-bit left-aligned data - holding register */ - __IO uint32 DHR12R2; /**< Channel 2 12-bit right-aligned data - holding register */ - __IO uint32 DHR12L2; /**< Channel 2 12-bit left-aligned data - holding register */ - __IO uint32 DHR8R2; /**< Channel 2 8-bit left-aligned data - holding register */ - __IO uint32 DHR12RD; /**< Dual DAC 12-bit right-aligned data - holding register */ - __IO uint32 DHR12LD; /**< Dual DAC 12-bit left-aligned data - holding register */ - __IO uint32 DHR8RD; /**< Dual DAC 8-bit right-aligned data holding - register */ - __IO uint32 DOR1; /**< Channel 1 data output register */ - __IO uint32 DOR2; /**< Channel 2 data output register */ -} dac_reg_map; - -//#define DAC1_BASE ((struct dac_reg_map*)0x40007400) -//#define DAC2_BASE ((struct dac_reg_map*)0x40009800) //TODO STM32F37/38xx - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/dma.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/dma.h deleted file mode 100644 index 1c73748..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/dma.h +++ /dev/null @@ -1,557 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Michael Hope. - * Copyright (c) 2012 LeafLabs, LLC - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/dma.h - * @author Marti Bolivar , - * Original implementation by Michael Hope, - * F3-port by Hanspeter Portner - * @brief STM32F3 DMA series header. - */ - -#ifndef _LIBMAPLE_STM32F3_DMA_H_ -#define _LIBMAPLE_STM32F3_DMA_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include - -/* - * Register maps and base pointers - */ - -/** - * @brief STM32F3 DMA register map type. - * - * Note that DMA controller 2 (register map base pointer DMA2_BASE) - * only supports channels 1--5. - */ -typedef struct dma_reg_map { - __IO uint32 ISR; /**< Interrupt status register */ - __IO uint32 IFCR; /**< Interrupt flag clear register */ - __IO uint32 CCR1; /**< Channel 1 configuration register */ - __IO uint32 CNDTR1; /**< Channel 1 number of data register */ - __IO uint32 CPAR1; /**< Channel 1 peripheral address register */ - __IO uint32 CMAR1; /**< Channel 1 memory address register */ - const uint32 RESERVED1; /**< Reserved. */ - __IO uint32 CCR2; /**< Channel 2 configuration register */ - __IO uint32 CNDTR2; /**< Channel 2 number of data register */ - __IO uint32 CPAR2; /**< Channel 2 peripheral address register */ - __IO uint32 CMAR2; /**< Channel 2 memory address register */ - const uint32 RESERVED2; /**< Reserved. */ - __IO uint32 CCR3; /**< Channel 3 configuration register */ - __IO uint32 CNDTR3; /**< Channel 3 number of data register */ - __IO uint32 CPAR3; /**< Channel 3 peripheral address register */ - __IO uint32 CMAR3; /**< Channel 3 memory address register */ - const uint32 RESERVED3; /**< Reserved. */ - __IO uint32 CCR4; /**< Channel 4 configuration register */ - __IO uint32 CNDTR4; /**< Channel 4 number of data register */ - __IO uint32 CPAR4; /**< Channel 4 peripheral address register */ - __IO uint32 CMAR4; /**< Channel 4 memory address register */ - const uint32 RESERVED4; /**< Reserved. */ - __IO uint32 CCR5; /**< Channel 5 configuration register */ - __IO uint32 CNDTR5; /**< Channel 5 number of data register */ - __IO uint32 CPAR5; /**< Channel 5 peripheral address register */ - __IO uint32 CMAR5; /**< Channel 5 memory address register */ - const uint32 RESERVED5; /**< Reserved. */ - __IO uint32 CCR6; /**< Channel 6 configuration register */ - __IO uint32 CNDTR6; /**< Channel 6 number of data register */ - __IO uint32 CPAR6; /**< Channel 6 peripheral address register */ - __IO uint32 CMAR6; /**< Channel 6 memory address register */ - const uint32 RESERVED6; /**< Reserved. */ - __IO uint32 CCR7; /**< Channel 7 configuration register */ - __IO uint32 CNDTR7; /**< Channel 7 number of data register */ - __IO uint32 CPAR7; /**< Channel 7 peripheral address register */ - __IO uint32 CMAR7; /**< Channel 7 memory address register */ - const uint32 RESERVED7; /**< Reserved. */ -} dma_reg_map; - -/** DMA controller 1 register map base pointer */ -#define DMA1_BASE ((struct dma_reg_map*)0x40020000) -/** DMA controller 2 register map base pointer */ -#define DMA2_BASE ((struct dma_reg_map*)0x40020400) - -/** - * @brief STM32F3 DMA channel (i.e. tube) register map type. - * Provides access to an individual channel's registers. - * @see dma_tube_regs() - */ -typedef struct dma_tube_reg_map { - __IO uint32 CCR; /**< Channel configuration register */ - __IO uint32 CNDTR; /**< Channel number of data register */ - __IO uint32 CPAR; /**< Channel peripheral address register */ - __IO uint32 CMAR; /**< Channel memory address register */ -} dma_tube_reg_map; - -/** DMA1 channel 1 register map base pointer */ -#define DMA1CH1_BASE ((struct dma_tube_reg_map*)0x40020008) -/** DMA1 channel 2 register map base pointer */ -#define DMA1CH2_BASE ((struct dma_tube_reg_map*)0x4002001C) -/** DMA1 channel 3 register map base pointer */ -#define DMA1CH3_BASE ((struct dma_tube_reg_map*)0x40020030) -/** DMA1 channel 4 register map base pointer */ -#define DMA1CH4_BASE ((struct dma_tube_reg_map*)0x40020044) -/** DMA1 channel 5 register map base pointer */ -#define DMA1CH5_BASE ((struct dma_tube_reg_map*)0x40020058) -/** DMA1 channel 6 register map base pointer */ -#define DMA1CH6_BASE ((struct dma_tube_reg_map*)0x4002006C) -/** DMA1 channel 7 register map base pointer */ -#define DMA1CH7_BASE ((struct dma_tube_reg_map*)0x40020080) - -/** DMA2 channel 1 register map base pointer */ -#define DMA2CH1_BASE ((struct dma_tube_reg_map*)0x40020408) -/** DMA2 channel 2 register map base pointer */ -#define DMA2CH2_BASE ((struct dma_tube_reg_map*)0x4002041C) -/** DMA2 channel 3 register map base pointer */ -#define DMA2CH3_BASE ((struct dma_tube_reg_map*)0x40020430) -/** DMA2 channel 4 register map base pointer */ -#define DMA2CH4_BASE ((struct dma_tube_reg_map*)0x40020444) -/** DMA2 channel 5 register map base pointer */ -#define DMA2CH5_BASE ((struct dma_tube_reg_map*)0x40020458) - -/* - * Register bit definitions - */ - -/* Interrupt status register */ - -#define DMA_ISR_TEIF_BIT 3 -#define DMA_ISR_HTIF_BIT 2 -#define DMA_ISR_TCIF_BIT 1 -#define DMA_ISR_GIF_BIT 0 - -#define DMA_ISR_TEIF (1 << DMA_ISR_TEIF_BIT) -#define DMA_ISR_HTIF (1 << DMA_ISR_HTIF_BIT) -#define DMA_ISR_TCIF (1 << DMA_ISR_TCIF_BIT) -#define DMA_ISR_GIF (1 << DMA_ISR_GIF_BIT) - -#define DMA_ISR_TEIF7_BIT 27 -#define DMA_ISR_HTIF7_BIT 26 -#define DMA_ISR_TCIF7_BIT 25 -#define DMA_ISR_GIF7_BIT 24 -#define DMA_ISR_TEIF6_BIT 23 -#define DMA_ISR_HTIF6_BIT 22 -#define DMA_ISR_TCIF6_BIT 21 -#define DMA_ISR_GIF6_BIT 20 -#define DMA_ISR_TEIF5_BIT 19 -#define DMA_ISR_HTIF5_BIT 18 -#define DMA_ISR_TCIF5_BIT 17 -#define DMA_ISR_GIF5_BIT 16 -#define DMA_ISR_TEIF4_BIT 15 -#define DMA_ISR_HTIF4_BIT 14 -#define DMA_ISR_TCIF4_BIT 13 -#define DMA_ISR_GIF4_BIT 12 -#define DMA_ISR_TEIF3_BIT 11 -#define DMA_ISR_HTIF3_BIT 10 -#define DMA_ISR_TCIF3_BIT 9 -#define DMA_ISR_GIF3_BIT 8 -#define DMA_ISR_TEIF2_BIT 7 -#define DMA_ISR_HTIF2_BIT 6 -#define DMA_ISR_TCIF2_BIT 5 -#define DMA_ISR_GIF2_BIT 4 -#define DMA_ISR_TEIF1_BIT 3 -#define DMA_ISR_HTIF1_BIT 2 -#define DMA_ISR_TCIF1_BIT 1 -#define DMA_ISR_GIF1_BIT 0 - -#define DMA_ISR_TEIF7 (1U << DMA_ISR_TEIF7_BIT) -#define DMA_ISR_HTIF7 (1U << DMA_ISR_HTIF7_BIT) -#define DMA_ISR_TCIF7 (1U << DMA_ISR_TCIF7_BIT) -#define DMA_ISR_GIF7 (1U << DMA_ISR_GIF7_BIT) -#define DMA_ISR_TEIF6 (1U << DMA_ISR_TEIF6_BIT) -#define DMA_ISR_HTIF6 (1U << DMA_ISR_HTIF6_BIT) -#define DMA_ISR_TCIF6 (1U << DMA_ISR_TCIF6_BIT) -#define DMA_ISR_GIF6 (1U << DMA_ISR_GIF6_BIT) -#define DMA_ISR_TEIF5 (1U << DMA_ISR_TEIF5_BIT) -#define DMA_ISR_HTIF5 (1U << DMA_ISR_HTIF5_BIT) -#define DMA_ISR_TCIF5 (1U << DMA_ISR_TCIF5_BIT) -#define DMA_ISR_GIF5 (1U << DMA_ISR_GIF5_BIT) -#define DMA_ISR_TEIF4 (1U << DMA_ISR_TEIF4_BIT) -#define DMA_ISR_HTIF4 (1U << DMA_ISR_HTIF4_BIT) -#define DMA_ISR_TCIF4 (1U << DMA_ISR_TCIF4_BIT) -#define DMA_ISR_GIF4 (1U << DMA_ISR_GIF4_BIT) -#define DMA_ISR_TEIF3 (1U << DMA_ISR_TEIF3_BIT) -#define DMA_ISR_HTIF3 (1U << DMA_ISR_HTIF3_BIT) -#define DMA_ISR_TCIF3 (1U << DMA_ISR_TCIF3_BIT) -#define DMA_ISR_GIF3 (1U << DMA_ISR_GIF3_BIT) -#define DMA_ISR_TEIF2 (1U << DMA_ISR_TEIF2_BIT) -#define DMA_ISR_HTIF2 (1U << DMA_ISR_HTIF2_BIT) -#define DMA_ISR_TCIF2 (1U << DMA_ISR_TCIF2_BIT) -#define DMA_ISR_GIF2 (1U << DMA_ISR_GIF2_BIT) -#define DMA_ISR_TEIF1 (1U << DMA_ISR_TEIF1_BIT) -#define DMA_ISR_HTIF1 (1U << DMA_ISR_HTIF1_BIT) -#define DMA_ISR_TCIF1 (1U << DMA_ISR_TCIF1_BIT) -#define DMA_ISR_GIF1 (1U << DMA_ISR_GIF1_BIT) - -/* Interrupt flag clear register */ - -#define DMA_IFCR_CTEIF7_BIT 27 -#define DMA_IFCR_CHTIF7_BIT 26 -#define DMA_IFCR_CTCIF7_BIT 25 -#define DMA_IFCR_CGIF7_BIT 24 -#define DMA_IFCR_CTEIF6_BIT 23 -#define DMA_IFCR_CHTIF6_BIT 22 -#define DMA_IFCR_CTCIF6_BIT 21 -#define DMA_IFCR_CGIF6_BIT 20 -#define DMA_IFCR_CTEIF5_BIT 19 -#define DMA_IFCR_CHTIF5_BIT 18 -#define DMA_IFCR_CTCIF5_BIT 17 -#define DMA_IFCR_CGIF5_BIT 16 -#define DMA_IFCR_CTEIF4_BIT 15 -#define DMA_IFCR_CHTIF4_BIT 14 -#define DMA_IFCR_CTCIF4_BIT 13 -#define DMA_IFCR_CGIF4_BIT 12 -#define DMA_IFCR_CTEIF3_BIT 11 -#define DMA_IFCR_CHTIF3_BIT 10 -#define DMA_IFCR_CTCIF3_BIT 9 -#define DMA_IFCR_CGIF3_BIT 8 -#define DMA_IFCR_CTEIF2_BIT 7 -#define DMA_IFCR_CHTIF2_BIT 6 -#define DMA_IFCR_CTCIF2_BIT 5 -#define DMA_IFCR_CGIF2_BIT 4 -#define DMA_IFCR_CTEIF1_BIT 3 -#define DMA_IFCR_CHTIF1_BIT 2 -#define DMA_IFCR_CTCIF1_BIT 1 -#define DMA_IFCR_CGIF1_BIT 0 - -#define DMA_IFCR_CTEIF7 (1U << DMA_IFCR_CTEIF7_BIT) -#define DMA_IFCR_CHTIF7 (1U << DMA_IFCR_CHTIF7_BIT) -#define DMA_IFCR_CTCIF7 (1U << DMA_IFCR_CTCIF7_BIT) -#define DMA_IFCR_CGIF7 (1U << DMA_IFCR_CGIF7_BIT) -#define DMA_IFCR_CTEIF6 (1U << DMA_IFCR_CTEIF6_BIT) -#define DMA_IFCR_CHTIF6 (1U << DMA_IFCR_CHTIF6_BIT) -#define DMA_IFCR_CTCIF6 (1U << DMA_IFCR_CTCIF6_BIT) -#define DMA_IFCR_CGIF6 (1U << DMA_IFCR_CGIF6_BIT) -#define DMA_IFCR_CTEIF5 (1U << DMA_IFCR_CTEIF5_BIT) -#define DMA_IFCR_CHTIF5 (1U << DMA_IFCR_CHTIF5_BIT) -#define DMA_IFCR_CTCIF5 (1U << DMA_IFCR_CTCIF5_BIT) -#define DMA_IFCR_CGIF5 (1U << DMA_IFCR_CGIF5_BIT) -#define DMA_IFCR_CTEIF4 (1U << DMA_IFCR_CTEIF4_BIT) -#define DMA_IFCR_CHTIF4 (1U << DMA_IFCR_CHTIF4_BIT) -#define DMA_IFCR_CTCIF4 (1U << DMA_IFCR_CTCIF4_BIT) -#define DMA_IFCR_CGIF4 (1U << DMA_IFCR_CGIF4_BIT) -#define DMA_IFCR_CTEIF3 (1U << DMA_IFCR_CTEIF3_BIT) -#define DMA_IFCR_CHTIF3 (1U << DMA_IFCR_CHTIF3_BIT) -#define DMA_IFCR_CTCIF3 (1U << DMA_IFCR_CTCIF3_BIT) -#define DMA_IFCR_CGIF3 (1U << DMA_IFCR_CGIF3_BIT) -#define DMA_IFCR_CTEIF2 (1U << DMA_IFCR_CTEIF2_BIT) -#define DMA_IFCR_CHTIF2 (1U << DMA_IFCR_CHTIF2_BIT) -#define DMA_IFCR_CTCIF2 (1U << DMA_IFCR_CTCIF2_BIT) -#define DMA_IFCR_CGIF2 (1U << DMA_IFCR_CGIF2_BIT) -#define DMA_IFCR_CTEIF1 (1U << DMA_IFCR_CTEIF1_BIT) -#define DMA_IFCR_CHTIF1 (1U << DMA_IFCR_CHTIF1_BIT) -#define DMA_IFCR_CTCIF1 (1U << DMA_IFCR_CTCIF1_BIT) -#define DMA_IFCR_CGIF1 (1U << DMA_IFCR_CGIF1_BIT) - -/* Channel configuration register */ - -#define DMA_CCR_MEM2MEM_BIT 14 -#define DMA_CCR_MINC_BIT 7 -#define DMA_CCR_PINC_BIT 6 -#define DMA_CCR_CIRC_BIT 5 -#define DMA_CCR_DIR_BIT 4 -#define DMA_CCR_TEIE_BIT 3 -#define DMA_CCR_HTIE_BIT 2 -#define DMA_CCR_TCIE_BIT 1 -#define DMA_CCR_EN_BIT 0 - -#define DMA_CCR_MEM2MEM (1U << DMA_CCR_MEM2MEM_BIT) -#define DMA_CCR_PL (0x3 << 12) -#define DMA_CCR_PL_LOW (0x0 << 12) -#define DMA_CCR_PL_MEDIUM (0x1 << 12) -#define DMA_CCR_PL_HIGH (0x2 << 12) -#define DMA_CCR_PL_VERY_HIGH (0x3 << 12) -#define DMA_CCR_MSIZE (0x3 << 10) -#define DMA_CCR_MSIZE_8BITS (0x0 << 10) -#define DMA_CCR_MSIZE_16BITS (0x1 << 10) -#define DMA_CCR_MSIZE_32BITS (0x2 << 10) -#define DMA_CCR_PSIZE (0x3 << 8) -#define DMA_CCR_PSIZE_8BITS (0x0 << 8) -#define DMA_CCR_PSIZE_16BITS (0x1 << 8) -#define DMA_CCR_PSIZE_32BITS (0x2 << 8) -#define DMA_CCR_MINC (1U << DMA_CCR_MINC_BIT) -#define DMA_CCR_PINC (1U << DMA_CCR_PINC_BIT) -#define DMA_CCR_CIRC (1U << DMA_CCR_CIRC_BIT) -#define DMA_CCR_DIR (1U << DMA_CCR_DIR_BIT) -#define DMA_CCR_DIR_FROM_PER (0U << DMA_CCR_DIR_BIT) -#define DMA_CCR_DIR_FROM_MEM (1U << DMA_CCR_DIR_BIT) -#define DMA_CCR_TEIE (1U << DMA_CCR_TEIE_BIT) -#define DMA_CCR_HTIE (1U << DMA_CCR_HTIE_BIT) -#define DMA_CCR_TCIE (1U << DMA_CCR_TCIE_BIT) -#define DMA_CCR_EN (1U << DMA_CCR_EN_BIT) - -/* - * Devices - */ - -extern dma_dev *DMA1; -extern dma_dev *DMA2; - -/* - * Other types needed by, or useful for, . - */ - -/** - * @brief STM32F3 dma_tube. - * On STM32F3, DMA tubes are just channels. - */ -#define dma_tube dma_channel - -/** - * @brief On STM32F3, dma_channel_reg_map is an alias for dma_tube_reg_map. - * This is for backwards compatibility. */ -#define dma_channel_reg_map dma_tube_reg_map - -/** - * @brief STM32F3 configuration flags for dma_tube_config - * @see struct dma_tube_config - */ -typedef enum dma_cfg_flags { - /** - * Source address increment mode - * - * If this flag is set, the source address is incremented (by the - * source size) after each DMA transfer. - */ - DMA_CFG_SRC_INC = 1U << 31, - - /** - * Destination address increment mode - * - * If this flag is set, the destination address is incremented (by - * the destination size) after each DMA transfer. - */ - DMA_CFG_DST_INC = 1U << 30, - - /** - * Circular mode - * - * This mode is not available for memory-to-memory transfers. - */ - DMA_CFG_CIRC = DMA_CCR_CIRC, - - /** Transfer complete interrupt enable */ - DMA_CFG_CMPLT_IE = DMA_CCR_TCIE, - /** Transfer half-complete interrupt enable */ - DMA_CFG_HALF_CMPLT_IE = DMA_CCR_HTIE, - /** Transfer error interrupt enable */ - DMA_CFG_ERR_IE = DMA_CCR_TEIE, -} dma_cfg_flags; - -/** - * @brief STM32F3 DMA request sources. - * - * IMPORTANT: - * - * 1. On STM32F3, each dma_request_src can only be used by a - * particular tube on a particular DMA controller. For example, - * DMA_REQ_SRC_ADC1 belongs to DMA1, tube 1. DMA2 cannot serve - * requests from ADC1, nor can DMA1 tube 2, etc. If you try to use a - * request source with the wrong DMA controller or tube on STM32F3, - * dma_tube_cfg() will fail. - * - * 2. In general, a DMA tube can only serve a single request source at - * a time, and on STM32F3, Terrible Super-Bad Things will happen if - * two request sources are active for a single tube. - * - * To make all this easier to sort out, these dma_request_src - * enumerators are grouped by DMA controller and tube. - * - * @see struct dma_tube_config - * @see dma_tube_cfg() - */ -typedef enum dma_request_src { - /* Each request source encodes the DMA controller and channel it - * belongs to, for error checking in dma_tube_cfg(). */ - - /* DMA1 request sources */ - - /**@{*/ - /** (DMA1, tube 1) */ - DMA_REQ_SRC_ADC1 = (RCC_DMA1 << 3) | 1, - DMA_REQ_SRC_TIM2_CH3 = (RCC_DMA1 << 3) | 1, - DMA_REQ_SRC_TIM4_CH1 = (RCC_DMA1 << 3) | 1, - DMA_REQ_SRC_TIM17_CH1 = (RCC_DMA1 << 3) | 1, - DMA_REQ_SRC_TIM17_UP = (RCC_DMA1 << 3) | 1, - /**@}*/ - - /**@{*/ - /** (DMA1, tube 2)*/ - DMA_REQ_SRC_SPI1_RX = (RCC_DMA1 << 3) | 2, - DMA_REQ_SRC_USART3_TX = (RCC_DMA1 << 3) | 2, - DMA_REQ_SRC_TIM1_CH1 = (RCC_DMA1 << 3) | 2, - DMA_REQ_SRC_TIM2_UP = (RCC_DMA1 << 3) | 2, - DMA_REQ_SRC_TIM3_CH3 = (RCC_DMA1 << 3) | 2, - /**@}*/ - - /**@{*/ - /** (DMA1, tube 3)*/ - DMA_REQ_SRC_SPI1_TX = (RCC_DMA1 << 3) | 3, - DMA_REQ_SRC_USART3_RX = (RCC_DMA1 << 3) | 3, - DMA_REQ_SRC_TIM1_CH2 = (RCC_DMA1 << 3) | 3, - DMA_REQ_SRC_TIM3_CH4 = (RCC_DMA1 << 3) | 3, - DMA_REQ_SRC_TIM3_UP = (RCC_DMA1 << 3) | 3, - /*DMA_REQ_SRC_TIM6_UP = (RCC_DMA1 << 3) | 3,*/ /* remap in SYSCFGR */ - /*DMA_REQ_SRC_DAC_CH1 = (RCC_DMA1 << 3) | 3,*/ /* remap in SYSCFGR */ - DMA_REQ_SRC_TIM16_CH1 = (RCC_DMA1 << 3) | 3, - DMA_REQ_SRC_TIM16_UP = (RCC_DMA1 << 3) | 3, - /**@}*/ - - /**@{*/ - /** (DMA1, tube 4)*/ - DMA_REQ_SRC_SPI2_RX = (RCC_DMA1 << 3) | 4, - DMA_REQ_SRC_USART1_TX = (RCC_DMA1 << 3) | 4, - DMA_REQ_SRC_I2C2_TX = (RCC_DMA1 << 3) | 4, - DMA_REQ_SRC_TIM1_CH4 = (RCC_DMA1 << 3) | 4, - DMA_REQ_SRC_TIM1_TRIG = (RCC_DMA1 << 3) | 4, - DMA_REQ_SRC_TIM1_COM = (RCC_DMA1 << 3) | 4, - DMA_REQ_SRC_TIM4_CH2 = (RCC_DMA1 << 3) | 4, - /*DMA_REQ_SRC_TIM7_UP = (RCC_DMA1 << 3) | 4,*/ /* remap in SYSCFGR */ - /*DMA_REQ_SRC_DAC_CH2 = (RCC_DMA1 << 3) | 4,*/ /* remap in SYSCFGR */ - /**@}*/ - - /**@{*/ - /** (DMA1, tube 5)*/ - DMA_REQ_SRC_SPI2_TX = (RCC_DMA1 << 3) | 5, - DMA_REQ_SRC_USART1_RX = (RCC_DMA1 << 3) | 5, - DMA_REQ_SRC_I2C2_RX = (RCC_DMA1 << 3) | 5, - DMA_REQ_SRC_TIM1_UP = (RCC_DMA1 << 3) | 5, - DMA_REQ_SRC_TIM2_CH1 = (RCC_DMA1 << 3) | 5, - DMA_REQ_SRC_TIM4_CH3 = (RCC_DMA1 << 3) | 5, - DMA_REQ_SRC_TIM15_CH1 = (RCC_DMA1 << 3) | 5, - DMA_REQ_SRC_TIM15_UP = (RCC_DMA1 << 3) | 5, - DMA_REQ_SRC_TIM15_TRIG = (RCC_DMA1 << 3) | 5, - DMA_REQ_SRC_TIM15_COM = (RCC_DMA1 << 3) | 5, - /**@}*/ - - /**@{*/ - /** (DMA1, tube 6)*/ - DMA_REQ_SRC_USART2_RX = (RCC_DMA1 << 3) | 6, - DMA_REQ_SRC_I2C1_TX = (RCC_DMA1 << 3) | 6, - DMA_REQ_SRC_TIM1_CH3 = (RCC_DMA1 << 3) | 6, - DMA_REQ_SRC_TIM3_CH1 = (RCC_DMA1 << 3) | 6, - DMA_REQ_SRC_TIM3_TRIG = (RCC_DMA1 << 3) | 6, - /*DMA_REQ_SRC_TIM16_CH1 = (RCC_DMA1 << 3) | 6,*/ /* remap in SYSCFGR */ - /*DMA_REQ_SRC_TIM16_UP = (RCC_DMA1 << 3) | 6,*/ /* remap in SYSCFGR */ - /**@}*/ - - /**@{*/ - /* Tube 7 */ - DMA_REQ_SRC_USART2_TX = (RCC_DMA1 << 3) | 7, - DMA_REQ_SRC_I2C1_RX = (RCC_DMA1 << 3) | 7, - DMA_REQ_SRC_TIM2_CH2 = (RCC_DMA1 << 3) | 7, - DMA_REQ_SRC_TIM2_CH4 = (RCC_DMA1 << 3) | 7, - DMA_REQ_SRC_TIM4_UP = (RCC_DMA1 << 3) | 7, - /**@}*/ - - /* DMA2 request sources */ - - /**@{*/ - /** (DMA2, tube 1)*/ - DMA_REQ_SRC_ADC2 = (RCC_DMA2 << 3) | 1, - DMA_REQ_SRC_SPI3_RX = (RCC_DMA2 << 3) | 1, - DMA_REQ_SRC_TIM8_CH3 = (RCC_DMA2 << 3) | 1, - DMA_REQ_SRC_TIM8_UP = (RCC_DMA2 << 3) | 1, - /**@}*/ - - /**@{*/ - /** (DMA2, tube 2)*/ - DMA_REQ_SRC_ADC4 = (RCC_DMA2 << 3) | 2, - DMA_REQ_SRC_SPI3_TX = (RCC_DMA2 << 3) | 2, - DMA_REQ_SRC_TIM8_CH4 = (RCC_DMA2 << 3) | 2, - DMA_REQ_SRC_TIM8_TRIG = (RCC_DMA2 << 3) | 2, - DMA_REQ_SRC_TIM8_COM = (RCC_DMA2 << 3) | 2, - /**@}*/ - - /**@{*/ - /** (DMA2, tube 3)*/ - /* DMA_REQ_SRC_ADC2 = (RCC_DMA2 << 3) | 3,*/ /* remap in SYSCFGR */ - DMA_REQ_SRC_UART4_RX = (RCC_DMA2 << 3) | 3, - DMA_REQ_SRC_TIM6_UP = (RCC_DMA2 << 3) | 3, - DMA_REQ_SRC_DAC1_CH1 = (RCC_DMA2 << 3) | 3, - DMA_REQ_SRC_TIM8_CH1 = (RCC_DMA2 << 3) | 3, - /**@}*/ - - /**@{*/ - /** (DMA2, tube 4)*/ - /*DMA_REQ_SRC_ADC4 = (RCC_DMA2 << 3) | 4,*/ /* remap in SYSCFGR */ - DMA_REQ_SRC_TIM7_UP = (RCC_DMA2 << 3) | 4, - DMA_REQ_SRC_DAC1_CH2 = (RCC_DMA2 << 3) | 4, - /**@}*/ - - /**@{*/ - /** (DMA2, tube 5)*/ - DMA_REQ_SRC_ADC3 = (RCC_DMA2 << 3) | 5, - DMA_REQ_SRC_UART4_TX = (RCC_DMA2 << 3) | 5, - DMA_REQ_SRC_TIM8_CH2 = (RCC_DMA2 << 3) | 5, - /**@}*/ -} dma_request_src; - -/* - * Convenience routines. - */ - -/** - * @brief On STM32F3, dma_is_channel_enabled() is an alias for - * dma_is_enabled(). - * This is for backwards compatibility. - */ -#define dma_is_channel_enabled dma_is_enabled - -#define DMA_CHANNEL_NREGS 5 /* accounts for reserved word */ -static inline dma_tube_reg_map* dma_tube_regs(dma_dev *dev, dma_tube tube) { - __IO uint32 *ccr1 = &dev->regs->CCR1; - return (dma_channel_reg_map*)(ccr1 + DMA_CHANNEL_NREGS * (tube - 1)); -} - -/** - * @brief On STM32F3, dma_channel_regs() is an alias for dma_tube_regs(). - * This is for backwards compatibility. */ -#define dma_channel_regs(dev, ch) dma_tube_regs(dev, ch) - -static inline uint8 dma_is_enabled(dma_dev *dev, dma_tube tube) { - return (uint8)(dma_tube_regs(dev, tube)->CCR & DMA_CCR_EN); -} - -static inline uint8 dma_get_isr_bits(dma_dev *dev, dma_tube tube) { - uint8 shift = (tube - 1) * 4; - return (dev->regs->ISR >> shift) & 0xF; -} - -static inline void dma_clear_isr_bits(dma_dev *dev, dma_tube tube) { - dev->regs->IFCR = (1U << (4 * (tube - 1))); -} - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/exti.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/exti.h deleted file mode 100644 index 05ed1e6..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/exti.h +++ /dev/null @@ -1,49 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/exti.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 external interrupts - */ - -#ifndef _LIBMAPLE_STM32F3_EXTI_H_ -#define _LIBMAPLE_STM32F3_EXTI_H_ - -#ifdef __cpluspus -extern "C" { -#endif - -//FIXME F3 has up to 36 EXTIs, expose and handle internal EXTIs 16-35 -struct exti_reg_map; -#define EXTI_BASE ((struct exti_reg_map*)0x40010400) - -#ifdef __cpluspus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/flash.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/flash.h deleted file mode 100644 index 8bc6114..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/flash.h +++ /dev/null @@ -1,164 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/flash.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 Flash header. - * - * Provides register map, base pointer, and register bit definitions - * for the Flash controller on the STM32F3 line, along with - * series-specific configuration values. - */ - -#ifndef _LIBMAPLE_STM32F3_FLASH_H_ -#define _LIBMAPLE_STM32F3_FLASH_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/* - * Register map - */ - -/** @brief STM32F3 Flash register map type */ -typedef struct flash_reg_map { - __IO uint32 ACR; /**< Access control register */ - __IO uint32 KEYR; /**< Key register */ - __IO uint32 OPTKEYR; /**< OPTKEY register */ - __IO uint32 SR; /**< Status register */ - __IO uint32 CR; /**< Control register */ - __IO uint32 AR; /**< Address register */ - __IO uint32 OBR; /**< Option byte register */ - __IO uint32 WRPR; /**< Write protection register */ -} flash_reg_map; - -#define FLASH_BASE ((struct flash_reg_map*)0x40022000) - -/* - * Register bit definitions - */ - -/* Access control register */ - -#define FLASH_ACR_PRFTBS_BIT 5 -#define FLASH_ACR_PRFTBE_BIT 4 -#define FLASH_ACR_HLFCYA_BIT 3 - -#define FLASH_ACR_PRFTBS (1U << FLASH_ACR_PRFTBS_BIT) -#define FLASH_ACR_PRFTBE (1U << FLASH_ACR_PRFTBE_BIT) -#define FLASH_ACR_HLFCYA (1U << FLASH_ACR_HLFCYA_BIT) -#define FLASH_ACR_LATENCY 0x7 - -/* Status register */ - -#define FLASH_SR_EOP_BIT 5 -#define FLASH_SR_WRPRTERR_BIT 4 -#define FLASH_SR_PGERR_BIT 2 -#define FLASH_SR_BSY_BIT 0 - -#define FLASH_SR_EOP (1U << FLASH_SR_EOP_BIT) -#define FLASH_SR_WRPRTERR (1U << FLASH_SR_WRPRTERR_BIT) -#define FLASH_SR_PGERR (1U << FLASH_SR_PGERR_BIT) -#define FLASH_SR_BSY (1U << FLASH_SR_BSY_BIT) - -/* Control register */ - -#define FLASH_CR_OBL_LAUNCH_BIT 13 -#define FLASH_CR_EOPIE_BIT 12 -#define FLASH_CR_ERRIE_BIT 10 -#define FLASH_CR_OPTWRE_BIT 9 -#define FLASH_CR_LOCK_BIT 7 -#define FLASH_CR_STRT_BIT 6 -#define FLASH_CR_OPTER_BIT 5 -#define FLASH_CR_OPTPG_BIT 4 -#define FLASH_CR_MER_BIT 2 -#define FLASH_CR_PER_BIT 1 -#define FLASH_CR_PG_BIT 0 - -#define FLASH_CR_OBL_LAUNCH (1U << FLASH_CR_OBL_LAUNCH_BIT) -#define FLASH_CR_EOPIE (1U << FLASH_CR_EOPIE_BIT) -#define FLASH_CR_ERRIE (1U << FLASH_CR_ERRIE_BIT) -#define FLASH_CR_OPTWRE (1U << FLASH_CR_OPTWRE_BIT) -#define FLASH_CR_LOCK (1U << FLASH_CR_LOCK_BIT) -#define FLASH_CR_STRT (1U << FLASH_CR_STRT_BIT) -#define FLASH_CR_OPTER (1U << FLASH_CR_OPTER_BIT) -#define FLASH_CR_OPTPG (1U << FLASH_CR_OPTPG_BIT) -#define FLASH_CR_MER (1U << FLASH_CR_MER_BIT) -#define FLASH_CR_PER (1U << FLASH_CR_PER_BIT) -#define FLASH_CR_PG (1U << FLASH_CR_PG_BIT) - -/* Option byte register */ - -#define FLASH_OBR_DATA1_SHIFT 24 -#define FLASH_OBR_DATA0_SHIFT 16 -#define FLASH_OBR_BYTE_SHIFT 8 -#define FLASH_OBR_SRAM_PE_BIT 14 -#define FLASH_OBR_VDDA_MONITOR_BIT 13 -#define FLASH_OBR_nBOOT1_BIT 12 -#define FLASH_OBR_nRST_STDBY_BIT 10 -#define FLASH_OBR_nRST_STOP_BIT 9 -#define FLASH_OBR_WDG_SW_BIT 8 -#define FLASH_OBR_RDPRT_SHIFT 1 -#define FLASH_OBR_OPTERR_BIT 0 - -#define FLASH_OBR_DATA1 (0xFF << FLASH_OBR_DATA1_SHIFT) -#define FLASH_OBR_DATA0 (0xFF << FLASH_OBR_DATA0_SHIFT) -#define FLASH_OBR_BYTE (0xFF << FLASH_OBR_BYTE_SHIFT) -#define FLASH_OBR_SRAM_PE_STDBY (1U << FLASH_OBR_SRAM_PE_STDBY_BIT) -#define FLASH_OBR_VDDA_MONITOR_STDBY (1U << FLASH_OBR_VDDA_MONITOR_STDBY_BIT) -#define FLASH_OBR_nBOOT1_STDBY (1U << FLASH_OBR_nBOOT1_STDBY_BIT) -#define FLASH_OBR_nRST_STDBY (1U << FLASH_OBR_nRST_STDBY_BIT) -#define FLASH_OBR_nRST_STOP (1U << FLASH_OBR_nRST_STOP_BIT) -#define FLASH_OBR_WDG_SW (1U << FLASH_OBR_WDG_SW_BIT) -#define FLASH_OBR_RDPRT (0x3 << FLASH_OBR_RDPRT_SHIFT) -#define FLASH_OBR_OPTERR (1U << FLASH_OBR_OPTERR_BIT) - -/* - * Series-specific configuration values. - */ - -#define FLASH_SAFE_WAIT_STATES FLASH_WAIT_STATE_2 - -/* Flash memory features available via ACR */ -enum { - FLASH_PREFETCH = 0x10, - FLASH_HALF_CYCLE = 0x8, - FLASH_ICACHE = 0x0, /* Not available on STM32F3 */ - FLASH_DCACHE = 0x0, /* Not available on STM32F3 */ -}; - -/* TODO add routines for option byte handling, e.g. nBoot1 */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/fpu.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/fpu.h deleted file mode 100644 index ee5d5c1..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/fpu.h +++ /dev/null @@ -1,65 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/fpu.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 Floating Point Unit support. - */ - -#ifndef _LIBMAPLE_STM32F3_FPU_H_ -#define _LIBMAPLE_STM32F3_FPU_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include - -/* - * FPU register maps and devices - */ - -/** FPU register map type */ -typedef struct fpu_reg_map { - __IO uint32 CPACR; /**< coprocessor access control register */ - __IO uint32 FPCCR; /**< floating-point context control register */ - __IO uint32 FPCAR; /**< floating-point context address register */ - __IO uint32 FPDSCR; /**< floating-point default status control register */ -} fpu_reg_map; - -#define FPU_BASE ((struct fpu_reg_map*)(SCB_BASE + 0x88)) - -/* TODO - * give registry bitfields here - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/gpio.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/gpio.h deleted file mode 100644 index 268c9c2..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/gpio.h +++ /dev/null @@ -1,255 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/gpio.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 GPIO support. - */ - -#ifndef _LIBMAPLE_STM32F3_GPIO_H_ -#define _LIBMAPLE_STM32F3_GPIO_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/* - * GPIO register maps and devices - */ - -/** GPIO register map type */ -typedef struct gpio_reg_map { - __IO uint32 MODER; /**< Mode register */ - __IO uint32 OTYPER; /**< Output type register */ - __IO uint32 OSPEEDR; /**< Output speed register */ - __IO uint32 PUPDR; /**< Pull-up/pull-down register */ - __IO uint32 IDR; /**< Input data register */ - __IO uint32 ODR; /**< Output data register */ - __IO uint32 BSRR; /**< Bit set/reset register */ - __IO uint32 LCKR; /**< Configuration lock register */ - __IO uint32 AFRL; /**< Alternate function low register */ - __IO uint32 AFRH; /**< Alternate function high register */ - __IO uint32 BRR; /**< Port bit reset register */ -} gpio_reg_map; - -/** GPIO port A register map base pointer */ -#define GPIOA_BASE ((struct gpio_reg_map*)0x48000000) -/** GPIO port B register map base pointer */ -#define GPIOB_BASE ((struct gpio_reg_map*)0x48000400) -/** GPIO port C register map base pointer */ -#define GPIOC_BASE ((struct gpio_reg_map*)0x48000800) -/** GPIO port D register map base pointer */ -#define GPIOD_BASE ((struct gpio_reg_map*)0x48000C00) -/** GPIO port E register map base pointer */ -#define GPIOE_BASE ((struct gpio_reg_map*)0x48001000) -/** GPIO port F register map base pointer */ -#define GPIOF_BASE ((struct gpio_reg_map*)0x48001400) - -struct gpio_dev; -extern struct gpio_dev* const GPIOA; -extern struct gpio_dev gpioa; -extern struct gpio_dev* const GPIOB; -extern struct gpio_dev gpiob; -extern struct gpio_dev* const GPIOC; -extern struct gpio_dev gpioc; -extern struct gpio_dev* const GPIOD; -extern struct gpio_dev gpiod; -extern struct gpio_dev* const GPIOE; -extern struct gpio_dev gpioe; -extern struct gpio_dev* const GPIOF; -extern struct gpio_dev gpiof; - -/* - * Register bit definitions - * - * Currently, we only provide masks to be used for shifting for some - * registers, rather than repeating the same values 16 times. - */ - -/* Mode register */ - -#define GPIO_MODER_INPUT 0x0 -#define GPIO_MODER_OUTPUT 0x1 -#define GPIO_MODER_AF 0x2 -#define GPIO_MODER_ANALOG 0x3 - -/* Output type register */ - -#define GPIO_OTYPER_PP 0x0 -#define GPIO_OTYPER_OD 0x1 - -/* Output speed register */ - -#define GPIO_OSPEEDR_LOW 0x0 -#define GPIO_OSPEEDR_MED 0x1 -#define GPIO_OSPEEDR_FAST 0x2 -#define GPIO_OSPEEDR_HIGH 0x3 - -/* Pull-up/pull-down register */ - -#define GPIO_PUPDR_NOPUPD 0x0 -#define GPIO_PUPDR_PU 0x1 -#define GPIO_PUPDR_PD 0x2 - -/* Alternate function register low */ - -#define GPIO_AFRL_AF0 (0xFU << 0) -#define GPIO_AFRL_AF1 (0xFU << 4) -#define GPIO_AFRL_AF2 (0xFU << 8) -#define GPIO_AFRL_AF3 (0xFU << 12) -#define GPIO_AFRL_AF4 (0xFU << 16) -#define GPIO_AFRL_AF5 (0xFU << 20) -#define GPIO_AFRL_AF6 (0xFU << 24) -#define GPIO_AFRL_AF7 (0xFU << 28) - -/* Alternate function register high */ - -#define GPIO_AFRH_AF8 (0xFU << 0) -#define GPIO_AFRH_AF9 (0xFU << 4) -#define GPIO_AFRH_AF10 (0xFU << 8) -#define GPIO_AFRH_AF11 (0xFU << 12) -#define GPIO_AFRH_AF12 (0xFU << 16) -#define GPIO_AFRH_AF13 (0xFU << 20) -#define GPIO_AFRH_AF14 (0xFU << 24) -#define GPIO_AFRH_AF15 (0xFU << 28) - -/* - * GPIO routines - */ - -/** - * @brief GPIO pin modes - */ -typedef enum gpio_pin_mode { - GPIO_MODE_INPUT = GPIO_MODER_INPUT, /**< Input mode */ - GPIO_MODE_OUTPUT = GPIO_MODER_OUTPUT, /**< Output mode */ - GPIO_MODE_AF = GPIO_MODER_AF, /**< Alternate function mode */ - GPIO_MODE_ANALOG = GPIO_MODER_ANALOG, /**< Analog mode */ -} gpio_pin_mode; - -/** - * @brief Additional flags to be used when setting a pin's mode. - * - * Beyond the basic modes (input, general purpose output, alternate - * function, and analog), there are three parameters that can affect a - * pin's mode: - * - * 1. Output type: push/pull or open-drain. This only has an effect - * for output modes. Choices are: GPIO_MODEF_TYPE_PP (the default) - * and GPIO_MODEF_TYPE_OD. - * - * 2. Output speed: specifies the frequency at which a pin changes - * state. This only has an effect for output modes. Choices are: - * GPIO_MODEF_SPEED_LOW (default), GPIO_MODEF_SPEED_MED, - * GPIO_MODEF_SPEED_FAST, and GPIO_MODEF_SPEED_HIGH. - * - * 3. Push/pull setting: All GPIO pins have weak pull-up and pull-down - * resistors that can be enabled when the pin's mode is - * set. Choices are: GPIO_MODEF_PUPD_NONE (default), - * GPIO_MODEF_PUPD_PU, and GPIO_MODEF_PUPD_PD. - */ -typedef enum gpio_mode_flags { - /* Output type in bit 0 */ - GPIO_MODEF_TYPE_PP = GPIO_OTYPER_PP, /**< Output push/pull (default). - Applies only when the mode - specifies output. */ - GPIO_MODEF_TYPE_OD = GPIO_OTYPER_OD, /**< Output open drain. - Applies only when the mode - specifies output. */ - - /* Speed in bits 2:1 */ - GPIO_MODEF_SPEED_LOW = GPIO_OSPEEDR_LOW << 1, /**< Low speed (default): - 2 MHz. */ - GPIO_MODEF_SPEED_MED = GPIO_OSPEEDR_MED << 1, /**< Medium speed: 25 MHz. */ - GPIO_MODEF_SPEED_FAST = GPIO_OSPEEDR_FAST << 1, /**< Fast speed: 50 MHz. */ - GPIO_MODEF_SPEED_HIGH = GPIO_OSPEEDR_HIGH << 1, /**< High speed: FIXME one of those does not exist on the F3 - 100 MHz on 30 pF, - 80 MHz on 15 pF. */ - - /* Pull-up/pull-down in bits 4:3 */ - GPIO_MODEF_PUPD_NONE = GPIO_PUPDR_NOPUPD << 3, /**< No pull-up/pull-down - (default). */ - GPIO_MODEF_PUPD_PU = GPIO_PUPDR_PU << 3, /**< Pull-up */ - GPIO_MODEF_PUPD_PD = GPIO_PUPDR_PD << 3, /**< Pull-down */ -} gpio_mode_flags; - -void gpio_set_modef(struct gpio_dev *dev, - uint8 bit, - gpio_pin_mode mode, - unsigned flags); - -/** - * @brief Set the mode of a GPIO pin. - * - * Calling this function is equivalent to calling gpio_set_modef(dev, - * pin, mode, GPIO_MODE_SPEED_HIGH). Note that this overrides the - * default speed. - * - * @param dev GPIO device. - * @param bit Bit on the device whose mode to set, 0--15. - * @param mode Mode to set the pin to. - */ -static inline void gpio_set_mode(struct gpio_dev *dev, - uint8 bit, - gpio_pin_mode mode) { - gpio_set_modef(dev, bit, mode, GPIO_MODEF_SPEED_HIGH); -} - -/** - * @brief GPIO alternate functions. - * Use these to select an alternate function for a pin. - * @see gpio_set_af() - */ -typedef enum gpio_af { - GPIO_AF_0 = 0x0, /**< alternate function 0. */ - GPIO_AF_1 = 0x1, /**< alternate function 1. */ - GPIO_AF_2 = 0x2, /**< alternate function 2. */ - GPIO_AF_3 = 0x3, /**< alternate function 3. */ - GPIO_AF_4 = 0x4, /**< alternate function 4. */ - GPIO_AF_5 = 0x5, /**< alternate function 5. */ - GPIO_AF_6 = 0x6, /**< alternate function 6. */ - GPIO_AF_7 = 0x7, /**< alternate function 7. */ - GPIO_AF_8 = 0x8, /**< alternate function 8. */ - GPIO_AF_9 = 0x9, /**< alternate function 9. */ - GPIO_AF_10 = 0xA, /**< alternate function 10. */ - GPIO_AF_11 = 0xB, /**< alternate function 11. */ - GPIO_AF_12 = 0xC, /**< alternate function 12. */ - GPIO_AF_13 = 0xD, /**< alternate function 13. */ - GPIO_AF_14 = 0xE, /**< alternate function 14. */ - GPIO_AF_15 = 0xF, /**< alternate function 14. */ -} gpio_af; - -void gpio_set_af(struct gpio_dev *dev, uint8 bit, gpio_af af); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/i2c.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/i2c.h deleted file mode 100644 index ef1b0ff..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/i2c.h +++ /dev/null @@ -1,315 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/i2c.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 I2C - */ - -#ifndef _LIBMAPLE_STM32F3_I2C_H_ -#define _LIBMAPLE_STM32F3_I2C_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include -#include - -/* - * Register maps - */ - -/** I2C register map type */ -typedef struct i2c_reg_map { - __IO uint32 CR1; /**< Control register 1 */ - __IO uint32 CR2; /**< Control register 2 */ - __IO uint32 OAR1; /**< Own address register 1 */ - __IO uint32 OAR2; /**< Own address register 2 */ - __IO uint32 TIMINGR; /**< Timing register */ - __IO uint32 TIMEOUTR; /**< Timeout register */ - __IO uint32 ISR; /**< Interrupt and status register */ - __IO uint32 ICR; /**< Interrupt clear register */ - __IO uint32 PECR; /**< PEC register */ - __IO uint32 RXDR; /**< Receive data register */ - __IO uint32 TXDR; /**< Transmit data register */ -} i2c_reg_map; - -extern i2c_dev* const I2C1; -extern i2c_dev* const I2C2; - -/* - * Register map base pointers - */ - -/** STM32F3 I2C1 register map base pointer */ -#define I2C1_BASE ((struct i2c_reg_map*)0x40005400) -/** STM32F3 I2C2 register map base pointer */ -#define I2C2_BASE ((struct i2c_reg_map*)0x40005800) - -/* - * Register bit definitions - */ - -/* Control register 1 */ -#define I2C_CR1_PECEN_BIT 23 -#define I2C_CR1_ALERTEN_BIT 22 -#define I2C_CR1_SMBDEN_BIT 21 -#define I2C_CR1_SMBHEN_BIT 20 -#define I2C_CR1_GCEN_BIT 19 -#define I2C_CR1_WUPEN_BIT 18 -#define I2C_CR1_NOSTRETCH_BIT 17 -#define I2C_CR1_SBC_BIT 16 -#define I2C_CR1_RXDMAEN_BIT 15 -#define I2C_CR1_TXDMAEN_BIT 14 -#define I2C_CR1_ANFOFF_BIT 12 -#define I2C_CR1_DNF_SHIFT 8 -#define I2C_CR1_ERRIE_BIT 7 -#define I2C_CR1_TCIE_BIT 6 -#define I2C_CR1_STOPIE_BIT 5 -#define I2C_CR1_NACKIE_BIT 4 -#define I2C_CR1_ADDRIE_BIT 3 -#define I2C_CR1_RXIE_BIT 2 -#define I2C_CR1_TXIE_BIT 1 -#define I2C_CR1_PE_BIT 0 - -#define I2C_CR1_PECEN (1U << I2C_CR1_PECEN_BIT) -#define I2C_CR1_ALERTEN (1U << I2C_CR1_ALERTEN_BIT) -#define I2C_CR1_SMBDEN (1U << I2C_CR1_SMBDEN_BIT) -#define I2C_CR1_SMBHEN (1U << I2C_CR1_SMBHEN_BIT) -#define I2C_CR1_GCEN (1U << I2C_CR1_GCEN_BIT) -#define I2C_CR1_WUPEN (1U << I2C_CR1_WUPEN_BIT) -#define I2C_CR1_NOSTRETCH (1U << I2C_CR1_NOSTRETCH_BIT) -#define I2C_CR1_SBC (1U << I2C_CR1_SBC_BIT) -#define I2C_CR1_RXDMAEN (1U << I2C_CR1_RXDMAEN_BIT) -#define I2C_CR1_TXDMAEN (1U << I2C_CR1_TXDMAEN_BIT) -#define I2C_CR1_ANFOFF (1U << I2C_CR1_ANFOFF_BIT) -#define I2C_CR1_DNF (0xF << I2C_CR1_DNF_SHIFT) -#define I2C_CR1_ERRIE (1U << I2C_CR1_ERRIE_BIT) -#define I2C_CR1_TCIE (1U << I2C_CR1_TCIE_BIT) -#define I2C_CR1_STOPIE (1U << I2C_CR1_STOPIE_BIT) -#define I2C_CR1_NACKIE (1U << I2C_CR1_NACKIE_BIT) -#define I2C_CR1_ADDRIE (1U << I2C_CR1_ADDRIE_BIT) -#define I2C_CR1_RXIE (1U << I2C_CR1_RXIE_BIT) -#define I2C_CR1_TXIE (1U << I2C_CR1_TXIE_BIT) -#define I2C_CR1_PE (1U << I2C_CR1_PE_BIT) - -/* Control register 2 */ -#define I2C_CR2_PECBYTE_BIT 26 -#define I2C_CR2_AUTOEND_BIT 25 -#define I2C_CR2_RELOAD_BIT 24 -#define I2C_CR2_NBYTES_SHIFT 16 -#define I2C_CR2_NACK_BIT 15 -#define I2C_CR2_STOP_BIT 14 -#define I2C_CR2_START_BIT 13 -#define I2C_CR2_HEAD10R_BIT 12 -#define I2C_CR2_ADD10_BIT 11 -#define I2C_CR2_RD_WRN_BIT 10 -#define I2C_CR2_SADD_7_BIT_SHIFT 1 -#define I2C_CR2_SADD_10_BIT_SHIFT 0 - -#define I2C_CR2_PECBYTE (1U << I2C_CR2_PECBYTE_BIT) -#define I2C_CR2_AUTOEND (1U << I2C_CR2_AUTOEND_BIT) -#define I2C_CR2_RELOAD (1U << I2C_CR2_RELOAD_BIT) -#define I2C_CR2_NBYTES (0xFF << I2C_CR2_NBYTES_SHIFT) -#define I2C_CR2_NACK (1U << I2C_CR2_NACK_BIT) -#define I2C_CR2_STOP (1U << I2C_CR2_STOP_BIT) -#define I2C_CR2_START (1U << I2C_CR2_START_BIT) -#define I2C_CR2_HEAD10R (1U << I2C_CR2_HEAD10R_BIT) -#define I2C_CR2_ADD10 (1U << I2C_CR2_ADD10_BIT) -#define I2C_CR2_RD_WRN (1U << I2C_CR2_RD_WRN_BIT) -#define I2C_CR2_SADD_7_BIT (0x7F << I2C_CR2_SADD_7_BIT_SHIFT) -#define I2C_CR2_SADD_10_BIT (0x3FF << I2C_CR2_SADD_10_BIT_SHIFT) - -/* Own address register 1 */ -#define I2C_OAR1_OA1EN_BIT 15 -#define I2C_OAR1_OA1MODE_BIT 10 -#define I2C_OAR1_OA1_7_BIT_SHIFT 1 -#define I2C_OAR1_OA1_10_BIT_SHIFT 0 - -#define I2C_OAR1_OA1EN (1U << I2C_OAR1_OA1EN_BIT) -#define I2C_OAR1_OA1MODE (1U << I2C_OAR1_OA1MODE_BIT) -#define I2C_OAR1_OA1_7_BIT (0x7F << I2C_OAR1_OA1_7_BIT_SHIFT) -#define I2C_OAR1_OA1_10_BIT (0x3FF << I2C_OAR1_OA1_10_BIT_SHIFT) - -/* Own address register 2 */ -#define I2C_OAR2_OA2EN_BIT 15 -#define I2C_OAR2_OA2MSK_SHIFT 8 -#define I2C_OAR2_OA2_7_BIT_SHIFT 1 - -#define I2C_OAR2_OA2EN (1U << I2C_OAR2_OA2EN_BIT) -#define I2C_OAR2_OA2MSK (0x7 << I2C_OAR2_OA2MSK_SHIFT) -#define I2C_OAR2_OA2_7_BIT (0x7F << I2C_OAR2_OA2_7_BIT_SHIFT) - -/* Timing register */ -#define I2C_TIMINGR_PRESC_SHIFT 28 -#define I2C_TIMINGR_SCLDEL_SHIFT 20 -#define I2C_TIMINGR_SDADEL_SHIFT 16 -#define I2C_TIMINGR_SCLH_SHIFT 8 -#define I2C_TIMINGR_SCLL_SHIFT 0 - -#define I2C_TIMINGR_PRESC (0xF << I2C_TIMINGR_PRESC_SHIFT) -#define I2C_TIMINGR_SCLDEL (0xF << I2C_TIMINGR_SCLDEL_SHIFT) -#define I2C_TIMINGR_SCADEL (0xF << I2C_TIMINGR_SCADEL_SHIFT) -#define I2C_TIMINGR_SCLH (0xFF << I2C_TIMINGR_SCLH_SHIFT) -#define I2C_TIMINGR_SCLL (0xFF << I2C_TIMINGR_SCLL_SHIFT) - -/* Timeout register */ -#define I2C_TIMEOUTR_TEXTEN_BIT 31 -#define I2C_TIMEOUTR_TIMEOUTB_SHIFT 16 -#define I2C_TIMEOUTR_TIMOUTEN_BIT 15 -#define I2C_TIMEOUTR_TIDLE_BIT 12 -#define I2C_TIMEOUTR_TIMEOUTA_SHIFT 0 - -#define I2C_TIMEOUTR_TEXTEN (1U << I2C_TIMEOUTR_TEXTEN_BIT) -#define I2C_TIMEOUTR_TIMEOUTB (0xFFF << I2C_TIMEOUTR_TIMEOUTB_SHIFT) -#define I2C_TIMEOUTR_TIMOUTEN (1U << I2C_TIMEOUTR_TIMOUTEN_BIT) -#define I2C_TIMEOUTR_TIDLE (1U << I2C_TIMEOUTR_TIDLE_BIT) -#define I2C_TIMEOUTR_TIMEOUTA (0xFFF << I2C_TIMEOUTR_TIMEOUTA_SHIFT) - -/* Interrupt and status register */ -#define I2C_ISR_ADDCODE_SHIFT 17 -#define I2C_ISR_DIR_BIT 16 -#define I2C_ISR_BUSY_BIT 15 -#define I2C_ISR_ALERT_BIT 13 -#define I2C_ISR_TIMEOUT_BIT 12 -#define I2C_ISR_PECERR_BIT 11 -#define I2C_ISR_OVR_BIT 10 -#define I2C_ISR_ARLO_BIT 9 -#define I2C_ISR_BERR_BIT 8 -#define I2C_ISR_TCR_BIT 7 -#define I2C_ISR_TC_BIT 6 -#define I2C_ISR_STOPF_BIT 5 -#define I2C_ISR_NACKF_BIT 4 -#define I2C_ISR_ADDR_BIT 3 -#define I2C_ISR_RXNE_BIT 2 -#define I2C_ISR_TXIS_BIT 1 -#define I2C_ISR_TXE_BIT 0 - -#define I2C_ISR_ADDCODE (0x7F << I2C_ISR_ADDCODE_SHIFT) -#define I2C_ISR_ALERTCF (1U << I2C_ISR_ALERTCF_BIT) -#define I2C_ISR_DIR (1U << I2C_ISR_DIR_BIT) -#define I2C_ISR_BUSY (1U << I2C_ISR_BUSY_BIT) -#define I2C_ISR_ALERT (1U << I2C_ISR_ALERT_BIT) -#define I2C_ISR_TIMEOUT (1U << I2C_ISR_TIMEOUT_BIT) -#define I2C_ISR_PECERR (1U << I2C_ISR_PECERR_BIT) -#define I2C_ISR_OVR (1U << I2C_ISR_OVR_BIT) -#define I2C_ISR_ARLO (1U << I2C_ISR_ARLO_BIT) -#define I2C_ISR_BERR (1U << I2C_ISR_BERR_BIT) -#define I2C_ISR_TCR (1U << I2C_ISR_TCR_BIT) -#define I2C_ISR_TC (1U << I2C_ISR_TC_BIT) -#define I2C_ISR_STOPF (1U << I2C_ISR_STOPF_BIT) -#define I2C_ISR_NACKF (1U << I2C_ISR_NACKF_BIT) -#define I2C_ISR_ADDR (1U << I2C_ISR_ADDR_BIT) -#define I2C_ISR_RXNE (1U << I2C_ISR_RXNE_BIT) -#define I2C_ISR_TXIS (1U << I2C_ISR_TXIS_BIT) -#define I2C_ISR_TXE (1U << I2C_ISR_TXE_BIT) - -/* Interrupt clear register */ -#define I2C_ICR_ALERTCF_BIT 13 -#define I2C_ICR_TIMOUTCF_BIT 12 -#define I2C_ICR_PECCF_BIT 11 -#define I2C_ICR_OVRCF_BIT 10 -#define I2C_ICR_ARLOCF_BIT 9 -#define I2C_ICR_BERRCF_BIT 8 -#define I2C_ICR_STOPCF_BIT 5 -#define I2C_ICR_NACKCF_BIT 4 -#define I2C_ICR_ADDRCF_BIT 3 - -#define I2C_ICR_ALERTCF (1U << I2C_ICR_ALERTCF_BIT) -#define I2C_ICR_TIMOUTCF (1U << I2C_ICR_TIMOUTCF_BIT) -#define I2C_ICR_PECCF (1U << I2C_ICR_PECERRCF_BIT) -#define I2C_ICR_OVRCF (1U << I2C_ICR_OVRCF_BIT) -#define I2C_ICR_ARLOCF (1U << I2C_ICR_ARLOCF_BIT) -#define I2C_ICR_BERRCF (1U << I2C_ICR_BERRCF_BIT) -#define I2C_ICR_STOPCF (1U << I2C_ICR_STOPCF_BIT) -#define I2C_ICR_NACKCF (1U << I2C_ICR_NACKCF_BIT) -#define I2C_ICR_ADDRCF (1U << I2C_ICR_ADDRCF_BIT) - -/* PEC register */ -#define I2C_PEC_PEC 0xFF - -/* Receive data register */ -#define I2C_RXDR_RXDATA 0xFF - -/* Transmit data register */ -#define I2C_TXDR_TXDATA 0xFF - -/* - * Timing configurations - */ - -/* Timing configuration for I2C clock running at 8MHz */ - -/* NOTE: - * I2C is clocked by HSI (8MHz) by default - * if clock source is changed with RCC_CFGR_I2C1SW/I2C2SW, - * these values have to be adapted - */ -typedef enum i2c_timing { - I2C_TIMING_10_kHz = (0x01 << I2C_TIMINGR_PRESC_SHIFT) - + (0x04 << I2C_TIMINGR_SCLDEL_SHIFT) - + (0x02 << I2C_TIMINGR_SDADEL_SHIFT) - + (0xC3 << I2C_TIMINGR_SCLH_SHIFT) - + (0xC7 << I2C_TIMINGR_SCLL_SHIFT), - - I2C_TIMING_100_kHz = (0x01 << I2C_TIMINGR_PRESC_SHIFT) - + (0x04 << I2C_TIMINGR_SCLDEL_SHIFT) - + (0x02 << I2C_TIMINGR_SDADEL_SHIFT) - + (0x0F << I2C_TIMINGR_SCLH_SHIFT) - + (0x13 << I2C_TIMINGR_SCLL_SHIFT), - - I2C_TIMING_400_kHz = (0x00 << I2C_TIMINGR_PRESC_SHIFT) - + (0x03 << I2C_TIMINGR_SCLDEL_SHIFT) - + (0x01 << I2C_TIMINGR_SDADEL_SHIFT) - + (0x03 << I2C_TIMINGR_SCLH_SHIFT) - + (0x09 << I2C_TIMINGR_SCLL_SHIFT), - - I2C_TIMING_500_kHz = (0x00 << I2C_TIMINGR_PRESC_SHIFT) - + (0x01 << I2C_TIMINGR_SCLDEL_SHIFT) - + (0x01 << I2C_TIMINGR_SDADEL_SHIFT) - + (0x03 << I2C_TIMINGR_SCLH_SHIFT) - + (0x06 << I2C_TIMINGR_SCLL_SHIFT), -} i2c_timing; - -/* - * For internal use - */ - -static inline uint32 _i2c_bus_clk(i2c_dev *dev) { /* FIXME remove, is a remainder of F1 code */ - /* Both I2C peripherals are on APB1 */ - return STM32_PCLK1 / (1000 * 1000); -} - -extern uint8 i2c_read(i2c_dev *dev); - -#ifdef __cplusplus -} -#endif - -#endif /* _LIBMAPLE_STM32F3_I2C_H_ */ diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/nvic.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/nvic.h deleted file mode 100644 index 7643c32..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/nvic.h +++ /dev/null @@ -1,153 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/nvic.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 Nested Vectored Interrupt Controller (NVIC) support. - */ - -#ifndef _LIBMAPLE_STM32F3_NVIC_H_ -#define _LIBMAPLE_STM32F3_NVIC_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include -#include - -/** - * @brief STM32F1 interrupt vector table interrupt numbers. - * @see - */ -typedef enum nvic_irq_num { - NVIC_NMI = -14, /**< Non-maskable interrupt */ - NVIC_HARDFAULT = -13, /**< Hard fault (all class of fault) */ - NVIC_MEM_MANAGE = -12, /**< Memory management */ - NVIC_BUS_FAULT = -11, /**< Bus fault: prefetch fault, memory - access fault. */ - NVIC_USAGE_FAULT = -10, /**< Usage fault: Undefined instruction or - illegal state. */ - NVIC_SVC = -5, /**< System service call via SWI insruction */ - NVIC_DEBUG_MON = -4, /**< Debug monitor */ - NVIC_PEND_SVC = -2, /**< Pendable request for system service */ - NVIC_SYSTICK = -1, /**< System tick timer */ - - NVIC_WWDG = 0, /**< Window watchdog interrupt */ - NVIC_PVD = 1, /**< PVD through EXTI line detection */ - NVIC_TAMP_STAMP = 2, /**< Tamper */ - NVIC_RTC_WKUP = 3, /**< Real-time clock */ - NVIC_FLASH = 4, /**< Flash */ - NVIC_RCC = 5, /**< Reset and clock control */ - NVIC_EXTI0 = 6, /**< EXTI line 0 */ - NVIC_EXTI1 = 7, /**< EXTI line 1 */ - NVIC_EXTI2 = 8, /**< EXTI line 2 */ //FIXME capacitive touch - NVIC_EXTI3 = 9, /**< EXTI line 3 */ - NVIC_EXTI4 = 10, /**< EXTI line 4 */ - NVIC_DMA_CH1 = 11, /**< DMA1 channel 1 */ - NVIC_DMA_CH2 = 12, /**< DMA1 channel 2 */ - NVIC_DMA_CH3 = 13, /**< DMA1 channel 3 */ - NVIC_DMA_CH4 = 14, /**< DMA1 channel 4 */ - NVIC_DMA_CH5 = 15, /**< DMA1 channel 5 */ - NVIC_DMA_CH6 = 16, /**< DMA1 channel 6 */ - NVIC_DMA_CH7 = 17, /**< DMA1 channel 7 */ - NVIC_ADC1_2 = 18, /**< ADC1 and ADC2 */ - NVIC_USB_HP_CAN_TX = 19, /**< USB high priority or CAN TX */ - NVIC_USB_LP_CAN_RX0 = 20, /**< USB low priority or CAN RX0 */ - NVIC_CAN_RX1 = 21, /**< CAN RX1 */ - NVIC_CAN_SCE = 22, /**< CAN SCE */ - NVIC_EXTI_9_5 = 23, /**< EXTI line [9:5] */ - //NVIC_TIMER1_BRK_TIMER15 = 24, // FIXME hack - NVIC_TIMER1_BRK_TIMER9 = 24, /**< Timer 1 break, Timer 9. */ // FIXME rm - //NVIC_TIMER1_UP_TIMER16 = 25, // FIXME hack - NVIC_TIMER1_UP_TIMER10 = 25, /**< Timer 1 update, Timer 10. */ //FIXME rm - //NVIC_TIMER1_TRG_COM_TIMER17 = 26, // FIXME hack - NVIC_TIMER1_TRG_COM_TIMER11 = 26, /**< - * Timer 1 trigger and commutation, - * Timer 11. */ // FIXME rm - NVIC_TIMER1_CC = 27, /**< Timer 1 capture/compare */ - NVIC_TIMER2 = 28, /**< Timer 2 */ - NVIC_TIMER3 = 29, /**< Timer 3 */ - NVIC_TIMER4 = 30, /**< Timer 4 */ - NVIC_I2C1_EV = 31, /**< I2C1 event */ - NVIC_I2C1_ER = 32, /**< I2C1 error */ - NVIC_I2C2_EV = 33, /**< I2C2 event */ - NVIC_I2C2_ER = 34, /**< I2C2 error */ - NVIC_SPI1 = 35, /**< SPI1 */ - NVIC_SPI2 = 36, /**< SPI2 */ - NVIC_USART1 = 37, /**< USART1 */ - NVIC_USART2 = 38, /**< USART2 */ - NVIC_USART3 = 39, /**< USART3 */ - NVIC_EXTI_15_10 = 40, /**< EXTI line [15:10] */ - NVIC_RTC_ALARM = 41, /**< RTC alarm through EXTI line */ - NVIC_USB_WKUP = 42, /**< USB wakeup from suspend through - EXTI line */ - NVIC_TIMER8_BRK_TIMER12 = 43, /**< Timer 8 break, timer 12 */ //TODO rm TIMER12 - NVIC_TIMER8_UP_TIMER13 = 44, /**< Timer 8 update, timer 13 */ // TODO rm TIMER13 - NVIC_TIMER8_TRG_COM_TIMER14 = 45, /**< - * Timer 8 trigger and commutation, - * Timer 14. */ //TODO rm TIMER14 - NVIC_TIMER8_CC = 46, /**< Timer 8 capture/compare */ - NVIC_ADC3 = 47, /**< ADC3 */ - - NVIC_SPI3 = 51, /**< SPI3 */ - NVIC_UART4 = 52, /**< UART4 */ - NVIC_UART5 = 53, /**< UART5 */ - //NVIC_TIMER6_DAC = 54, // TODO hack - NVIC_TIMER6 = 54, /**< Timer 6 */ //TODO add DAC - NVIC_TIMER7 = 55, /**< Timer 7 */ - NVIC_DMA2_CH1 = 56, /**< DMA2 channel 1 */ - NVIC_DMA2_CH2 = 57, /**< DMA2 channel 2 */ - NVIC_DMA2_CH3 = 58, /**< DMA2 channel 3 */ - NVIC_DMA2_CH4 = 59, /**< DMA2 channel 4 */ - NVIC_DMA2_CH5 = 60, /**< DMA2 channel 5 */ - - NVIC_ADC4 = 61, /**< DMA2 channels 4 and 5 */ - - NVIC_COMP123 = 64, /**< DMA2 channels 4 and 5 */ - NVIC_COMP456 = 65, /**< DMA2 channels 4 and 5 */ - NVIC_COMP7 = 66, /**< DMA2 channels 4 and 5 */ - - NVIC_USB_HP = 74, /**< DMA2 channels 4 and 5 */ - NVIC_USB_LP = 75, /**< DMA2 channels 4 and 5 */ - NVIC_USB_WKUP2 = 76, /**< DMA2 channels 4 and 5 */ - - NVIC_FPU = 81, /**< DMA2 channels 4 and 5 */ -} nvic_irq_num; - -static inline void nvic_irq_disable_all(void) { - NVIC_BASE->ICER[0] = 0xFFFFFFFF; - NVIC_BASE->ICER[1] = 0xFFFFFFFF; - NVIC_BASE->ICER[2] = 0xFFFFFFFF; -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/opamp.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/opamp.h deleted file mode 100644 index a5c627b..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/opamp.h +++ /dev/null @@ -1,123 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/ompamp.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 Operational Amplifier support. - */ - -#ifndef _LIBMAPLE_STM32F3_OPAMP_H_ -#define _LIBMAPLE_STM32F3_OPAMP_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/* - * Register map - */ - -/* - * OpAmp individual register map type. - */ -typedef struct opamp_reg_map { - __IO uint32 CSR; /**< */ -} opamp_reg_map; - -/** OpAmp device type. */ -typedef struct opamp_dev { - opamp_reg_map *regs; /**< Register map */ -} opamp_dev; - -/* - * Devices - */ - -extern const struct opamp_dev *OPAMP1; /* OpAmp amplifier 1 */ -extern const struct opamp_dev *OPAMP2; /* OpAmp amplifier 2 */ -extern const struct opamp_dev *OPAMP3; /* OpAmp amplifier 3 */ -extern const struct opamp_dev *OPAMP4; /* OpAmp amplifier 4 */ - -/* - * Register map base pointers - */ - -#define OPAMP1_BASE ((struct opamp_reg_map*)0x40010038) -#define OPAMP2_BASE ((struct opamp_reg_map*)0x4001003C) -#define OPAMP3_BASE ((struct opamp_reg_map*)0x40010040) -#define OPAMP4_BASE ((struct opamp_reg_map*)0x40010044) - -/* - * Register bit definitions - */ - -/* Control and status register */ -#define OPAMP_CSR_LOCK_BIT 31 -#define OPAMP_CSR_OUTCAL_BIT 30 -#define OPAMP_CSR_TSTREF_BIT 29 -#define OPAMP_CSR_TRIMOFFSETN_SHIFT 24 -#define OPAMP_CSR_TRIMOFFSETP_SHIFT 19 -#define OPAMP_CSR_USER_TRIM_BIT 18 -#define OPAMP_CSR_PGA_GAIN_SHIFT 14 -#define OPAMP_CSR_CAL_SEL_SHIFT 12 -#define OPAMP_CSR_CAL_ON_BIT 11 -#define OPAMP_CSR_VPS_SEL_SHIFT 9 -#define OPAMP_CSR_VMS_SEL_BIT 8 -#define OPAMP_CSR_TCM_EN_BIT 7 -#define OPAMP_CSR_VM_SEL_SHIFT 5 -#define OPAMP_CSR_VP_SEL_SHIFT 2 -#define OPAMP_CSR_FORCE_VP_BIT 1 -#define OPAMP_CSR_EN_BIT 0 - -#define OPAMP_CSR_LOCK (1U << OPAMP_CSR_LOCK_BIT) -#define OPAMP_CSR_OUTCAL (1U << OPAMP_CSR_OUTCAL_BIT) -#define OPAMP_CSR_TSTREF (1U << OPAMP_CSR_TSTREF_BIT) -#define COMP_CSR_TRIMOFFSETN (0x1F << COMP_CSR_TRIMOFFSETN_SHIFT) -#define COMP_CSR_TRIMOFFSETP (0x1F << COMP_CSR_TRIMOFFSETP_SHIFT) -#define OPAMP_CSR_USER_TRIM (1U << OPAMP_CSR_USER_TRIM_BIT) -#define COMP_CSR_PGA_GAIN (0xF << COMP_CSR_PGA_GAIN_SHIFT) -#define COMP_CSR_CAL_SEL (0x3 << COMP_CSR_CAL_SEL_SHIFT) -#define OPAMP_CSR_CAL_ON (1U << OPAMP_CSR_CAL_ON_BIT) -#define COMP_CSR_VPS_SEL (0x3 << COMP_CSR_VPS_SEL_SHIFT) -#define OPAMP_CSR_VMS_SEL (1U << OPAMP_CSR_VMS_SEL_BIT) -#define OPAMP_CSR_TCM_EN (1U << OPAMP_CSR_TCM_EN_BIT) -#define COMP_CSR_VM_SEL (0x3 << COMP_CSR_VM_SEL_SHIFT) -#define COMP_CSR_VP_SEL (0x3 << COMP_CSR_VP_SEL_SHIFT) -#define OPAMP_CSR_FORCE_VP (1U << OPAMP_CSR_FORCE_VP_BIT) -#define OPAMP_CSR_EN (1U << OPAMP_CSR_EN_BIT) - -/* TODO - * actually implement me ;-) - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/pwr.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/pwr.h deleted file mode 100644 index d3564e8..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/pwr.h +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f1/include/series/pwr.h - * @author Marti Bolivar - * @brief STM32F3 Power control (PWR) support. - */ - -#ifndef _LIBMAPLE_STM32F3_PWR_H_ -#define _LIBMAPLE_STM32F3_PWR_H_ - -/* - * Register bit definitions - */ - -/* Control register */ - -/* PVD level selection */ -#define PWR_CR_PLS_2_2V (0x0 << 5) -#define PWR_CR_PLS_2_3V (0x1 << 5) -#define PWR_CR_PLS_2_4V (0x2 << 5) -#define PWR_CR_PLS_2_5V (0x3 << 5) -#define PWR_CR_PLS_2_6V (0x4 << 5) -#define PWR_CR_PLS_2_7V (0x5 << 5) -#define PWR_CR_PLS_2_8V (0x6 << 5) -#define PWR_CR_PLS_2_9V (0x7 << 5) - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/rcc.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/rcc.h deleted file mode 100644 index b8f4b34..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/rcc.h +++ /dev/null @@ -1,632 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/rcc.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 reset and clock control (RCC) support. - */ - -#ifndef _LIBMAPLE_STM32F3_RCC_H_ -#define _LIBMAPLE_STM32F3_RCC_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include - -/* - * Register map - */ - -/** STM32F3 RCC register map type */ -typedef struct rcc_reg_map { - __IO uint32 CR; /**< Clock control register */ - __IO uint32 CFGR; /**< Clock configuration register */ - __IO uint32 CIR; /**< Clock interrupt register */ - __IO uint32 APB2RSTR; /**< APB2 peripheral reset register */ - __IO uint32 APB1RSTR; /**< APB1 peripheral reset register */ - __IO uint32 AHBENR; /**< AHB peripheral clock enable register */ - __IO uint32 APB2ENR; /**< APB2 peripheral clock enable register */ - __IO uint32 APB1ENR; /**< APB1 peripheral clock enable register */ - __IO uint32 BDCR; /**< Backup domain control register */ - __IO uint32 CSR; /**< Control/status register */ - __IO uint32 AHBRSTR; /**< AHB peripheral reset register */ - __IO uint32 CFGR2; /**< Control/status register 2 */ - __IO uint32 CFGR3; /**< Control/status register 3 */ -} rcc_reg_map; - -#define RCC_BASE ((struct rcc_reg_map*)0x40021000) - -/* - * Register bit definitions - */ - -/* Clock control register */ - -#define RCC_CR_PLLRDY_BIT 25 -#define RCC_CR_PLLON_BIT 24 -#define RCC_CR_CSSON_BIT 19 -#define RCC_CR_HSEBYP_BIT 18 -#define RCC_CR_HSERDY_BIT 17 -#define RCC_CR_HSEON_BIT 16 -#define RCC_CR_HSIRDY_BIT 1 -#define RCC_CR_HSION_BIT 0 - -#define RCC_CR_PLLRDY (1U << RCC_CR_PLLRDY_BIT) -#define RCC_CR_PLLON (1U << RCC_CR_PLLON_BIT) -#define RCC_CR_CSSON (1U << RCC_CR_CSSON_BIT) -#define RCC_CR_HSEBYP (1U << RCC_CR_HSEBYP_BIT) -#define RCC_CR_HSERDY (1U << RCC_CR_HSERDY_BIT) -#define RCC_CR_HSEON (1U << RCC_CR_HSEON_BIT) -#define RCC_CR_HSICAL (0xFF << 8) -#define RCC_CR_HSITRIM (0x1F << 3) -#define RCC_CR_HSIRDY (1U << RCC_CR_HSIRDY_BIT) -#define RCC_CR_HSION (1U << RCC_CR_HSION_BIT) - -/* Clock configuration register */ - -#define RCC_CFGR_I2SSRC_BIT 23 -#define RCC_CFGR_USBPRE_BIT 22 -#define RCC_CFGR_PLLMUL_BIT 18 -#define RCC_CFGR_PLLXTPRE_BIT 17 -#define RCC_CFGR_PLLSRC_BIT 16 -#define RCC_CFGR_PPRE2_BIT 11 -#define RCC_CFGR_PPRE1_BIT 8 -#define RCC_CFGR_HPRE_BIT 4 - -#define RCC_CFGR_MCO (0x3 << 24) -#define RCC_CFGR_I2SSRC (1U << RCC_CFGR_I2CSRC_BIT) -#define RCC_CFGR_USBPRE (1U << RCC_CFGR_USBPRE_BIT) -#define RCC_CFGR_PLLMUL (0xF << RCC_CFGR_PLLMUL_BIT) -#define RCC_CFGR_PLLXTPRE (1U << RCC_CFGR_PLLXTPRE_BIT) -#define RCC_CFGR_PLLSRC (1U << RCC_CFGR_PLLSRC_BIT) -#define RCC_CFGR_PPRE2 (0x7 << RCC_CFGR_PPRE2_BIT) -#define RCC_CFGR_PPRE1 (0x7 << RCC_CFGR_PPRE1_BIT) -#define RCC_CFGR_HPRE (0xF << RCC_CFGR_HPRE_BIT) -#define RCC_CFGR_SWS (0x3 << 2) -#define RCC_CFGR_SWS_PLL (0x2 << 2) -#define RCC_CFGR_SWS_HSE (0x1 << 2) -#define RCC_CFGR_SW 0x3 -#define RCC_CFGR_SW_PLL 0x2 -#define RCC_CFGR_SW_HSE 0x1 - -/* Clock interrupt register */ - -#define RCC_CIR_CSSC_BIT 23 -#define RCC_CIR_PLLRDYC_BIT 20 -#define RCC_CIR_HSERDYC_BIT 19 -#define RCC_CIR_HSIRDYC_BIT 18 -#define RCC_CIR_LSERDYC_BIT 17 -#define RCC_CIR_LSIRDYC_BIT 16 -#define RCC_CIR_PLLRDYIE_BIT 12 -#define RCC_CIR_HSERDYIE_BIT 11 -#define RCC_CIR_HSIRDYIE_BIT 10 -#define RCC_CIR_LSERDYIE_BIT 9 -#define RCC_CIR_LSIRDYIE_BIT 8 -#define RCC_CIR_CSSF_BIT 7 -#define RCC_CIR_PLLRDYF_BIT 4 -#define RCC_CIR_HSERDYF_BIT 3 -#define RCC_CIR_HSIRDYF_BIT 2 -#define RCC_CIR_LSERDYF_BIT 1 -#define RCC_CIR_LSIRDYF_BIT 0 - -#define RCC_CIR_CSSC (1U << RCC_CIR_CSSC_BIT) -#define RCC_CIR_PLLRDYC (1U << RCC_CIR_PLLRDYC_BIT) -#define RCC_CIR_HSERDYC (1U << RCC_CIR_HSERDYC_BIT) -#define RCC_CIR_HSIRDYC (1U << RCC_CIR_HSIRDYC_BIT) -#define RCC_CIR_LSERDYC (1U << RCC_CIR_LSERDYC_BIT) -#define RCC_CIR_LSIRDYC (1U << RCC_CIR_LSIRDYC_BIT) -#define RCC_CIR_PLLRDYIE (1U << RCC_CIR_PLLRDYIE_BIT) -#define RCC_CIR_HSERDYIE (1U << RCC_CIR_HSERDYIE_BIT) -#define RCC_CIR_HSIRDYIE (1U << RCC_CIR_HSIRDYIE_BIT) -#define RCC_CIR_LSERDYIE (1U << RCC_CIR_LSERDYIE_BIT) -#define RCC_CIR_LSIRDYIE (1U << RCC_CIR_LSIRDYIE_BIT) -#define RCC_CIR_CSSF (1U << RCC_CIR_CSSF_BIT) -#define RCC_CIR_PLLRDYF (1U << RCC_CIR_PLLRDYF_BIT) -#define RCC_CIR_HSERDYF (1U << RCC_CIR_HSERDYF_BIT) -#define RCC_CIR_HSIRDYF (1U << RCC_CIR_HSIRDYF_BIT) -#define RCC_CIR_LSERDYF (1U << RCC_CIR_LSERDYF_BIT) -#define RCC_CIR_LSIRDYF (1U << RCC_CIR_LSIRDYF_BIT) - -/* APB2 peripheral reset register */ - -#define RCC_APB2RSTR_TIM17RST_BIT 18 -#define RCC_APB2RSTR_TIM16RST_BIT 17 -#define RCC_APB2RSTR_TIM15RST_BIT 16 -#define RCC_APB2RSTR_USART1RST_BIT 14 -#define RCC_APB2RSTR_TIM8RST_BIT 13 -#define RCC_APB2RSTR_SPI1RST_BIT 12 -#define RCC_APB2RSTR_TIM1RST_BIT 11 -#define RCC_APB2RSTR_SYSCFGRST_BIT 0 - -#define RCC_APB2RSTR_TIM17RST (1U << RCC_APB2RSTR_TIM17RST_BIT) -#define RCC_APB2RSTR_TIM16RST (1U << RCC_APB2RSTR_TIM16RST_BIT) -#define RCC_APB2RSTR_TIM15RST (1U << RCC_APB2RSTR_TIM15RST_BIT) -#define RCC_APB2RSTR_USART1RST (1U << RCC_APB2RSTR_USART1RST_BIT) -#define RCC_APB2RSTR_TIM8RST (1U << RCC_APB2RSTR_TIM8RST_BIT) -#define RCC_APB2RSTR_SPI1RST (1U << RCC_APB2RSTR_SPI1RST_BIT) -#define RCC_APB2RSTR_TIM1RST (1U << RCC_APB2RSTR_TIM1RST_BIT) -#define RCC_APB2RSTR_SYSCFGRST (1U << RCC_APB2RSTR_SYSCFGRST_BIT) - -/* APB1 peripheral reset register */ - -#define RCC_APB1RSTR_DACRST_BIT 29 -#define RCC_APB1RSTR_PWRRST_BIT 28 -#define RCC_APB1RSTR_CANRST_BIT 25 -#define RCC_APB1RSTR_USBRST_BIT 23 -#define RCC_APB1RSTR_I2C2RST_BIT 22 -#define RCC_APB1RSTR_I2C1RST_BIT 21 -#define RCC_APB1RSTR_UART5RST_BIT 20 -#define RCC_APB1RSTR_UART4RST_BIT 19 -#define RCC_APB1RSTR_USART3RST_BIT 18 -#define RCC_APB1RSTR_USART2RST_BIT 17 -#define RCC_APB1RSTR_SPI3RST_BIT 15 -#define RCC_APB1RSTR_SPI2RST_BIT 14 -#define RCC_APB1RSTR_WWDRST_BIT 11 -#define RCC_APB1RSTR_TIM7RST_BIT 5 -#define RCC_APB1RSTR_TIM6RST_BIT 4 -#define RCC_APB1RSTR_TIM4RST_BIT 2 -#define RCC_APB1RSTR_TIM3RST_BIT 1 -#define RCC_APB1RSTR_TIM2RST_BIT 0 - -#define RCC_APB1RSTR_DACRST (1U << RCC_APB1RSTR_DACRST_BIT) -#define RCC_APB1RSTR_PWRRST (1U << RCC_APB1RSTR_PWRRST_BIT) -#define RCC_APB1RSTR_CANRST (1U << RCC_APB1RSTR_CANRST_BIT) -#define RCC_APB1RSTR_USBRST (1U << RCC_APB1RSTR_USBRST_BIT) -#define RCC_APB1RSTR_I2C2RST (1U << RCC_APB1RSTR_I2C2RST_BIT) -#define RCC_APB1RSTR_I2C1RST (1U << RCC_APB1RSTR_I2C1RST_BIT) -#define RCC_APB1RSTR_UART5RST (1U << RCC_APB1RSTR_UART5RST_BIT) -#define RCC_APB1RSTR_UART4RST (1U << RCC_APB1RSTR_UART4RST_BIT) -#define RCC_APB1RSTR_USART3RST (1U << RCC_APB1RSTR_USART3RST_BIT) -#define RCC_APB1RSTR_USART2RST (1U << RCC_APB1RSTR_USART2RST_BIT) -#define RCC_APB1RSTR_SPI3RST (1U << RCC_APB1RSTR_SPI3RST_BIT) -#define RCC_APB1RSTR_SPI2RST (1U << RCC_APB1RSTR_SPI2RST_BIT) -#define RCC_APB1RSTR_WWDRST (1U << RCC_APB1RSTR_WWDRST_BIT) -#define RCC_APB1RSTR_TIM7RST (1U << RCC_APB1RSTR_TIM7RST_BIT) -#define RCC_APB1RSTR_TIM6RST (1U << RCC_APB1RSTR_TIM6RST_BIT) -#define RCC_APB1RSTR_TIM4RST (1U << RCC_APB1RSTR_TIM4RST_BIT) -#define RCC_APB1RSTR_TIM3RST (1U << RCC_APB1RSTR_TIM3RST_BIT) -#define RCC_APB1RSTR_TIM2RST (1U << RCC_APB1RSTR_TIM2RST_BIT) - -/* AHB peripheral clock enable register */ - -#define RCC_AHBENR_ADC34EN_BIT 29 -#define RCC_AHBENR_ADC12EN_BIT 28 -#define RCC_AHBENR_TSCEN_BIT 24 -#define RCC_AHBENR_IOPFEN_BIT 22 -#define RCC_AHBENR_IOPEEN_BIT 21 -#define RCC_AHBENR_IOPDEN_BIT 20 -#define RCC_AHBENR_IOPCEN_BIT 19 -#define RCC_AHBENR_IOPBEN_BIT 18 -#define RCC_AHBENR_IOPAEN_BIT 17 -#define RCC_AHBENR_CRCEN_BIT 6 -#define RCC_AHBENR_FLITFEN_BIT 4 -#define RCC_AHBENR_SRAMEN_BIT 2 -#define RCC_AHBENR_DMA2EN_BIT 1 -#define RCC_AHBENR_DMA1EN_BIT 0 - -#define RCC_AHBENR_ADC34EN (1U << RCC_AHBENR_ADC34EN_BIT) -#define RCC_AHBENR_ADC12EN (1U << RCC_AHBENR_ADC12EN_BIT) -#define RCC_AHBENR_TSCEN (1U << RCC_AHBENR_TSCEN_BIT) -#define RCC_AHBENR_IOPFEN (1U << RCC_AHBENR_IOPFEN_BIT) -#define RCC_AHBENR_IOPEEN (1U << RCC_AHBENR_IOPEEN_BIT) -#define RCC_AHBENR_IOPDEN (1U << RCC_AHBENR_IOPDEN_BIT) -#define RCC_AHBENR_IOPCEN (1U << RCC_AHBENR_IOPCEN_BIT) -#define RCC_AHBENR_IOPBEN (1U << RCC_AHBENR_IOPBEN_BIT) -#define RCC_AHBENR_IOPAEN (1U << RCC_AHBENR_IOPAEN_BIT) -#define RCC_AHBENR_CRCEN (1U << RCC_AHBENR_CRCEN_BIT) -#define RCC_AHBENR_FLITFEN (1U << RCC_AHBENR_FLITFEN_BIT) -#define RCC_AHBENR_SRAMEN (1U << RCC_AHBENR_SRAMEN_BIT) -#define RCC_AHBENR_DMA2EN (1U << RCC_AHBENR_DMA2EN_BIT) -#define RCC_AHBENR_DMA1EN (1U << RCC_AHBENR_DMA1EN_BIT) - -/* APB2 peripheral clock enable register */ - -#define RCC_APB2ENR_TIM17EN_BIT 18 -#define RCC_APB2ENR_TIM16EN_BIT 17 -#define RCC_APB2ENR_TIM15EN_BIT 16 -#define RCC_APB2ENR_USART1EN_BIT 14 -#define RCC_APB2ENR_TIM8EN_BIT 13 -#define RCC_APB2ENR_SPI1EN_BIT 12 -#define RCC_APB2ENR_TIM1EN_BIT 11 -#define RCC_APB2ENR_SYSCFGEN_BIT 0 - -#define RCC_APB2ENR_TIM17EN (1U << RCC_APB2ENR_TIM17EN_BIT) -#define RCC_APB2ENR_TIM16EN (1U << RCC_APB2ENR_TIM16EN_BIT) -#define RCC_APB2ENR_TIM15EN (1U << RCC_APB2ENR_TIM15EN_BIT) -#define RCC_APB2ENR_USART1EN (1U << RCC_APB2ENR_USART1EN_BIT) -#define RCC_APB2ENR_TIM8EN (1U << RCC_APB2ENR_TIM8EN_BIT) -#define RCC_APB2ENR_SPI1EN (1U << RCC_APB2ENR_SPI1EN_BIT) -#define RCC_APB2ENR_TIM1EN (1U << RCC_APB2ENR_TIM1EN_BIT) -#define RCC_APB2ENR_SYSCFGEN (1U << RCC_APB2ENR_SYSCFGEN_BIT) - -/* APB1 peripheral clock enable register */ - -#define RCC_APB1ENR_DACEN_BIT 29 -#define RCC_APB1ENR_PWREN_BIT 28 -#define RCC_APB1ENR_CANEN_BIT 25 -#define RCC_APB1ENR_USBEN_BIT 23 -#define RCC_APB1ENR_I2C2EN_BIT 22 -#define RCC_APB1ENR_I2C1EN_BIT 21 -#define RCC_APB1ENR_UART5EN_BIT 20 -#define RCC_APB1ENR_UART4EN_BIT 19 -#define RCC_APB1ENR_USART3EN_BIT 18 -#define RCC_APB1ENR_USART2EN_BIT 17 -#define RCC_APB1ENR_SPI3EN_BIT 15 -#define RCC_APB1ENR_SPI2EN_BIT 14 -#define RCC_APB1ENR_WWDEN_BIT 11 -#define RCC_APB1ENR_TIM7EN_BIT 5 -#define RCC_APB1ENR_TIM6EN_BIT 4 -#define RCC_APB1ENR_TIM4EN_BIT 2 -#define RCC_APB1ENR_TIM3EN_BIT 1 -#define RCC_APB1ENR_TIM2EN_BIT 0 - -#define RCC_APB1ENR_DACEN (1U << RCC_APB1ENR_DACEN_BIT) -#define RCC_APB1ENR_PWREN (1U << RCC_APB1ENR_PWREN_BIT) -#define RCC_APB1ENR_CANEN (1U << RCC_APB1ENR_CANEN_BIT) -#define RCC_APB1ENR_USBEN (1U << RCC_APB1ENR_USBEN_BIT) -#define RCC_APB1ENR_I2C2EN (1U << RCC_APB1ENR_I2C2EN_BIT) -#define RCC_APB1ENR_I2C1EN (1U << RCC_APB1ENR_I2C1EN_BIT) -#define RCC_APB1ENR_UART5EN (1U << RCC_APB1ENR_UART5EN_BIT) -#define RCC_APB1ENR_UART4EN (1U << RCC_APB1ENR_UART4EN_BIT) -#define RCC_APB1ENR_USART3EN (1U << RCC_APB1ENR_USART3EN_BIT) -#define RCC_APB1ENR_USART2EN (1U << RCC_APB1ENR_USART2EN_BIT) -#define RCC_APB1ENR_SPI3EN (1U << RCC_APB1ENR_SPI3EN_BIT) -#define RCC_APB1ENR_SPI2EN (1U << RCC_APB1ENR_SPI2EN_BIT) -#define RCC_APB1ENR_WWDEN (1U << RCC_APB1ENR_WWDEN_BIT) -#define RCC_APB1ENR_TIM7EN (1U << RCC_APB1ENR_TIM7EN_BIT) -#define RCC_APB1ENR_TIM6EN (1U << RCC_APB1ENR_TIM6EN_BIT) -#define RCC_APB1ENR_TIM4EN (1U << RCC_APB1ENR_TIM4EN_BIT) -#define RCC_APB1ENR_TIM3EN (1U << RCC_APB1ENR_TIM3EN_BIT) -#define RCC_APB1ENR_TIM2EN (1U << RCC_APB1ENR_TIM2EN_BIT) - -/* Backup domain control register */ - -#define RCC_BDCR_BDRST_BIT 16 -#define RCC_BDCR_RTCEN_BIT 15 -#define RCC_BDCR_LSEBYP_BIT 2 -#define RCC_BDCR_LSERDY_BIT 1 -#define RCC_BDCR_LSEON_BIT 0 - -#define RCC_BDCR_BDRST (1U << RCC_BDCR_BDRST_BIT) -#define RCC_BDCR_RTCEN (1U << RCC_BDCR_RTC_BIT) -#define RCC_BDCR_RTCSEL (0x3 << 8) -#define RCC_BDCR_RTCSEL_NONE (0x0 << 8) -#define RCC_BDCR_RTCSEL_LSE (0x1 << 8) -#define RCC_BDCR_RTCSEL_HSE (0x3 << 8) -#define RCC_BDCR_LSEBYP (1U << RCC_BDCR_LSEBYP_BIT) -#define RCC_BDCR_LSERDY (1U << RCC_BDCR_LSERDY_BIT) -#define RCC_BDCR_LSEON (1U << RCC_BDCR_LSEON_BIT) - -/* Control/status register */ - -#define RCC_CSR_LPWRRSTF_BIT 31 -#define RCC_CSR_WWDGRSTF_BIT 30 -#define RCC_CSR_IWDGRSTF_BIT 29 -#define RCC_CSR_SFTRSTF_BIT 28 -#define RCC_CSR_PORRSTF_BIT 27 -#define RCC_CSR_PINRSTF_BIT 26 -#define RCC_CSR_OBLRSTF_BIT 25 -#define RCC_CSR_RMVF_BIT 24 -#define RCC_CSR_LSIRDY_BIT 1 -#define RCC_CSR_LSION_BIT 0 - -#define RCC_CSR_LPWRRSTF (1U << RCC_CSR_LPWRRSTF_BIT) -#define RCC_CSR_WWDGRSTF (1U << RCC_CSR_WWDGRSTF_BIT) -#define RCC_CSR_IWDGRSTF (1U << RCC_CSR_IWDGRSTF_BIT) -#define RCC_CSR_SFTRSTF (1U << RCC_CSR_SFTRSTF_BIT) -#define RCC_CSR_PORRSTF (1U << RCC_CSR_PORRSTF_BIT) -#define RCC_CSR_PINRSTF (1U << RCC_CSR_PINRSTF_BIT) -#define RCC_CSR_OBLRSTF (1U << RCC_CSR_OBLRSTF_BIT) -#define RCC_CSR_RMVF (1U << RCC_CSR_RMVF_BIT) -#define RCC_CSR_LSIRDY (1U << RCC_CSR_LSIRDY_BIT) -#define RCC_CSR_LSION (1U << RCC_CSR_LSION_BIT) - -/* AHB peripheral reset register */ - -#define RCC_AHBRSTR_ADC34RST_BIT 29 -#define RCC_AHBRSTR_ADC12RST_BIT 28 -#define RCC_AHBRSTR_TSCRST_BIT 24 -#define RCC_AHBRSTR_IOPFRST_BIT 22 -#define RCC_AHBRSTR_IOPERST_BIT 21 -#define RCC_AHBRSTR_IOPDRST_BIT 20 -#define RCC_AHBRSTR_IOPCRST_BIT 19 -#define RCC_AHBRSTR_IOPBRST_BIT 18 -#define RCC_AHBRSTR_IOPARST_BIT 17 - -#define RCC_AHBRSTR_ADC34RST (1U << RCC_AHBRSTR_ADC34RST_BIT) -#define RCC_AHBRSTR_ADC12RST (1U << RCC_AHBRSTR_ADC12RST_BIT) -#define RCC_AHBRSTR_TSCRST (1U << RCC_AHBRSTR_TSCRST_BIT) -#define RCC_AHBRSTR_IOPFRST (1U << RCC_AHBRSTR_IOPFRST_BIT) -#define RCC_AHBRSTR_IOPERST (1U << RCC_AHBRSTR_IOPERST_BIT) -#define RCC_AHBRSTR_IOPDRST (1U << RCC_AHBRSTR_IOPDRST_BIT) -#define RCC_AHBRSTR_IOPCRST (1U << RCC_AHBRSTR_IOPCRST_BIT) -#define RCC_AHBRSTR_IOPBRST (1U << RCC_AHBRSTR_IOPBRST_BIT) -#define RCC_AHBRSTR_IOPARST (1U << RCC_AHBRSTR_IOPARST_BIT) - -/* Clock configuration register 2 */ - -#define RCC_CFGR2_ADC34PRES_SHIFT 9 -#define RCC_CFGR2_ADC12PRES_SHIFT 4 - -#define RCC_CFGR2_ADC34PRES (0x1f << RCC_CFGR2_ADC34PRES_SHIFT) -#define RCC_CFGR2_ADC12PRES (0x1f << RCC_CFGR2_ADC12PRES_SHIFT) -#define RCC_CFGR2_PREDIV 0xf - -/* Clock configuration register 3 */ //TODO make clock sources configurable - -#define RCC_CFGR3_TIM8SW_BIT 9 -#define RCC_CFGR3_TIM1SW_BIT 8 -#define RCC_CFGR3_I2C2SW_BIT 5 -#define RCC_CFGR3_I2C1SW_BIT 4 - -#define RCC_CFGR3_UART5SW (0x3 << 22) -#define RCC_CFGR3_UART4SW (0x3 << 20) -#define RCC_CFGR3_USART3SW (0x3 << 18) -#define RCC_CFGR3_USART2SW (0x3 << 16) -#define RCC_CFGR_TIM8SW (1U << RCC_CFGR3_TIM8SW_BIT) -#define RCC_CFGR_TIM1SW (1U << RCC_CFGR3_TIM1SW_BIT) -#define RCC_CFGR_I2C2SW (1U << RCC_CFGR3_I2C2SW_BIT) -#define RCC_CFGR_I2C1SW (1U << RCC_CFGR3_I2C1SW_BIT) -#define RCC_CFGR3_USART1SW 0x3 - -/* - * libmaple-mandated enumeration types. - */ - -/** - * @brief STM32F3 rcc_clk_id. - */ -typedef enum rcc_clk_id { - RCC_GPIOA, - RCC_GPIOB, - RCC_GPIOC, - RCC_GPIOD, - RCC_GPIOE, - RCC_GPIOF, - - RCC_ADC12, - RCC_ADC34, - - RCC_DAC, - - RCC_DMA1, - RCC_DMA2, - - RCC_I2C1, - RCC_I2C2, - - RCC_SPI1, - RCC_SPI2, - RCC_SPI3, - - RCC_USART1, - RCC_USART2, - RCC_USART3, - RCC_UART4, - RCC_UART5, - - RCC_TIMER1, - RCC_TIMER2, - RCC_TIMER3, - RCC_TIMER4, - RCC_TIMER5, - RCC_TIMER6, - RCC_TIMER7, - RCC_TIMER8, - RCC_TIMER9, - RCC_TIMER10, - RCC_TIMER11, - RCC_TIMER12, - RCC_TIMER13, - RCC_TIMER14, - RCC_TIMER15, - RCC_TIMER16, - RCC_TIMER17, - - RCC_SYSCFG, - RCC_CRC, - RCC_FLITF, - RCC_PWR, - RCC_SRAM, - RCC_USB, -} rcc_clk_id; - -/** - * @brief STM32F3 PLL clock sources. - * @see rcc_configure_pll() - */ -typedef enum rcc_pllsrc { - RCC_PLLSRC_HSE = (0x1 << RCC_CFGR_PLLSRC_BIT), - RCC_PLLSRC_HSI_DIV_2 = (0x0 << RCC_CFGR_PLLSRC_BIT) -} rcc_pllsrc; - -/** - * @brief STM32F3 clock domains. - * @see rcc_dev_clk() - */ -typedef enum rcc_clk_domain { - RCC_APB1, - RCC_APB2, - RCC_AHB -} rcc_clk_domain; - -/** - * @brief STM32F3 Prescaler identifiers - * @see rcc_set_prescaler() - */ -typedef enum rcc_prescaler { - RCC_PRESCALER_AHB, - RCC_PRESCALER_APB1, - RCC_PRESCALER_APB2, - RCC_PRESCALER_USB, -} rcc_prescaler; - -/** - * @brief STM32F3 ADC prescaler dividers - * @see rcc_set_prescaler() - */ -typedef enum rcc_adc_divider { - RCC_ADCPRE_PCLK_DISABLED = 0x00, - RCC_ADCPRE_PCLK_DIV_1 = 0x10, - RCC_ADCPRE_PCLK_DIV_2 = 0x11, - RCC_ADCPRE_PCLK_DIV_4 = 0x12, - RCC_ADCPRE_PCLK_DIV_6 = 0x13, - RCC_ADCPRE_PCLK_DIV_8 = 0x14, - RCC_ADCPRE_PCLK_DIV_10 = 0x15, - RCC_ADCPRE_PCLK_DIV_12 = 0x16, - RCC_ADCPRE_PCLK_DIV_16 = 0x17, - RCC_ADCPRE_PCLK_DIV_32 = 0x18, - RCC_ADCPRE_PCLK_DIV_64 = 0x19, - RCC_ADCPRE_PCLK_DIV_128 = 0x1A, - RCC_ADCPRE_PCLK_DIV_256 = 0x1B, -} rcc_adc_divider; - -/** - * @brief STM32F3 PREDIV prescaler dividers - * @see rcc_set_prescaler() - */ -typedef enum rcc_prediv_divider { - RCC_PREDIV_PCLK_DIV_1 = 0x0, - RCC_PREDIV_PCLK_DIV_2 = 0x1, - RCC_PREDIV_PCLK_DIV_3 = 0x2, - RCC_PREDIV_PCLK_DIV_4 = 0x3, - RCC_PREDIV_PCLK_DIV_5 = 0x4, - RCC_PREDIV_PCLK_DIV_6 = 0x5, - RCC_PREDIV_PCLK_DIV_7 = 0x6, - RCC_PREDIV_PCLK_DIV_8 = 0x7, - RCC_PREDIV_PCLK_DIV_9 = 0x8, - RCC_PREDIV_PCLK_DIV_10 = 0x9, - RCC_PREDIV_PCLK_DIV_11 = 0xA, - RCC_PREDIV_PCLK_DIV_12 = 0xB, - RCC_PREDIV_PCLK_DIV_13 = 0xC, - RCC_PREDIV_PCLK_DIV_14 = 0xD, - RCC_PREDIV_PCLK_DIV_15 = 0xE, - RCC_PREDIV_PCLK_DIV_16 = 0xF, -} rcc_prediv_divider; - -/** - * @brief STM32F3 APB1 prescaler dividers - * @see rcc_set_prescaler() - */ -typedef enum rcc_apb1_divider { - RCC_APB1_HCLK_DIV_1 = 0x0 << RCC_CFGR_PPRE1_BIT, - RCC_APB1_HCLK_DIV_2 = 0x4 << RCC_CFGR_PPRE1_BIT, - RCC_APB1_HCLK_DIV_4 = 0x5 << RCC_CFGR_PPRE1_BIT, - RCC_APB1_HCLK_DIV_8 = 0x6 << RCC_CFGR_PPRE1_BIT, - RCC_APB1_HCLK_DIV_16 = 0x7 << RCC_CFGR_PPRE1_BIT, -} rcc_apb1_divider; - -/** - * @brief STM32F3 APB2 prescaler dividers - * @see rcc_set_prescaler() - */ -typedef enum rcc_apb2_divider { - RCC_APB2_HCLK_DIV_1 = 0x0 << RCC_CFGR_PPRE2_BIT, - RCC_APB2_HCLK_DIV_2 = 0x4 << RCC_CFGR_PPRE2_BIT, - RCC_APB2_HCLK_DIV_4 = 0x5 << RCC_CFGR_PPRE2_BIT, - RCC_APB2_HCLK_DIV_8 = 0x6 << RCC_CFGR_PPRE2_BIT, - RCC_APB2_HCLK_DIV_16 = 0x7 << RCC_CFGR_PPRE2_BIT, -} rcc_apb2_divider; - -/** - * @brief STM32F3 AHB prescaler dividers - * @see rcc_set_prescaler() - */ -typedef enum rcc_ahb_divider { - RCC_AHB_SYSCLK_DIV_1 = 0x0 << RCC_CFGR_HPRE_BIT, - RCC_AHB_SYSCLK_DIV_2 = 0x8 << RCC_CFGR_HPRE_BIT, - RCC_AHB_SYSCLK_DIV_4 = 0x9 << RCC_CFGR_HPRE_BIT, - RCC_AHB_SYSCLK_DIV_8 = 0xA << RCC_CFGR_HPRE_BIT, - RCC_AHB_SYSCLK_DIV_16 = 0xB << RCC_CFGR_HPRE_BIT, - RCC_AHB_SYSCLK_DIV_32 = 0xC << RCC_CFGR_HPRE_BIT, - RCC_AHB_SYSCLK_DIV_64 = 0xD << RCC_CFGR_HPRE_BIT, - RCC_AHB_SYSCLK_DIV_128 = 0xD << RCC_CFGR_HPRE_BIT, - RCC_AHB_SYSCLK_DIV_256 = 0xE << RCC_CFGR_HPRE_BIT, - RCC_AHB_SYSCLK_DIV_512 = 0xF << RCC_CFGR_HPRE_BIT, -} rcc_ahb_divider; - -/** - * @brief STM32F3 clock sources. - */ -typedef enum rcc_clk { - RCC_CLK_PLL = (uint16)((offsetof(struct rcc_reg_map, CR) << 8) | - RCC_CR_PLLON_BIT), /**< Main PLL, clocked by - HSI or HSE. */ - RCC_CLK_HSE = (uint16)((offsetof(struct rcc_reg_map, CR) << 8) | - RCC_CR_HSEON_BIT), /**< High speed external. */ - RCC_CLK_HSI = (uint16)((offsetof(struct rcc_reg_map, CR) << 8) | - RCC_CR_HSION_BIT), /**< High speed internal. */ - RCC_CLK_LSE = (uint16)((offsetof(struct rcc_reg_map, BDCR) << 8) | - RCC_BDCR_LSEON_BIT), /**< Low-speed external - * (32.768 KHz). */ - RCC_CLK_LSI = (uint16)((offsetof(struct rcc_reg_map, CSR) << 8) | - RCC_CSR_LSION_BIT), /**< Low-speed internal - * (approximately 32 KHz). */ -} rcc_clk; - -/** - * @brief STM32F3 PLL multipliers. - */ -typedef enum rcc_pll_multiplier { - RCC_PLLMUL_2 = (0x0 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_3 = (0x1 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_4 = (0x2 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_5 = (0x3 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_6 = (0x4 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_7 = (0x5 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_8 = (0x6 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_9 = (0x7 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_10 = (0x8 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_11 = (0x9 << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_12 = (0xA << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_13 = (0xB << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_14 = (0xC << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_15 = (0xD << RCC_CFGR_PLLMUL_BIT), - RCC_PLLMUL_16 = (0xE << RCC_CFGR_PLLMUL_BIT), -} rcc_pll_multiplier; - -/* FIXME [0.0.13] Just have data point to an rcc_pll_multiplier! */ - -/** - * @brief STM32F3 PLL configuration values. - * Point to one of these with the "data" field in a struct rcc_pll_cfg. - * @see struct rcc_pll_cfg. - */ -typedef struct stm32f3_rcc_pll_data { - rcc_pll_multiplier pll_mul; /**< PLL multiplication factor. */ - rcc_prediv_divider pclk_prediv; /**< PCLK predivider. */ -} stm32f3_rcc_pll_data; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/simd.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/simd.h deleted file mode 100644 index 8325d5d..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/simd.h +++ /dev/null @@ -1,109 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -/** - * @file libmaple/include/libmaple/simd.h - * @author F3-port by Hanspeter Portner - * @brief Convenience macros for the digital signal processing (DSP) - * instruction set of the ARM Cortex M4 microcontroller. - */ - -#ifndef _LIBMAPLE_DSP_H_ -#define _LIBMAPLE_DSP_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#define DSP3(ID, A, B, C) \ -({ \ - uint32_t X; \ - asm volatile (ID" %[res], %[val1], %[val2], %[val3]" \ - : [res]"=r" (X) \ - : [val1]"r" (A), [val2]"r" (B), [val3]"r" (C) \ - ); \ - (uint32_t)X; \ -}) - -#define DSP2(ID, A, B) \ -({ \ - uint32_t X; \ - asm volatile (ID" %[res], %[val1], %[val2]" \ - : [res]"=r" (X) \ - : [val1]"r" (A), [val2]"r" (B) \ - );\ - (uint32_t)X; \ -}) - -#define DSP1(ID, A) \ -({ \ - uint32_t X; \ - asm volatile (ID" %[res], %[val1]" \ - : [res]"=r" (X) \ - : [val1]"r" (A) \ - ); \ - (uint32_t)X; \ -}) - -/* General data processing instructions */ -#define __rev16(A) DSP1("REV16", A) - -/* SIMD instructions (single instruction multiple data) */ -#define __sadd16(A, B) DSP2("SADD16", A, B) -#define __shadd16(A, B) DSP2("SHADD16", A, B) -#define __ssub16(A, B) DSP2("SSUB16", A, B) -#define __shsub16(A, B) DSP2("SHSUB16", A, B) -#define __uadd16(A, B) DSP2("UADD16", A, B) -#define __uhadd16(A, B) DSP2("UHADD16", A, B) -#define __usub16(A, B) DSP2("USUB16", A, B) -#define __uhsub16(A, B) DSP2("UHSUB16", A, B) - -#define __sadd8(A, B) DSP2("SADD8", A, B) -#define __shadd8(A, B) DSP2("SHADD8", A, B) -#define __ssub8(A, B) DSP2("SSUB8", A, B) -#define __shsub8(A, B) DSP2("SHSUB8", A, B) -#define __uadd8(A, B) DSP2("UADD8", A, B) -#define __uhadd8(A, B) DSP2("UHADD8", A, B) -#define __usub8(A, B) DSP2("USUB8", A, B) -#define __uhsub8(A, B) DSP2("UHSUB8", A, B) - -#define __sasx(A, B) DSP2("SASX", A, B) -#define __ssax(A, B) DSP2("SSAX", A, B) -#define __shasx(A, B) DSP2("SHASX", A, B) -#define __shsax(A, B) DSP2("SHSAX", A, B) -#define __uasx(A, B) DSP2("UASX", A, B) -#define __usax(A, B) DSP2("USAX", A, B) -#define __uhasx(A, B) DSP2("UHASX", A, B) -#define __uhsax(A, B) DSP2("UHSAX", A, B) - -#define __usad8(A, B) DSP2("USAD8", A, B) -#define __usada8(A, B, C) DSP3("USADA8", A, B, C) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/spi.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/spi.h deleted file mode 100644 index 5b1de09..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/spi.h +++ /dev/null @@ -1,178 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/spi.h - * @author Marti Bolivar , - * F3-port by Hanspeter Portner - * @brief STM32F3 SPI/I2S series header. - */ - -#ifndef _LIBMAPLE_STM32F3_SPI_H_ -#define _LIBMAPLE_STM32F3_SPI_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Register map base pointers - */ - -struct spi_reg_map; - -#define SPI1_BASE ((struct spi_reg_map*)0x40013000) -#define SPI2_BASE ((struct spi_reg_map*)0x40003800) -#define SPI3_BASE ((struct spi_reg_map*)0x40003C00) - -/* - * F3 additional registry items - */ - -/* Control register 1 */ -/* CRC length bitfield in F3 overwrites the data length field in F1/F2 */ -#define SPI_CR1_CRCL_BIT 11 - -#define SPI_CR1_CRCL (1U << SPI_CR1_CRCL_BIT) - -/* Control register 2 */ -#define SPI_CR2_LDMA_TX_BIT 14 -#define SPI_CR2_LDMA_RX_BIT 13 -#define SPI_CR2_FRXTH_BIT 12 -#define SPI_CR2_DS_SHIFT 8 -#define SPI_CR2_FRF_BIT 4 -#define SPI_CR2_NSSP_BIT 3 - -#define SPI_CR2_LDMA_TX (1U << SPI_CR2_LDMA_TX_BIT) -#define SPI_CR2_LDMA_RX (1U << SPI_CR2_LDMA_RX_BIT) -#define SPI_CR2_FRXTH (1U << SPI_CR2_FRXTH_BIT) -#define SPI_CR2_DS (0x7 << SPI_CR2_DS_SHIFT) -#define SPI_CR2_FRF (1U << SPI_CR2_FRF_BIT) -#define SPI_CR2_NSSP (1U << SPI_CR2_NSSP_BIT) - -/* Status register */ -#define SPI_SR_FTLVL_SHIFT 11 -#define SPI_SR_FRLVL_SHIFT 9 -#define SPI_SR_FRE_BIT 8 - -#define SPI_SR_FTLVL (0x3 << SPI_SR_FTLVL_SHIFT) -#define SPI_SR_FRLVL (0x3 << SPI_SR_FRLVL_SHIFT) -#define SPI_SR_FRE (1U << SPI_SR_FRE_SHIFT) - -/** - * @brief TODO document me - */ -typedef enum spi_crc_size { - SPI_CRC_SIZE_8_BIT = (0x0 << SPI_CR1_CRCL_BIT), - SPI_CRC_SIZE_16_BIT = (0x1 << SPI_CR1_CRCL_BIT), -} spi_crc_size; - -/** - * @brief TODO document me - */ -typedef enum spi_frame_format { - SPI_FRAME_FORMAT_MOTOROLA = (0x0 << SPI_CR2_FRF_BIT), - SPI_FRAME_FORMAT_TI = (0x1 << SPI_CR2_FRF_BIT), -} spi_frame_format; - -/** - * @brief TODO document me - */ -typedef enum spi_ds { - SPI_DATA_SIZE_DEFAULT = (0x0 << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_4_BIT = (0x3 << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_5_BIT = (0x4 << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_6_BIT = (0x5 << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_7_BIT = (0x6 << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_8_BIT = (0x7 << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_9_BIT = (0x8 << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_10_BIT = (0x9 << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_11_BIT = (0xA << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_12_BIT = (0xB << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_13_BIT = (0xC << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_14_BIT = (0xD << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_15_BIT = (0xE << SPI_CR2_DS_SHIFT), - SPI_DATA_SIZE_16_BIT = (0xF << SPI_CR2_DS_SHIFT), -} spi_ds; - -/** - * @brief TODO document me - */ -typedef enum spi_fifo_transmission_level { - SPI_FIFO_TRANSMISSION_LEVEL_EMPTY = (0x0 << SPI_SR_FTLVL_SHIFT), - SPI_FIFO_TRANSMISSION_LEVEL_QUARTER = (0x1 << SPI_SR_FTLVL_SHIFT), - SPI_FIFO_TRANSMISSION_LEVEL_HALF = (0x2 << SPI_SR_FTLVL_SHIFT), - SPI_FIFO_TRANSMISSION_LEVEL_FULL = (0x3 << SPI_SR_FTLVL_SHIFT), -} spi_fifo_transmission_level; - -/** - * @brief TODO document me - */ -typedef enum spi_fifo_reception_level { - SPI_FIFO_RECEPTION_LEVEL_EMPTY = (0x0 << SPI_SR_FRLVL_SHIFT), - SPI_FIFO_RECEPTION_LEVEL_QUARTER = (0x1 << SPI_SR_FRLVL_SHIFT), - SPI_FIFO_RECEPTION_LEVEL_HALF = (0x2 << SPI_SR_FRLVL_SHIFT), - SPI_FIFO_RECEPTION_LEVEL_FULL = (0x3 << SPI_SR_FRLVL_SHIFT), -} spi_fifo_reception_level; - -/* - * Device pointers - */ - -struct spi_dev; - -extern struct spi_dev *SPI1; -extern struct spi_dev *SPI2; -extern struct spi_dev *SPI3; - -/* - * Routines - */ - -struct gpio_dev; -extern void spi_config_gpios(struct spi_dev*, uint8, - struct gpio_dev*, uint8, - struct gpio_dev*, uint8, uint8, uint8); - -/** - * @brief Set the data size of the given SPI device. - * - * @param dev SPI device - * @param ds SPI data size - * @see spi_ds - * @see spi_reconfigure() - */ -extern void spi_data_size(struct spi_dev *, spi_ds); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/stm32.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/stm32.h deleted file mode 100644 index c40627c..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/stm32.h +++ /dev/null @@ -1,238 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010, 2011 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f1/include/series/stm32.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 chip- and series-specific definitions. - */ - -#ifndef _LIBMAPLE_STM32F3_H_ -#define _LIBMAPLE_STM32F3_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#define __CCM__ __attribute__((section(".CCM"))) - -#define STM32_MCU_SERIES STM32_SERIES_F3 - -/* The STM32F3 series is subdivided into "lines". libmaple currently - * officially supports STM32F303 performance line MCUs (see the - * MCU-specific value section below). - * - * You can use these F3 line defines if porting libmaple to support - * MCUs on other lines. */ -/** STM32F3 302 line (STM32F302 MCUs). */ -#define STM32_F3_LINE_302 0 -/** STM32F3 303 line (STM32F303 MCUs). */ -#define STM32_F3_LINE_303 1 - -/* - * MCU-specific values. - * - * You can use this section to override any of the below settings on a - * per-MCU basis. For example, if your MCU has different STM32_PCLK1 - * or STM32_PCLK2 values, you can set them here and the values for - * STM32F303 microcontrollers set below won't take effect. - */ - -#if defined(MCU_STM32F302CB) -# define STM32_F3_LINE STM32_F3_LINE_302 -# define STM32_NR_GPIO_PORTS 20 -# define STM32_SRAM_END ((void*)0x20008000) -# define STM32_MEDIUM_DENSITY // 48pin package - -#elif defined(MCU_STM32F302RB) -# define STM32_F3_LINE STM32_F3_LINE_302 -# define STM32_NR_GPIO_PORTS 27 -# define STM32_SRAM_END ((void*)0x20008000) -# define STM32_HIGH_DENSITY // 64pin package - -#elif defined(MCU_STM32F302VB) -# define STM32_F3_LINE STM32_F3_LINE_302 -# define STM32_NR_GPIO_PORTS 45 -# define STM32_SRAM_END ((void*)0x20008000) -# define STM32_XL_DENSITY // 100pin package - -#elif defined(MCU_STM32F302CC) -# define STM32_F3_LINE STM32_F3_LINE_302 -# define STM32_NR_GPIO_PORTS 20 -# define STM32_SRAM_END ((void*)0x2000A000) -# define STM32_MEDIUM_DENSITY // 48pin package - -#elif defined(MCU_STM32F302RC) -# define STM32_F3_LINE STM32_F3_LINE_302 -# define STM32_NR_GPIO_PORTS 27 -# define STM32_SRAM_END ((void*)0x2000A000) -# define STM32_HIGH_DENSITY // 64pin package - -#elif defined(MCU_STM32F302VC) -# define STM32_F3_LINE STM32_F3_LINE_302 -# define STM32_NR_GPIO_PORTS 45 -# define STM32_SRAM_END ((void*)0x2000A000) -# define STM32_XL_DENSITY // 100pin package - -#elif defined(MCU_STM32F303CB) -# define STM32_F3_LINE STM32_F3_LINE_303 -# define STM32_NR_GPIO_PORTS 20 -# define STM32_SRAM_END ((void*)0x2000A000) -# define STM32_MEDIUM_DENSITY // 48pin package - -#elif defined(MCU_STM32F303RB) -# define STM32_F3_LINE STM32_F3_LINE_303 -# define STM32_NR_GPIO_PORTS 27 -# define STM32_SRAM_END ((void*)0x2000A000) -# define STM32_HIGH_DENSITY // 64pin package - -#elif defined(MCU_STM32F303VB) -# define STM32_F3_LINE STM32_F3_LINE_303 -# define STM32_NR_GPIO_PORTS 45 -# define STM32_SRAM_END ((void*)0x2000A000) -# define STM32_XL_DENSITY // 100pin package - -#elif defined(MCU_STM32F303CC) -# define STM32_F3_LINE STM32_F3_LINE_303 -# define STM32_NR_GPIO_PORTS 20 -# define STM32_SRAM_END ((void*)0x2000C000) -# define STM32_MEDIUM_DENSITY // 48pin package - -#elif defined(MCU_STM32F303RC) -# define STM32_F3_LINE STM32_F3_LINE_303 -# define STM32_NR_GPIO_PORTS 27 -# define STM32_SRAM_END ((void*)0x2000C000) -# define STM32_HIGH_DENSITY // 64pin package - -#elif defined(MCU_STM32F303VC) -# define STM32_F3_LINE STM32_F3_LINE_303 -# define STM32_NR_GPIO_PORTS 45 -# define STM32_SRAM_END ((void*)0x2000C000) -// # define STM32_XL_DENSITY // 100pin package - -#else -#warning "Unsupported or unspecified STM32F3 MCU." -#endif - -/* - * Derived values. - */ - -#if STM32_F3_LINE == STM32_F3_LINE_302 -# define STM32_HAVE_USB 1 - -# ifdef STM32_MEDIUM_DENSITY -# define STM32_NR_INTERRUPTS 82 -# define STM32_TIMER_MASK 0b111000000001011110 -# define STM32_HAVE_FSMC 0 -# define STM32_HAVE_DAC 1 -# elif defined(STM32_HIGH_DENSITY) -# define STM32_NR_INTERRUPTS 82 -# define STM32_TIMER_MASK 0b111000000001011110 -# define STM32_HAVE_FSMC 0 -# define STM32_HAVE_DAC 1 -# elif defined(STM32_XL_DENSITY) -# define STM32_NR_INTERRUPTS 82 -# define STM32_TIMER_MASK 0b111000000001011110 -# define STM32_HAVE_FSMC 0 -# define STM32_HAVE_DAC 1 -# endif - -#elif STM32_F3_LINE == STM32_F3_LINE_303 -# define STM32_HAVE_USB 1 - -# ifdef STM32_MEDIUM_DENSITY -# define STM32_NR_INTERRUPTS 82 -# define STM32_TIMER_MASK 0b111000000111011110 -# define STM32_HAVE_FSMC 0 -# define STM32_HAVE_DAC 1 -# elif defined(STM32_HIGH_DENSITY) -# define STM32_NR_INTERRUPTS 82 -# define STM32_TIMER_MASK 0b111000000111011110 -# define STM32_HAVE_FSMC 0 -# define STM32_HAVE_DAC 1 -# elif defined(STM32_XL_DENSITY) -# define STM32_NR_INTERRUPTS 82 -# define STM32_TIMER_MASK 0b111000000111011110 -# define STM32_HAVE_FSMC 0 -# define STM32_HAVE_DAC 1 -# endif - -#endif - -/* - * Clock configuration. - * - * You can patch these for your line, MCU, clock configuration, - * etc. here or by setting cflags when compiling libmaple. - */ - -#ifndef STM32_PCLK1 -#define STM32_PCLK1 36000000U -#endif - -#ifndef STM32_PCLK2 -#define STM32_PCLK2 72000000U -#endif - -#ifndef STM32_DELAY_US_MULT -#define STM32_DELAY_US_MULT 12 /* FIXME: value is incorrect. */ -#endif - -/* - * Sanity checks. - * - * Make sure we have the F3-specific defines we need. - * will check that we've defined everything it needs. - */ - -#if !defined(STM32_F3_LINE) -#error "Bad STM32F3 configuration. Check STM32F3 header." -#endif - -/* - * Doxygen - */ - -#ifdef __DOXYGEN__ - -/** - * @brief STM32 line value for the STM32F3 MCU being targeted. - * - * At time of writing, allowed values are: STM32_F3_LINE_303, - * STM32_F3_LINE_302. This set of values may expand as libmaple adds - * support for more STM32F3 lines. - */ -#define STM32_F3_LINE - -#endif /* __DOXYGEN__ */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/syscfg.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/syscfg.h deleted file mode 100644 index 2565290..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/syscfg.h +++ /dev/null @@ -1,138 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/syscfg.h - * @author F3-port by Hanspeter Portner - * @brief System configuration controller (SYSCFG) - */ - -#ifndef _LIBMAPLE_STM32F3_SYSCFG_H_ -#define _LIBMAPLE_STM32F3_SYSCFG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* - * Register map and base pointer - */ - -/** - * @brief SYSCFG register map type. - */ -typedef struct syscfg_reg_map { - __IO uint32 CFGR1; /**< Configuration register 1*/ - __IO uint32 RCR; /**< CCM SRAM protection register */ - __IO uint32 EXTICR[4]; /**< External Interrupt configuration register */ - __IO uint32 CFGR2; /**< Configuration register 2 */ -} syscfg_reg_map; - -/** SYSCFG register map base pointer */ -#define SYSCFG_BASE ((struct syscfg_reg_map*)0x40010000) - -/* - * Register bit definitions - */ - -/* Configuration register 1 */ - -#define SYSCFG_CFGR1_FPU_IE_SHIFT 26 -#define SYSCFG_CFGR1_ENCODE_MODE_SHIFT 22 -#define SYSCFG_CFGR1_I2C2_FM_PLUS_BIT 21 -#define SYSCFG_CFGR1_I2C1_FM_PLUS_BIT 20 -#define SYSCFG_CFGR1_I2C_PB9_FM_PLUS_BIT 19 -#define SYSCFG_CFGR1_I2C_PB8_FM_PLUS_BIT 18 -#define SYSCFG_CFGR1_I2C_PB7_FM_PLUS_BIT 17 -#define SYSCFG_CFGR1_I2C_PB6_FM_PLUS_BIT 16 -#define SYSCFG_CFGR1_TIM7_DAC2_DMA_RMP_BIT 14 -#define SYSCFG_CFGR1_TIM6_DAC1_DMA_RMP_BIT 13 -#define SYSCFG_CFGR1_TIM17_DMA_RMP_BIT 12 -#define SYSCFG_CFGR1_TIM16_DMA_RMP_BIT 11 -#define SYSCFG_CFGR1_ADC24_DMA_RMP_BIT 8 -#define SYSCFG_CFGR1_DAC_TRIG_RMP_BIT 7 -#define SYSCFG_CFGR1_TIM1_ITR3_RMP_BIT 6 -#define SYSCFG_CFGR1_USB_IT_RMP_BIT 5 - -//FIXME FPU_IE -//FIXME ENCODE_MODE -#define SYSCFG_CFGR1_I2C2_FM_PLUS (1U << SYSCFG_CFGR1_I2C2_FM_PLUS_BIT) -#define SYSCFG_CFGR1_I2C1_FM_PLUS (1U << SYSCFG_CFGR1_I2C1_FM_PLUS_BIT) -#define SYSCFG_CFGR1_I2C1_PB9_FM_PLUS (1U << SYSCFG_CFGR1_I2C1_PB9_FM_PLUS_BIT) -#define SYSCFG_CFGR1_I2C1_PB8_FM_PLUS (1U << SYSCFG_CFGR1_I2C1_PB8_FM_PLUS_BIT) -#define SYSCFG_CFGR1_I2C1_PB7_FM_PLUS (1U << SYSCFG_CFGR1_I2C1_PB7_FM_PLUS_BIT) -#define SYSCFG_CFGR1_I2C1_PB6_FM_PLUS (1U << SYSCFG_CFGR1_I2C1_PB6_FM_PLUS_BIT) -#define SYSCFG_CFGR1_TIM7_DAC2_DMA_RMP (1U << SYSCFG_CFGR1_TIM7_DAC2_DMA_RMP_BIT) -#define SYSCFG_CFGR1_TIM6_DAC1_DMA_RMP (1U << SYSCFG_CFGR1_TIM6_DAC1_DMA_RMP_BIT) -#define SYSCFG_CFGR1_TIM17_DMA_RMP (1U << SYSCFG_CFGR1_TIM17_DMA_RMP_BIT) -#define SYSCFG_CFGR1_TIM16_DMA_RMP (1U << SYSCFG_CFGR1_TIM16_DMA_RMP_BIT) -#define SYSCFG_CFGR1_ADC23_DMA_RMP (1U << SYSCFG_CFGR1_ADC23_DMA_RMP_BIT) -#define SYSCFG_CFGR1_DAC_TRIG_RMP (1U << SYSCFG_CFGR1_DAC_TRIG_RMP_BIT) -#define SYSCFG_CFGR1_TIM1_ITR3_RMP (1U << SYSCFG_CFGR1_TIM1_ITR3_RMP_BIT) -#define SYSCFG_CFGR1_USB_IT_RMP (1U << SYSCFG_CFGR1_USB_IT_RMP_BIT) -#define SYSCFG_CFGR1_MEM_MODE 0X3 - -/* CCM SRAM protection register */ - -#define SYSCFG_RCR_PAGE7_WP_BIT 7 -#define SYSCFG_RCR_PAGE6_WP_BIT 6 -#define SYSCFG_RCR_PAGE5_WP_BIT 5 -#define SYSCFG_RCR_PAGE4_WP_BIT 4 -#define SYSCFG_RCR_PAGE3_WP_BIT 3 -#define SYSCFG_RCR_PAGE2_WP_BIT 2 -#define SYSCFG_RCR_PAGE1_WP_BIT 1 -#define SYSCFG_RCR_PAGE0_WP_BIT 0 - -#define SYSCFG_RCR_PAGE_7 (1U << SYSCFG_RCR_PAGE7_WP_BIT) -#define SYSCFG_RCR_PAGE_6 (1U << SYSCFG_RCR_PAGE6_WP_BIT) -#define SYSCFG_RCR_PAGE_5 (1U << SYSCFG_RCR_PAGE5_WP_BIT) -#define SYSCFG_RCR_PAGE_4 (1U << SYSCFG_RCR_PAGE4_WP_BIT) -#define SYSCFG_RCR_PAGE_3 (1U << SYSCFG_RCR_PAGE3_WP_BIT) -#define SYSCFG_RCR_PAGE_2 (1U << SYSCFG_RCR_PAGE2_WP_BIT) -#define SYSCFG_RCR_PAGE_1 (1U << SYSCFG_RCR_PAGE1_WP_BIT) -#define SYSCFG_RCR_PAGE_0 (1U << SYSCFG_RCR_PAGE0_WP_BIT) - -/* Configuration register 2 */ - -#define SYSCFG_CFGR2_SRAM_PEF_BIT 8 -#define SYSCFG_CFGR2_BYP_ADDR_PAR_BIT 4 -#define SYSCFG_CFGR2_PVD_LOCK_BIT 2 -#define SYSCFG_CFGR2_SRAM_PARITY_LOCK_BIT 1 -#define SYSCFG_CFGR2_LOCKUP_LOCK_BIT 0 - -#define SYSCFG_CFGR2_SRAM_PEF (1U << SYSCFG_CFGR2_SRAM_PEF_BIT) -#define SYSCFG_CFGR2_BYP_ADDR_PAR (1U << SYSCFG_CFGR2_BYP_ADDR_PAR_BIT) -#define SYSCFG_CFGR2_PVD_LOCK (1U << SYSCFG_CFGR2_PVD_LOCK_BIT) -#define SYSCFG_CFGR2_SRAM_PARITY_LOCK (1U << SYSCFG_CFGR2_SRAM_PARITY_LOCK_BIT) -#define SYSCFG_CFGR2_LOCKUP_LOCK (1U << SYSCFG_CFGR2_LOCKUP_LOCK_BIT) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/timer.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/timer.h deleted file mode 100644 index 01e2c88..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/timer.h +++ /dev/null @@ -1,123 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/timer.h - * @author Marti Bolivar , - * F3-port by Hanspeter Portner - * @brief STM32F3 timer support. - */ - -#ifndef _LIBMAPLE_STM32F3_TIMER_H_ -#define _LIBMAPLE_STM32F3_TIMER_H_ - -#include -#include - -/* - * Register maps and base pointers - */ - -/** STM32F1 general purpose timer register map type */ -typedef struct timer_gen_reg_map { - __IO uint32 CR1; /**< Control register 1 */ - __IO uint32 CR2; /**< Control register 2 */ - __IO uint32 SMCR; /**< Slave mode control register */ - __IO uint32 DIER; /**< DMA/Interrupt enable register */ - __IO uint32 SR; /**< Status register */ - __IO uint32 EGR; /**< Event generation register */ - __IO uint32 CCMR1; /**< Capture/compare mode register 1 */ - __IO uint32 CCMR2; /**< Capture/compare mode register 2 */ - __IO uint32 CCER; /**< Capture/compare enable register */ - __IO uint32 CNT; /**< Counter */ - __IO uint32 PSC; /**< Prescaler */ - __IO uint32 ARR; /**< Auto-reload register */ - const uint32 RESERVED1; /**< Reserved */ - __IO uint32 CCR1; /**< Capture/compare register 1 */ - __IO uint32 CCR2; /**< Capture/compare register 2 */ - __IO uint32 CCR3; /**< Capture/compare register 3 */ - __IO uint32 CCR4; /**< Capture/compare register 4 */ - const uint32 RESERVED2; /**< Reserved */ - __IO uint32 DCR; /**< DMA control register */ - __IO uint32 DMAR; /**< DMA address for full transfer */ -} timer_gen_reg_map; - -struct timer_adv_reg_map; -struct timer_bas_reg_map; - -/** Timer 1 register map base pointer */ -#define TIMER1_BASE ((struct timer_adv_reg_map*)0x40012C00) -/** Timer 2 register map base pointer */ -#define TIMER2_BASE ((struct timer_gen_reg_map*)0x40000000) -/** Timer 3 register map base pointer */ -#define TIMER3_BASE ((struct timer_gen_reg_map*)0x40000400) -/** Timer 4 register map base pointer */ -#define TIMER4_BASE ((struct timer_gen_reg_map*)0x40000800) - -/** Timer 6 register map base pointer */ -#define TIMER6_BASE ((struct timer_bas_reg_map*)0x40001000) -/** Timer 7 register map base pointer */ -#define TIMER7_BASE ((struct timer_bas_reg_map*)0x40001400) -/** Timer 8 register map base pointer */ -#define TIMER8_BASE ((struct timer_adv_reg_map*)0x40013400) - -/** Timer 15 register map base pointer */ -#define TIMER15_BASE ((struct timer_gen_reg_map*)0x40014000) -/** Timer 16 register map base pointer */ -#define TIMER16_BASE ((struct timer_gen_reg_map*)0x40014400) -/** Timer 17 register map base pointer */ -#define TIMER17_BASE ((struct timer_gen_reg_map*)0x40014800) - -/* - * Device pointers - * - * We only declare device pointers to timers which actually exist on - * the target MCU. - */ - -struct timer_dev; - -extern struct timer_dev *TIMER1; -extern struct timer_dev *TIMER2; /* FIXME 32bit-capable counter */ -extern struct timer_dev *TIMER3; -extern struct timer_dev *TIMER4; -extern struct timer_dev *TIMER6; -#if STM32_F3_LINE == STM32_F3_LINE_303 -extern struct timer_dev *TIMER7; -extern struct timer_dev *TIMER8; -#endif -extern struct timer_dev *TIMER15; -extern struct timer_dev *TIMER16; -extern struct timer_dev *TIMER17; - -/* - * Routines - */ - -gpio_af timer_get_af(struct timer_dev *dev); - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/include/series/usart.h b/STM32F3/cores/maple/libmaple/stm32f3/include/series/usart.h deleted file mode 100644 index 94a25d9..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/include/series/usart.h +++ /dev/null @@ -1,277 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/stm32f3/include/series/usart.h - * @author F3-port by Hanspeter Portner - * @brief STM32F3 USART support. - */ - -#ifndef _LIBMAPLE_STM32F3_USART_H_ -#define _LIBMAPLE_STM32F3_USART_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -#include /* for gpio_af */ - -/* - * Register maps - */ - -/** USART register map type */ -typedef struct usart_reg_map { - __IO uint32 CR1; /**< Control register 1 */ - __IO uint32 CR2; /**< Control register 2 */ - __IO uint32 CR3; /**< Control register 3 */ - __IO uint32 BRR; /**< Baud rate register */ - __IO uint32 GTPR; /**< Guard time and prescaler register */ - __IO uint32 RTOR; /**< Receiver timeout register */ - __IO uint32 RQR; /**< Request register */ - __IO uint32 SR; /**< ISR Interrupt and status register */ - __IO uint32 ICR; /**< Interrupt clear register */ - __IO uint16 RDR; /**< Receive data register */ - uint16 RESERVED1; - __IO uint16 TDR; /**< Transmit data register */ - uint16 RESERVED2; -} usart_reg_map; - -/* - * Register map base pointers - */ - -/** USART1 register map base pointer */ -#define USART1_BASE ((struct usart_reg_map*)0x40013800) -/** USART2 register map base pointer */ -#define USART2_BASE ((struct usart_reg_map*)0x40004400) -/** USART3 register map base pointer */ -#define USART3_BASE ((struct usart_reg_map*)0x40004800) - -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) -/** UART4 register map base pointer */ -#define UART4_BASE ((struct usart_reg_map*)0x40004C00) -/** UART5 register map base pointer */ -#define UART5_BASE ((struct usart_reg_map*)0x40005000) -#endif - -/* - * Devices - */ - -struct usart_dev; -extern struct usart_dev *USART1; -extern struct usart_dev *USART2; -extern struct usart_dev *USART3; -#ifdef STM32_HIGH_DENSITY -extern struct usart_dev *UART4; -extern struct usart_dev *UART5; -#endif - -/* - * F3-only register bit definitions. - */ - -/* Control register 1 */ -#define USART_CR1_EOBIE_BIT 27 -#define USART_CR1_RTOIE_BIT 26 -#define USART_CR1_DEAT4_BIT 25 -#define USART_CR1_DEAT3_BIT 24 -#define USART_CR1_DEAT2_BIT 23 -#define USART_CR1_DEAT1_BIT 22 -#define USART_CR1_DEAT0_BIT 21 -#define USART_CR1_DEDT4_BIT 20 -#define USART_CR1_DEDT3_BIT 19 -#define USART_CR1_DEDT2_BIT 18 -#define USART_CR1_DEDT1_BIT 17 -#define USART_CR1_DEDT0_BIT 16 -#define USART_CR1_OVER8_BIT 15 -#define USART_CR1_CMIE_BIT 14 -#define USART_CR1_MME_BIT 13 -#define USART_CR1_UESM_BIT 1 -#define USART_CR1_UE_BIT 0 - -#define USART_CR1_EOBIE (1UL << USART_CR1_EOBIE_BIT) -#define USART_CR1_RTOIE (1UL << USART_CR1_RTOIE_BIT) -#define USART_CR1_DEAT4 (1UL << USART_CR1_DEAT4_BIT) -#define USART_CR1_DEAT3 (1UL << USART_CR1_DEAT3_BIT) -#define USART_CR1_DEAT2 (1UL << USART_CR1_DEAT2_BIT) -#define USART_CR1_DEAT1 (1UL << USART_CR1_DEAT1_BIT) -#define USART_CR1_DEAT0 (1UL << USART_CR1_DEAT0_BIT) -#define USART_CR1_DEDT4 (1UL << USART_CR1_DEDT4_BIT) -#define USART_CR1_DEDT3 (1UL << USART_CR1_DEDT3_BIT) -#define USART_CR1_DEDT2 (1UL << USART_CR1_DEDT2_BIT) -#define USART_CR1_DEDT1 (1UL << USART_CR1_DEDT1_BIT) -#define USART_CR1_DEDT0 (1UL << USART_CR1_DEDT0_BIT) -#define USART_CR1_OVER8 (1UL << USART_CR1_OVER8_BIT) -#define USART_CR1_CMIE (1UL << USART_CR1_CMIE_BIT) -#define USART_CR1_MME (1UL << USART_CR1_MME_BIT) -#define USART_CR1_UESM (1UL << USART_CR1_UESM_BIT) -#define USART_CR1_UE (1UL << USART_CR1_UE_BIT) - -/* Control register 2 */ -#define USART_CR2_ADD_SHIFT 24 -#define USART_CR2_RTOEN_BIT 23 -#define USART_CR2_ABRMOD1_BIT 22 -#define USART_CR2_ABRMOD0_BIT 21 -#define USART_CR2_ABREN_BIT 20 -#define USART_CR2_MSBFIRST_BIT 19 -#define USART_CR2_DATAINV_BIT 18 -#define USART_CR2_TXINV_BIT 17 -#define USART_CR2_RXINV_BIT 16 -#define USART_CR2_SWAP_BIT 15 -#define USART_CR2_ADDM7_BIT 4 - -#define USART_CR2_ADD (0xFF << USART_CR2_ADD_SHIFT) -#define USART_CR2_RTOEN (1UL << USART_CR2_RTOEN_BIT) -#define USART_CR2_ABRMOD1 (1UL << USART_CR2_ABRMOD1_BIT) -#define USART_CR2_ABRMOD0 (1UL << USART_CR2_ABRMOD0_BIT) -#define USART_CR2_ABREN (1UL << USART_CR2_ABREN_BIT) -#define USART_CR2_MSBFIRST (1UL << USART_CR2_MSBFIRST_BIT) -#define USART_CR2_DATAINV (1UL << USART_CR2_DATAINV_BIT) -#define USART_CR2_TXINV (1UL << USART_CR2_TXINV_BIT) -#define USART_CR2_RXINV (1UL << USART_CR2_RXINV_BIT) -#define USART_CR2_SWAP (1UL << USART_CR2_SWAP_BIT) -#define USART_CR2_ADDM7 (1UL << USART_CR2_ADDM7_BIT) - -/* Control register 3 */ -#define USART_CR3_WUFIE_BIT 22 -#define USART_CR3_WUS_SHIFT 20 -#define USART_CR3_SCAR_SHIFT 17 -#define USART_CR3_DEP_BIT 15 -#define USART_CR3_DEM_BIT 14 -#define USART_CR3_DDRE_BIT 13 -#define USART_CR3_OVRDIS_BIT 12 -#define USART_CR3_ONEBIT_BIT 11 - -#define USART_CR3_WUFIE (1UL << USART_CR3_WUFIE_BIT) -#define USART_CR3_WUS (0x3 << USART_CR3_WUS_SHIFT) -#define USART_CR3_SCAR (0x7 << USART_CR3_SCAR_SHIFT) -#define USART_CR3_DEP (1UL << USART_CR3_DEP_BIT) -#define USART_CR3_DEM (1UL << USART_CR3_DEM_BIT) -#define USART_CR3_DDRE (1UL << USART_CR3_DDRE_BIT) -#define USART_CR3_OVRDIS (1UL << USART_CR3_OVRDIS_BIT) -#define USART_CR3_ONEBIT (1UL << USART_CR3_ONEBIT_BIT) - -/* Receive timeout register */ -#define USART_RTOR_BLEN_SHIFT 24 -#define USART_RTOR_RTO_SHIFT 0 - -#define USART_RTOR_BLEN (0xF << USART_RTOR_BLEN_SHIFT) -#define USART_RTOR_RTO (0xFFF << USART_RTOR_RTO_SHIFT) - -/* Request register */ -#define USART_RQR_TXFRQ_BIT 4 -#define USART_RQR_RXFRQ_BIT 3 -#define USART_RQR_MMRQ_BIT 2 -#define USART_RQR_SBKRQ_BIT 1 -#define USART_RQR_ABRRQ_BIT 0 - -#define USART_RQR_TXFRQ (1UL << USART_RQR_TXFRQ_BIT) -#define USART_RQR_RXFRQ (1UL << USART_RQR_RXFRQ_BIT) -#define USART_RQR_MMRQ (1UL << USART_RQR_MMRQ_BIT) -#define USART_RQR_SBKRQ (1UL << USART_RQR_SBKRQ_BIT) -#define USART_RQR_ABRRQ (1UL << USART_RQR_ABRRQ_BIT) - -/* Interrupt and status register */ -// common register bits with other STM32 series are defined as USART_SR_* for compatibility -#define USART_SR_REACK_BIT 22 -#define USART_SR_TEACK_BIT 21 -#define USART_SR_WUF_BIT 20 -#define USART_SR_RWU_BIT 19 -#define USART_SR_SBKF_BIT 18 -#define USART_SR_CMF_BIT 17 -#define USART_SR_BUSY_BIT 16 -#define USART_SR_ABRF_BIT 15 -#define USART_SR_ABRE_BIT 14 -#define USART_SR_EOBF_BIT 12 -#define USART_SR_RTOF_BIT 11 -#define USART_SR_CTS_BIT 10 -#define USART_SR_CTSIF_BIT 9 - -#define USART_SR_REACK (1UL << USART_ISR_REACK_BIT) -#define USART_SR_TEACK (1UL << USART_ISR_TEACK_BIT) -#define USART_SR_WUF (1UL << USART_ISR_WUF_BIT) -#define USART_SR_RWU (1UL << USART_ISR_RWU_BIT) -#define USART_SR_SBKF (1UL << USART_ISR_SBKF_BIT) -#define USART_SR_CMF (1UL << USART_ISR_CMF_BIT) -#define USART_SR_BUSY (1UL << USART_ISR_BUSY_BIT) -#define USART_SR_ABRF (1UL << USART_ISR_ABRF_BIT) -#define USART_SR_ABRE (1UL << USART_ISR_ABRE_BIT) -#define USART_SR_EOBF (1UL << USART_ISR_EOBF_BIT) -#define USART_SR_RTOF (1UL << USART_ISR_RTOF_BIT) -#define USART_SR_CTS (1UL << USART_ISR_CTS_BIT) -#define USART_SR_CTSIF (1UL << USART_ISR_CTSIF_BIT) - -/* Interrupt clear register */ -#define USART_ICR_WUFCF_BIT 20 -#define USART_ICR_CMCF_BIT 17 -#define USART_ICR_EOBCF_BIT 12 -#define USART_ICR_RTOCF_BIT 11 -#define USART_ICR_CTSCF_BIT 9 -#define USART_ICR_LBDCF_BIT 8 -#define USART_ICR_TCCF_BIT 6 -#define USART_ICR_IDLECF_BIT 4 -#define USART_ICR_ORECF_BIT 3 -#define USART_ICR_NCF_BIT 2 -#define USART_ICR_FECF_BIT 1 -#define USART_ICR_PECF_BIT 0 - -#define USART_ICR_WUFCF (1UL << USART_ICR_WUFCF_BIT) -#define USART_ICR_CMCF (1UL << USART_ICR_CMCF_BIT) -#define USART_ICR_EOBCF (1UL << USART_ICR_EOBCF_BIT) -#define USART_ICR_RTOCF (1UL << USART_ICR_RTOCF_BIT) -#define USART_ICR_CTSCF (1UL << USART_ICR_CTSCF_BIT) -#define USART_ICR_LBDCF (1UL << USART_ICR_LBDCF_BIT) -#define USART_ICR_TCCF (1UL << USART_ICR_TCCF_BIT) -#define USART_ICR_IDLECF (1UL << USART_ICR_IDLECF_BIT) -#define USART_ICR_ORECF (1UL << USART_ICR_ORECF_BIT) -#define USART_ICR_NCF (1UL << USART_ICR_NCF_BIT) -#define USART_ICR_FECF (1UL << USART_ICR_FECF_BIT) -#define USART_ICR_PECF (1UL << USART_ICR_PECF_BIT) - -/* Receive data register */ -#define USART_RDR_RDR_SHIFT 0 - -#define USART_RDR_RDR (0x1FF << USART_RDR_RDR_SHIFT) - - -/* Transmit data register */ -#define USART_TDR_TDR_SHIFT 0 - -#define USART_TDR_TDR (0x1FF << USART_TDR_TDR_SHIFT) - -/* - * Routines - */ - -gpio_af usart_get_af(struct usart_dev *dev); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/stm32f3/rules.mk b/STM32F3/cores/maple/libmaple/stm32f3/rules.mk deleted file mode 100644 index f17f745..0000000 --- a/STM32F3/cores/maple/libmaple/stm32f3/rules.mk +++ /dev/null @@ -1,48 +0,0 @@ -# Standard things -sp := $(sp).x -dirstack_$(sp) := $(d) -d := $(dir) -BUILDDIRS += $(BUILD_PATH)/$(d) - -# Local flags -CFLAGS_$(d) = -I$(d) $(LIBMAPLE_PRIVATE_INCLUDES) $(LIBMAPLE_INCLUDES) -Wall -Werror -ASFLAGS_$(d) = -I$(d) $(LIBMAPLE_PRIVATE_INCLUDES) $(LIBMAPLE_INCLUDES) -Wall -Werror - -# Extra BUILDDIRS -BUILDDIRS += $(BUILD_PATH)/$(d)/F30xxx - -# Local rules and targets -sSRCS_$(d) := F30xxx/isrs.S -sSRCS_$(d) += F30xxx/vector_table.S - -cSRCS_$(d) := adc.c -cSRCS_$(d) += dma.c -cSRCS_$(d) += exti.c -cSRCS_$(d) += gpio.c -cSRCS_$(d) += i2c.c -cSRCS_$(d) += rcc.c -cSRCS_$(d) += spi.c -cSRCS_$(d) += timer.c -cSRCS_$(d) += usart.c -cSRCS_$(d) += syscfg.c -cSRCS_$(d) += fpu.c -cSRCS_$(d) += comp.c -cSRCS_$(d) += opamp.c -cSRCS_$(d) += bkp.c - -sFILES_$(d) := $(sSRCS_$(d):%=$(d)/%) -cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%) - -OBJS_$(d) := $(sFILES_$(d):%.S=$(BUILD_PATH)/%.o) \ - $(cFILES_$(d):%.c=$(BUILD_PATH)/%.o) -DEPS_$(d) := $(OBJS_$(d):%.o=%.d) - -$(OBJS_$(d)): TGT_ASFLAGS := $(ASFLAGS_$(d)) -$(OBJS_$(d)): TGT_CFLAGS := $(CFLAGS_$(d)) - -TGT_BIN += $(OBJS_$(d)) - -# Standard things --include $(DEPS_$(d)) -d := $(dirstack_$(sp)) -sp := $(basename $(sp)) diff --git a/STM32F3/cores/maple/libmaple/syscfg.c b/STM32F3/cores/maple/libmaple/syscfg.c deleted file mode 100644 index 8b3c963..0000000 --- a/STM32F3/cores/maple/libmaple/syscfg.c +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/syscfg.c - * @brief System configuration controller (SYSCFG) - * @author F3-port by Hanspeter Portner - * - * Availability: STM32F2, STM32F3, STM32F4. - */ - -#include -#include - -void syscfg_init(void) { - rcc_clk_enable(RCC_SYSCFG); - rcc_reset_dev(RCC_SYSCFG); -} diff --git a/STM32F3/cores/maple/libmaple/systick.c b/STM32F3/cores/maple/libmaple/systick.c deleted file mode 100644 index 7568abe..0000000 --- a/STM32F3/cores/maple/libmaple/systick.c +++ /dev/null @@ -1,88 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2010, 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/systick.c - * @brief System timer (SysTick). - */ - -#include - -volatile uint32 systick_uptime_millis; -static void (*systick_user_callback)(void); - -/** - * @brief Initialize and enable SysTick. - * - * Clocks the system timer with the core clock, turns it on, and - * enables interrupts. - * - * @param reload_val Appropriate reload counter to tick every 1 ms. - */ -void systick_init(uint32 reload_val) { - SYSTICK_BASE->RVR = reload_val; - systick_enable(); -} - -/** - * Clock the system timer with the core clock, but don't turn it - * on or enable interrupt. - */ -void systick_disable() { - SYSTICK_BASE->CSR = SYSTICK_CSR_CLKSOURCE_CORE; -} - -/** - * Clock the system timer with the core clock and turn it on; - * interrupt every 1 ms, for systick_timer_millis. - */ -void systick_enable() { - /* re-enables init registers without changing reload val */ - SYSTICK_BASE->CSR = (SYSTICK_CSR_CLKSOURCE_CORE | - SYSTICK_CSR_ENABLE | - SYSTICK_CSR_TICKINT_PEND); -} - -/** - * @brief Attach a callback to be called from the SysTick exception handler. - * - * To detach a callback, call this function again with a null argument. - */ -void systick_attach_callback(void (*callback)(void)) { - systick_user_callback = callback; -} - -/* - * SysTick ISR - */ - -void __exc_systick(void) { - systick_uptime_millis++; - if (systick_user_callback) { - systick_user_callback(); - } -} diff --git a/STM32F3/cores/maple/libmaple/timer.c b/STM32F3/cores/maple/libmaple/timer.c deleted file mode 100644 index e48cb1a..0000000 --- a/STM32F3/cores/maple/libmaple/timer.c +++ /dev/null @@ -1,456 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/timer.c - * @author Marti Bolivar - * @brief Portable timer routines. - */ - -#include -#include -#include "timer_private.h" - -static void disable_channel(timer_dev *dev, uint8 channel); -static void pwm_mode(timer_dev *dev, uint8 channel); -static void output_compare_mode(timer_dev *dev, uint8 channel); - -static inline void enable_irq(timer_dev *dev, uint8 interrupt); - -/* - * Devices - * - * Defer to the timer_private API for declaring these. - */ - -#if STM32_HAVE_TIMER(1) -static timer_dev timer1 = ADVANCED_TIMER(1); -/** Timer 1 device (advanced) */ -timer_dev *TIMER1 = &timer1; -#endif -#if STM32_HAVE_TIMER(2) -static timer_dev timer2 = GENERAL_TIMER(2); -/** Timer 2 device (general-purpose) */ -timer_dev *TIMER2 = &timer2; -#endif -#if STM32_HAVE_TIMER(3) -static timer_dev timer3 = GENERAL_TIMER(3); -/** Timer 3 device (general-purpose) */ -timer_dev *TIMER3 = &timer3; -#endif -#if STM32_HAVE_TIMER(4) -static timer_dev timer4 = GENERAL_TIMER(4); -/** Timer 4 device (general-purpose) */ -timer_dev *TIMER4 = &timer4; -#endif -#if STM32_HAVE_TIMER(5) -static timer_dev timer5 = GENERAL_TIMER(5); -/** Timer 5 device (general-purpose) */ -timer_dev *TIMER5 = &timer5; -#endif -#if STM32_HAVE_TIMER(6) -static timer_dev timer6 = BASIC_TIMER(6); -/** Timer 6 device (basic) */ -timer_dev *TIMER6 = &timer6; -#endif -#if STM32_HAVE_TIMER(7) -static timer_dev timer7 = BASIC_TIMER(7); -/** Timer 7 device (basic) */ -timer_dev *TIMER7 = &timer7; -#endif -#if STM32_HAVE_TIMER(8) -static timer_dev timer8 = ADVANCED_TIMER(8); -/** Timer 8 device (advanced) */ -timer_dev *TIMER8 = &timer8; -#endif -#if STM32_HAVE_TIMER(9) -static timer_dev timer9 = RESTRICTED_GENERAL_TIMER(9, TIMER_DIER_TIE_BIT); -/** Timer 9 device (general-purpose) */ -timer_dev *TIMER9 = &timer9; -#endif -#if STM32_HAVE_TIMER(10) -static timer_dev timer10 = RESTRICTED_GENERAL_TIMER(10, TIMER_DIER_CC1IE_BIT); -/** Timer 10 device (general-purpose) */ -timer_dev *TIMER10 = &timer10; -#endif -#if STM32_HAVE_TIMER(11) -static timer_dev timer11 = RESTRICTED_GENERAL_TIMER(11, TIMER_DIER_CC1IE_BIT); -/** Timer 11 device (general-purpose) */ -timer_dev *TIMER11 = &timer11; -#endif -#if STM32_HAVE_TIMER(12) -static timer_dev timer12 = RESTRICTED_GENERAL_TIMER(12, TIMER_DIER_TIE_BIT); -/** Timer 12 device (general-purpose) */ -timer_dev *TIMER12 = &timer12; -#endif -#if STM32_HAVE_TIMER(13) -static timer_dev timer13 = RESTRICTED_GENERAL_TIMER(13, TIMER_DIER_CC1IE_BIT); -/** Timer 13 device (general-purpose) */ -timer_dev *TIMER13 = &timer13; -#endif -#if STM32_HAVE_TIMER(14) -static timer_dev timer14 = RESTRICTED_GENERAL_TIMER(14, TIMER_DIER_CC1IE_BIT); -/** Timer 14 device (general-purpose) */ -timer_dev *TIMER14 = &timer14; -#endif -#if STM32_HAVE_TIMER(15) -static timer_dev timer15 = RESTRICTED_GENERAL_TIMER(15, TIMER_DIER_TIE_BIT); //XXX -/** Timer 15 device (general-purpose) */ -timer_dev *TIMER15 = &timer15; -#endif -#if STM32_HAVE_TIMER(16) -static timer_dev timer16 = RESTRICTED_GENERAL_TIMER(16, TIMER_DIER_CC1IE_BIT); //XXX -/** Timer 16 device (general-purpose) */ -timer_dev *TIMER16 = &timer16; -#endif -#if STM32_HAVE_TIMER(17) -static timer_dev timer17 = RESTRICTED_GENERAL_TIMER(17, TIMER_DIER_CC1IE_BIT); //XXX -/** Timer 17 device (general-purpose) */ -timer_dev *TIMER17 = &timer17; -#endif - -/* - * Routines - */ - -/** - * @brief Call a function on timer devices. - * @param fn Function to call on each timer device. - */ -void timer_foreach(void (*fn)(timer_dev*)) { -#if STM32_HAVE_TIMER(1) - fn(TIMER1); -#endif -#if STM32_HAVE_TIMER(2) - fn(TIMER2); -#endif -#if STM32_HAVE_TIMER(3) - fn(TIMER3); -#endif -#if STM32_HAVE_TIMER(4) - fn(TIMER4); -#endif -#if STM32_HAVE_TIMER(5) - fn(TIMER5); -#endif -#if STM32_HAVE_TIMER(6) - fn(TIMER6); -#endif -#if STM32_HAVE_TIMER(7) - fn(TIMER7); -#endif -#if STM32_HAVE_TIMER(8) - fn(TIMER8); -#endif -#if STM32_HAVE_TIMER(9) - fn(TIMER9); -#endif -#if STM32_HAVE_TIMER(10) - fn(TIMER10); -#endif -#if STM32_HAVE_TIMER(11) - fn(TIMER11); -#endif -#if STM32_HAVE_TIMER(12) - fn(TIMER12); -#endif -#if STM32_HAVE_TIMER(13) - fn(TIMER13); -#endif -#if STM32_HAVE_TIMER(14) - fn(TIMER14); -#endif -#if STM32_HAVE_TIMER(15) - fn(TIMER15); -#endif -#if STM32_HAVE_TIMER(16) - fn(TIMER16); -#endif -#if STM32_HAVE_TIMER(17) - fn(TIMER17); -#endif -} - -/** - * Initialize a timer, and reset its register map. - * @param dev Timer to initialize - */ -void timer_init(timer_dev *dev) { - rcc_clk_enable(dev->clk_id); - rcc_reset_dev(dev->clk_id); -} - -/** - * @brief Disable a timer. - * - * The timer will stop counting, all DMA requests and interrupts will - * be disabled, and no state changes will be output. - * - * @param dev Timer to disable. - */ -void timer_disable(timer_dev *dev) { - (dev->regs).bas->CR1 = 0; - (dev->regs).bas->DIER = 0; - switch (dev->type) { - case TIMER_ADVANCED: /* fall-through */ - case TIMER_GENERAL: - (dev->regs).gen->CCER = 0; - break; - case TIMER_BASIC: - break; - } -} - -/** - * Sets the mode of an individual timer channel. - * - * Note that not all timers can be configured in every mode. For - * example, basic timers cannot be configured to output compare mode. - * Be sure to use a timer which is appropriate for the mode you want. - * - * @param dev Timer whose channel mode to set - * @param channel Relevant channel - * @param mode New timer mode for channel - */ -void timer_set_mode(timer_dev *dev, uint8 channel, timer_mode mode) { - ASSERT_FAULT(channel > 0 && channel <= 4); - - /* TODO decide about the basic timers */ - ASSERT(dev->type != TIMER_BASIC); - if (dev->type == TIMER_BASIC) - return; - - switch (mode) { - case TIMER_DISABLED: - disable_channel(dev, channel); - break; - case TIMER_PWM: - pwm_mode(dev, channel); - break; - case TIMER_OUTPUT_COMPARE: - output_compare_mode(dev, channel); - break; - } -} - -/** - * @brief Determine whether a timer has a particular capture/compare channel. - * - * Different timers have different numbers of capture/compare channels - * (and some have none at all). Use this function to test whether a - * given timer/channel combination will work. - * - * @param dev Timer device - * @param channel Capture/compare channel, from 1 to 4 - * @return Nonzero if dev has channel, zero otherwise. - */ -int timer_has_cc_channel(timer_dev *dev, uint8 channel) { - /* On all currently supported series: advanced and "full-featured" - * general purpose timers have all four channels. Of the - * restricted general timers, timers 9, 12 and 15 have channels 1 and - * 2; the others have channel 1 only. Basic timers have none. */ - rcc_clk_id id = dev->clk_id; - ASSERT((1 <= channel) && (channel <= 4)); - if (id <= RCC_TIMER5 || id == RCC_TIMER8) { - return 1; /* 1 and 8 are advanced, 2-5 are "full" general */ - } else if (id <= RCC_TIMER7) { - return 0; /* 6 and 7 are basic */ - } - /* The rest are restricted general. */ - return (((id == RCC_TIMER9 || id == RCC_TIMER12 || id == RCC_TIMER15) && channel <= 2) || - channel == 1); -} - -/** - * @brief Attach a timer interrupt. - * @param dev Timer device - * @param interrupt Interrupt number to attach to; this may be any - * timer_interrupt_id or timer_channel value appropriate - * for the timer. - * @param handler Handler to attach to the given interrupt. - * @see timer_interrupt_id - * @see timer_channel - */ -void timer_attach_interrupt(timer_dev *dev, - uint8 interrupt, - voidFuncPtr handler) { - dev->handlers[interrupt] = handler; - timer_enable_irq(dev, interrupt); - enable_irq(dev, interrupt); -} - -/** - * @brief Detach a timer interrupt. - * @param dev Timer device - * @param interrupt Interrupt number to detach; this may be any - * timer_interrupt_id or timer_channel value appropriate - * for the timer. - * @see timer_interrupt_id - * @see timer_channel - */ -void timer_detach_interrupt(timer_dev *dev, uint8 interrupt) { - timer_disable_irq(dev, interrupt); - dev->handlers[interrupt] = NULL; -} - -/* - * Utilities - */ - -static void disable_channel(timer_dev *dev, uint8 channel) { - timer_detach_interrupt(dev, channel); - timer_cc_disable(dev, channel); -} - -static void pwm_mode(timer_dev *dev, uint8 channel) { - timer_disable_irq(dev, channel); - timer_oc_set_mode(dev, channel, TIMER_OC_MODE_PWM_1, TIMER_OC_PE); - timer_cc_enable(dev, channel); -} - -static void output_compare_mode(timer_dev *dev, uint8 channel) { - timer_oc_set_mode(dev, channel, TIMER_OC_MODE_ACTIVE_ON_MATCH, 0); - timer_cc_enable(dev, channel); -} - -static void enable_adv_irq(timer_dev *dev, timer_interrupt_id id); -static void enable_bas_gen_irq(timer_dev *dev); - -static inline void enable_irq(timer_dev *dev, timer_interrupt_id iid) { - if (dev->type == TIMER_ADVANCED) { - enable_adv_irq(dev, iid); - } else { - enable_bas_gen_irq(dev); - } -} - -/* Advanced control timers have several IRQ lines corresponding to - * different timer interrupts. - * - * Note: This function assumes that the only advanced timers are TIM1 - * and TIM8, and needs the obvious changes if that assumption is - * violated by a later STM32 series. */ -static void enable_adv_irq(timer_dev *dev, timer_interrupt_id id) { - uint8 is_tim1 = dev->clk_id == RCC_TIMER1; - nvic_irq_num irq_num; - switch (id) { - case TIMER_UPDATE_INTERRUPT: - irq_num = (is_tim1 ? - NVIC_TIMER1_UP_TIMER10 : - NVIC_TIMER8_UP_TIMER13); - break; - case TIMER_CC1_INTERRUPT: /* Fall through */ - case TIMER_CC2_INTERRUPT: /* ... */ - case TIMER_CC3_INTERRUPT: /* ... */ - case TIMER_CC4_INTERRUPT: - irq_num = is_tim1 ? NVIC_TIMER1_CC : NVIC_TIMER8_CC; - break; - case TIMER_COM_INTERRUPT: /* Fall through */ - case TIMER_TRG_INTERRUPT: - irq_num = (is_tim1 ? - NVIC_TIMER1_TRG_COM_TIMER11 : - NVIC_TIMER8_TRG_COM_TIMER14); - break; - case TIMER_BREAK_INTERRUPT: - irq_num = (is_tim1 ? - NVIC_TIMER1_BRK_TIMER9 : - NVIC_TIMER8_BRK_TIMER12); - break; - default: - /* Can't happen, but placate the compiler */ - ASSERT(0); - return; - } - nvic_irq_enable(irq_num); -} - -/* Basic and general purpose timers have a single IRQ line, which is - * shared by all interrupts supported by a particular timer. */ -static void enable_bas_gen_irq(timer_dev *dev) { - nvic_irq_num irq_num; - switch (dev->clk_id) { - case RCC_TIMER2: - irq_num = NVIC_TIMER2; - break; - case RCC_TIMER3: - irq_num = NVIC_TIMER3; - break; - case RCC_TIMER4: - irq_num = NVIC_TIMER4; - break; -#if STM32_HAVE_TIMER(5) - case RCC_TIMER5: - irq_num = NVIC_TIMER5; - break; -#endif - case RCC_TIMER6: - irq_num = NVIC_TIMER6; - break; - case RCC_TIMER7: - irq_num = NVIC_TIMER7; - break; - case RCC_TIMER9: - irq_num = NVIC_TIMER1_BRK_TIMER9; - break; - case RCC_TIMER10: - irq_num = NVIC_TIMER1_UP_TIMER10; - break; - case RCC_TIMER11: - irq_num = NVIC_TIMER1_TRG_COM_TIMER11; - break; - case RCC_TIMER12: - irq_num = NVIC_TIMER8_BRK_TIMER12; - break; - case RCC_TIMER13: - irq_num = NVIC_TIMER8_UP_TIMER13; - break; - case RCC_TIMER14: - irq_num = NVIC_TIMER8_TRG_COM_TIMER14; - break; -#if STM32_HAVE_TIMER(15) - case RCC_TIMER15: - //irq_num = NVIC_TIMER1_BRK_TIMER15; - irq_num = NVIC_TIMER1_BRK_TIMER9; - break; -#endif -#if STM32_HAVE_TIMER(16) - case RCC_TIMER16: - //irq_num = NVIC_TIMER1_UP_TIMER16; - irq_num = NVIC_TIMER1_UP_TIMER10; - break; -#endif -#if STM32_HAVE_TIMER(17) - case RCC_TIMER17: - //irq_num = NVIC_TIMER1_TRG_COM_TIMER17; - irq_num = NVIC_TIMER1_TRG_COM_TIMER11; - break; -#endif - default: - ASSERT_FAULT(0); - return; - } - nvic_irq_enable(irq_num); -} diff --git a/STM32F3/cores/maple/libmaple/timer_private.h b/STM32F3/cores/maple/libmaple/timer_private.h deleted file mode 100644 index 320c636..0000000 --- a/STM32F3/cores/maple/libmaple/timer_private.h +++ /dev/null @@ -1,235 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/timer_private.h - * @author Marti Bolivar - * @brief Private, internal timer APIs. - */ - -#ifndef _LIBMAPLE_TIMER_PRIVATE_H_ -#define _LIBMAPLE_TIMER_PRIVATE_H_ - -/* - * Helper macros for declaring timer_devs of various timer_types - */ - -/* The indexes of user handlers in a timer_dev.handlers are just like - * the corresponding DIER bits, as follows: */ - -/* Advanced timers: - * [0] = Update handler; - * [1,2,3,4] = capture/compare 1,2,3,4 handlers, respectively; - * [5] = COM; - * [6] = TRG; - * [7] = BRK. */ -#define NR_ADV_HANDLERS 8 -/* General purpose timers: - * [0] = update; - * [1,2,3,4] = capture/compare 1,2,3,4; - * [5] = ; - * [6] = trigger. */ -#define NR_GEN_HANDLERS 7 -/* Basic timers: - * [0] = update. */ -#define NR_BAS_HANDLERS 1 - -/* For declaring advanced timers. */ -#define ADVANCED_TIMER(num) \ - { \ - .regs = { .adv = TIMER##num##_BASE }, \ - .clk_id = RCC_TIMER##num, \ - .type = TIMER_ADVANCED, \ - .handlers = { [NR_ADV_HANDLERS - 1] = 0 }, \ - } - -/* For declaring full-featured general purpose timers. */ -#define GENERAL_TIMER(num) \ - { \ - .regs = { .gen = TIMER##num##_BASE }, \ - .clk_id = RCC_TIMER##num, \ - .type = TIMER_GENERAL, \ - .handlers = { [NR_GEN_HANDLERS - 1] = 0 }, \ - } - -/* For declaring general purpose timers with limited interrupt - * capability (e.g. timers 9 through 14 on STM32F2 and XL-density - * STM32F1). */ -#define RESTRICTED_GENERAL_TIMER(num, max_dier_bit) \ - { \ - .regs = { .gen = TIMER##num##_BASE }, \ - .clk_id = RCC_TIMER##num, \ - .type = TIMER_GENERAL, \ - .handlers = { [max_dier_bit] = 0 }, \ - } - -/* For declaring basic timers (e.g. TIM6 and TIM7). */ -#define BASIC_TIMER(num) \ - { \ - .regs = { .bas = TIMER##num##_BASE }, \ - .clk_id = RCC_TIMER##num, \ - .type = TIMER_BASIC, \ - .handlers = { [NR_BAS_HANDLERS - 1] = 0 }, \ - } - -/* - * IRQ handlers - * - * These decode TIMx_DIER and TIMx_SR, then dispatch to the user-level - * IRQ handlers. They also clean up TIMx_SR afterwards, so the user - * doesn't have to deal with register details. - * - * Notes: - * - * - These dispatch routines make use of the fact that DIER interrupt - * enable bits and SR interrupt flags have common bit positions. - * Thus, ANDing DIER and SR lets us check if an interrupt is enabled - * and if it has occurred simultaneously. - * - * - We force these routines to inline to avoid call overhead, but - * there aren't any measurements to prove that this is actually a - * good idea. Profile-directed optimizations are definitely wanted. */ - -/* A special-case dispatch routine for timers which only serve a - * single interrupt on a given IRQ line. - * - * This function still checks DIER & SR, as in some cases, a timer may - * only serve a single interrupt on a particular NVIC line, but that - * line may be shared with another timer. For example, the timer 1 - * update interrupt shares an IRQ line with the timer 10 interrupt on - * STM32F1 (XL-density), STM32F2, and STM32F4. */ -static __always_inline void dispatch_single_irq(timer_dev *dev, - timer_interrupt_id iid, - uint32 irq_mask) { - timer_bas_reg_map *regs = (dev->regs).bas; - if (regs->DIER & regs->SR & irq_mask) { - void (*handler)(void) = dev->handlers[iid]; - if (handler) { - handler(); - regs->SR &= ~irq_mask; - } - } -} - -/* Helper macro for dispatch routines which service multiple interrupts. */ -#define handle_irq(dier_sr, irq_mask, handlers, iid, handled_irq) do { \ - if ((dier_sr) & (irq_mask)) { \ - void (*__handler)(void) = (handlers)[iid]; \ - if (__handler) { \ - __handler(); \ - handled_irq |= (irq_mask); \ - } \ - } \ - } while (0) - -static __always_inline void dispatch_adv_brk(timer_dev *dev) { - dispatch_single_irq(dev, TIMER_BREAK_INTERRUPT, TIMER_SR_BIF); -} - -static __always_inline void dispatch_adv_up(timer_dev *dev) { - dispatch_single_irq(dev, TIMER_UPDATE_INTERRUPT, TIMER_SR_UIF); -} - -static __always_inline void dispatch_adv_trg_com(timer_dev *dev) { - timer_adv_reg_map *regs = (dev->regs).adv; - uint32 dsr = regs->DIER & regs->SR; - void (**hs)(void) = dev->handlers; - uint32 handled = 0; /* Logical OR of SR interrupt flags we end up - * handling. We clear these. User handlers - * must clear overcapture flags, to avoid - * wasting time in output mode. */ - - handle_irq(dsr, TIMER_SR_TIF, hs, TIMER_TRG_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_COMIF, hs, TIMER_COM_INTERRUPT, handled); - - regs->SR &= ~handled; -} - -static __always_inline void dispatch_adv_cc(timer_dev *dev) { - timer_adv_reg_map *regs = (dev->regs).adv; - uint32 dsr = regs->DIER & regs->SR; - void (**hs)(void) = dev->handlers; - uint32 handled = 0; - - handle_irq(dsr, TIMER_SR_CC4IF, hs, TIMER_CC4_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_CC3IF, hs, TIMER_CC3_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_CC2IF, hs, TIMER_CC2_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_CC1IF, hs, TIMER_CC1_INTERRUPT, handled); - - regs->SR &= ~handled; -} - -static __always_inline void dispatch_general(timer_dev *dev) { - timer_gen_reg_map *regs = (dev->regs).gen; - uint32 dsr = regs->DIER & regs->SR; - void (**hs)(void) = dev->handlers; - uint32 handled = 0; - - handle_irq(dsr, TIMER_SR_TIF, hs, TIMER_TRG_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_CC4IF, hs, TIMER_CC4_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_CC3IF, hs, TIMER_CC3_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_CC2IF, hs, TIMER_CC2_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_CC1IF, hs, TIMER_CC1_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_UIF, hs, TIMER_UPDATE_INTERRUPT, handled); - - regs->SR &= ~handled; -} - -/* On F1 (XL-density), F2, and F4, TIM9 and TIM12 are restricted - * general-purpose timers with update, CC1, CC2, and TRG interrupts. */ -static __always_inline void dispatch_tim_9_12(timer_dev *dev) { - timer_gen_reg_map *regs = (dev->regs).gen; - uint32 dsr = regs->DIER & regs->SR; - void (**hs)(void) = dev->handlers; - uint32 handled = 0; - - handle_irq(dsr, TIMER_SR_TIF, hs, TIMER_TRG_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_CC2IF, hs, TIMER_CC2_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_CC1IF, hs, TIMER_CC1_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_UIF, hs, TIMER_UPDATE_INTERRUPT, handled); - - regs->SR &= ~handled; -} - -/* On F1 (XL-density), F2, and F4, timers 10, 11, 13, and 14 are - * restricted general-purpose timers with update and CC1 interrupts. */ -static __always_inline void dispatch_tim_10_11_13_14(timer_dev *dev) { - timer_gen_reg_map *regs = (dev->regs).gen; - uint32 dsr = regs->DIER & regs->SR; - void (**hs)(void) = dev->handlers; - uint32 handled = 0; - - handle_irq(dsr, TIMER_SR_CC1IF, hs, TIMER_CC1_INTERRUPT, handled); - handle_irq(dsr, TIMER_SR_UIF, hs, TIMER_UPDATE_INTERRUPT, handled); - - regs->SR &= ~handled; -} - -static __always_inline void dispatch_basic(timer_dev *dev) { - dispatch_single_irq(dev, TIMER_UPDATE_INTERRUPT, TIMER_SR_UIF); -} - -#endif diff --git a/STM32F3/cores/maple/libmaple/usart.c b/STM32F3/cores/maple/libmaple/usart.c deleted file mode 100644 index 52da4d1..0000000 --- a/STM32F3/cores/maple/libmaple/usart.c +++ /dev/null @@ -1,122 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/usart.c - * @author Marti Bolivar , - * Perry Hung - * @brief Portable USART routines - */ - -#include - -/** - * @brief Initialize a serial port. - * @param dev Serial port to be initialized - */ -void usart_init(usart_dev *dev) { - rb_init(dev->rb, USART_RX_BUF_SIZE, dev->rx_buf); - rcc_clk_enable(dev->clk_id); - nvic_irq_enable(dev->irq_num); -} - -/** - * @brief Enable a serial port. - * - * USART is enabled in single buffer transmission mode, multibuffer - * receiver mode, 8n1. - * - * Serial port must have a baud rate configured to work properly. - * - * @param dev Serial port to enable. - * @see usart_set_baud_rate() - */ -void usart_enable(usart_dev *dev) { - usart_reg_map *regs = dev->regs; - regs->CR1 = (USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE | - USART_CR1_M_8N1); - regs->CR1 |= USART_CR1_UE; -} - -/** - * @brief Turn off a serial port. - * @param dev Serial port to be disabled - */ -void usart_disable(usart_dev *dev) { - /* FIXME this misbehaves (on F1) if you try to use PWM on TX afterwards */ - usart_reg_map *regs = dev->regs; - - /* TC bit must be high before disabling the USART */ - while((regs->CR1 & USART_CR1_UE) && !(regs->SR & USART_SR_TC)) - ; - - /* Disable UE */ - regs->CR1 &= ~USART_CR1_UE; - - /* Clean up buffer */ - usart_reset_rx(dev); -} - -/** - * @brief Nonblocking USART receive. - * @param dev Serial port to receive bytes from - * @param buf Buffer to store received bytes into - * @param len Maximum number of bytes to store - * @return Number of bytes received - */ -uint32 usart_rx(usart_dev *dev, uint8 *buf, uint32 len) { - uint32 rxed = 0; - while (usart_data_available(dev) && rxed < len) { - *buf++ = usart_getc(dev); - rxed++; - } - return rxed; -} - -/** - * @brief Transmit an unsigned integer to the specified serial port in - * decimal format. - * - * This function blocks until the integer's digits have been - * completely transmitted. - * - * @param dev Serial port to send on - * @param val Number to print - */ -void usart_putudec(usart_dev *dev, uint32 val) { - char digits[12]; - int i = 0; - - do { - digits[i++] = val % 10 + '0'; - val /= 10; - } while (val > 0); - - while (--i >= 0) { - usart_putc(dev, digits[i]); - } -} diff --git a/STM32F3/cores/maple/libmaple/usart_private.c b/STM32F3/cores/maple/libmaple/usart_private.c deleted file mode 100644 index 0eaacdf..0000000 --- a/STM32F3/cores/maple/libmaple/usart_private.c +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/usart_private.c - * @author Marti Bolivar - * @brief Private USART routines. - */ - -#include "usart_private.h" -#include -#include - -uint32 _usart_clock_freq(usart_dev *dev) { - rcc_clk_domain domain = rcc_dev_clk(dev->clk_id); - return (domain == RCC_APB1 ? STM32_PCLK1 : - (domain == RCC_APB2 ? STM32_PCLK2 : 0)); -} diff --git a/STM32F3/cores/maple/libmaple/usart_private.h b/STM32F3/cores/maple/libmaple/usart_private.h deleted file mode 100644 index e6044d8..0000000 --- a/STM32F3/cores/maple/libmaple/usart_private.h +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/usart_private.h - * @author Marti Bolivar - * @brief Private USART header. - */ - -#ifndef _LIBMAPLE_USART_PRIVATE_H_ -#define _LIBMAPLE_USART_PRIVATE_H_ - -#include -#include - -uint32 _usart_clock_freq(usart_dev *dev); - -#endif diff --git a/STM32F3/cores/maple/libmaple/usb/README b/STM32F3/cores/maple/libmaple/usb/README deleted file mode 100644 index d0fca8d..0000000 --- a/STM32F3/cores/maple/libmaple/usb/README +++ /dev/null @@ -1,63 +0,0 @@ -The USB submodule of libmaple is a separate piece of the codebase for -reasons that are largely historical. - -Current Status: - - There's only support for the USB device peripheral found on - STM32F103s. - - We rely on the low level core library provided by ST to implement - the USB transfer protocol for control endpoint transfers. - - The virtual com port (which is exposed via - ) serves two important purposes. - - 1) It allows serial data transfers between user sketches an a - host computer. - - 2) It allows the host PC to issue a system reset into the DFU - bootloader with the DTR + RTS + "1EAF" sequence (see - leaflabs.com/docs/bootloader.html for more information on - this). - - After reset, Maple will run the DFU bootloader for a few seconds, - during which the user can begin a DFU upload operation (uploads - application binary into RAM/FLASH). Thus, without this virtual com - port, it would be necessary to find an alternative means to reset - the chip in order to enable the bootloader. - - If you would like to develop your own USB application for whatever - reason (e.g. to use faster isochronous enpoints for streaming - audio, or implement the USB HID or Mass Storage specs), then - ensure that you leave some hook for resetting Maple remotely in - order to spin up the DFU bootloader. Please make sure to get - yourself a unique vendor/product ID pair for your application, as - some operating systems will assign a host-side driver based on - these tags. - - It would be possible to build a compound USB device, that - implements endpoints for both the virtual COM port as well as some - other components (mass storage etc.). However, this turns out to - be a burden from the host driver side, as Windows and *nix handle - compound USB devices quite differently. - - Be mindful that enabling the USB peripheral isn't "free." The - device must respond to periodic bus activity (every few - milliseconds) by servicing an ISR. Therefore, the USB application - should be disabled inside of timing critical applications. - - In order to disconnect the device from the host, a USB_DISC pin is - asserted (e.g. on Maple, this is PC12). Alternatively, the NVIC - can be directly configured to disable the USB LP/HP IRQ's. - - The files inside of usb_lib were provided by ST and are subject to - their own license, all other files were written by the LeafLabs - team and fall under the MIT license. - -TODO: - - - Generic USB driver core with series-provided backends, like - libopencm3 has. - - Strip out ST code. - - Integration with a high level USB library (like LUFA/MyUSB) to - allow users to write custom USB applications. diff --git a/STM32F3/cores/maple/libmaple/usb/usb.c b/STM32F3/cores/maple/libmaple/usb/usb.c deleted file mode 100644 index f694f04..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb.c +++ /dev/null @@ -1,387 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/usb/stm32f1/usb.c - * @brief USB support. - * - * This is a mess. - */ - -#include - -#include -#include - -/* Private headers */ -#include "usb_reg_map.h" -#include "usb_lib_globals.h" - -/* usb_lib headers */ -#include "usb_type.h" -#include "usb_core.h" - -static void dispatch_ctr_lp(void); - -/* - * usb_lib/ globals - */ - -uint16 SaveTState; /* caches TX status for later use */ -uint16 SaveRState; /* caches RX status for later use */ - -/* - * Other state - */ - -typedef enum { - RESUME_EXTERNAL, - RESUME_INTERNAL, - RESUME_LATER, - RESUME_WAIT, - RESUME_START, - RESUME_ON, - RESUME_OFF, - RESUME_ESOF -} RESUME_STATE; - -struct { - volatile RESUME_STATE eState; - volatile uint8 bESOFcnt; -} ResumeS; - -static usblib_dev usblib = { - .irq_mask = USB_ISR_MSK, - .state = USB_UNCONNECTED, - .prevState = USB_UNCONNECTED, - .clk_id = RCC_USB, -}; -usblib_dev *USBLIB = &usblib; - -/* - * Routines - */ - -void usb_init_usblib(usblib_dev *dev, - void (**ep_int_in)(void), - void (**ep_int_out)(void)) { - rcc_clk_enable(dev->clk_id); - - dev->ep_int_in = ep_int_in; - dev->ep_int_out = ep_int_out; - - /* usb_lib/ declares both and then assumes that pFoo points to Foo - * (even though the names don't always match), which is stupid for - * all of the obvious reasons, but whatever. Here we are. */ - pInformation = &Device_Info; - pProperty = &Device_Property; - pUser_Standard_Requests = &User_Standard_Requests; - - pInformation->ControlState = 2; /* FIXME [0.0.12] use - CONTROL_STATE enumerator */ - pProperty->Init(); -} - -static void usb_suspend(void) { - uint16 cntr; - - /* TODO decide if read/modify/write is really what we want - * (e.g. usb_resume_init() reconfigures CNTR). */ - cntr = USB_BASE->CNTR; - cntr |= USB_CNTR_FSUSP; - USB_BASE->CNTR = cntr; - cntr |= USB_CNTR_LP_MODE; - USB_BASE->CNTR = cntr; - - USBLIB->prevState = USBLIB->state; - USBLIB->state = USB_SUSPENDED; -} - -static void usb_resume_init(void) { - uint16 cntr; - - cntr = USB_BASE->CNTR; - cntr &= ~USB_CNTR_LP_MODE; - USB_BASE->CNTR = cntr; - - /* Enable interrupt lines */ - USB_BASE->CNTR = USB_ISR_MSK; -} - -static void usb_resume(RESUME_STATE eResumeSetVal) { - uint16 cntr; - - if (eResumeSetVal != RESUME_ESOF) { - ResumeS.eState = eResumeSetVal; - } - - switch (ResumeS.eState) { - case RESUME_EXTERNAL: - usb_resume_init(); - ResumeS.eState = RESUME_OFF; - USBLIB->state = USBLIB->prevState; - break; - case RESUME_INTERNAL: - usb_resume_init(); - ResumeS.eState = RESUME_START; - break; - case RESUME_LATER: - ResumeS.bESOFcnt = 2; - ResumeS.eState = RESUME_WAIT; - break; - case RESUME_WAIT: - ResumeS.bESOFcnt--; - if (ResumeS.bESOFcnt == 0) { - ResumeS.eState = RESUME_START; - } - break; - case RESUME_START: - cntr = USB_BASE->CNTR; - cntr |= USB_CNTR_RESUME; - USB_BASE->CNTR = cntr; - ResumeS.eState = RESUME_ON; - ResumeS.bESOFcnt = 10; - break; - case RESUME_ON: - ResumeS.bESOFcnt--; - if (ResumeS.bESOFcnt == 0) { - cntr = USB_BASE->CNTR; - cntr &= ~USB_CNTR_RESUME; - USB_BASE->CNTR = cntr; - USBLIB->state = USBLIB->prevState; - ResumeS.eState = RESUME_OFF; - } - break; - case RESUME_OFF: - case RESUME_ESOF: - default: - ResumeS.eState = RESUME_OFF; - break; - } -} - -#define SUSPEND_ENABLED 1 -void __irq_usb_lp_can_rx0(void) { - uint16 istr = USB_BASE->ISTR; - - /* Use USB_ISR_MSK to only include code for bits we care about. */ - -#if (USB_ISR_MSK & USB_ISTR_RESET) - if (istr & USB_ISTR_RESET & USBLIB->irq_mask) { - USB_BASE->ISTR = ~USB_ISTR_RESET; - pProperty->Reset(); - } -#endif - -#if (USB_ISR_MSK & USB_ISTR_PMAOVR) - if (istr & ISTR_PMAOVR & USBLIB->irq_mask) { - USB_BASE->ISTR = ~USB_ISTR_PMAOVR; - } -#endif - -#if (USB_ISR_MSK & USB_ISTR_ERR) - if (istr & USB_ISTR_ERR & USBLIB->irq_mask) { - USB_BASE->ISTR = ~USB_ISTR_ERR; - } -#endif - -#if (USB_ISR_MSK & USB_ISTR_WKUP) - if (istr & USB_ISTR_WKUP & USBLIB->irq_mask) { - USB_BASE->ISTR = ~USB_ISTR_WKUP; - usb_resume(RESUME_EXTERNAL); - } -#endif - -#if (USB_ISR_MSK & USB_ISTR_SUSP) - if (istr & USB_ISTR_SUSP & USBLIB->irq_mask) { - /* check if SUSPEND is possible */ - if (SUSPEND_ENABLED) { - usb_suspend(); - } else { - /* if not possible then resume after xx ms */ - usb_resume(RESUME_LATER); - } - /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ - USB_BASE->ISTR = ~USB_ISTR_SUSP; - } -#endif - -#if (USB_ISR_MSK & USB_ISTR_SOF) - if (istr & USB_ISTR_SOF & USBLIB->irq_mask) { - USB_BASE->ISTR = ~USB_ISTR_SOF; - } -#endif - -#if (USB_ISR_MSK & USB_ISTR_ESOF) - if (istr & USB_ISTR_ESOF & USBLIB->irq_mask) { - USB_BASE->ISTR = ~USB_ISTR_ESOF; - /* resume handling timing is made with ESOFs */ - usb_resume(RESUME_ESOF); /* request without change of the machine state */ - } -#endif - - /* - * Service the correct transfer interrupt. - */ - -#if (USB_ISR_MSK & USB_ISTR_CTR) - if (istr & USB_ISTR_CTR & USBLIB->irq_mask) { - dispatch_ctr_lp(); - } -#endif -} - -/* - * Auxiliary routines - */ - -static inline uint8 dispatch_endpt_zero(uint16 istr_dir); -static inline void dispatch_endpt(uint8 ep); -static inline void set_rx_tx_status0(uint16 rx, uint16 tx); - -static void handle_setup0(void); -static void handle_in0(void); -static void handle_out0(void); - -static void dispatch_ctr_lp() { - uint16 istr; - while (((istr = USB_BASE->ISTR) & USB_ISTR_CTR) != 0) { - /* TODO WTF, figure this out: RM0008 says CTR is read-only, - * but ST's firmware claims it's clear-only, and emphasizes - * the importance of clearing it in more than one place. */ - USB_BASE->ISTR = ~USB_ISTR_CTR; - uint8 ep_id = istr & USB_ISTR_EP_ID; - if (ep_id == 0) { - /* TODO figure out why it's OK to break out of the loop - * once we're done serving endpoint zero, but not okay if - * there are multiple nonzero endpoint transfers to - * handle. */ - if (dispatch_endpt_zero(istr & USB_ISTR_DIR)) { - return; - } - } else { - dispatch_endpt(ep_id); - } - } -} - -/* FIXME Dataflow on endpoint 0 RX/TX status is based off of ST's - * code, and is ugly/confusing in its use of SaveRState/SaveTState. - * Fixing this requires filling in handle_in0(), handle_setup0(), - * handle_out0(). */ -static inline uint8 dispatch_endpt_zero(uint16 istr_dir) { - uint32 epr = (uint16)USB_BASE->EP[0]; - - if (!(epr & (USB_EP_CTR_TX | USB_EP_SETUP | USB_EP_CTR_RX))) { - return 0; - } - - /* Cache RX/TX statuses in SaveRState/SaveTState, respectively. - * The various handle_foo0() may clobber these values - * before we reset them at the end of this routine. */ - SaveRState = epr & USB_EP_STAT_RX; - SaveTState = epr & USB_EP_STAT_TX; - - /* Set actual RX/TX statuses to NAK while we're thinking */ - set_rx_tx_status0(USB_EP_STAT_RX_NAK, USB_EP_STAT_TX_NAK); - - if (istr_dir == 0) { - /* ST RM0008: "If DIR bit=0, CTR_TX bit is set in the USB_EPnR - * register related to the interrupting endpoint. The - * interrupting transaction is of IN type (data transmitted by - * the USB peripheral to the host PC)." */ - ASSERT_FAULT(epr & USB_EP_CTR_TX); - usb_clear_ctr_tx(USB_EP0); - handle_in0(); - } else { - /* RM0008: "If DIR bit=1, CTR_RX bit or both CTR_TX/CTR_RX - * are set in the USB_EPnR register related to the - * interrupting endpoint. The interrupting transaction is of - * OUT type (data received by the USB peripheral from the host - * PC) or two pending transactions are waiting to be - * processed." - * - * [mbolivar] Note how the following control flow (which - * replicates ST's) doesn't seem to actually handle both - * interrupts that are ostensibly pending when both CTR_RX and - * CTR_TX are set. - * - * TODO sort this mess out. - */ - if (epr & USB_EP_CTR_TX) { - usb_clear_ctr_tx(USB_EP0); - handle_in0(); - } else { /* SETUP or CTR_RX */ - /* SETUP is held constant while CTR_RX is set, so clear it - * either way */ - usb_clear_ctr_rx(USB_EP0); - if (epr & USB_EP_SETUP) { - handle_setup0(); - } else { /* CTR_RX */ - handle_out0(); - } - } - } - - set_rx_tx_status0(SaveRState, SaveTState); - return 1; -} - -static inline void dispatch_endpt(uint8 ep) { - uint32 epr = USB_BASE->EP[ep]; - /* If ISTR_CTR is set and the ISTR gave us this EP_ID to handle, - * then presumably at least one of CTR_RX and CTR_TX is set, but - * again, ST's control flow allows for the possibility of neither. - * - * TODO try to find out if neither being set is possible. */ - if (epr & USB_EP_CTR_RX) { - usb_clear_ctr_rx(ep); - (USBLIB->ep_int_out[ep - 1])(); - } - if (epr & USB_EP_CTR_TX) { - usb_clear_ctr_tx(ep); - (USBLIB->ep_int_in[ep - 1])(); - } -} - -static inline void set_rx_tx_status0(uint16 rx, uint16 tx) { - usb_set_ep_rx_stat(USB_EP0, rx); - usb_set_ep_tx_stat(USB_EP0, tx); -} - -/* TODO Rip out usb_lib/ dependency from the following functions: */ - -static void handle_setup0(void) { - Setup0_Process(); -} - -static void handle_in0(void) { - In0_Process(); -} - -static void handle_out0(void) { - Out0_Process(); -} diff --git a/STM32F3/cores/maple/libmaple/usb/usb_cdcacm.c b/STM32F3/cores/maple/libmaple/usb/usb_cdcacm.c deleted file mode 100644 index bafb90b..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_cdcacm.c +++ /dev/null @@ -1,723 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/usb/stm32f1/usb_cdcacm.c - * @brief USB CDC ACM (a.k.a. virtual serial terminal, VCOM). - * - * FIXME: this works on the STM32F1 USB peripherals, and probably no - * place else. Nonportable bits really need to be factored out, and - * the result made cleaner. - */ - -#include - -#include -#include -#include - -/* Private headers */ -#include "usb_lib_globals.h" -#include "usb_reg_map.h" - -/* usb_lib headers */ -#include "usb_type.h" -#include "usb_core.h" -#include "usb_def.h" - -/****************************************************************************** - ****************************************************************************** - *** - *** HACK ALERT! FIXME FIXME FIXME FIXME! - *** - *** A bunch of LeafLabs-specific configuration lives in here for - *** now. This mess REALLY needs to get teased apart, with - *** appropriate pieces moved into Wirish. - *** - ****************************************************************************** - *****************************************************************************/ - -#if !(defined(BOARD_maple_mini_f3)) -#warning USB CDC ACM relies on LeafLabs board-specific configuration.\ - You may have problems on non-LeafLabs boards. -#endif - -static void vcomDataTxCb(void); -static void vcomDataRxCb(void); -static uint8* vcomGetSetLineCoding(uint16); - -static void usbInit(void); -static void usbReset(void); -static RESULT usbDataSetup(uint8 request); -static RESULT usbNoDataSetup(uint8 request); -static RESULT usbGetInterfaceSetting(uint8 interface, uint8 alt_setting); -static uint8* usbGetDeviceDescriptor(uint16 length); -static uint8* usbGetConfigDescriptor(uint16 length); -static uint8* usbGetStringDescriptor(uint16 length); -static void usbSetConfiguration(void); -static void usbSetDeviceAddress(void); - -/* - * Descriptors - */ - -/* FIXME move to Wirish */ -#define LEAFLABS_ID_VENDOR 0x1EAF -#define MAPLE_ID_PRODUCT 0x0004 -static const usb_descriptor_device usbVcomDescriptor_Device = - USB_CDCACM_DECLARE_DEV_DESC(LEAFLABS_ID_VENDOR, MAPLE_ID_PRODUCT); - -typedef struct { - usb_descriptor_config_header Config_Header; - usb_descriptor_interface CCI_Interface; - CDC_FUNCTIONAL_DESCRIPTOR(2) CDC_Functional_IntHeader; - CDC_FUNCTIONAL_DESCRIPTOR(2) CDC_Functional_CallManagement; - CDC_FUNCTIONAL_DESCRIPTOR(1) CDC_Functional_ACM; - CDC_FUNCTIONAL_DESCRIPTOR(2) CDC_Functional_Union; - usb_descriptor_endpoint ManagementEndpoint; - usb_descriptor_interface DCI_Interface; - usb_descriptor_endpoint DataOutEndpoint; - usb_descriptor_endpoint DataInEndpoint; -} __packed usb_descriptor_config; - -#define MAX_POWER (100 >> 1) -static const usb_descriptor_config usbVcomDescriptor_Config = { - .Config_Header = { - .bLength = sizeof(usb_descriptor_config_header), - .bDescriptorType = USB_DESCRIPTOR_TYPE_CONFIGURATION, - .wTotalLength = sizeof(usb_descriptor_config), - .bNumInterfaces = 0x02, - .bConfigurationValue = 0x01, - .iConfiguration = 0x00, - .bmAttributes = (USB_CONFIG_ATTR_BUSPOWERED | - USB_CONFIG_ATTR_SELF_POWERED), - .bMaxPower = MAX_POWER, - }, - - .CCI_Interface = { - .bLength = sizeof(usb_descriptor_interface), - .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE, - .bInterfaceNumber = 0x00, - .bAlternateSetting = 0x00, - .bNumEndpoints = 0x01, - .bInterfaceClass = USB_INTERFACE_CLASS_CDC, - .bInterfaceSubClass = USB_INTERFACE_SUBCLASS_CDC_ACM, - .bInterfaceProtocol = 0x01, /* Common AT Commands */ - .iInterface = 0x00, - }, - - .CDC_Functional_IntHeader = { - .bLength = CDC_FUNCTIONAL_DESCRIPTOR_SIZE(2), - .bDescriptorType = 0x24, - .SubType = 0x00, - .Data = {0x01, 0x10}, - }, - - .CDC_Functional_CallManagement = { - .bLength = CDC_FUNCTIONAL_DESCRIPTOR_SIZE(2), - .bDescriptorType = 0x24, - .SubType = 0x01, - .Data = {0x03, 0x01}, - }, - - .CDC_Functional_ACM = { - .bLength = CDC_FUNCTIONAL_DESCRIPTOR_SIZE(1), - .bDescriptorType = 0x24, - .SubType = 0x02, - .Data = {0x06}, - }, - - .CDC_Functional_Union = { - .bLength = CDC_FUNCTIONAL_DESCRIPTOR_SIZE(2), - .bDescriptorType = 0x24, - .SubType = 0x06, - .Data = {0x00, 0x01}, - }, - - .ManagementEndpoint = { - .bLength = sizeof(usb_descriptor_endpoint), - .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, - .bEndpointAddress = (USB_DESCRIPTOR_ENDPOINT_IN | - USB_CDCACM_MANAGEMENT_ENDP), - .bmAttributes = USB_EP_TYPE_INTERRUPT, - .wMaxPacketSize = USB_CDCACM_MANAGEMENT_EPSIZE, - .bInterval = 0xFF, - }, - - .DCI_Interface = { - .bLength = sizeof(usb_descriptor_interface), - .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE, - .bInterfaceNumber = 0x01, - .bAlternateSetting = 0x00, - .bNumEndpoints = 0x02, - .bInterfaceClass = USB_INTERFACE_CLASS_DIC, - .bInterfaceSubClass = 0x00, /* None */ - .bInterfaceProtocol = 0x00, /* None */ - .iInterface = 0x00, - }, - - .DataOutEndpoint = { - .bLength = sizeof(usb_descriptor_endpoint), - .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, - .bEndpointAddress = (USB_DESCRIPTOR_ENDPOINT_OUT | - USB_CDCACM_RX_ENDP), - .bmAttributes = USB_EP_TYPE_BULK, - .wMaxPacketSize = USB_CDCACM_RX_EPSIZE, - .bInterval = 0x00, - }, - - .DataInEndpoint = { - .bLength = sizeof(usb_descriptor_endpoint), - .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, - .bEndpointAddress = (USB_DESCRIPTOR_ENDPOINT_IN | USB_CDCACM_TX_ENDP), - .bmAttributes = USB_EP_TYPE_BULK, - .wMaxPacketSize = USB_CDCACM_TX_EPSIZE, - .bInterval = 0x00, - }, -}; - -/* - String Descriptors: - - we may choose to specify any or none of the following string - identifiers: - - iManufacturer: LeafLabs - iProduct: Maple - iSerialNumber: NONE - iConfiguration: NONE - iInterface(CCI): NONE - iInterface(DCI): NONE - -*/ - -/* Unicode language identifier: 0x0409 is US English */ -/* FIXME move to Wirish */ -static const usb_descriptor_string usbVcomDescriptor_LangID = { - .bLength = USB_DESCRIPTOR_STRING_LEN(1), - .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING, - .bString = {0x09, 0x04}, -}; - -/* FIXME move to Wirish */ -static const usb_descriptor_string usbVcomDescriptor_iManufacturer = { - .bLength = USB_DESCRIPTOR_STRING_LEN(8), - .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING, - .bString = {'L', 0, 'e', 0, 'a', 0, 'f', 0, - 'L', 0, 'a', 0, 'b', 0, 's', 0}, -}; - -/* FIXME move to Wirish */ -static const usb_descriptor_string usbVcomDescriptor_iProduct = { - .bLength = USB_DESCRIPTOR_STRING_LEN(5), - .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING, - .bString = {'M', 0, 'a', 0, 'p', 0, 'l', 0, 'e', 0}, -}; - -static ONE_DESCRIPTOR Device_Descriptor = { - (uint8*)&usbVcomDescriptor_Device, - sizeof(usb_descriptor_device) -}; - -static ONE_DESCRIPTOR Config_Descriptor = { - (uint8*)&usbVcomDescriptor_Config, - sizeof(usb_descriptor_config) -}; - -#define N_STRING_DESCRIPTORS 3 -static ONE_DESCRIPTOR String_Descriptor[N_STRING_DESCRIPTORS] = { - {(uint8*)&usbVcomDescriptor_LangID, USB_DESCRIPTOR_STRING_LEN(1)}, - {(uint8*)&usbVcomDescriptor_iManufacturer,USB_DESCRIPTOR_STRING_LEN(8)}, - {(uint8*)&usbVcomDescriptor_iProduct, USB_DESCRIPTOR_STRING_LEN(5)} -}; - -/* - * Etc. - */ - -/* I/O state */ - -/* Received data */ -static volatile uint8 vcomBufferRx[USB_CDCACM_RX_EPSIZE]; -/* Read index into vcomBufferRx */ -static volatile uint32 rx_offset = 0; -/* Number of bytes left to transmit */ -static volatile uint32 n_unsent_bytes = 0; -/* Are we currently sending an IN packet? */ -static volatile uint8 transmitting = 0; -/* Number of unread bytes */ -static volatile uint32 n_unread_bytes = 0; - -/* Other state (line coding, DTR/RTS) */ - -static volatile usb_cdcacm_line_coding line_coding = { - /* This default is 115200 baud, 8N1. */ - .dwDTERate = 115200, - .bCharFormat = USB_CDCACM_STOP_BITS_1, - .bParityType = USB_CDCACM_PARITY_NONE, - .bDataBits = 8, -}; - -/* DTR in bit 0, RTS in bit 1. */ -static volatile uint8 line_dtr_rts = 0; - -/* - * Endpoint callbacks - */ - -static void (*ep_int_in[7])(void) = - {vcomDataTxCb, - NOP_Process, - NOP_Process, - NOP_Process, - NOP_Process, - NOP_Process, - NOP_Process}; - -static void (*ep_int_out[7])(void) = - {NOP_Process, - NOP_Process, - vcomDataRxCb, - NOP_Process, - NOP_Process, - NOP_Process, - NOP_Process}; - -/* - * Globals required by usb_lib/ - * - * Mark these weak so they can be overriden to implement other USB - * functionality. - */ - -#define NUM_ENDPTS 0x04 -__weak DEVICE Device_Table = { - .Total_Endpoint = NUM_ENDPTS, - .Total_Configuration = 1 -}; - -#define MAX_PACKET_SIZE 0x40 /* 64B, maximum for USB FS Devices */ -__weak DEVICE_PROP Device_Property = { - .Init = usbInit, - .Reset = usbReset, - .Process_Status_IN = NOP_Process, - .Process_Status_OUT = NOP_Process, - .Class_Data_Setup = usbDataSetup, - .Class_NoData_Setup = usbNoDataSetup, - .Class_Get_Interface_Setting = usbGetInterfaceSetting, - .GetDeviceDescriptor = usbGetDeviceDescriptor, - .GetConfigDescriptor = usbGetConfigDescriptor, - .GetStringDescriptor = usbGetStringDescriptor, - .RxEP_buffer = NULL, - .MaxPacketSize = MAX_PACKET_SIZE -}; - -__weak USER_STANDARD_REQUESTS User_Standard_Requests = { - .User_GetConfiguration = NOP_Process, - .User_SetConfiguration = usbSetConfiguration, - .User_GetInterface = NOP_Process, - .User_SetInterface = NOP_Process, - .User_GetStatus = NOP_Process, - .User_ClearFeature = NOP_Process, - .User_SetEndPointFeature = NOP_Process, - .User_SetDeviceFeature = NOP_Process, - .User_SetDeviceAddress = usbSetDeviceAddress -}; - -/* - * User hooks - */ - -static void (*rx_hook)(unsigned, void*) = 0; -static void (*iface_setup_hook)(unsigned, void*) = 0; - -void usb_cdcacm_set_hooks(unsigned hook_flags, void (*hook)(unsigned, void*)) { - if (hook_flags & USB_CDCACM_HOOK_RX) { - rx_hook = hook; - } - if (hook_flags & USB_CDCACM_HOOK_IFACE_SETUP) { - iface_setup_hook = hook; - } -} - -/* - * CDC ACM interface - */ - -void usb_cdcacm_enable(gpio_dev *disc_dev, uint8 disc_bit) { - /* Present ourselves to the host. Writing 0 to "disc" pin must - * pull USB_DP pin up while leaving USB_DM pulled down by the - * transceiver. See USB 2.0 spec, section 7.1.7.3. */ - gpio_set_modef(disc_dev, disc_bit, GPIO_MODE_OUTPUT, GPIO_MODEF_TYPE_PP); - gpio_write_bit(disc_dev, disc_bit, 0); - - /* - * set USB_DP and USB_DM pins to alternate mode and set alternate function to USB - */ - gpio_set_modef(GPIOA, 12, GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - gpio_set_modef(GPIOA, 11, GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - gpio_set_af(GPIOA, 12, GPIO_AF_14); - gpio_set_af(GPIOA, 11, GPIO_AF_14); - - /* Initialize the USB peripheral. */ - usb_init_usblib(USBLIB, ep_int_in, ep_int_out); -} - -void usb_cdcacm_disable(gpio_dev *disc_dev, uint8 disc_bit) { - /* Turn off the interrupt and signal disconnect (see e.g. USB 2.0 - * spec, section 7.1.7.3). */ - nvic_irq_disable(NVIC_USB_LP_CAN_RX0); - gpio_write_bit(disc_dev, disc_bit, 1); - - /* - * set USB_DP and USB_DM pins to input floating mode, reset alternate function to system default - */ - gpio_set_modef(GPIOA, 12, GPIO_MODE_INPUT, GPIO_MODEF_PUPD_NONE); - gpio_set_modef(GPIOA, 11, GPIO_MODE_INPUT, GPIO_MODEF_PUPD_NONE); - gpio_set_af(GPIOA, 12, GPIO_AF_0); - gpio_set_af(GPIOA, 11, GPIO_AF_0); -} - -void usb_cdcacm_putc(char ch) { - while (!usb_cdcacm_tx((uint8*)&ch, 1)) - ; -} - -/* This function is non-blocking. - * - * It copies data from a usercode buffer into the USB peripheral TX - * buffer, and returns the number of bytes copied. */ -uint32 usb_cdcacm_tx(const uint8* buf, uint32 len) { - /* Last transmission hasn't finished, so abort. */ - if (usb_cdcacm_is_transmitting()) { - return 0; - } - - /* We can only put USB_CDCACM_TX_EPSIZE bytes in the buffer. */ - if (len > USB_CDCACM_TX_EPSIZE) { - len = USB_CDCACM_TX_EPSIZE; - } - - /* Queue bytes for sending. */ - if (len) { - usb_copy_to_pma(buf, len, USB_CDCACM_TX_ADDR); - } - // We still need to wait for the interrupt, even if we're sending - // zero bytes. (Sending zero-size packets is useful for flushing - // host-side buffers.) - usb_set_ep_tx_count(USB_CDCACM_TX_ENDP, len); - n_unsent_bytes = len; - transmitting = 1; - usb_set_ep_tx_stat(USB_CDCACM_TX_ENDP, USB_EP_STAT_TX_VALID); - - return len; -} - -uint32 usb_cdcacm_data_available(void) { - return n_unread_bytes; -} - -uint8 usb_cdcacm_is_transmitting(void) { - return transmitting; -} - -uint16 usb_cdcacm_get_pending(void) { - return n_unsent_bytes; -} - -/* Nonblocking byte receive. - * - * Copies up to len bytes from our private data buffer (*NOT* the PMA) - * into buf and deq's the FIFO. */ -uint32 usb_cdcacm_rx(uint8* buf, uint32 len) { - /* Copy bytes to buffer. */ - uint32 n_copied = usb_cdcacm_peek(buf, len); - - /* Mark bytes as read. */ - n_unread_bytes -= n_copied; - rx_offset += n_copied; - - /* If all bytes have been read, re-enable the RX endpoint, which - * was set to NAK when the current batch of bytes was received. */ - if (n_unread_bytes == 0) { - usb_set_ep_rx_count(USB_CDCACM_RX_ENDP, USB_CDCACM_RX_EPSIZE); - usb_set_ep_rx_stat(USB_CDCACM_RX_ENDP, USB_EP_STAT_RX_VALID); - rx_offset = 0; - } - - return n_copied; -} - -/* Nonblocking byte lookahead. - * - * Looks at unread bytes without marking them as read. */ -uint32 usb_cdcacm_peek(uint8* buf, uint32 len) { - int i; - - if (len > n_unread_bytes) { - len = n_unread_bytes; - } - - for (i = 0; i < len; i++) { - buf[i] = vcomBufferRx[i + rx_offset]; - } - - return len; -} - -uint8 usb_cdcacm_get_dtr() { - return ((line_dtr_rts & USB_CDCACM_CONTROL_LINE_DTR) != 0); -} - -uint8 usb_cdcacm_get_rts() { - return ((line_dtr_rts & USB_CDCACM_CONTROL_LINE_RTS) != 0); -} - -void usb_cdcacm_get_line_coding(usb_cdcacm_line_coding *ret) { - ret->dwDTERate = line_coding.dwDTERate; - ret->bCharFormat = line_coding.bCharFormat; - ret->bParityType = line_coding.bParityType; - ret->bDataBits = line_coding.bDataBits; -} - -int usb_cdcacm_get_baud(void) { - return line_coding.dwDTERate; -} - -int usb_cdcacm_get_stop_bits(void) { - return line_coding.bCharFormat; -} - -int usb_cdcacm_get_parity(void) { - return line_coding.bParityType; -} - -int usb_cdcacm_get_n_data_bits(void) { - return line_coding.bDataBits; -} - - -/* - * Callbacks - */ - -static void vcomDataTxCb(void) { - n_unsent_bytes = 0; - transmitting = 0; -} - -static void vcomDataRxCb(void) { - usb_set_ep_rx_stat(USB_CDCACM_RX_ENDP, USB_EP_STAT_RX_NAK); - n_unread_bytes = usb_get_ep_rx_count(USB_CDCACM_RX_ENDP); - /* This copy won't overwrite unread bytes, since we've set the RX - * endpoint to NAK, and will only set it to VALID when all bytes - * have been read. */ - usb_copy_from_pma((uint8*)vcomBufferRx, n_unread_bytes, - USB_CDCACM_RX_ADDR); - - - if (n_unread_bytes == 0) { - usb_set_ep_rx_count(USB_CDCACM_RX_ENDP, USB_CDCACM_RX_EPSIZE); - usb_set_ep_rx_stat(USB_CDCACM_RX_ENDP, USB_EP_STAT_RX_VALID); - rx_offset = 0; - } - - if (rx_hook) { - rx_hook(USB_CDCACM_HOOK_RX, 0); - } -} - -static uint8* vcomGetSetLineCoding(uint16 length) { - if (length == 0) { - pInformation->Ctrl_Info.Usb_wLength = sizeof(struct usb_cdcacm_line_coding); - } - return (uint8*)&line_coding; -} - -static void usbInit(void) { - pInformation->Current_Configuration = 0; - - USB_BASE->CNTR = USB_CNTR_FRES; - - USBLIB->irq_mask = 0; - USB_BASE->CNTR = USBLIB->irq_mask; - USB_BASE->ISTR = 0; - USBLIB->irq_mask = USB_CNTR_RESETM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; - USB_BASE->CNTR = USBLIB->irq_mask; - - USB_BASE->ISTR = 0; - USBLIB->irq_mask = USB_ISR_MSK; - USB_BASE->CNTR = USBLIB->irq_mask; - - nvic_irq_enable(NVIC_USB_LP_CAN_RX0); - USBLIB->state = USB_UNCONNECTED; -} - -#define BTABLE_ADDRESS 0x00 -static void usbReset(void) { - pInformation->Current_Configuration = 0; - - /* current feature is current bmAttributes */ - pInformation->Current_Feature = (USB_CONFIG_ATTR_BUSPOWERED | - USB_CONFIG_ATTR_SELF_POWERED); - - USB_BASE->BTABLE = BTABLE_ADDRESS; - - /* setup control endpoint 0 */ - usb_set_ep_type(USB_EP0, USB_EP_EP_TYPE_CONTROL); - usb_set_ep_tx_stat(USB_EP0, USB_EP_STAT_TX_STALL); - usb_set_ep_rx_addr(USB_EP0, USB_CDCACM_CTRL_RX_ADDR); - usb_set_ep_tx_addr(USB_EP0, USB_CDCACM_CTRL_TX_ADDR); - usb_clear_status_out(USB_EP0); - - usb_set_ep_rx_count(USB_EP0, pProperty->MaxPacketSize); - usb_set_ep_rx_stat(USB_EP0, USB_EP_STAT_RX_VALID); - - /* setup management endpoint 1 */ - usb_set_ep_type(USB_CDCACM_MANAGEMENT_ENDP, USB_EP_EP_TYPE_INTERRUPT); - usb_set_ep_tx_addr(USB_CDCACM_MANAGEMENT_ENDP, - USB_CDCACM_MANAGEMENT_ADDR); - usb_set_ep_tx_stat(USB_CDCACM_MANAGEMENT_ENDP, USB_EP_STAT_TX_NAK); - usb_set_ep_rx_stat(USB_CDCACM_MANAGEMENT_ENDP, USB_EP_STAT_RX_DISABLED); - - /* TODO figure out differences in style between RX/TX EP setup */ - - /* set up data endpoint OUT (RX) */ - usb_set_ep_type(USB_CDCACM_RX_ENDP, USB_EP_EP_TYPE_BULK); - usb_set_ep_rx_addr(USB_CDCACM_RX_ENDP, USB_CDCACM_RX_ADDR); - usb_set_ep_rx_count(USB_CDCACM_RX_ENDP, USB_CDCACM_RX_EPSIZE); - usb_set_ep_rx_stat(USB_CDCACM_RX_ENDP, USB_EP_STAT_RX_VALID); - - /* set up data endpoint IN (TX) */ - usb_set_ep_type(USB_CDCACM_TX_ENDP, USB_EP_EP_TYPE_BULK); - usb_set_ep_tx_addr(USB_CDCACM_TX_ENDP, USB_CDCACM_TX_ADDR); - usb_set_ep_tx_stat(USB_CDCACM_TX_ENDP, USB_EP_STAT_TX_NAK); - usb_set_ep_rx_stat(USB_CDCACM_TX_ENDP, USB_EP_STAT_RX_DISABLED); - - USBLIB->state = USB_ATTACHED; - SetDeviceAddress(0); - - /* Reset the RX/TX state */ - n_unread_bytes = 0; - n_unsent_bytes = 0; - rx_offset = 0; -} - -static RESULT usbDataSetup(uint8 request) { - uint8* (*CopyRoutine)(uint16) = 0; - - if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) { - switch (request) { - case USB_CDCACM_GET_LINE_CODING: - CopyRoutine = vcomGetSetLineCoding; - break; - case USB_CDCACM_SET_LINE_CODING: - CopyRoutine = vcomGetSetLineCoding; - break; - default: - break; - } - - /* Call the user hook. */ - if (iface_setup_hook) { - uint8 req_copy = request; - iface_setup_hook(USB_CDCACM_HOOK_IFACE_SETUP, &req_copy); - } - } - - if (CopyRoutine == NULL) { - return USB_UNSUPPORT; - } - - pInformation->Ctrl_Info.CopyData = CopyRoutine; - pInformation->Ctrl_Info.Usb_wOffset = 0; - (*CopyRoutine)(0); - return USB_SUCCESS; -} - -static RESULT usbNoDataSetup(uint8 request) { - RESULT ret = USB_UNSUPPORT; - - if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) { - switch (request) { - case USB_CDCACM_SET_COMM_FEATURE: - /* We support set comm. feature, but don't handle it. */ - ret = USB_SUCCESS; - break; - case USB_CDCACM_SET_CONTROL_LINE_STATE: - /* Track changes to DTR and RTS. */ - line_dtr_rts = (pInformation->USBwValues.bw.bb0 & - (USB_CDCACM_CONTROL_LINE_DTR | - USB_CDCACM_CONTROL_LINE_RTS)); - ret = USB_SUCCESS; - break; - } - - /* Call the user hook. */ - if (iface_setup_hook) { - uint8 req_copy = request; - iface_setup_hook(USB_CDCACM_HOOK_IFACE_SETUP, &req_copy); - } - } - return ret; -} - -static RESULT usbGetInterfaceSetting(uint8 interface, uint8 alt_setting) { - if (alt_setting > 0) { - return USB_UNSUPPORT; - } else if (interface > 1) { - return USB_UNSUPPORT; - } - - return USB_SUCCESS; -} - -static uint8* usbGetDeviceDescriptor(uint16 length) { - return Standard_GetDescriptorData(length, &Device_Descriptor); -} - -static uint8* usbGetConfigDescriptor(uint16 length) { - return Standard_GetDescriptorData(length, &Config_Descriptor); -} - -static uint8* usbGetStringDescriptor(uint16 length) { - uint8 wValue0 = pInformation->USBwValue0; - - if (wValue0 > N_STRING_DESCRIPTORS) { - return NULL; - } - return Standard_GetDescriptorData(length, &String_Descriptor[wValue0]); -} - -static void usbSetConfiguration(void) { - if (pInformation->Current_Configuration != 0) { - USBLIB->state = USB_CONFIGURED; - } -} - -static void usbSetDeviceAddress(void) { - USBLIB->state = USB_ADDRESSED; -} diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_core.c b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_core.c deleted file mode 100644 index 5cf9e87..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_core.c +++ /dev/null @@ -1,1013 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_core.c -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Standard protocol processing (USB v2.0) -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Includes ------------------------------------------------------------------*/ -#include "usb_lib.h" -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -#define ValBit(VAR,Place) (VAR & (1 << Place)) -#define SetBit(VAR,Place) (VAR |= (1 << Place)) -#define ClrBit(VAR,Place) (VAR &= ((1 << Place) ^ 255)) - -#define Send0LengthData() { _SetEPTxCount(ENDP0, 0); \ - vSetEPTxStatus(EP_TX_VALID); \ - } - -#define vSetEPRxStatus(st) (SaveRState = st) -#define vSetEPTxStatus(st) (SaveTState = st) - -#define USB_StatusIn() Send0LengthData() -#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID) - -#define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */ -#define StatusInfo1 StatusInfo.bw.bb0 - -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -u16_u8 StatusInfo; -USB_Bool Data_Mul_MaxPacketSize = FALSE; -/* Private function prototypes -----------------------------------------------*/ -static void DataStageOut(void); -static void DataStageIn(void); -static void NoData_Setup0(void); -static void Data_Setup0(void); -/* Private functions ---------------------------------------------------------*/ - -/******************************************************************************* -* Function Name : Standard_GetConfiguration. -* Description : Return the current configuration variable address. -* Input : Length - How many bytes are needed. -* Output : None. -* Return : Return 1 , if the request is invalid when "Length" is 0. -* Return "Buffer" if the "Length" is not 0. -*******************************************************************************/ -u8 *Standard_GetConfiguration(u16 Length) -{ - if (Length == 0) - { - pInformation->Ctrl_Info.Usb_wLength = - sizeof(pInformation->Current_Configuration); - return 0; - } - pUser_Standard_Requests->User_GetConfiguration(); - return (u8 *)&pInformation->Current_Configuration; -} - -/******************************************************************************* -* Function Name : Standard_SetConfiguration. -* Description : This routine is called to set the configuration value -* Then each class should configure device themself. -* Input : None. -* Output : None. -* Return : Return USB_SUCCESS, if the request is performed. -* Return USB_UNSUPPORT, if the request is invalid. -*******************************************************************************/ -RESULT Standard_SetConfiguration(void) -{ - - if ((pInformation->USBwValue0 <= - Device_Table.Total_Configuration) && (pInformation->USBwValue1 == 0) - && (pInformation->USBwIndex == 0)) /*call Back usb spec 2.0*/ - { - pInformation->Current_Configuration = pInformation->USBwValue0; - pUser_Standard_Requests->User_SetConfiguration(); - return USB_SUCCESS; - } - else - { - return USB_UNSUPPORT; - } -} - -/******************************************************************************* -* Function Name : Standard_GetInterface. -* Description : Return the Alternate Setting of the current interface. -* Input : Length - How many bytes are needed. -* Output : None. -* Return : Return 0, if the request is invalid when "Length" is 0. -* Return "Buffer" if the "Length" is not 0. -*******************************************************************************/ -u8 *Standard_GetInterface(u16 Length) -{ - if (Length == 0) - { - pInformation->Ctrl_Info.Usb_wLength = - sizeof(pInformation->Current_AlternateSetting); - return 0; - } - pUser_Standard_Requests->User_GetInterface(); - return (u8 *)&pInformation->Current_AlternateSetting; -} - -/******************************************************************************* -* Function Name : Standard_SetInterface. -* Description : This routine is called to set the interface. -* Then each class should configure the interface them self. -* Input : None. -* Output : None. -* Return : - Return USB_SUCCESS, if the request is performed. -* - Return USB_UNSUPPORT, if the request is invalid. -*******************************************************************************/ -RESULT Standard_SetInterface(void) -{ - RESULT Re; - /*Test if the specified Interface and Alternate Setting are supported by - the application Firmware*/ - Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, pInformation->USBwValue0); - - if (pInformation->Current_Configuration != 0) - { - if ((Re != USB_SUCCESS) || (pInformation->USBwIndex1 != 0) - || (pInformation->USBwValue1 != 0)) - { - return USB_UNSUPPORT; - } - else if (Re == USB_SUCCESS) - { - pUser_Standard_Requests->User_SetInterface(); - pInformation->Current_Interface = pInformation->USBwIndex0; - pInformation->Current_AlternateSetting = pInformation->USBwValue0; - return USB_SUCCESS; - } - - } - - return USB_UNSUPPORT; -} - -/******************************************************************************* -* Function Name : Standard_GetStatus. -* Description : Copy the device request data to "StatusInfo buffer". -* Input : - Length - How many bytes are needed. -* Output : None. -* Return : Return 0, if the request is at end of data block, -* or is invalid when "Length" is 0. -*******************************************************************************/ -u8 *Standard_GetStatus(u16 Length) -{ - if (Length == 0) - { - pInformation->Ctrl_Info.Usb_wLength = 2; - return 0; - } - - StatusInfo.w = 0; - /* Reset Status Information */ - - if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - { - /*Get Device Status */ - u8 Feature = pInformation->Current_Feature; - - /* Remote Wakeup enabled */ - if (ValBit(Feature, 5)) - { - SetBit(StatusInfo0, 1); - } - - /* Bus-powered */ - if (ValBit(Feature, 6)) - { - ClrBit(StatusInfo0, 0); - } - else /* Self-powered */ - { - SetBit(StatusInfo0, 0); - } - } - /*Interface Status*/ - else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) - { - return (u8 *)&StatusInfo; - } - /*Get EndPoint Status*/ - else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) - { - u8 Related_Endpoint; - u8 wIndex0 = pInformation->USBwIndex0; - - Related_Endpoint = (wIndex0 & 0x0f); - if (ValBit(wIndex0, 7)) - { - /* IN endpoint */ - if (_GetTxStallStatus(Related_Endpoint)) - { - SetBit(StatusInfo0, 0); /* IN Endpoint stalled */ - } - } - else - { - /* OUT endpoint */ - if (_GetRxStallStatus(Related_Endpoint)) - { - SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */ - } - } - - } - else - { - return NULL; - } - pUser_Standard_Requests->User_GetStatus(); - return (u8 *)&StatusInfo; -} - -/******************************************************************************* -* Function Name : Standard_ClearFeature. -* Description : Clear or disable a specific feature. -* Input : None. -* Output : None. -* Return : - Return USB_SUCCESS, if the request is performed. -* - Return USB_UNSUPPORT, if the request is invalid. -*******************************************************************************/ -RESULT Standard_ClearFeature(void) -{ - u32 Type_Rec = Type_Recipient; - u32 Status; - - - if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - {/*Device Clear Feature*/ - ClrBit(pInformation->Current_Feature, 5); - return USB_SUCCESS; - } - else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) - {/*EndPoint Clear Feature*/ - DEVICE* pDev; - u32 Related_Endpoint; - u32 wIndex0; - u32 rEP; - - if ((pInformation->USBwValue != ENDPOINT_STALL) - || (pInformation->USBwIndex1 != 0)) - { - return USB_UNSUPPORT; - } - - pDev = &Device_Table; - wIndex0 = pInformation->USBwIndex0; - rEP = wIndex0 & ~0x80; - Related_Endpoint = ENDP0 + rEP; - - if (ValBit(pInformation->USBwIndex0, 7)) - { - /*Get Status of endpoint & stall the request if the related_ENdpoint - is Disabled*/ - Status = _GetEPTxStatus(Related_Endpoint); - } - else - { - Status = _GetEPRxStatus(Related_Endpoint); - } - - if ((rEP >= pDev->Total_Endpoint) || (Status == 0) - || (pInformation->Current_Configuration == 0)) - { - return USB_UNSUPPORT; - } - - - if (wIndex0 & 0x80) - { - /* IN endpoint */ - if (_GetTxStallStatus(Related_Endpoint )) - { - ClearDTOG_TX(Related_Endpoint); - SetEPTxStatus(Related_Endpoint, EP_TX_VALID); - } - } - else - { - /* OUT endpoint */ - if (_GetRxStallStatus(Related_Endpoint)) - { - if (Related_Endpoint == ENDP0) - { - /* After clear the STALL, enable the default endpoint receiver */ - SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize); - _SetEPRxStatus(Related_Endpoint, EP_RX_VALID); - } - else - { - ClearDTOG_RX(Related_Endpoint); - _SetEPRxStatus(Related_Endpoint, EP_RX_VALID); - } - } - } - pUser_Standard_Requests->User_ClearFeature(); - return USB_SUCCESS; - } - - return USB_UNSUPPORT; -} - -/******************************************************************************* -* Function Name : Standard_SetEndPointFeature -* Description : Set or enable a specific feature of EndPoint -* Input : None. -* Output : None. -* Return : - Return USB_SUCCESS, if the request is performed. -* - Return USB_UNSUPPORT, if the request is invalid. -*******************************************************************************/ -RESULT Standard_SetEndPointFeature(void) -{ - u32 wIndex0; - u32 Related_Endpoint; - u32 rEP; - u32 Status; - - wIndex0 = pInformation->USBwIndex0; - rEP = wIndex0 & ~0x80; - Related_Endpoint = ENDP0 + rEP; - - if (ValBit(pInformation->USBwIndex0, 7)) - { - /* get Status of endpoint & stall the request if the related_ENdpoint - is Disabled*/ - Status = _GetEPTxStatus(Related_Endpoint); - } - else - { - Status = _GetEPRxStatus(Related_Endpoint); - } - - if (Related_Endpoint >= Device_Table.Total_Endpoint - || pInformation->USBwValue != 0 || Status == 0 - || pInformation->Current_Configuration == 0) - { - return USB_UNSUPPORT; - } - else - { - if (wIndex0 & 0x80) - { - /* IN endpoint */ - _SetEPTxStatus(Related_Endpoint, EP_TX_STALL); - } - - else - { - /* OUT endpoint */ - _SetEPRxStatus(Related_Endpoint, EP_RX_STALL); - } - } - pUser_Standard_Requests->User_SetEndPointFeature(); - return USB_SUCCESS; -} - -/******************************************************************************* -* Function Name : Standard_SetDeviceFeature. -* Description : Set or enable a specific feature of Device. -* Input : None. -* Output : None. -* Return : - Return USB_SUCCESS, if the request is performed. -* - Return USB_UNSUPPORT, if the request is invalid. -*******************************************************************************/ -RESULT Standard_SetDeviceFeature(void) -{ - SetBit(pInformation->Current_Feature, 5); - pUser_Standard_Requests->User_SetDeviceFeature(); - return USB_SUCCESS; -} - -/******************************************************************************* -* Function Name : Standard_GetDescriptorData. -* Description : Standard_GetDescriptorData is used for descriptors transfer. -* : This routine is used for the descriptors resident in Flash -* or RAM -* pDesc can be in either Flash or RAM -* The purpose of this routine is to have a versatile way to -* response descriptors request. It allows user to generate -* certain descriptors with software or read descriptors from -* external storage part by part. -* Input : - Length - Length of the data in this transfer. -* - pDesc - A pointer points to descriptor struct. -* The structure gives the initial address of the descriptor and -* its original size. -* Output : None. -* Return : Address of a part of the descriptor pointed by the Usb_ -* wOffset The buffer pointed by this address contains at least -* Length bytes. -*******************************************************************************/ -u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc) -{ - u32 wOffset; - - wOffset = pInformation->Ctrl_Info.Usb_wOffset; - if (Length == 0) - { - pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset; - return 0; - } - - return pDesc->Descriptor + wOffset; -} - -/******************************************************************************* -* Function Name : DataStageOut. -* Description : Data stage of a Control Write Transfer. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ -void DataStageOut(void) -{ - ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info; - u32 save_rLength; - - save_rLength = pEPinfo->Usb_rLength; - - if (pEPinfo->CopyData && save_rLength) - { - u8 *Buffer; - u32 Length; - - Length = pEPinfo->PacketSize; - if (Length > save_rLength) - { - Length = save_rLength; - } - - Buffer = (*pEPinfo->CopyData)(Length); - pEPinfo->Usb_rLength -= Length; - pEPinfo->Usb_rOffset += Length; - - PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length); - } - - if (pEPinfo->Usb_rLength != 0) - { - vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */ - SetEPTxCount(ENDP0, 0); - vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */ - } - /* Set the next State*/ - if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize) - { - pInformation->ControlState = OUT_DATA; - } - else - { - if (pEPinfo->Usb_rLength > 0) - { - pInformation->ControlState = LAST_OUT_DATA; - } - else if (pEPinfo->Usb_rLength == 0) - { - pInformation->ControlState = WAIT_STATUS_IN; - USB_StatusIn(); - } - } -} - -/******************************************************************************* -* Function Name : DataStageIn. -* Description : Data stage of a Control Read Transfer. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ -void DataStageIn(void) -{ - ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info; - u32 save_wLength = pEPinfo->Usb_wLength; - u32 ControlState = pInformation->ControlState; - - u8 *DataBuffer; - u32 Length; - - if ((save_wLength == 0) && (ControlState == LAST_IN_DATA)) - { - if(Data_Mul_MaxPacketSize == TRUE) - { - /* No more data to send and empty packet */ - Send0LengthData(); - ControlState = LAST_IN_DATA; - Data_Mul_MaxPacketSize = FALSE; - } - else - { - /* No more data to send so STALL the TX Status*/ - ControlState = WAIT_STATUS_OUT; - vSetEPTxStatus(EP_TX_STALL); - } - - goto Expect_Status_Out; - } - - Length = pEPinfo->PacketSize; - ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA; - - if (Length > save_wLength) - { - Length = save_wLength; - } - - DataBuffer = (*pEPinfo->CopyData)(Length); - - UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length); - - SetEPTxCount(ENDP0, Length); - - pEPinfo->Usb_wLength -= Length; - pEPinfo->Usb_wOffset += Length; - vSetEPTxStatus(EP_TX_VALID); - - USB_StatusOut();/* Expect the host to abort the data IN stage */ - -Expect_Status_Out: - pInformation->ControlState = ControlState; -} - -/******************************************************************************* -* Function Name : NoData_Setup0. -* Description : Proceed the processing of setup request without data stage. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ -void NoData_Setup0(void) -{ - RESULT Result = USB_UNSUPPORT; - u32 RequestNo = pInformation->USBbRequest; - u32 ControlState; - - if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - { - /* Device Request*/ - /* SET_CONFIGURATION*/ - if (RequestNo == SET_CONFIGURATION) - { - Result = Standard_SetConfiguration(); - } - - /*SET ADDRESS*/ - else if (RequestNo == SET_ADDRESS) - { - if ((pInformation->USBwValue0 > 127) || (pInformation->USBwValue1 != 0) - || (pInformation->USBwIndex != 0) - || (pInformation->Current_Configuration != 0)) - /* Device Address should be 127 or less*/ - { - ControlState = STALLED; - goto exit_NoData_Setup0; - } - else - { - Result = USB_SUCCESS; - } - } - /*SET FEATURE for Device*/ - else if (RequestNo == SET_FEATURE) - { - if ((pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP) - && (pInformation->USBwIndex == 0) - && (ValBit(pInformation->Current_Feature, 5))) - { - Result = Standard_SetDeviceFeature(); - } - else - { - Result = USB_UNSUPPORT; - } - } - /*Clear FEATURE for Device */ - else if (RequestNo == CLEAR_FEATURE) - { - if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP - && pInformation->USBwIndex == 0 - && ValBit(pInformation->Current_Feature, 5)) - { - Result = Standard_ClearFeature(); - } - else - { - Result = USB_UNSUPPORT; - } - } - - } - - /* Interface Request*/ - else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) - { - /*SET INTERFACE*/ - if (RequestNo == SET_INTERFACE) - { - Result = Standard_SetInterface(); - } - } - - /* EndPoint Request*/ - else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) - { - /*CLEAR FEATURE for EndPoint*/ - if (RequestNo == CLEAR_FEATURE) - { - Result = Standard_ClearFeature(); - } - /* SET FEATURE for EndPoint*/ - else if (RequestNo == SET_FEATURE) - { - Result = Standard_SetEndPointFeature(); - } - } - else - { - Result = USB_UNSUPPORT; - } - - - if (Result != USB_SUCCESS) - { - Result = (*pProperty->Class_NoData_Setup)(RequestNo); - if (Result == USB_NOT_READY) - { - ControlState = PAUSE; - goto exit_NoData_Setup0; - } - } - - if (Result != USB_SUCCESS) - { - ControlState = STALLED; - goto exit_NoData_Setup0; - } - - ControlState = WAIT_STATUS_IN;/* After no data stage SETUP */ - - USB_StatusIn(); - -exit_NoData_Setup0: - pInformation->ControlState = ControlState; - return; -} - -/******************************************************************************* -* Function Name : Data_Setup0. -* Description : Proceed the processing of setup request with data stage. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ -void Data_Setup0(void) -{ - u8 *(*CopyRoutine)(u16); - RESULT Result; - u32 Request_No = pInformation->USBbRequest; - - u32 Related_Endpoint, Reserved; - u32 wOffset, Status; - - - - CopyRoutine = NULL; - wOffset = 0; - - if (Request_No == GET_DESCRIPTOR) - { - if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - { - u8 wValue1 = pInformation->USBwValue1; - if (wValue1 == DEVICE_DESCRIPTOR) - { - CopyRoutine = pProperty->GetDeviceDescriptor; - } - else if (wValue1 == CONFIG_DESCRIPTOR) - { - CopyRoutine = pProperty->GetConfigDescriptor; - } - else if (wValue1 == STRING_DESCRIPTOR) - { - CopyRoutine = pProperty->GetStringDescriptor; - } /* End of GET_DESCRIPTOR */ - } - } - - /*GET STATUS*/ - else if ((Request_No == GET_STATUS) && (pInformation->USBwValue == 0) - && (pInformation->USBwLength == 0x0002) - && (pInformation->USBwIndex1 == 0)) - { - /* GET STATUS for Device*/ - if ((Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - && (pInformation->USBwIndex == 0)) - { - CopyRoutine = Standard_GetStatus; - } - - /* GET STATUS for Interface*/ - else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) - { - if (((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS) - && (pInformation->Current_Configuration != 0)) - { - CopyRoutine = Standard_GetStatus; - } - } - - /* GET STATUS for EndPoint*/ - else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) - { - Related_Endpoint = (pInformation->USBwIndex0 & 0x0f); - Reserved = pInformation->USBwIndex0 & 0x70; - - if (ValBit(pInformation->USBwIndex0, 7)) - { - /*Get Status of endpoint & stall the request if the related_ENdpoint - is Disabled*/ - Status = _GetEPTxStatus(Related_Endpoint); - } - else - { - Status = _GetEPRxStatus(Related_Endpoint); - } - - if ((Related_Endpoint < Device_Table.Total_Endpoint) && (Reserved == 0) - && (Status != 0)) - { - CopyRoutine = Standard_GetStatus; - } - } - - } - - /*GET CONFIGURATION*/ - else if (Request_No == GET_CONFIGURATION) - { - if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - { - CopyRoutine = Standard_GetConfiguration; - } - } - /*GET INTERFACE*/ - else if (Request_No == GET_INTERFACE) - { - if ((Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) - && (pInformation->Current_Configuration != 0) && (pInformation->USBwValue == 0) - && (pInformation->USBwIndex1 == 0) && (pInformation->USBwLength == 0x0001) - && ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS)) - { - CopyRoutine = Standard_GetInterface; - } - - } - - if (CopyRoutine) - { - pInformation->Ctrl_Info.Usb_wOffset = wOffset; - pInformation->Ctrl_Info.CopyData = CopyRoutine; - /* sb in the original the cast to word was directly */ - /* now the cast is made step by step */ - (*CopyRoutine)(0); - Result = USB_SUCCESS; - } - else - { - Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest); - if (Result == USB_NOT_READY) - { - pInformation->ControlState = PAUSE; - return; - } - } - - if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF) - { - /* Data is not ready, wait it */ - pInformation->ControlState = PAUSE; - return; - } - if ((Result == USB_UNSUPPORT) || (pInformation->Ctrl_Info.Usb_wLength == 0)) - { - /* Unsupported request */ - pInformation->ControlState = STALLED; - return; - } - - - if (ValBit(pInformation->USBbmRequestType, 7)) - { - /* Device ==> Host */ - vu32 wLength = pInformation->USBwLength; - - /* Restrict the data length to be the one host asks */ - if (pInformation->Ctrl_Info.Usb_wLength > wLength) - { - pInformation->Ctrl_Info.Usb_wLength = wLength; - } - - else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength) - { - if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize) - { - Data_Mul_MaxPacketSize = FALSE; - } - else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0) - { - Data_Mul_MaxPacketSize = TRUE; - } - } - - pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize; - DataStageIn(); - } - else - { - pInformation->ControlState = OUT_DATA; - vSetEPRxStatus(EP_RX_VALID); /* enable for next data reception */ - } - - return; -} - -/******************************************************************************* -* Function Name : Setup0_Process -* Description : Get the device request data and dispatch to individual process. -* Input : None. -* Output : None. -* Return : Post0_Process. -*******************************************************************************/ -u8 Setup0_Process(void) -{ - - union - { - u8* b; - u16* w; - } pBuf; - - pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */ - - if (pInformation->ControlState != PAUSE) - { - pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */ - pInformation->USBbRequest = *pBuf.b++; /* bRequest */ - pBuf.w++; /* word not accessed because of 32 bits addressing */ - pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */ - pBuf.w++; /* word not accessed because of 32 bits addressing */ - pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */ - pBuf.w++; /* word not accessed because of 32 bits addressing */ - pInformation->USBwLength = *pBuf.w; /* wLength */ - } - - pInformation->ControlState = SETTING_UP; - if (pInformation->USBwLength == 0) - { - /* Setup with no data stage */ - NoData_Setup0(); - } - else - { - /* Setup with data stage */ - Data_Setup0(); - } - return Post0_Process(); -} - -/******************************************************************************* -* Function Name : In0_Process -* Description : Process the IN token on all default endpoint. -* Input : None. -* Output : None. -* Return : Post0_Process. -*******************************************************************************/ -u8 In0_Process(void) -{ - u32 ControlState = pInformation->ControlState; - - if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA)) - { - DataStageIn(); - /* ControlState may be changed outside the function */ - ControlState = pInformation->ControlState; - } - - else if (ControlState == WAIT_STATUS_IN) - { - if ((pInformation->USBbRequest == SET_ADDRESS) && - (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))) - { - SetDeviceAddress(pInformation->USBwValue0); - pUser_Standard_Requests->User_SetDeviceAddress(); - } - (*pProperty->Process_Status_IN)(); - ControlState = STALLED; - } - - else - { - ControlState = STALLED; - } - - pInformation->ControlState = ControlState; - - return Post0_Process(); -} - -/******************************************************************************* -* Function Name : Out0_Process -* Description : Process the OUT token on all default endpoint. -* Input : None. -* Output : None. -* Return : Post0_Process. -*******************************************************************************/ -u8 Out0_Process(void) -{ - u32 ControlState = pInformation->ControlState; - - if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA)) - { - DataStageOut(); - ControlState = pInformation->ControlState; /* may be changed outside the function */ - } - - else if (ControlState == WAIT_STATUS_OUT) - { - (*pProperty->Process_Status_OUT)(); - ControlState = STALLED; - } - - else if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA)) - { - /* host aborts the transfer before finish */ - ControlState = STALLED; - } - - /* Unexpect state, STALL the endpoint */ - else - { - ControlState = STALLED; - } - - pInformation->ControlState = ControlState; - - return Post0_Process(); -} - -/******************************************************************************* -* Function Name : Post0_Process -* Description : Stall the Endpoint 0 in case of error. -* Input : None. -* Output : None. -* Return : - 0 if the control State is in PAUSE -* - 1 if not. -*******************************************************************************/ -u8 Post0_Process(void) -{ - SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); - - if (pInformation->ControlState == STALLED) - { - vSetEPRxStatus(EP_RX_STALL); - vSetEPTxStatus(EP_TX_STALL); - } - - return (pInformation->ControlState == PAUSE); -} - -/******************************************************************************* -* Function Name : SetDeviceAddress. -* Description : Set the device and all the used Endpoints addresses. -* Input : - Val: device adress. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetDeviceAddress(u8 Val) -{ - u32 i; - u32 nEP = Device_Table.Total_Endpoint; - - /* set address in every used endpoint */ - for (i = 0; i < nEP; i++) - { - _SetEPAddress((u8)i, (u8)i); - } /* for */ - _SetDADDR(Val | DADDR_EF); /* set device address and enable function */ -} - -/******************************************************************************* -* Function Name : NOP_Process -* Description : No operation function. -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ -void NOP_Process(void) -{ -} - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_core.h b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_core.h deleted file mode 100644 index fa29a18..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_core.h +++ /dev/null @@ -1,251 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_core.h -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Standard protocol processing functions prototypes -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_CORE_H -#define __USB_CORE_H - -#if defined(__cplusplus) -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -typedef enum _CONTROL_STATE -{ - WAIT_SETUP, /* 0 */ - SETTING_UP, /* 1 */ - IN_DATA, /* 2 */ - OUT_DATA, /* 3 */ - LAST_IN_DATA, /* 4 */ - LAST_OUT_DATA, /* 5 */ - WAIT_STATUS_IN, /* 7 */ - WAIT_STATUS_OUT, /* 8 */ - STALLED, /* 9 */ - PAUSE /* 10 */ -} CONTROL_STATE; /* The state machine states of a control pipe */ - -typedef struct OneDescriptor -{ - u8 *Descriptor; - u16 Descriptor_Size; -} -ONE_DESCRIPTOR, *PONE_DESCRIPTOR; -/* All the request process routines return a value of this type - If the return value is not SUCCESS or NOT_READY, - the software will STALL the correspond endpoint */ -typedef enum _RESULT -{ - USB_SUCCESS = 0, /* Process sucessfully */ - USB_ERROR, - USB_UNSUPPORT, - USB_NOT_READY /* The process has not been finished, endpoint will be - NAK to further rquest */ -} RESULT; - - -/*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/ -typedef struct _ENDPOINT_INFO -{ - /* When send data out of the device, - CopyData() is used to get data buffer 'Length' bytes data - if Length is 0, - CopyData() returns the total length of the data - if the request is not supported, returns 0 - (NEW Feature ) - if CopyData() returns -1, the calling routine should not proceed - further and will resume the SETUP process by the class device - if Length is not 0, - CopyData() returns a pointer to indicate the data location - Usb_wLength is the data remain to be sent, - Usb_wOffset is the Offset of original data - When receive data from the host, - CopyData() is used to get user data buffer which is capable - of Length bytes data to copy data from the endpoint buffer. - if Length is 0, - CopyData() returns the available data length, - if Length is not 0, - CopyData() returns user buffer address - Usb_rLength is the data remain to be received, - Usb_rPointer is the Offset of data buffer - */ - u16 Usb_wLength; - u16 Usb_wOffset; - u16 PacketSize; - u8 *(*CopyData)(u16 Length); -}ENDPOINT_INFO; - -/*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/ - -typedef struct _DEVICE -{ - u8 Total_Endpoint; /* Number of endpoints that are used */ - u8 Total_Configuration;/* Number of configuration available */ -} -DEVICE; - -typedef union -{ - u16 w; - struct BW - { - u8 bb1; - u8 bb0; - } - bw; -} u16_u8; - -typedef struct _DEVICE_INFO -{ - u8 USBbmRequestType; /* bmRequestType */ - u8 USBbRequest; /* bRequest */ - u16_u8 USBwValues; /* wValue */ - u16_u8 USBwIndexs; /* wIndex */ - u16_u8 USBwLengths; /* wLength */ - - u8 ControlState; /* of type CONTROL_STATE */ - u8 Current_Feature; - u8 Current_Configuration; /* Selected configuration */ - u8 Current_Interface; /* Selected interface of current configuration */ - u8 Current_AlternateSetting;/* Selected Alternate Setting of current - interface*/ - - ENDPOINT_INFO Ctrl_Info; -}DEVICE_INFO; - -typedef struct _DEVICE_PROP -{ - void (*Init)(void); /* Initialize the device */ - void (*Reset)(void); /* Reset routine of this device */ - - /* Device dependent process after the status stage */ - void (*Process_Status_IN)(void); - void (*Process_Status_OUT)(void); - - /* Procedure of process on setup stage of a class specified request with data stage */ - /* All class specified requests with data stage are processed in Class_Data_Setup - Class_Data_Setup() - responses to check all special requests and fills ENDPOINT_INFO - according to the request - If IN tokens are expected, then wLength & wOffset will be filled - with the total transferring bytes and the starting position - If OUT tokens are expected, then rLength & rOffset will be filled - with the total expected bytes and the starting position in the buffer - - If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT - - CAUTION: - Since GET_CONFIGURATION & GET_INTERFACE are highly related to - the individual classes, they will be checked and processed here. - */ - RESULT (*Class_Data_Setup)(u8 RequestNo); - - /* Procedure of process on setup stage of a class specified request without data stage */ - /* All class specified requests without data stage are processed in Class_NoData_Setup - Class_NoData_Setup - responses to check all special requests and perform the request - - CAUTION: - Since SET_CONFIGURATION & SET_INTERFACE are highly related to - the individual classes, they will be checked and processed here. - */ - RESULT (*Class_NoData_Setup)(u8 RequestNo); - - /*Class_Get_Interface_Setting - This function is used by the file usb_core.c to test if the selected Interface - and Alternate Setting (u8 Interface, u8 AlternateSetting) are supported by - the application. - This function is writing by user. It should return "SUCCESS" if the Interface - and Alternate Setting are supported by the application or "UNSUPPORT" if they - are not supported. */ - - RESULT (*Class_Get_Interface_Setting)(u8 Interface, u8 AlternateSetting); - - u8* (*GetDeviceDescriptor)(u16 Length); - u8* (*GetConfigDescriptor)(u16 Length); - u8* (*GetStringDescriptor)(u16 Length); - - u8* RxEP_buffer; - u8 MaxPacketSize; - -}DEVICE_PROP; - -typedef struct _USER_STANDARD_REQUESTS -{ - void (*User_GetConfiguration)(void); /* Get Configuration */ - void (*User_SetConfiguration)(void); /* Set Configuration */ - void (*User_GetInterface)(void); /* Get Interface */ - void (*User_SetInterface)(void); /* Set Interface */ - void (*User_GetStatus)(void); /* Get Status */ - void (*User_ClearFeature)(void); /* Clear Feature */ - void (*User_SetEndPointFeature)(void); /* Set Endpoint Feature */ - void (*User_SetDeviceFeature)(void); /* Set Device Feature */ - void (*User_SetDeviceAddress)(void); /* Set Device Address */ -} -USER_STANDARD_REQUESTS; - -/* Exported constants --------------------------------------------------------*/ -#define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT)) - -#define Usb_rLength Usb_wLength -#define Usb_rOffset Usb_wOffset - -#define USBwValue USBwValues.w -#define USBwValue0 USBwValues.bw.bb0 -#define USBwValue1 USBwValues.bw.bb1 -#define USBwIndex USBwIndexs.w -#define USBwIndex0 USBwIndexs.bw.bb0 -#define USBwIndex1 USBwIndexs.bw.bb1 -#define USBwLength USBwLengths.w -#define USBwLength0 USBwLengths.bw.bb0 -#define USBwLength1 USBwLengths.bw.bb1 - -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -u8 Setup0_Process(void); -u8 Post0_Process(void); -u8 Out0_Process(void); -u8 In0_Process(void); - -RESULT Standard_SetEndPointFeature(void); -RESULT Standard_SetDeviceFeature(void); - -u8 *Standard_GetConfiguration(u16 Length); -RESULT Standard_SetConfiguration(void); -u8 *Standard_GetInterface(u16 Length); -RESULT Standard_SetInterface(void); -u8 *Standard_GetDescriptorData(u16 Length, PONE_DESCRIPTOR pDesc); - -u8 *Standard_GetStatus(u16 Length); -RESULT Standard_ClearFeature(void); -void SetDeviceAddress(u8); -void NOP_Process(void); - -extern DEVICE_PROP Device_Property; -extern USER_STANDARD_REQUESTS User_Standard_Requests; -extern DEVICE Device_Table; -extern DEVICE_INFO Device_Info; - -/* cells saving status during interrupt servicing */ -extern u16 SaveRState; -extern u16 SaveTState; - -#if defined(__cplusplus) -} -#endif - -#endif /* __USB_CORE_H */ - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_def.h b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_def.h deleted file mode 100644 index 80aa303..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_def.h +++ /dev/null @@ -1,88 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_def.h -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Definitions related to USB Core -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_DEF_H -#define __USB_DEF_H - -#if defined(__cplusplus) -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -typedef enum _RECIPIENT_TYPE -{ - DEVICE_RECIPIENT, /* Recipient device */ - INTERFACE_RECIPIENT, /* Recipient interface */ - ENDPOINT_RECIPIENT, /* Recipient endpoint */ - OTHER_RECIPIENT -} RECIPIENT_TYPE; - - -typedef enum _STANDARD_REQUESTS -{ - GET_STATUS = 0, - CLEAR_FEATURE, - RESERVED1, - SET_FEATURE, - RESERVED2, - SET_ADDRESS, - GET_DESCRIPTOR, - SET_DESCRIPTOR, - GET_CONFIGURATION, - SET_CONFIGURATION, - GET_INTERFACE, - SET_INTERFACE, - TOTAL_sREQUEST, /* Total number of Standard request */ - SYNCH_FRAME = 12 -} STANDARD_REQUESTS; - -/* Definition of "USBwValue" */ -typedef enum _DESCRIPTOR_TYPE -{ - DEVICE_DESCRIPTOR = 1, - CONFIG_DESCRIPTOR, - STRING_DESCRIPTOR, - INTERFACE_DESCRIPTOR, - ENDPOINT_DESCRIPTOR -} DESCRIPTOR_TYPE; - -/* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ -typedef enum _FEATURE_SELECTOR -{ - ENDPOINT_STALL, - DEVICE_REMOTE_WAKEUP -} FEATURE_SELECTOR; - -/* Exported constants --------------------------------------------------------*/ -/* Definition of "USBbmRequestType" */ -#define REQUEST_TYPE 0x60 /* Mask to get request type */ -#define STANDARD_REQUEST 0x00 /* Standard request */ -#define CLASS_REQUEST 0x20 /* Class request */ -#define VENDOR_REQUEST 0x40 /* Vendor request */ - -#define RECIPIENT 0x1F /* Mask to get recipient */ - -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ - -#if defined(__cplusplus) -} -#endif - -#endif /* __USB_DEF_H */ - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_init.c b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_init.c deleted file mode 100644 index 94f3a83..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_init.c +++ /dev/null @@ -1,64 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_init.c -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Initialization routines & global variables -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Includes ------------------------------------------------------------------*/ -#include "usb_lib.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* The number of current endpoint, it will be used to specify an endpoint */ - u8 EPindex; -/* The number of current device, it is an index to the Device_Table */ -/* u8 Device_no; */ -/* Points to the DEVICE_INFO structure of current device */ -/* The purpose of this register is to speed up the execution */ -DEVICE_INFO *pInformation; -/* Points to the DEVICE_PROP structure of current device */ -/* The purpose of this register is to speed up the execution */ -DEVICE_PROP *pProperty; -/* Temporary save the state of Rx & Tx status. */ -/* Whenever the Rx or Tx state is changed, its value is saved */ -/* in this variable first and will be set to the EPRB or EPRA */ -/* at the end of interrupt process */ -u16 SaveState ; -u16 wInterrupt_Mask; -DEVICE_INFO Device_Info; -USER_STANDARD_REQUESTS *pUser_Standard_Requests; - -/* Extern variables ----------------------------------------------------------*/ -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ - -/******************************************************************************* -* Function Name : USB_Init -* Description : USB system initialization -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ -void USB_Init(void) -{ - pInformation = &Device_Info; - pInformation->ControlState = 2; - pProperty = &Device_Property; - pUser_Standard_Requests = &User_Standard_Requests; - /* Initialize devices one by one */ - - pProperty->Init(); -} - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_init.h b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_init.h deleted file mode 100644 index 80ee2fb..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_init.h +++ /dev/null @@ -1,57 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_init.h -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Initialization routines & global variables -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_INIT_H -#define __USB_INIT_H - -#if defined(__cplusplus) -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -void USB_Init(void); - -/* External variables --------------------------------------------------------*/ -/* The number of current endpoint, it will be used to specify an endpoint */ -extern u8 EPindex; -/* The number of current device, it is an index to the Device_Table */ -/*extern u8 Device_no; */ -/* Points to the DEVICE_INFO structure of current device */ -/* The purpose of this register is to speed up the execution */ -extern DEVICE_INFO* pInformation; -/* Points to the DEVICE_PROP structure of current device */ -/* The purpose of this register is to speed up the execution */ -extern DEVICE_PROP* pProperty; -/* Temporary save the state of Rx & Tx status. */ -/* Whenever the Rx or Tx state is changed, its value is saved */ -/* in this variable first and will be set to the EPRB or EPRA */ -/* at the end of interrupt process */ -extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; - -extern u16 SaveState ; -extern u16 wInterrupt_Mask; - -#if defined(__cplusplus) -} -#endif - -#endif /* __USB_INIT_H */ - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_lib.h b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_lib.h deleted file mode 100644 index 85f94ab..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_lib.h +++ /dev/null @@ -1,36 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_lib.h -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : USB library include files -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_LIB_H -#define __USB_LIB_H - -/* Includes ------------------------------------------------------------------*/ -#include "usb_type.h" -#include "usb_regs.h" -#include "usb_def.h" -#include "usb_core.h" -#include "usb_init.h" -#include "usb_mem.h" - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -/* External variables --------------------------------------------------------*/ - -#endif /* __USB_LIB_H */ - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_mem.c b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_mem.c deleted file mode 100644 index ad9740a..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_mem.c +++ /dev/null @@ -1,73 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_mem.c -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Utility functions for memory transfers to/from PMA -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Includes ------------------------------------------------------------------*/ -#include "usb_lib.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* Extern variables ----------------------------------------------------------*/ -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ -/******************************************************************************* -* Function Name : UserToPMABufferCopy -* Description : Copy a buffer from user memory area to packet memory area (PMA) -* Input : - pbUsrBuf: pointer to user memory area. -* - wPMABufAddr: address into PMA. -* - wNBytes: no. of bytes to be copied. -* Output : None. -* Return : None . -*******************************************************************************/ -void UserToPMABufferCopy(const u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes) -{ - u32 n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ - u32 i, temp1, temp2; - u16 *pdwVal; - pdwVal = (u16 *)(wPMABufAddr * 2 + PMAAddr); - for (i = n; i != 0; i--) - { - temp1 = (u16) * pbUsrBuf; - pbUsrBuf++; - temp2 = temp1 | (u16) * pbUsrBuf << 8; - *pdwVal++ = temp2; - pdwVal++; - pbUsrBuf++; - } -} -/******************************************************************************* -* Function Name : PMAToUserBufferCopy -* Description : Copy a buffer from user memory area to packet memory area (PMA) -* Input : - pbUsrBuf = pointer to user memory area. -* - wPMABufAddr = address into PMA. -* - wNBytes = no. of bytes to be copied. -* Output : None. -* Return : None. -*******************************************************************************/ -void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes) -{ - u32 n = (wNBytes + 1) >> 1;/* /2*/ - u32 i; - u32 *pdwVal; - pdwVal = (u32 *)(wPMABufAddr * 2 + PMAAddr); - for (i = n; i != 0; i--) - { - *(u16*)pbUsrBuf++ = *pdwVal++; - pbUsrBuf++; - } -} - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_mem.h b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_mem.h deleted file mode 100644 index b0e0474..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_mem.h +++ /dev/null @@ -1,40 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_mem.h -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Utility prototypes functions for memory/PMA transfers -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_MEM_H -#define __USB_MEM_H - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -#if defined(__cplusplus) -extern "C" { -#endif - -void UserToPMABufferCopy(const u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes); -void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes); - -#if defined(__cplusplus) -} -#endif - -/* External variables --------------------------------------------------------*/ - -#endif /*__USB_MEM_H*/ - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_regs.c b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_regs.c deleted file mode 100644 index c7e0276..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_regs.c +++ /dev/null @@ -1,748 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_regs.c -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Interface functions to USB cell registers -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Includes ------------------------------------------------------------------*/ -#include "usb_lib.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* Extern variables ----------------------------------------------------------*/ -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ - -/******************************************************************************* -* Function Name : SetCNTR. -* Description : Set the CNTR register value. -* Input : wRegValue: new register value. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetCNTR(u16 wRegValue) -{ - _SetCNTR(wRegValue); -} - -/******************************************************************************* -* Function Name : GetCNTR. -* Description : returns the CNTR register value. -* Input : None. -* Output : None. -* Return : CNTR register Value. -*******************************************************************************/ -u16 GetCNTR(void) -{ - return(_GetCNTR()); -} - -/******************************************************************************* -* Function Name : SetISTR. -* Description : Set the ISTR register value. -* Input : wRegValue: new register value. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetISTR(u16 wRegValue) -{ - _SetISTR(wRegValue); -} - -/******************************************************************************* -* Function Name : GetISTR -* Description : Returns the ISTR register value. -* Input : None. -* Output : None. -* Return : ISTR register Value -*******************************************************************************/ -u16 GetISTR(void) -{ - return(_GetISTR()); -} - -/******************************************************************************* -* Function Name : GetFNR -* Description : Returns the FNR register value. -* Input : None. -* Output : None. -* Return : FNR register Value -*******************************************************************************/ -u16 GetFNR(void) -{ - return(_GetFNR()); -} - -/******************************************************************************* -* Function Name : SetDADDR -* Description : Set the DADDR register value. -* Input : wRegValue: new register value. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetDADDR(u16 wRegValue) -{ - _SetDADDR(wRegValue); -} - -/******************************************************************************* -* Function Name : GetDADDR -* Description : Returns the DADDR register value. -* Input : None. -* Output : None. -* Return : DADDR register Value -*******************************************************************************/ -u16 GetDADDR(void) -{ - return(_GetDADDR()); -} - -/******************************************************************************* -* Function Name : SetBTABLE -* Description : Set the BTABLE. -* Input : wRegValue: New register value. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetBTABLE(u16 wRegValue) -{ - _SetBTABLE(wRegValue); -} - -/******************************************************************************* -* Function Name : GetBTABLE. -* Description : Returns the BTABLE register value. -* Input : None. -* Output : None. -* Return : BTABLE address. -*******************************************************************************/ -u16 GetBTABLE(void) -{ - return(_GetBTABLE()); -} - -/******************************************************************************* -* Function Name : SetENDPOINT -* Description : Setthe Endpoint register value. -* Input : bEpNum: Endpoint Number. -* wRegValue. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetENDPOINT(u8 bEpNum, u16 wRegValue) -{ - _SetENDPOINT(bEpNum, wRegValue); -} - -/******************************************************************************* -* Function Name : GetENDPOINT -* Description : Return the Endpoint register value. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Endpoint register value. -*******************************************************************************/ -u16 GetENDPOINT(u8 bEpNum) -{ - return(_GetENDPOINT(bEpNum)); -} - -/******************************************************************************* -* Function Name : SetEPType -* Description : sets the type in the endpoint register. -* Input : bEpNum: Endpoint Number. -* wType: type definition. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPType(u8 bEpNum, u16 wType) -{ - _SetEPType(bEpNum, wType); -} - -/******************************************************************************* -* Function Name : GetEPType -* Description : Returns the endpoint type. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Endpoint Type -*******************************************************************************/ -u16 GetEPType(u8 bEpNum) -{ - return(_GetEPType(bEpNum)); -} - -/******************************************************************************* -* Function Name : SetEPTxStatus -* Description : Set the status of Tx endpoint. -* Input : bEpNum: Endpoint Number. -* wState: new state. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPTxStatus(u8 bEpNum, u16 wState) -{ - _SetEPTxStatus(bEpNum, wState); -} - -/******************************************************************************* -* Function Name : SetEPRxStatus -* Description : Set the status of Rx endpoint. -* Input : bEpNum: Endpoint Number. -* wState: new state. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPRxStatus(u8 bEpNum, u16 wState) -{ - _SetEPRxStatus(bEpNum, wState); -} - -/******************************************************************************* -* Function Name : SetDouBleBuffEPStall -* Description : sets the status for Double Buffer Endpoint to STALL -* Input : bEpNum: Endpoint Number. -* bDir: Endpoint direction. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetDouBleBuffEPStall(u8 bEpNum, u8 bDir) -{ - u16 Endpoint_DTOG_Status; - Endpoint_DTOG_Status = GetENDPOINT(bEpNum); - if (bDir == EP_DBUF_OUT) - { /* OUT double buffered endpoint */ - _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPRX_DTOG1); - } - else if (bDir == EP_DBUF_IN) - { /* IN double buffered endpoint */ - _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPTX_DTOG1); - } -} - -/******************************************************************************* -* Function Name : GetEPTxStatus -* Description : Returns the endpoint Tx status. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Endpoint TX Status -*******************************************************************************/ -u16 GetEPTxStatus(u8 bEpNum) -{ - return(_GetEPTxStatus(bEpNum)); -} - -/******************************************************************************* -* Function Name : GetEPRxStatus -* Description : Returns the endpoint Rx status. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Endpoint RX Status -*******************************************************************************/ -u16 GetEPRxStatus(u8 bEpNum) -{ - return(_GetEPRxStatus(bEpNum)); -} - -/******************************************************************************* -* Function Name : SetEPTxValid -* Description : Valid the endpoint Tx Status. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPTxValid(u8 bEpNum) -{ - _SetEPTxStatus(bEpNum, EP_TX_VALID); -} - -/******************************************************************************* -* Function Name : SetEPRxValid -* Description : Valid the endpoint Rx Status. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPRxValid(u8 bEpNum) -{ - _SetEPRxStatus(bEpNum, EP_RX_VALID); -} - -/******************************************************************************* -* Function Name : SetEP_KIND -* Description : Clear the EP_KIND bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEP_KIND(u8 bEpNum) -{ - _SetEP_KIND(bEpNum); -} - -/******************************************************************************* -* Function Name : ClearEP_KIND -* Description : set the EP_KIND bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void ClearEP_KIND(u8 bEpNum) -{ - _ClearEP_KIND(bEpNum); -} -/******************************************************************************* -* Function Name : Clear_Status_Out -* Description : Clear the Status Out of the related Endpoint -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void Clear_Status_Out(u8 bEpNum) -{ - _ClearEP_KIND(bEpNum); -} -/******************************************************************************* -* Function Name : Set_Status_Out -* Description : Set the Status Out of the related Endpoint -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void Set_Status_Out(u8 bEpNum) -{ - _SetEP_KIND(bEpNum); -} -/******************************************************************************* -* Function Name : SetEPDoubleBuff -* Description : Enable the double buffer feature for the endpoint. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPDoubleBuff(u8 bEpNum) -{ - _SetEP_KIND(bEpNum); -} -/******************************************************************************* -* Function Name : ClearEPDoubleBuff -* Description : Disable the double buffer feature for the endpoint. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void ClearEPDoubleBuff(u8 bEpNum) -{ - _ClearEP_KIND(bEpNum); -} -/******************************************************************************* -* Function Name : GetTxStallStatus -* Description : Returns the Stall status of the Tx endpoint. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Tx Stall status. -*******************************************************************************/ -u16 GetTxStallStatus(u8 bEpNum) -{ - return(_GetTxStallStatus(bEpNum)); -} -/******************************************************************************* -* Function Name : GetRxStallStatus -* Description : Returns the Stall status of the Rx endpoint. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Rx Stall status. -*******************************************************************************/ -u16 GetRxStallStatus(u8 bEpNum) -{ - return(_GetRxStallStatus(bEpNum)); -} -/******************************************************************************* -* Function Name : ClearEP_CTR_RX -* Description : Clear the CTR_RX bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void ClearEP_CTR_RX(u8 bEpNum) -{ - _ClearEP_CTR_RX(bEpNum); -} -/******************************************************************************* -* Function Name : ClearEP_CTR_TX -* Description : Clear the CTR_TX bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void ClearEP_CTR_TX(u8 bEpNum) -{ - _ClearEP_CTR_TX(bEpNum); -} -/******************************************************************************* -* Function Name : ToggleDTOG_RX -* Description : Toggle the DTOG_RX bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void ToggleDTOG_RX(u8 bEpNum) -{ - _ToggleDTOG_RX(bEpNum); -} -/******************************************************************************* -* Function Name : ToggleDTOG_TX -* Description : Toggle the DTOG_TX bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void ToggleDTOG_TX(u8 bEpNum) -{ - _ToggleDTOG_TX(bEpNum); -} -/******************************************************************************* -* Function Name : ClearDTOG_RX. -* Description : Clear the DTOG_RX bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void ClearDTOG_RX(u8 bEpNum) -{ - _ClearDTOG_RX(bEpNum); -} -/******************************************************************************* -* Function Name : ClearDTOG_TX. -* Description : Clear the DTOG_TX bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -void ClearDTOG_TX(u8 bEpNum) -{ - _ClearDTOG_TX(bEpNum); -} -/******************************************************************************* -* Function Name : SetEPAddress -* Description : Set the endpoint address. -* Input : bEpNum: Endpoint Number. -* bAddr: New endpoint address. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPAddress(u8 bEpNum, u8 bAddr) -{ - _SetEPAddress(bEpNum, bAddr); -} -/******************************************************************************* -* Function Name : GetEPAddress -* Description : Get the endpoint address. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Endpoint address. -*******************************************************************************/ -u8 GetEPAddress(u8 bEpNum) -{ - return(_GetEPAddress(bEpNum)); -} -/******************************************************************************* -* Function Name : SetEPTxAddr -* Description : Set the endpoint Tx buffer address. -* Input : bEpNum: Endpoint Number. -* wAddr: new address. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPTxAddr(u8 bEpNum, u16 wAddr) -{ - _SetEPTxAddr(bEpNum, wAddr); -} -/******************************************************************************* -* Function Name : SetEPRxAddr -* Description : Set the endpoint Rx buffer address. -* Input : bEpNum: Endpoint Number. -* wAddr: new address. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPRxAddr(u8 bEpNum, u16 wAddr) -{ - _SetEPRxAddr(bEpNum, wAddr); -} -/******************************************************************************* -* Function Name : GetEPTxAddr -* Description : Returns the endpoint Tx buffer address. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Rx buffer address. -*******************************************************************************/ -u16 GetEPTxAddr(u8 bEpNum) -{ - return(_GetEPTxAddr(bEpNum)); -} -/******************************************************************************* -* Function Name : GetEPRxAddr. -* Description : Returns the endpoint Rx buffer address. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Rx buffer address. -*******************************************************************************/ -u16 GetEPRxAddr(u8 bEpNum) -{ - return(_GetEPRxAddr(bEpNum)); -} -/******************************************************************************* -* Function Name : SetEPTxCount. -* Description : Set the Tx count. -* Input : bEpNum: Endpoint Number. -* wCount: new count value. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPTxCount(u8 bEpNum, u16 wCount) -{ - _SetEPTxCount(bEpNum, wCount); -} -/******************************************************************************* -* Function Name : SetEPCountRxReg. -* Description : Set the Count Rx Register value. -* Input : *pdwReg: point to the register. -* wCount: the new register value. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPCountRxReg(u32 *pdwReg, u16 wCount) -{ - _SetEPCountRxReg(dwReg, wCount); -} -/******************************************************************************* -* Function Name : SetEPRxCount -* Description : Set the Rx count. -* Input : bEpNum: Endpoint Number. -* wCount: the new count value. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPRxCount(u8 bEpNum, u16 wCount) -{ - _SetEPRxCount(bEpNum, wCount); -} -/******************************************************************************* -* Function Name : GetEPTxCount -* Description : Get the Tx count. -* Input : bEpNum: Endpoint Number. -* Output : None -* Return : Tx count value. -*******************************************************************************/ -u16 GetEPTxCount(u8 bEpNum) -{ - return(_GetEPTxCount(bEpNum)); -} -/******************************************************************************* -* Function Name : GetEPRxCount -* Description : Get the Rx count. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Rx count value. -*******************************************************************************/ -u16 GetEPRxCount(u8 bEpNum) -{ - return(_GetEPRxCount(bEpNum)); -} -/******************************************************************************* -* Function Name : SetEPDblBuffAddr -* Description : Set the addresses of the buffer 0 and 1. -* Input : bEpNum: Endpoint Number. -* wBuf0Addr: new address of buffer 0. -* wBuf1Addr: new address of buffer 1. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPDblBuffAddr(u8 bEpNum, u16 wBuf0Addr, u16 wBuf1Addr) -{ - _SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr); -} -/******************************************************************************* -* Function Name : SetEPDblBuf0Addr -* Description : Set the Buffer 1 address. -* Input : bEpNum: Endpoint Number -* wBuf0Addr: new address. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPDblBuf0Addr(u8 bEpNum, u16 wBuf0Addr) -{ - _SetEPDblBuf0Addr(bEpNum, wBuf0Addr); -} -/******************************************************************************* -* Function Name : SetEPDblBuf1Addr -* Description : Set the Buffer 1 address. -* Input : bEpNum: Endpoint Number -* wBuf1Addr: new address. -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPDblBuf1Addr(u8 bEpNum, u16 wBuf1Addr) -{ - _SetEPDblBuf1Addr(bEpNum, wBuf1Addr); -} -/******************************************************************************* -* Function Name : GetEPDblBuf0Addr -* Description : Returns the address of the Buffer 0. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -u16 GetEPDblBuf0Addr(u8 bEpNum) -{ - return(_GetEPDblBuf0Addr(bEpNum)); -} -/******************************************************************************* -* Function Name : GetEPDblBuf1Addr -* Description : Returns the address of the Buffer 1. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Address of the Buffer 1. -*******************************************************************************/ -u16 GetEPDblBuf1Addr(u8 bEpNum) -{ - return(_GetEPDblBuf1Addr(bEpNum)); -} -/******************************************************************************* -* Function Name : SetEPDblBuffCount -* Description : Set the number of bytes for a double Buffer -* endpoint. -* Input : bEpNum,bDir, wCount -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPDblBuffCount(u8 bEpNum, u8 bDir, u16 wCount) -{ - _SetEPDblBuffCount(bEpNum, bDir, wCount); -} -/******************************************************************************* -* Function Name : SetEPDblBuf0Count -* Description : Set the number of bytes in the buffer 0 of a double Buffer -* endpoint. -* Input : bEpNum, bDir, wCount -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPDblBuf0Count(u8 bEpNum, u8 bDir, u16 wCount) -{ - _SetEPDblBuf0Count(bEpNum, bDir, wCount); -} -/******************************************************************************* -* Function Name : SetEPDblBuf1Count -* Description : Set the number of bytes in the buffer 0 of a double Buffer -* endpoint. -* Input : bEpNum, bDir, wCount -* Output : None. -* Return : None. -*******************************************************************************/ -void SetEPDblBuf1Count(u8 bEpNum, u8 bDir, u16 wCount) -{ - _SetEPDblBuf1Count(bEpNum, bDir, wCount); -} -/******************************************************************************* -* Function Name : GetEPDblBuf0Count -* Description : Returns the number of byte received in the buffer 0 of a double -* Buffer endpoint. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Endpoint Buffer 0 count -*******************************************************************************/ -u16 GetEPDblBuf0Count(u8 bEpNum) -{ - return(_GetEPDblBuf0Count(bEpNum)); -} -/******************************************************************************* -* Function Name : GetEPDblBuf1Count -* Description : Returns the number of data received in the buffer 1 of a double -* Buffer endpoint. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Endpoint Buffer 1 count. -*******************************************************************************/ -u16 GetEPDblBuf1Count(u8 bEpNum) -{ - return(_GetEPDblBuf1Count(bEpNum)); -} -/******************************************************************************* -* Function Name : GetEPDblBufDir -* Description : gets direction of the double buffered endpoint -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : EP_DBUF_OUT, EP_DBUF_IN, -* EP_DBUF_ERR if the endpoint counter not yet programmed. -*******************************************************************************/ -EP_DBUF_DIR GetEPDblBufDir(u8 bEpNum) -{ - if ((u16)(*_pEPRxCount(bEpNum) & 0xFC00) != 0) - return(EP_DBUF_OUT); - else if (((u16)(*_pEPTxCount(bEpNum)) & 0x03FF) != 0) - return(EP_DBUF_IN); - else - return(EP_DBUF_ERR); -} -/******************************************************************************* -* Function Name : FreeUserBuffer -* Description : free buffer used from the application realizing it to the line - toggles bit SW_BUF in the double buffered endpoint register -* Input : bEpNum, bDir -* Output : None. -* Return : None. -*******************************************************************************/ -void FreeUserBuffer(u8 bEpNum, u8 bDir) -{ - if (bDir == EP_DBUF_OUT) - { /* OUT double buffered endpoint */ - _ToggleDTOG_TX(bEpNum); - } - else if (bDir == EP_DBUF_IN) - { /* IN double buffered endpoint */ - _ToggleDTOG_RX(bEpNum); - } -} - -/******************************************************************************* -* Function Name : ToWord -* Description : merge two byte in a word. -* Input : bh: byte high, bl: bytes low. -* Output : None. -* Return : resulted word. -*******************************************************************************/ -u16 ToWord(u8 bh, u8 bl) -{ - u16 wRet; - wRet = (u16)bl | ((u16)bh << 8); - return(wRet); -} -/******************************************************************************* -* Function Name : ByteSwap -* Description : Swap two byte in a word. -* Input : wSwW: word to Swap. -* Output : None. -* Return : resulted word. -*******************************************************************************/ -u16 ByteSwap(u16 wSwW) -{ - u8 bTemp; - u16 wRet; - bTemp = (u8)(wSwW & 0xff); - wRet = (wSwW >> 8) | ((u16)bTemp << 8); - return(wRet); -} - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_regs.h b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_regs.h deleted file mode 100644 index b63cc5f..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_regs.h +++ /dev/null @@ -1,627 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_regs.h -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Interface prototype functions to USB cell registers -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_REGS_H -#define __USB_REGS_H - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -#if defined(__cplusplus) -extern "C" { -#endif - -typedef enum _EP_DBUF_DIR -{ - /* double buffered endpoint direction */ - EP_DBUF_ERR, - EP_DBUF_OUT, - EP_DBUF_IN -}EP_DBUF_DIR; - -/* endpoint buffer number */ -enum EP_BUF_NUM -{ - EP_NOBUF, - EP_BUF0, - EP_BUF1 -}; - -/* Exported constants --------------------------------------------------------*/ -#define RegBase (0x40005C00L) /* USB_IP Peripheral Registers base address */ -#define PMAAddr (0x40006000L) /* USB_IP Packet Memory Area base address */ - -/******************************************************************************/ -/* General registers */ -/******************************************************************************/ - -/* Control register */ -#define CNTR ((volatile unsigned *)(RegBase + 0x40)) -/* Interrupt status register */ -#define ISTR ((volatile unsigned *)(RegBase + 0x44)) -/* Frame number register */ -#define FNR ((volatile unsigned *)(RegBase + 0x48)) -/* Device address register */ -#define DADDR ((volatile unsigned *)(RegBase + 0x4C)) -/* Buffer Table address register */ -#define BTABLE ((volatile unsigned *)(RegBase + 0x50)) -/******************************************************************************/ -/* Endpoint registers */ -/******************************************************************************/ -#define EP0REG ((volatile unsigned *)(RegBase)) /* endpoint 0 register address */ - -/* endpoints enumeration */ -#define ENDP0 ((u8)0) -#define ENDP1 ((u8)1) -#define ENDP2 ((u8)2) -#define ENDP3 ((u8)3) -#define ENDP4 ((u8)4) -#define ENDP5 ((u8)5) -#define ENDP6 ((u8)6) -#define ENDP7 ((u8)7) -/******************************************************************************/ -/* ISTR interrupt events */ -/******************************************************************************/ -#define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */ -#define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */ -#define ISTR_ERR (0x2000) /* ERRor (clear-only bit) */ -#define ISTR_WKUP (0x1000) /* WaKe UP (clear-only bit) */ -#define ISTR_SUSP (0x0800) /* SUSPend (clear-only bit) */ -#define ISTR_RESET (0x0400) /* RESET (clear-only bit) */ -#define ISTR_SOF (0x0200) /* Start Of Frame (clear-only bit) */ -#define ISTR_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */ - - -#define ISTR_DIR (0x0010) /* DIRection of transaction (read-only bit) */ -#define ISTR_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */ - -#define CLR_CTR (~ISTR_CTR) /* clear Correct TRansfer bit */ -#define CLR_DOVR (~ISTR_DOVR) /* clear DMA OVeR/underrun bit*/ -#define CLR_ERR (~ISTR_ERR) /* clear ERRor bit */ -#define CLR_WKUP (~ISTR_WKUP) /* clear WaKe UP bit */ -#define CLR_SUSP (~ISTR_SUSP) /* clear SUSPend bit */ -#define CLR_RESET (~ISTR_RESET) /* clear RESET bit */ -#define CLR_SOF (~ISTR_SOF) /* clear Start Of Frame bit */ -#define CLR_ESOF (~ISTR_ESOF) /* clear Expected Start Of Frame bit */ - -/******************************************************************************/ -/* CNTR control register bits definitions */ -/******************************************************************************/ -#define CNTR_CTRM (0x8000) /* Correct TRansfer Mask */ -#define CNTR_DOVRM (0x4000) /* DMA OVeR/underrun Mask */ -#define CNTR_ERRM (0x2000) /* ERRor Mask */ -#define CNTR_WKUPM (0x1000) /* WaKe UP Mask */ -#define CNTR_SUSPM (0x0800) /* SUSPend Mask */ -#define CNTR_RESETM (0x0400) /* RESET Mask */ -#define CNTR_SOFM (0x0200) /* Start Of Frame Mask */ -#define CNTR_ESOFM (0x0100) /* Expected Start Of Frame Mask */ - - -#define CNTR_RESUME (0x0010) /* RESUME request */ -#define CNTR_FSUSP (0x0008) /* Force SUSPend */ -#define CNTR_LPMODE (0x0004) /* Low-power MODE */ -#define CNTR_PDWN (0x0002) /* Power DoWN */ -#define CNTR_FRES (0x0001) /* Force USB RESet */ - -/******************************************************************************/ -/* FNR Frame Number Register bit definitions */ -/******************************************************************************/ -#define FNR_RXDP (0x8000) /* status of D+ data line */ -#define FNR_RXDM (0x4000) /* status of D- data line */ -#define FNR_LCK (0x2000) /* LoCKed */ -#define FNR_LSOF (0x1800) /* Lost SOF */ -#define FNR_FN (0x07FF) /* Frame Number */ -/******************************************************************************/ -/* DADDR Device ADDRess bit definitions */ -/******************************************************************************/ -#define DADDR_EF (0x80) -#define DADDR_ADD (0x7F) -/******************************************************************************/ -/* Endpoint register */ -/******************************************************************************/ -/* bit positions */ -#define EP_CTR_RX (0x8000) /* EndPoint Correct TRansfer RX */ -#define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */ -#define EPRX_STAT (0x3000) /* EndPoint RX STATus bit field */ -#define EP_SETUP (0x0800) /* EndPoint SETUP */ -#define EP_T_FIELD (0x0600) /* EndPoint TYPE */ -#define EP_KIND (0x0100) /* EndPoint KIND */ -#define EP_CTR_TX (0x0080) /* EndPoint Correct TRansfer TX */ -#define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */ -#define EPTX_STAT (0x0030) /* EndPoint TX STATus bit field */ -#define EPADDR_FIELD (0x000F) /* EndPoint ADDRess FIELD */ - -/* EndPoint REGister MASK (no toggle fields) */ -#define EPREG_MASK (EP_CTR_RX|EP_SETUP|EP_T_FIELD|EP_KIND|EP_CTR_TX|EPADDR_FIELD) - -/* EP_TYPE[1:0] EndPoint TYPE */ -#define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */ -#define EP_BULK (0x0000) /* EndPoint BULK */ -#define EP_CONTROL (0x0200) /* EndPoint CONTROL */ -#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */ -#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */ -#define EP_T_MASK (~EP_T_FIELD & EPREG_MASK) - - -/* EP_KIND EndPoint KIND */ -#define EPKIND_MASK (~EP_KIND & EPREG_MASK) - -/* STAT_TX[1:0] STATus for TX transfer */ -#define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */ -#define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */ -#define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */ -#define EP_TX_VALID (0x0030) /* EndPoint TX VALID */ -#define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */ -#define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */ -#define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK) - -/* STAT_RX[1:0] STATus for RX transfer */ -#define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */ -#define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */ -#define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */ -#define EP_RX_VALID (0x3000) /* EndPoint RX VALID */ -#define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */ -#define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */ -#define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK) -/* Exported macro ------------------------------------------------------------*/ -/* SetCNTR */ -#define _SetCNTR(wRegValue) (*CNTR = (u16)wRegValue) - -/* SetISTR */ -#define _SetISTR(wRegValue) (*ISTR = (u16)wRegValue) - -/* SetDADDR */ -#define _SetDADDR(wRegValue) (*DADDR = (u16)wRegValue) - -/* SetBTABLE */ -#define _SetBTABLE(wRegValue)(*BTABLE = (u16)(wRegValue & 0xFFF8)) - -/* GetCNTR */ -#define _GetCNTR() ((u16) *CNTR) - -/* GetISTR */ -#define _GetISTR() ((u16) *ISTR) - -/* GetFNR */ -#define _GetFNR() ((u16) *FNR) - -/* GetDADDR */ -#define _GetDADDR() ((u16) *DADDR) - -/* GetBTABLE */ -#define _GetBTABLE() ((u16) *BTABLE) - -/* SetENDPOINT */ -#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \ - (u16)wRegValue) - -/* GetENDPOINT */ -#define _GetENDPOINT(bEpNum) ((u16)(*(EP0REG + bEpNum))) - -/******************************************************************************* -* Macro Name : SetEPType -* Description : sets the type in the endpoint register(bits EP_TYPE[1:0]) -* Input : bEpNum: Endpoint Number. -* wType -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\ - ((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType))) - -/******************************************************************************* -* Macro Name : GetEPType -* Description : gets the type in the endpoint register(bits EP_TYPE[1:0]) -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Endpoint Type -*******************************************************************************/ -#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD) - -/******************************************************************************* -* Macro Name : SetEPTxStatus -* Description : sets the status for tx transfer (bits STAT_TX[1:0]). -* Input : bEpNum: Endpoint Number. -* wState: new state -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPTxStatus(bEpNum,wState) {\ - register u16 _wRegVal; \ - _wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\ - /* toggle first bit ? */ \ - if((EPTX_DTOG1 & wState)!= 0) \ - _wRegVal ^= EPTX_DTOG1; \ - /* toggle second bit ? */ \ - if((EPTX_DTOG2 & wState)!= 0) \ - _wRegVal ^= EPTX_DTOG2; \ - _SetENDPOINT(bEpNum, _wRegVal); \ - } /* _SetEPTxStatus */ - -/******************************************************************************* -* Macro Name : SetEPRxStatus -* Description : sets the status for rx transfer (bits STAT_TX[1:0]) -* Input : bEpNum: Endpoint Number. -* wState: new state. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPRxStatus(bEpNum,wState) {\ - register u16 _wRegVal; \ - \ - _wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\ - /* toggle first bit ? */ \ - if((EPRX_DTOG1 & wState)!= 0) \ - _wRegVal ^= EPRX_DTOG1; \ - /* toggle second bit ? */ \ - if((EPRX_DTOG2 & wState)!= 0) \ - _wRegVal ^= EPRX_DTOG2; \ - _SetENDPOINT(bEpNum, _wRegVal); \ - } /* _SetEPRxStatus */ -/******************************************************************************* -* Macro Name : GetEPTxStatus / GetEPRxStatus -* Description : gets the status for tx/rx transfer (bits STAT_TX[1:0] -* /STAT_RX[1:0]) -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : status . -*******************************************************************************/ -#define _GetEPTxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPTX_STAT) - -#define _GetEPRxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPRX_STAT) - -/******************************************************************************* -* Macro Name : SetEPTxValid / SetEPRxValid -* Description : sets directly the VALID tx/rx-status into the enpoint register -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID)) - -#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID)) - -/******************************************************************************* -* Macro Name : GetTxStallStatus / GetRxStallStatus. -* Description : checks stall condition in an endpoint. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : TRUE = endpoint in stall condition. -*******************************************************************************/ -#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \ - == EP_TX_STALL) -#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \ - == EP_RX_STALL) - -/******************************************************************************* -* Macro Name : SetEP_KIND / ClearEP_KIND. -* Description : set & clear EP_KIND bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \ - (_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK)) -#define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \ - (_GetENDPOINT(bEpNum) & EPKIND_MASK))) - -/******************************************************************************* -* Macro Name : Set_Status_Out / Clear_Status_Out. -* Description : Sets/clears directly STATUS_OUT bit in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum) -#define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum) - -/******************************************************************************* -* Macro Name : SetEPDoubleBuff / ClearEPDoubleBuff. -* Description : Sets/clears directly EP_KIND bit in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum) -#define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum) - -/******************************************************************************* -* Macro Name : ClearEP_CTR_RX / ClearEP_CTR_TX. -* Description : Clears bit CTR_RX / CTR_TX in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\ - _GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK)) -#define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\ - _GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK)) - -/******************************************************************************* -* Macro Name : ToggleDTOG_RX / ToggleDTOG_TX . -* Description : Toggles DTOG_RX / DTOG_TX bit in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \ - EP_DTOG_RX | (_GetENDPOINT(bEpNum) & EPREG_MASK))) -#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \ - EP_DTOG_TX | (_GetENDPOINT(bEpNum) & EPREG_MASK))) - -/******************************************************************************* -* Macro Name : ClearDTOG_RX / ClearDTOG_TX. -* Description : Clears DTOG_RX / DTOG_TX bit in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\ - _ToggleDTOG_RX(bEpNum) -#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\ - _ToggleDTOG_TX(bEpNum) -/******************************************************************************* -* Macro Name : SetEPAddress. -* Description : Sets address in an endpoint register. -* Input : bEpNum: Endpoint Number. -* bAddr: Address. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\ - (_GetENDPOINT(bEpNum) & EPREG_MASK) | bAddr) - -/******************************************************************************* -* Macro Name : GetEPAddress. -* Description : Gets address in an endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _GetEPAddress(bEpNum) ((u8)(_GetENDPOINT(bEpNum) & EPADDR_FIELD)) - -#define _pEPTxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr)) -#define _pEPTxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr)) -#define _pEPRxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr)) -#define _pEPRxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr)) - -/******************************************************************************* -* Macro Name : SetEPTxAddr / SetEPRxAddr. -* Description : sets address of the tx/rx buffer. -* Input : bEpNum: Endpoint Number. -* wAddr: address to be set (must be word aligned). -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1)) -#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1)) - -/******************************************************************************* -* Macro Name : GetEPTxAddr / GetEPRxAddr. -* Description : Gets address of the tx/rx buffer. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : address of the buffer. -*******************************************************************************/ -#define _GetEPTxAddr(bEpNum) ((u16)*_pEPTxAddr(bEpNum)) -#define _GetEPRxAddr(bEpNum) ((u16)*_pEPRxAddr(bEpNum)) - -/******************************************************************************* -* Macro Name : SetEPCountRxReg. -* Description : Sets counter of rx buffer with no. of blocks. -* Input : pdwReg: pointer to counter. -* wCount: Counter. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _BlocksOf32(dwReg,wCount,wNBlocks) {\ - wNBlocks = wCount >> 5;\ - if((wCount & 0x1f) == 0)\ - wNBlocks--;\ - *pdwReg = (u32)((wNBlocks << 10) | 0x8000);\ - }/* _BlocksOf32 */ - -#define _BlocksOf2(dwReg,wCount,wNBlocks) {\ - wNBlocks = wCount >> 1;\ - if((wCount & 0x1) != 0)\ - wNBlocks++;\ - *pdwReg = (u32)(wNBlocks << 10);\ - }/* _BlocksOf2 */ - -#define _SetEPCountRxReg(dwReg,wCount) {\ - u16 wNBlocks;\ - if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\ - else {_BlocksOf2(dwReg,wCount,wNBlocks);}\ - }/* _SetEPCountRxReg */ - - - -#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\ - u32 *pdwReg = _pEPTxCount(bEpNum); \ - _SetEPCountRxReg(pdwReg, wCount);\ - } -/******************************************************************************* -* Macro Name : SetEPTxCount / SetEPRxCount. -* Description : sets counter for the tx/rx buffer. -* Input : bEpNum: endpoint number. -* wCount: Counter value. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount) -#define _SetEPRxCount(bEpNum,wCount) {\ - u32 *pdwReg = _pEPRxCount(bEpNum); \ - _SetEPCountRxReg(pdwReg, wCount);\ - } -/******************************************************************************* -* Macro Name : GetEPTxCount / GetEPRxCount. -* Description : gets counter of the tx buffer. -* Input : bEpNum: endpoint number. -* Output : None. -* Return : Counter value. -*******************************************************************************/ -#define _GetEPTxCount(bEpNum)((u16)(*_pEPTxCount(bEpNum)) & 0x3ff) -#define _GetEPRxCount(bEpNum)((u16)(*_pEPRxCount(bEpNum)) & 0x3ff) - -/******************************************************************************* -* Macro Name : SetEPDblBuf0Addr / SetEPDblBuf1Addr. -* Description : Sets buffer 0/1 address in a double buffer endpoint. -* Input : bEpNum: endpoint number. -* : wBuf0Addr: buffer 0 address. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);} -#define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);} - -/******************************************************************************* -* Macro Name : SetEPDblBuffAddr. -* Description : Sets addresses in a double buffer endpoint. -* Input : bEpNum: endpoint number. -* : wBuf0Addr: buffer 0 address. -* : wBuf1Addr = buffer 1 address. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \ - _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\ - _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\ - } /* _SetEPDblBuffAddr */ - -/******************************************************************************* -* Macro Name : GetEPDblBuf0Addr / GetEPDblBuf1Addr. -* Description : Gets buffer 0/1 address of a double buffer endpoint. -* Input : bEpNum: endpoint number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum)) -#define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum)) - -/******************************************************************************* -* Macro Name : SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count. -* Description : Gets buffer 0/1 address of a double buffer endpoint. -* Input : bEpNum: endpoint number. -* : bDir: endpoint dir EP_DBUF_OUT = OUT -* EP_DBUF_IN = IN -* : wCount: Counter value -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \ - if(bDir == EP_DBUF_OUT)\ - /* OUT endpoint */ \ - {_SetEPRxDblBuf0Count(bEpNum,wCount);} \ - else if(bDir == EP_DBUF_IN)\ - /* IN endpoint */ \ - *_pEPTxCount(bEpNum) = (u32)wCount; \ - } /* SetEPDblBuf0Count*/ - -#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \ - if(bDir == EP_DBUF_OUT)\ - /* OUT endpoint */ \ - {_SetEPRxCount(bEpNum,wCount);}\ - else if(bDir == EP_DBUF_IN)\ - /* IN endpoint */\ - *_pEPRxCount(bEpNum) = (u32)wCount; \ - } /* SetEPDblBuf1Count */ - -#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\ - _SetEPDblBuf0Count(bEpNum, bDir, wCount); \ - _SetEPDblBuf1Count(bEpNum, bDir, wCount); \ - } /* _SetEPDblBuffCount */ - -/******************************************************************************* -* Macro Name : GetEPDblBuf0Count / GetEPDblBuf1Count. -* Description : Gets buffer 0/1 rx/tx counter for double buffering. -* Input : bEpNum: endpoint number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum)) -#define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum)) - - -/* External variables --------------------------------------------------------*/ -extern volatile u16 wIstr; /* ISTR register last read value */ - -/* Exported functions ------------------------------------------------------- */ -void SetCNTR(u16 /*wRegValue*/); -void SetISTR(u16 /*wRegValue*/); -void SetDADDR(u16 /*wRegValue*/); -void SetBTABLE(u16 /*wRegValue*/); -u16 GetCNTR(void); -u16 GetISTR(void); -u16 GetFNR(void); -u16 GetDADDR(void); -u16 GetBTABLE(void); -void SetENDPOINT(u8 /*bEpNum*/, u16 /*wRegValue*/); -u16 GetENDPOINT(u8 /*bEpNum*/); -void SetEPType(u8 /*bEpNum*/, u16 /*wType*/); -u16 GetEPType(u8 /*bEpNum*/); -void SetEPTxStatus(u8 /*bEpNum*/, u16 /*wState*/); -void SetEPRxStatus(u8 /*bEpNum*/, u16 /*wState*/); -void SetDouBleBuffEPStall(u8 /*bEpNum*/, u8 bDir); -u16 GetEPTxStatus(u8 /*bEpNum*/); -u16 GetEPRxStatus(u8 /*bEpNum*/); -void SetEPTxValid(u8 /*bEpNum*/); -void SetEPRxValid(u8 /*bEpNum*/); -u16 GetTxStallStatus(u8 /*bEpNum*/); -u16 GetRxStallStatus(u8 /*bEpNum*/); -void SetEP_KIND(u8 /*bEpNum*/); -void ClearEP_KIND(u8 /*bEpNum*/); -void Set_Status_Out(u8 /*bEpNum*/); -void Clear_Status_Out(u8 /*bEpNum*/); -void SetEPDoubleBuff(u8 /*bEpNum*/); -void ClearEPDoubleBuff(u8 /*bEpNum*/); -void ClearEP_CTR_RX(u8 /*bEpNum*/); -void ClearEP_CTR_TX(u8 /*bEpNum*/); -void ToggleDTOG_RX(u8 /*bEpNum*/); -void ToggleDTOG_TX(u8 /*bEpNum*/); -void ClearDTOG_RX(u8 /*bEpNum*/); -void ClearDTOG_TX(u8 /*bEpNum*/); -void SetEPAddress(u8 /*bEpNum*/, u8 /*bAddr*/); -u8 GetEPAddress(u8 /*bEpNum*/); -void SetEPTxAddr(u8 /*bEpNum*/, u16 /*wAddr*/); -void SetEPRxAddr(u8 /*bEpNum*/, u16 /*wAddr*/); -u16 GetEPTxAddr(u8 /*bEpNum*/); -u16 GetEPRxAddr(u8 /*bEpNum*/); -void SetEPCountRxReg(u32 * /*pdwReg*/, u16 /*wCount*/); -void SetEPTxCount(u8 /*bEpNum*/, u16 /*wCount*/); -void SetEPRxCount(u8 /*bEpNum*/, u16 /*wCount*/); -u16 GetEPTxCount(u8 /*bEpNum*/); -u16 GetEPRxCount(u8 /*bEpNum*/); -void SetEPDblBuf0Addr(u8 /*bEpNum*/, u16 /*wBuf0Addr*/); -void SetEPDblBuf1Addr(u8 /*bEpNum*/, u16 /*wBuf1Addr*/); -void SetEPDblBuffAddr(u8 /*bEpNum*/, u16 /*wBuf0Addr*/, u16 /*wBuf1Addr*/); -u16 GetEPDblBuf0Addr(u8 /*bEpNum*/); -u16 GetEPDblBuf1Addr(u8 /*bEpNum*/); -void SetEPDblBuffCount(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/); -void SetEPDblBuf0Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/); -void SetEPDblBuf1Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/); -u16 GetEPDblBuf0Count(u8 /*bEpNum*/); -u16 GetEPDblBuf1Count(u8 /*bEpNum*/); -EP_DBUF_DIR GetEPDblBufDir(u8 /*bEpNum*/); -void FreeUserBuffer(u8 bEpNum/*bEpNum*/, u8 bDir); -u16 ToWord(u8, u8); -u16 ByteSwap(u16); - -#if defined(__cplusplus) -} -#endif - -#endif /* __USB_REGS_H */ - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_type.h b/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_type.h deleted file mode 100644 index 34b3bf5..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib/usb_type.h +++ /dev/null @@ -1,77 +0,0 @@ -/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** -* File Name : usb_type.h -* Author : MCD Application Team -* Version : V2.2.1 -* Date : 09/22/2008 -* Description : Type definitions used by the USB Library -******************************************************************************** -* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS -* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. -* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, -* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE -* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING -* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. -*******************************************************************************/ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_TYPE_H -#define __USB_TYPE_H - -#if defined(__cplusplus) -extern "C" { -#endif - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -#ifndef NULL -#define NULL ((void *)0) -#endif - -typedef signed long s32; -typedef signed short s16; -typedef signed char s8; - -typedef volatile signed long vs32; -typedef volatile signed short vs16; -typedef volatile signed char vs8; - -typedef unsigned long u32; -typedef unsigned short u16; -typedef unsigned char u8; - -typedef unsigned long const uc32; /* Read Only */ -typedef unsigned short const uc16; /* Read Only */ -typedef unsigned char const uc8; /* Read Only */ - -typedef volatile unsigned long vu32; -typedef volatile unsigned short vu16; -typedef volatile unsigned char vu8; - -typedef volatile unsigned long const vuc32; /* Read Only */ -typedef volatile unsigned short const vuc16; /* Read Only */ -typedef volatile unsigned char const vuc8; /* Read Only */ - - -typedef enum -{ - FALSE = 0, TRUE = !FALSE -} -USB_Bool; - -typedef enum { RESET = 0, SET = !RESET } FlagStatus, ITStatus; - -typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState; - -typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus; - -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -/* External variables --------------------------------------------------------*/ - -#if defined(__cplusplus) -} -#endif - -#endif /* __USB_TYPE_H */ - -/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ diff --git a/STM32F3/cores/maple/libmaple/usb/usb_lib_globals.h b/STM32F3/cores/maple/libmaple/usb/usb_lib_globals.h deleted file mode 100644 index 1cd2754..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_lib_globals.h +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#ifndef _USB_LIB_GLOBALS_H_ -#define _USB_LIB_GLOBALS_H_ - -/* usb_lib headers */ -#include "usb_type.h" -#include "usb_core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern USER_STANDARD_REQUESTS User_Standard_Requests; -extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; - -extern DEVICE_PROP Device_Property; -extern DEVICE_PROP *pProperty; - -extern DEVICE_INFO Device_Info; -extern DEVICE_INFO *pInformation; - -extern DEVICE Device_Table; -extern u16 SaveRState; -extern u16 SaveTState; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/STM32F3/cores/maple/libmaple/usb/usb_reg_map.c b/STM32F3/cores/maple/libmaple/usb/usb_reg_map.c deleted file mode 100644 index ea60cb3..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_reg_map.c +++ /dev/null @@ -1,88 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#include "usb_reg_map.h" - -/* TODO these could use some improvement; they're fairly - * straightforward ports of the analogous ST code. The PMA blit - * routines in particular are obvious targets for performance - * measurement and tuning. */ - -void usb_copy_to_pma(const uint8 *buf, uint16 len, uint16 pma_offset) { - uint16 *dst = (uint16*)usb_pma_ptr(pma_offset); - uint16 n = len >> 1; - uint16 i; - for (i = 0; i < n; i++) { - *dst = (uint16)(*buf) | *(buf + 1) << 8; - buf += 2; - dst += 2; - } - if (len & 1) { - *dst = *buf; - } -} - -void usb_copy_from_pma(uint8 *buf, uint16 len, uint16 pma_offset) { - uint32 *src = (uint32*)usb_pma_ptr(pma_offset); - uint16 *dst = (uint16*)buf; - uint16 n = len >> 1; - uint16 i; - for (i = 0; i < n; i++) { - *dst++ = *src++; - } - if (len & 1) { - *dst = *src & 0xFF; - } -} - -static void usb_set_ep_rx_count_common(uint32 *rxc, uint16 count) { - uint16 nblocks; - if (count > 62) { - /* use 32-byte memory block size */ - nblocks = count >> 5; - if ((count & 0x1F) == 0) { - nblocks--; - } - *rxc = (nblocks << 10) | 0x8000; - } else { - /* use 2-byte memory block size */ - nblocks = count >> 1; - if ((count & 0x1) != 0) { - nblocks++; - } - *rxc = nblocks << 10; - } -} - -void usb_set_ep_rx_buf0_count(uint8 ep, uint16 count) { - uint32 *rxc = usb_ep_rx_buf0_count_ptr(ep); - usb_set_ep_rx_count_common(rxc, count); -} - -void usb_set_ep_rx_count(uint8 ep, uint16 count) { - uint32 *rxc = usb_ep_rx_count_ptr(ep); - usb_set_ep_rx_count_common(rxc, count); -} diff --git a/STM32F3/cores/maple/libmaple/usb/usb_reg_map.h b/STM32F3/cores/maple/libmaple/usb/usb_reg_map.h deleted file mode 100644 index 2cd5e35..0000000 --- a/STM32F3/cores/maple/libmaple/usb/usb_reg_map.h +++ /dev/null @@ -1,617 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#include -#include - -#ifndef _USB_REG_MAP_H_ -#define _USB_REG_MAP_H_ - -/* TODO: - * - Pick one of "endp", "ep" "endpt" - */ - -/* - * Register map and base pointer - */ - -#define USB_NR_EP_REGS 8 - -/** USB register map type */ -typedef struct usb_reg_map { - __IO uint32 EP[USB_NR_EP_REGS]; /**< Endpoint registers */ - const uint32 RESERVED[8]; /**< Reserved */ - __IO uint32 CNTR; /**< Control register */ - __IO uint32 ISTR; /**< Interrupt status register */ - __IO uint32 FNR; /**< Frame number register */ - __IO uint32 DADDR; /**< Device address */ - __IO uint32 BTABLE; /**< @brief Buffer table address - * - * Address offset within the USB - * packet memory area which points - * to the base of the buffer - * descriptor table. Must be - * aligned to an 8 byte boundary. - */ -} usb_reg_map; - -/** USB register map base pointer */ -#define USB_BASE ((struct usb_reg_map*)0x40005C00) - -/* - * Register bit definitions - */ - -/* Endpoint registers (USB_EPnR) */ - -#define USB_EP_CTR_RX_BIT 15 -#define USB_EP_DTOG_RX_BIT 14 -#define USB_EP_SETUP_BIT 11 -#define USB_EP_EP_KIND_BIT 8 -#define USB_EP_CTR_TX_BIT 7 -#define USB_EP_DTOG_TX_BIT 6 - -#define USB_EP_CTR_RX BIT(USB_EP_CTR_RX_BIT) -#define USB_EP_DTOG_RX BIT(USB_EP_DTOG_RX_BIT) -#define USB_EP_STAT_RX (0x3 << 12) -#define USB_EP_STAT_RX_DISABLED (0x0 << 12) -#define USB_EP_STAT_RX_STALL (0x1 << 12) -#define USB_EP_STAT_RX_NAK (0x2 << 12) -#define USB_EP_STAT_RX_VALID (0x3 << 12) -#define USB_EP_SETUP BIT(USB_EP_SETUP_BIT) -#define USB_EP_EP_TYPE (0x3 << 9) -#define USB_EP_EP_TYPE_BULK (0x0 << 9) -#define USB_EP_EP_TYPE_CONTROL (0x1 << 9) -#define USB_EP_EP_TYPE_ISO (0x2 << 9) -#define USB_EP_EP_TYPE_INTERRUPT (0x3 << 9) -#define USB_EP_EP_KIND BIT(USB_EP_EP_KIND_BIT) -#define USB_EP_EP_KIND_DBL_BUF (0x1 << USB_EP_EP_KIND_BIT) -#define USB_EP_CTR_TX BIT(USB_EP_CTR_TX_BIT) -#define USB_EP_DTOG_TX BIT(USB_EP_DTOG_TX_BIT) -#define USB_EP_STAT_TX (0x3 << 4) -#define USB_EP_STAT_TX_DISABLED (0x0 << 4) -#define USB_EP_STAT_TX_STALL (0x1 << 4) -#define USB_EP_STAT_TX_NAK (0x2 << 4) -#define USB_EP_STAT_TX_VALID (0x3 << 4) -#define USB_EP_EA 0xF - -/* Control register (USB_CNTR) */ - -#define USB_CNTR_CTRM_BIT 15 -#define USB_CNTR_PMAOVERM_BIT 14 -#define USB_CNTR_ERRM_BIT 13 -#define USB_CNTR_WKUPM_BIT 12 -#define USB_CNTR_SUSPM_BIT 11 -#define USB_CNTR_RESETM_BIT 10 -#define USB_CNTR_SOFM_BIT 9 -#define USB_CNTR_ESOFM_BIT 8 -#define USB_CNTR_RESUME_BIT 4 -#define USB_CNTR_FSUSP_BIT 3 -#define USB_CNTR_LP_MODE_BIT 2 -#define USB_CNTR_PDWN_BIT 1 -#define USB_CNTR_FRES_BIT 0 - -#define USB_CNTR_CTRM BIT(USB_CNTR_CTRM_BIT) -#define USB_CNTR_PMAOVERM BIT(USB_CNTR_PMAOVERM_BIT) -#define USB_CNTR_ERRM BIT(USB_CNTR_ERRM_BIT) -#define USB_CNTR_WKUPM BIT(USB_CNTR_WKUPM_BIT) -#define USB_CNTR_SUSPM BIT(USB_CNTR_SUSPM_BIT) -#define USB_CNTR_RESETM BIT(USB_CNTR_RESETM_BIT) -#define USB_CNTR_SOFM BIT(USB_CNTR_SOFM_BIT) -#define USB_CNTR_ESOFM BIT(USB_CNTR_ESOFM_BIT) -#define USB_CNTR_RESUME BIT(USB_CNTR_RESUME_BIT) -#define USB_CNTR_FSUSP BIT(USB_CNTR_FSUSP_BIT) -#define USB_CNTR_LP_MODE BIT(USB_CNTR_LP_MODE_BIT) -#define USB_CNTR_PDWN BIT(USB_CNTR_PDWN_BIT) -#define USB_CNTR_FRES BIT(USB_CNTR_FRES_BIT) - -/* Interrupt status register (USB_ISTR) */ - -#define USB_ISTR_CTR_BIT 15 -#define USB_ISTR_PMAOVR_BIT 14 -#define USB_ISTR_ERR_BIT 13 -#define USB_ISTR_WKUP_BIT 12 -#define USB_ISTR_SUSP_BIT 11 -#define USB_ISTR_RESET_BIT 10 -#define USB_ISTR_SOF_BIT 9 -#define USB_ISTR_ESOF_BIT 8 -#define USB_ISTR_DIR_BIT 4 - -#define USB_ISTR_CTR BIT(USB_ISTR_CTR_BIT) -#define USB_ISTR_PMAOVR BIT(USB_ISTR_PMAOVR_BIT) -#define USB_ISTR_ERR BIT(USB_ISTR_ERR_BIT) -#define USB_ISTR_WKUP BIT(USB_ISTR_WKUP_BIT) -#define USB_ISTR_SUSP BIT(USB_ISTR_SUSP_BIT) -#define USB_ISTR_RESET BIT(USB_ISTR_RESET_BIT) -#define USB_ISTR_SOF BIT(USB_ISTR_SOF_BIT) -#define USB_ISTR_ESOF BIT(USB_ISTR_ESOF_BIT) -#define USB_ISTR_DIR BIT(USB_ISTR_DIR_BIT) -#define USB_ISTR_EP_ID 0xF - -/* Frame number register (USB_FNR) */ - -#define USB_FNR_RXDP_BIT 15 -#define USB_FNR_RXDM_BIT 14 -#define USB_FNR_LCK_BIT 13 - -#define USB_FNR_RXDP BIT(USB_FNR_RXDP_BIT) -#define USB_FNR_RXDM BIT(USB_FNR_RXDM_BIT) -#define USB_FNR_LCK BIT(USB_FNR_LCK_BIT) -#define USB_FNR_LSOF (0x3 << 11) -#define USB_FNR_FN 0x7FF - -/* Device address (USB_DADDR) */ - -#define USB_DADDR_EF_BIT 7 -#define USB_DADDR_ADD6_BIT 6 -#define USB_DADDR_ADD5_BIT 5 -#define USB_DADDR_ADD4_BIT 4 -#define USB_DADDR_ADD3_BIT 3 -#define USB_DADDR_ADD2_BIT 2 -#define USB_DADDR_ADD1_BIT 1 -#define USB_DADDR_ADD0_BIT 0 - -#define USB_DADDR_EF BIT(USB_DADDR_EF_BIT) -#define USB_DADDR_ADD6 BIT(USB_DADDR_ADD6_BIT) -#define USB_DADDR_ADD5 BIT(USB_DADDR_ADD5_BIT) -#define USB_DADDR_ADD4 BIT(USB_DADDR_ADD4_BIT) -#define USB_DADDR_ADD3 BIT(USB_DADDR_ADD3_BIT) -#define USB_DADDR_ADD2 BIT(USB_DADDR_ADD2_BIT) -#define USB_DADDR_ADD1 BIT(USB_DADDR_ADD1_BIT) -#define USB_DADDR_ADD0 BIT(USB_DADDR_ADD0_BIT) - -/* Buffer table address (USB_BTABLE) */ - -#define USB_BTABLE_BTABLE (0x1FFF << 3) - -/* - * Register convenience routines - */ - -#define __EP_CTR_NOP (USB_EP_CTR_RX | USB_EP_CTR_TX) -#define __EP_NONTOGGLE (USB_EP_CTR_RX | USB_EP_SETUP | \ - USB_EP_EP_TYPE | USB_EP_EP_KIND | \ - USB_EP_CTR_TX | USB_EP_EA) - -static inline void usb_clear_ctr_rx(uint8 ep) { - uint32 epr = USB_BASE->EP[ep]; - USB_BASE->EP[ep] = epr & ~USB_EP_CTR_RX & __EP_NONTOGGLE; -} - -static inline void usb_clear_ctr_tx(uint8 ep) { - uint32 epr = USB_BASE->EP[ep]; - USB_BASE->EP[ep] = epr & ~USB_EP_CTR_TX & __EP_NONTOGGLE; -} - -static inline uint32 usb_get_ep_dtog_tx(uint8 ep) { - uint32 epr = USB_BASE->EP[ep]; - return epr & USB_EP_DTOG_TX; -} - -static inline uint32 usb_get_ep_dtog_rx(uint8 ep) { - uint32 epr = USB_BASE->EP[ep]; - return epr & USB_EP_DTOG_RX; -} - -static inline uint32 usb_get_ep_tx_sw_buf(uint8 ep) { - return usb_get_ep_dtog_rx(ep); -} - -static inline uint32 usb_get_ep_rx_sw_buf(uint8 ep) { - return usb_get_ep_dtog_tx(ep); -} - -static inline void usb_toggle_ep_dtog_tx(uint8 ep) { - uint32 epr = USB_BASE->EP[ep]; - epr &= __EP_NONTOGGLE; - epr |= USB_EP_DTOG_TX; - USB_BASE->EP[ep] = epr; -} - -static inline void usb_toggle_ep_dtog_rx(uint8 ep) { - uint32 epr = USB_BASE->EP[ep]; - epr &= __EP_NONTOGGLE; - epr |= USB_EP_DTOG_RX; - USB_BASE->EP[ep] = epr; -} - -static inline void usb_clear_ep_dtog_tx(uint8 ep) { - if (usb_get_ep_dtog_tx(ep) != 0) { - usb_toggle_ep_dtog_tx(ep); - } -} - -static inline void usb_clear_ep_dtog_rx(uint8 ep) { - if (usb_get_ep_dtog_rx(ep) != 0) { - usb_toggle_ep_dtog_rx(ep); - } -} - -static inline void usb_set_ep_dtog_tx(uint8 ep) { - if (usb_get_ep_dtog_tx(ep) == 0) { - usb_toggle_ep_dtog_tx(ep); - } -} - -static inline void usb_set_ep_dtog_rx(uint8 ep) { - if (usb_get_ep_dtog_rx(ep) == 0) { - usb_toggle_ep_dtog_rx(ep); - } -} - -static inline void usb_toggle_ep_rx_sw_buf(uint8 ep) { - usb_toggle_ep_dtog_tx(ep); -} - -static inline void usb_toggle_ep_tx_sw_buf(uint8 ep) { - usb_toggle_ep_dtog_rx(ep); -} - -static inline void usb_clear_ep_rx_sw_buf(uint8 ep) { - usb_clear_ep_dtog_tx(ep); -} - -static inline void usb_clear_ep_tx_sw_buf(uint8 ep) { - usb_clear_ep_dtog_rx(ep); -} - -static inline void usb_set_ep_rx_sw_buf(uint8 ep) { - usb_set_ep_dtog_tx(ep); -} - -static inline void usb_set_ep_tx_sw_buf(uint8 ep) { - usb_set_ep_dtog_rx(ep); -} - -static inline void usb_set_ep_rx_stat(uint8 ep, uint32 status) { - uint32 epr = USB_BASE->EP[ep]; - epr &= ~(USB_EP_STAT_TX | USB_EP_DTOG_RX | USB_EP_DTOG_TX); - epr |= __EP_CTR_NOP; - epr ^= status; - USB_BASE->EP[ep] = epr; -} - -static inline void usb_set_ep_tx_stat(uint8 ep, uint32 status) { - uint32 epr = USB_BASE->EP[ep]; - epr &= ~(USB_EP_STAT_RX | USB_EP_DTOG_RX | USB_EP_DTOG_TX); - epr |= __EP_CTR_NOP; - epr ^= status; - USB_BASE->EP[ep] = epr; -} - -static inline void usb_set_ep_type(uint8 ep, uint32 type) { - uint32 epr = USB_BASE->EP[ep]; - epr &= ~USB_EP_EP_TYPE & __EP_NONTOGGLE; - epr |= type; - USB_BASE->EP[ep] = epr; -} - -static inline void usb_set_ep_kind(uint8 ep, uint32 kind) { - uint32 epr = USB_BASE->EP[ep]; - epr &= ~USB_EP_EP_KIND & __EP_NONTOGGLE; - epr |= kind; - USB_BASE->EP[ep] = epr; -} - -static inline uint32 usb_get_ep_type(uint8 ep) { - uint32 epr = USB_BASE->EP[ep]; - return epr & USB_EP_EP_TYPE; -} - -static inline uint32 usb_get_ep_kind(uint8 ep) { - uint32 epr = USB_BASE->EP[ep]; - return epr & USB_EP_EP_TYPE; -} - - -static inline void usb_clear_status_out(uint8 ep) { - usb_set_ep_kind(ep, 0); -} - -/* - * Packet memory area (PMA) base pointer - */ - -/** - * @brief USB packet memory area (PMA) base pointer. - * - * The USB PMA is SRAM shared between USB and CAN. The USB peripheral - * accesses this memory directly via the packet buffer interface. */ -#define USB_PMA_BASE ((__IO void*)0x40006000) - -/* - * PMA conveniences - */ - -void usb_copy_to_pma(const uint8 *buf, uint16 len, uint16 pma_offset); -void usb_copy_from_pma(uint8 *buf, uint16 len, uint16 pma_offset); - -static inline void* usb_pma_ptr(uint32 offset) { - return (void*)(USB_PMA_BASE + 2 * offset); -} - -/* - * BTABLE - */ - -/* (Forward-declared) BTABLE entry. - * - * The BTABLE can be viewed as an array of usb_btable_ent values; - * these vary in structure according to the configuration of the - * endpoint. - */ -union usb_btable_ent; - -/* Bidirectional endpoint BTABLE entry */ -typedef struct usb_btable_bidi { - __IO uint16 addr_tx; const uint16 PAD1; - __IO uint16 count_tx; const uint16 PAD2; - __IO uint16 addr_rx; const uint16 PAD3; - __IO uint16 count_rx; const uint16 PAD4; -} usb_btable_bidi; - -/* Unidirectional receive-only endpoint BTABLE entry */ -typedef struct usb_btable_uni_rx { - __IO uint16 empty1; const uint16 PAD1; - __IO uint16 empty2; const uint16 PAD2; - __IO uint16 addr_rx; const uint16 PAD3; - __IO uint16 count_rx; const uint16 PAD4; -} usb_btable_uni_rx; - -/* Unidirectional transmit-only endpoint BTABLE entry */ -typedef struct usb_btable_uni_tx { - __IO uint16 addr_tx; const uint16 PAD1; - __IO uint16 count_tx; const uint16 PAD2; - __IO uint16 empty1; const uint16 PAD3; - __IO uint16 empty2; const uint16 PAD4; -} usb_btable_uni_tx; - -/* Double-buffered transmission endpoint BTABLE entry */ -typedef struct usb_btable_dbl_tx { - __IO uint16 addr_tx0; const uint16 PAD1; - __IO uint16 count_tx0; const uint16 PAD2; - __IO uint16 addr_tx1; const uint16 PAD3; - __IO uint16 count_tx1; const uint16 PAD4; -} usb_btable_dbl_tx; - -/* Double-buffered reception endpoint BTABLE entry */ -typedef struct usb_btable_dbl_rx { - __IO uint16 addr_rx0; const uint16 PAD1; - __IO uint16 count_rx0; const uint16 PAD2; - __IO uint16 addr_rx1; const uint16 PAD3; - __IO uint16 count_rx1; const uint16 PAD4; -} usb_btable_dbl_rx; - -/* TODO isochronous endpoint entries */ - -/* Definition for above forward-declared BTABLE entry. */ -typedef union usb_btable_ent { - usb_btable_bidi bidi; - usb_btable_uni_rx u_rx; - usb_btable_uni_tx u_tx; - usb_btable_dbl_tx d_tx; - usb_btable_dbl_rx d_rx; -} usb_btable_ent; - -/* - * BTABLE conveniences - */ - -/* TODO (?) Convert usages of the many (and lengthily-named) - * accessors/mutators below to just manipulating usb_btable_entry - * values. */ - -static inline uint32* usb_btable_ptr(uint32 offset) { - return (uint32*)usb_pma_ptr(USB_BASE->BTABLE + offset); -} - -/* TX address */ - -static inline uint32* usb_ep_tx_addr_ptr(uint8 ep) { - return usb_btable_ptr(ep * 8); -} - -static inline uint16 usb_get_ep_tx_addr(uint8 ep) { - return (uint16)*usb_ep_tx_addr_ptr(ep); -} - -static inline void usb_set_ep_tx_addr(uint8 ep, uint16 addr) { - uint32 *tx_addr = usb_ep_tx_addr_ptr(ep); - *tx_addr = addr & ~0x1; -} - -/* RX address */ - -static inline uint32* usb_ep_rx_addr_ptr(uint8 ep) { - return usb_btable_ptr(ep * 8 + 4); -} - -static inline uint16 usb_get_ep_rx_addr(uint8 ep) { - return (uint16)*usb_ep_rx_addr_ptr(ep); -} - -static inline void usb_set_ep_rx_addr(uint8 ep, uint16 addr) { - uint32 *rx_addr = usb_ep_rx_addr_ptr(ep); - *rx_addr = addr & ~0x1; -} - -/* TX count (doesn't cover double-buffered and isochronous in) */ - -static inline uint32* usb_ep_tx_count_ptr(uint8 ep) { - return usb_btable_ptr(ep * 8 + 2); -} - -static inline uint16 usb_get_ep_tx_count(uint8 ep) { - /* FIXME: this is broken somehow; calling it seems to - * confuse/crash the chip. */ - return (uint16)(*usb_ep_tx_count_ptr(ep) & 0x3FF); -} - -static inline void usb_set_ep_tx_count(uint8 ep, uint16 count) { - uint32 *txc = usb_ep_tx_count_ptr(ep); - *txc = count; -} - -/* RX count */ - -static inline uint32* usb_ep_rx_count_ptr(uint8 ep) { - return usb_btable_ptr(ep * 8 + 6); -} - -static inline uint16 usb_get_ep_rx_count(uint8 ep) { - return (uint16)*usb_ep_rx_count_ptr(ep) & 0x3FF; -} - -void usb_set_ep_rx_count(uint8 ep, uint16 count); - -/* double buffer definitions */ -static inline uint32* usb_get_ep_tx_buf0_addr_ptr(uint8 ep) { - return usb_ep_tx_addr_ptr(ep); -} - -static inline uint16 usb_get_ep_tx_buf0_addr(uint8 ep) { - return usb_get_ep_tx_addr(ep); -} - -static inline void usb_set_ep_tx_buf0_addr(uint8 ep, uint16 addr) { - usb_set_ep_tx_addr(ep, addr); -} - -static inline uint32* usb_get_ep_tx_buf1_addr_ptr(uint8 ep) { - return usb_ep_rx_addr_ptr(ep); -} - -static inline uint16 usb_get_ep_tx_buf1_addr(uint8 ep) { - return usb_get_ep_rx_addr(ep); -} - -static inline void usb_set_ep_tx_buf1_addr(uint8 ep, uint16 addr) { - usb_set_ep_rx_addr(ep, addr); -} - -static inline uint32* usb_ep_tx_buf0_count_ptr(uint8 ep) { - return usb_ep_tx_count_ptr(ep); -} - -static inline uint16 usb_get_ep_tx_buf0_count(uint8 ep) { - return usb_get_ep_tx_count(ep); -} - -static inline void usb_set_ep_tx_buf0_count(uint8 ep, uint16 count) { - usb_set_ep_tx_count(ep, count); -} - -static inline uint32* usb_ep_tx_buf1_count_ptr(uint8 ep) { - return usb_ep_rx_count_ptr(ep); -} - -static inline uint16 usb_get_ep_tx_buf1_count(uint8 ep) { - return usb_get_ep_rx_count(ep); -} - -static inline void usb_set_ep_tx_buf1_count(uint8 ep, uint16 count) { - usb_set_ep_rx_count(ep, count); -} -static inline uint32* usb_get_ep_rx_buf0_addr_ptr(uint8 ep) { - return usb_ep_tx_addr_ptr(ep); -} - -static inline uint16 usb_get_ep_rx_buf0_addr(uint8 ep) { - return usb_get_ep_tx_addr(ep); -} - -static inline void usb_set_ep_rx_buf0_addr(uint8 ep, uint16 addr) { - usb_set_ep_tx_addr(ep, addr); -} - -static inline uint32* usb_get_ep_rx_buf1_addr_ptr(uint8 ep) { - return usb_ep_rx_addr_ptr(ep); -} - -static inline uint16 usb_get_ep_rx_buf1_addr(uint8 ep) { - return usb_get_ep_rx_addr(ep); -} - -static inline void usb_set_ep_rx_buf1_addr(uint8 ep, uint16 addr) { - usb_set_ep_rx_addr(ep, addr); -} - -static inline uint32* usb_ep_rx_buf0_count_ptr(uint8 ep) { - return usb_ep_tx_count_ptr(ep); -} - -static inline uint16 usb_get_ep_rx_buf0_count(uint8 ep) { - return usb_get_ep_tx_count(ep); -} - -void usb_set_ep_rx_buf0_count(uint8 ep, uint16 count); - -static inline uint32* usb_ep_rx_buf1_count_ptr(uint8 ep) { - return usb_ep_rx_count_ptr(ep); -} - -static inline uint16 usb_get_ep_rx_buf1_count(uint8 ep) { - return usb_get_ep_rx_count(ep); -} - -static inline void usb_set_ep_rx_buf1_count(uint8 ep, uint16 count) { - usb_set_ep_rx_count(ep, count); -} - -/* - * Misc. types - */ - -typedef enum usb_ep { - USB_EP0, - USB_EP1, - USB_EP2, - USB_EP3, - USB_EP4, - USB_EP5, - USB_EP6, - USB_EP7, -} usb_ep; - -typedef enum usb_ep_type { - USB_EP_T_CTL = USB_EP_EP_TYPE_CONTROL, - USB_EP_T_BULK = USB_EP_EP_TYPE_BULK, - USB_EP_T_INT = USB_EP_EP_TYPE_INTERRUPT, - USB_EP_T_ISO = USB_EP_EP_TYPE_ISO -} usb_ep_type; - -typedef enum usb_ep_stat { - USB_EP_ST_RX_DIS = USB_EP_STAT_RX_DISABLED, - USB_EP_ST_RX_STL = USB_EP_STAT_RX_STALL, - USB_EP_ST_RX_NAK = USB_EP_STAT_RX_NAK, - USB_EP_ST_RX_VAL = USB_EP_STAT_RX_VALID, - USB_EP_ST_TX_DIS = USB_EP_STAT_TX_DISABLED, - USB_EP_ST_TX_STL = USB_EP_STAT_TX_STALL, - USB_EP_ST_TX_NAK = USB_EP_STAT_TX_NAK, - USB_EP_ST_TX_VAL = USB_EP_STAT_TX_VALID -} usb_ep_stat; - -#endif diff --git a/STM32F3/cores/maple/libmaple/util.c b/STM32F3/cores/maple/libmaple/util.c deleted file mode 100644 index 4c0b2c8..0000000 --- a/STM32F3/cores/maple/libmaple/util.c +++ /dev/null @@ -1,150 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file libmaple/util.c - * @brief Utility procedures for debugging - */ - -#include -#include -#include -#include - -/* (Undocumented) hooks used by Wirish to direct our behavior here */ -extern __weak void __lm_error(void); -extern __weak usart_dev* __lm_enable_error_usart(void); - -/* If you define ERROR_LED_PORT and ERROR_LED_PIN, then a failed - * ASSERT() will also throb() an LED connected to that port and pin. - */ -#if defined(ERROR_LED_PORT) && defined(ERROR_LED_PIN) -#define HAVE_ERROR_LED -#endif - -/* (Called from exc.S with global interrupts disabled.) */ -__attribute__((noreturn)) void __error(void) { - if (__lm_error) { - __lm_error(); - } - /* Reenable global interrupts */ - nvic_globalirq_enable(); - throb(); -} - -/* - * Print an error message on a UART upon a failed assertion (if one is - * available), and punt to __error(). - * - * @param file Source file of failed assertion - * @param line Source line of failed assertion - * @param exp String representation of failed assertion - * @sideeffect Turns of all peripheral interrupts except USB. - */ -void _fail(const char* file, int line, const char* exp) { - if (__lm_enable_error_usart) { - /* Initialize the error USART */ - usart_dev *err_usart = __lm_enable_error_usart(); - - /* Print failed assert message */ - usart_putstr(err_usart, "ERROR: FAILED ASSERT("); - usart_putstr(err_usart, exp); - usart_putstr(err_usart, "): "); - usart_putstr(err_usart, file); - usart_putstr(err_usart, ": "); - usart_putudec(err_usart, line); - usart_putc(err_usart, '\n'); - usart_putc(err_usart, '\r'); - } - /* Shutdown and error fade */ - __error(); -} - -/* - * Provide an __assert_func handler to libc so that calls to assert() - * get redirected to _fail. - */ -void __assert_func(const char* file, int line, const char* method, - const char* expression) { - _fail(file, line, expression); -} - -/* - * Provide an abort() implementation that aborts execution and punts - * to __error(). - */ -void abort() { - if (__lm_enable_error_usart) { - /* Initialize the error USART */ - usart_dev *err_usart = __lm_enable_error_usart(); - /* Print abort message. */ - usart_putstr(err_usart, "ERROR: PROGRAM ABORTED VIA abort()\r\n"); - } - - /* Shutdown and error fade */ - __error(); -} - -/* This was public as of v0.0.12, so we've got to keep it public. */ -/** - * @brief Fades the error LED on and off - * @sideeffect Sets output push-pull on ERROR_LED_PIN. - */ -__attribute__((noreturn)) void throb(void) { -#ifdef HAVE_ERROR_LED - int32 slope = 1; - uint32 CC = 0x0000; - uint32 TOP_CNT = 0x0200; - uint32 i = 0; - - gpio_set_mode(ERROR_LED_PORT, ERROR_LED_PIN, GPIO_MODE_OUTPUT); - /* Error fade. */ - while (1) { - if (CC == TOP_CNT) { - slope = -1; - } else if (CC == 0) { - slope = 1; - } - - if (i == TOP_CNT) { - CC += slope; - i = 0; - } - - if (i < CC) { - gpio_write_bit(ERROR_LED_PORT, ERROR_LED_PIN, 1); - } else { - gpio_write_bit(ERROR_LED_PORT, ERROR_LED_PIN, 0); - } - i++; - } -#else - /* No error LED is defined; do nothing. */ - while (1) - ; -#endif -} diff --git a/STM32F3/cores/maple/main.cpp b/STM32F3/cores/maple/main.cpp deleted file mode 100644 index 7305100..0000000 --- a/STM32F3/cores/maple/main.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -extern void setup(void); -extern void loop(void); -extern void init(void); - -// Force init to be called *first*, i.e. before static object allocation. -// Otherwise, statically allocated objects that need libmaple may fail. - __attribute__(( constructor )) void premain() { - init(); -} - -int main(void) { - setup(); - - while (1) { - loop(); - } - return 0; -} diff --git a/STM32F3/cores/maple/wirish/HardwareSPI.cpp b/STM32F3/cores/maple/wirish/HardwareSPI.cpp deleted file mode 100644 index 60d210f..0000000 --- a/STM32F3/cores/maple/wirish/HardwareSPI.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @author Marti Bolivar - * @brief Wirish SPI implementation. - */ - -#include - -#include -#include -#include - -#include -#include - -#if CYCLES_PER_MICROSECOND != 72 -/* TODO [0.2.0?] something smarter than this */ -#warning "Unexpected clock speed; SPI frequency calculation will be incorrect" -#endif - -struct spi_pins { - uint8 nss; - uint8 sck; - uint8 miso; - uint8 mosi; -}; - -static const spi_pins* dev_to_spi_pins(spi_dev *dev); - -static void enable_device(spi_dev *dev, - bool as_master, - SPIFrequency frequency, - spi_cfg_flag endianness, - spi_mode mode); - -static const spi_pins board_spi_pins[] __FLASH__ = { - {BOARD_SPI1_NSS_PIN, - BOARD_SPI1_SCK_PIN, - BOARD_SPI1_MISO_PIN, - BOARD_SPI1_MOSI_PIN}, - {BOARD_SPI2_NSS_PIN, - BOARD_SPI2_SCK_PIN, - BOARD_SPI2_MISO_PIN, - BOARD_SPI2_MOSI_PIN}, -#if defined(STM32_HIGH_DENSITY) || (STM32_MCU_SERIES == STM32_SERIES_F3) - {BOARD_SPI3_NSS_PIN, - BOARD_SPI3_SCK_PIN, - BOARD_SPI3_MISO_PIN, - BOARD_SPI3_MOSI_PIN}, -#endif -}; - - -/* - * Constructor - */ - -HardwareSPI::HardwareSPI(uint32 spi_num) { - switch (spi_num) { - case 1: - this->spi_d = SPI1; - break; - case 2: - this->spi_d = SPI2; - break; -#if defined(STM32_HIGH_DENSITY) || (STM32_MCU_SERIES == STM32_SERIES_F3) - case 3: - this->spi_d = SPI3; - break; -#endif - default: - ASSERT(0); - } -} - -/* - * Set up/tear down - */ - -void HardwareSPI::begin(SPIFrequency frequency, uint32 bitOrder, uint32 mode) { - if (mode >= 4) { - ASSERT(0); - return; - } - spi_cfg_flag end = bitOrder == MSBFIRST ? SPI_FRAME_MSB : SPI_FRAME_LSB; - spi_mode m = (spi_mode)mode; - enable_device(this->spi_d, true, frequency, end, m); -} - -void HardwareSPI::begin(void) { - this->begin(SPI_1_125MHZ, MSBFIRST, 0); -} - -void HardwareSPI::beginSlave(uint32 bitOrder, uint32 mode) { - if (mode >= 4) { - ASSERT(0); - return; - } - spi_cfg_flag end = bitOrder == MSBFIRST ? SPI_FRAME_MSB : SPI_FRAME_LSB; - spi_mode m = (spi_mode)mode; - enable_device(this->spi_d, false, (SPIFrequency)0, end, m); -} - -void HardwareSPI::beginSlave(void) { - this->beginSlave(MSBFIRST, 0); -} - -void HardwareSPI::end(void) { - if (!spi_is_enabled(this->spi_d)) { - return; - } - - // Follows RM0008's sequence for disabling a SPI in master/slave - // full duplex mode. - while (spi_is_rx_nonempty(this->spi_d)) { - // FIXME [0.1.0] remove this once you have an interrupt based driver - volatile uint16 rx __attribute__((unused)) = spi_rx_reg(this->spi_d); - } - while (!spi_is_tx_empty(this->spi_d)) - ; - while (spi_is_busy(this->spi_d)) - ; - spi_peripheral_disable(this->spi_d); -} - -/* - * I/O - */ - -uint8 HardwareSPI::read(void) { - uint8 buf[1]; - this->read(buf, 1); - return buf[0]; -} - -void HardwareSPI::read(uint8 *buf, uint32 len) { - uint32 rxed = 0; - while (rxed < len) { - while (!spi_is_rx_nonempty(this->spi_d)) - ; - buf[rxed++] = (uint8)spi_rx_reg(this->spi_d); - } -} - -void HardwareSPI::write(uint8 byte) { - this->write(&byte, 1); -} - -void HardwareSPI::write(const uint8 *data, uint32 length) { - uint32 txed = 0; - while (txed < length) { - txed += spi_tx(this->spi_d, data + txed, length - txed); - } -} - -uint8 HardwareSPI::transfer(uint8 byte) { - this->write(byte); - return this->read(); -} - -/* - * Pin accessors - */ - -uint8 HardwareSPI::misoPin(void) { - return dev_to_spi_pins(this->spi_d)->miso; -} - -uint8 HardwareSPI::mosiPin(void) { - return dev_to_spi_pins(this->spi_d)->mosi; -} - -uint8 HardwareSPI::sckPin(void) { - return dev_to_spi_pins(this->spi_d)->sck; -} - -uint8 HardwareSPI::nssPin(void) { - return dev_to_spi_pins(this->spi_d)->nss; -} - -/* - * Deprecated functions - */ - -uint8 HardwareSPI::send(uint8 data) { - uint8 buf[] = {data}; - return this->send(buf, 1); -} - -uint8 HardwareSPI::send(uint8 *buf, uint32 len) { - uint32 txed = 0; - uint8 ret = 0; - while (txed < len) { - this->write(buf[txed++]); - ret = this->read(); - } - return ret; -} - -uint8 HardwareSPI::recv(void) { - return this->read(); -} - -/* - * Auxiliary functions - */ - -static void configure_gpios(spi_dev *dev, bool as_master); -static spi_baud_rate determine_baud_rate(spi_dev *dev, SPIFrequency freq); - -static const spi_pins* dev_to_spi_pins(spi_dev *dev) { - switch (dev->clk_id) { - case RCC_SPI1: return board_spi_pins; - case RCC_SPI2: return board_spi_pins + 1; -#if defined(STM32_HIGH_DENSITY) || (STM32_MCU_SERIES == STM32_SERIES_F3) - case RCC_SPI3: return board_spi_pins + 2; -#endif - default: return NULL; - } -} - -/* Enables the device in master or slave full duplex mode. If you - * change this code, you must ensure that appropriate changes are made - * to HardwareSPI::end(). */ -static void enable_device(spi_dev *dev, - bool as_master, - SPIFrequency freq, - spi_cfg_flag endianness, - spi_mode mode) { - spi_baud_rate baud = determine_baud_rate(dev, freq); - uint32 cfg_flags = (endianness | SPI_DFF_8_BIT | SPI_SW_SLAVE | - (as_master ? SPI_SOFT_SS : 0)); - - spi_init(dev); - configure_gpios(dev, as_master); - if (as_master) { - spi_master_enable(dev, baud, mode, cfg_flags); - } else { - spi_slave_enable(dev, mode, cfg_flags); - } -} - -static void disable_pwm(const stm32_pin_info *i) { - if (i->timer_device) { - timer_set_mode(i->timer_device, i->timer_channel, TIMER_DISABLED); - } -} - -static void configure_gpios(spi_dev *dev, bool as_master) { - const spi_pins *pins = dev_to_spi_pins(dev); - - if (!pins) { - return; - } - - const stm32_pin_info *nssi = &PIN_MAP[pins->nss]; - const stm32_pin_info *scki = &PIN_MAP[pins->sck]; - const stm32_pin_info *misoi = &PIN_MAP[pins->miso]; - const stm32_pin_info *mosii = &PIN_MAP[pins->mosi]; - - disable_pwm(nssi); - disable_pwm(scki); - disable_pwm(misoi); - disable_pwm(mosii); - - spi_config_gpios(dev, as_master, nssi->gpio_device, nssi->gpio_bit, - scki->gpio_device, scki->gpio_bit, misoi->gpio_bit, - mosii->gpio_bit); -} - -static const spi_baud_rate baud_rates[MAX_SPI_FREQS] __FLASH__ = { - SPI_BAUD_PCLK_DIV_2, - SPI_BAUD_PCLK_DIV_4, - SPI_BAUD_PCLK_DIV_8, - SPI_BAUD_PCLK_DIV_16, - SPI_BAUD_PCLK_DIV_32, - SPI_BAUD_PCLK_DIV_64, - SPI_BAUD_PCLK_DIV_128, - SPI_BAUD_PCLK_DIV_256, -}; - -/* - * Note: This assumes you're on a LeafLabs-style board - * (CYCLES_PER_MICROSECOND == 72, APB2 at 72MHz, APB1 at 36MHz). - */ -static spi_baud_rate determine_baud_rate(spi_dev *dev, SPIFrequency freq) { - if (rcc_dev_clk(dev->clk_id) == RCC_APB2 && freq == SPI_140_625KHZ) { - /* APB2 peripherals are too fast for 140.625 KHz */ - ASSERT(0); - return (spi_baud_rate)~0; - } - return (rcc_dev_clk(dev->clk_id) == RCC_APB2 ? - baud_rates[freq + 1] : - baud_rates[freq]); -} diff --git a/STM32F3/cores/maple/wirish/HardwareSPI.h b/STM32F3/cores/maple/wirish/HardwareSPI.h deleted file mode 100644 index 4b61b58..0000000 --- a/STM32F3/cores/maple/wirish/HardwareSPI.h +++ /dev/null @@ -1,225 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/HardwareSPI.h - * @brief High-level SPI interface - * - * This is a "bare essentials" polling driver for now. - */ - -/* TODO [0.1.0] Remove deprecated methods. */ - -#include -#include - -#include - -#ifndef _WIRISH_HARDWARESPI_H_ -#define _WIRISH_HARDWARESPI_H_ - -/** - * @brief Defines the possible SPI communication speeds. - */ -typedef enum SPIFrequency { - SPI_18MHZ = 0, /**< 18 MHz */ - SPI_9MHZ = 1, /**< 9 MHz */ - SPI_4_5MHZ = 2, /**< 4.5 MHz */ - SPI_2_25MHZ = 3, /**< 2.25 MHz */ - SPI_1_125MHZ = 4, /**< 1.125 MHz */ - SPI_562_500KHZ = 5, /**< 562.500 KHz */ - SPI_281_250KHZ = 6, /**< 281.250 KHz */ - SPI_140_625KHZ = 7, /**< 140.625 KHz */ -} SPIFrequency; - -#define MAX_SPI_FREQS 8 - -/** - * @brief Wirish SPI interface. - * - * This implementation uses software slave management, so the caller - * is responsible for controlling the slave select line. - */ -class HardwareSPI { -public: - /** - * @param spiPortNumber Number of the SPI port to manage. - */ - HardwareSPI(uint32 spiPortNumber); - - /* - * Set up/tear down - */ - - /** - * @brief Turn on a SPI port and set its GPIO pin modes for use as master. - * - * SPI port is enabled in full duplex mode, with software slave management. - * - * @param frequency Communication frequency - * @param bitOrder Either LSBFIRST (little-endian) or MSBFIRST (big-endian) - * @param mode SPI mode to use, one of SPI_MODE_0, SPI_MODE_1, - * SPI_MODE_2, and SPI_MODE_3. - */ - void begin(SPIFrequency frequency, uint32 bitOrder, uint32 mode); - - /** - * @brief Equivalent to begin(SPI_1_125MHZ, MSBFIRST, 0). - */ - void begin(void); - - /** - * @brief Turn on a SPI port and set its GPIO pin modes for use as a slave. - * - * SPI port is enabled in full duplex mode, with software slave management. - * - * @param bitOrder Either LSBFIRST (little-endian) or MSBFIRST(big-endian) - * @param mode SPI mode to use - */ - void beginSlave(uint32 bitOrder, uint32 mode); - - /** - * @brief Equivalent to beginSlave(MSBFIRST, 0). - */ - void beginSlave(void); - - /** - * @brief Disables the SPI port, but leaves its GPIO pin modes unchanged. - */ - void end(void); - - /* - * I/O - */ - - /** - * @brief Return the next unread byte. - * - * If there is no unread byte waiting, this function will block - * until one is received. - */ - uint8 read(void); - - /** - * @brief Read length bytes, storing them into buffer. - * @param buffer Buffer to store received bytes into. - * @param length Number of bytes to store in buffer. This - * function will block until the desired number of - * bytes have been read. - */ - void read(uint8 *buffer, uint32 length); - - /** - * @brief Transmit a byte. - * @param data Byte to transmit. - */ - void write(uint8 data); - - /** - * @brief Transmit multiple bytes. - * @param buffer Bytes to transmit. - * @param length Number of bytes in buffer to transmit. - */ - void write(const uint8 *buffer, uint32 length); - - /** - * @brief Transmit a byte, then return the next unread byte. - * - * This function transmits before receiving. - * - * @param data Byte to transmit. - * @return Next unread byte. - */ - uint8 transfer(uint8 data); - - /* - * Pin accessors - */ - - /** - * @brief Return the number of the MISO (master in, slave out) pin - */ - uint8 misoPin(void); - - /** - * @brief Return the number of the MOSI (master out, slave in) pin - */ - uint8 mosiPin(void); - - /** - * @brief Return the number of the SCK (serial clock) pin - */ - uint8 sckPin(void); - - /** - * @brief Return the number of the NSS (slave select) pin - */ - uint8 nssPin(void); - - /* Escape hatch */ - - /** - * @brief Get a pointer to the underlying libmaple spi_dev for - * this HardwareSPI instance. - */ - spi_dev* c_dev(void) { return this->spi_d; } - - /* -- The following methods are deprecated --------------------------- */ - - /** - * @brief Deprecated. - * - * Use HardwareSPI::transfer() instead. - * - * @see HardwareSPI::transfer() - */ - uint8 send(uint8 data); - - /** - * @brief Deprecated. - * - * Use HardwareSPI::write() in combination with - * HardwareSPI::read() (or HardwareSPI::transfer()) instead. - * - * @see HardwareSPI::write() - * @see HardwareSPI::read() - * @see HardwareSPI::transfer() - */ - uint8 send(uint8 *data, uint32 length); - - /** - * @brief Deprecated. - * - * Use HardwareSPI::read() instead. - * - * @see HardwareSPI::read() - */ - uint8 recv(void); -private: - spi_dev *spi_d; -}; - -#endif diff --git a/STM32F3/cores/maple/wirish/HardwareSerial.cpp b/STM32F3/cores/maple/wirish/HardwareSerial.cpp deleted file mode 100644 index 87f80d1..0000000 --- a/STM32F3/cores/maple/wirish/HardwareSerial.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/HardwareSerial.cpp - * @brief Wirish serial port implementation. - */ - -#include - -#include -#include -#include -#include - -#define DEFINE_HWSERIAL(name, n) \ - HardwareSerial name(USART##n, \ - BOARD_USART##n##_TX_PIN, \ - BOARD_USART##n##_RX_PIN) - -#if BOARD_HAVE_USART1 -DEFINE_HWSERIAL(Serial1, 1); -#endif -#if BOARD_HAVE_USART2 -DEFINE_HWSERIAL(Serial2, 2); -#endif -#if BOARD_HAVE_USART3 -DEFINE_HWSERIAL(Serial3, 3); -#endif -#if BOARD_HAVE_UART4 -DEFINE_HWSERIAL(Serial4, 4); -#endif -#if BOARD_HAVE_UART5 -DEFINE_HWSERIAL(Serial5, 5); -#endif -#if BOARD_HAVE_USART6 -DEFINE_HWSERIAL(Serial6, 6); -#endif - -HardwareSerial::HardwareSerial(usart_dev *usart_device, - uint8 tx_pin, - uint8 rx_pin) { - this->usart_device = usart_device; - this->tx_pin = tx_pin; - this->rx_pin = rx_pin; -} - -/* - * Set up/tear down - */ - -#if STM32_MCU_SERIES == STM32_SERIES_F1 -/* F1 MCUs have no GPIO_AFR[HL], so turn off PWM if there's a conflict - * on this GPIO bit. */ -static void disable_timer_if_necessary(timer_dev *dev, uint8 ch) { - if (dev != NULL) { - timer_set_mode(dev, ch, TIMER_DISABLED); - } -} -#elif (STM32_MCU_SERIES == STM32_SERIES_F2) || \ - (STM32_MCU_SERIES == STM32_SERIES_F3) || \ - (STM32_MCU_SERIES == STM32_SERIES_F4) -#define disable_timer_if_necessary(dev, ch) ((void)0) -#else -#warning "Unsupported STM32 series; timer conflicts are possible" -#endif - -void HardwareSerial::begin(uint32 baud) { - ASSERT(baud <= this->usart_device->max_baud); - - if (baud > this->usart_device->max_baud) { - return; - } - - const stm32_pin_info *txi = &PIN_MAP[this->tx_pin]; - const stm32_pin_info *rxi = &PIN_MAP[this->rx_pin]; - - disable_timer_if_necessary(txi->timer_device, txi->timer_channel); - - usart_config_gpios_async(this->usart_device, - rxi->gpio_device, rxi->gpio_bit, - txi->gpio_device, txi->gpio_bit, - 0); - usart_init(this->usart_device); - usart_set_baud_rate(this->usart_device, USART_USE_PCLK, baud); - usart_enable(this->usart_device); -} - -void HardwareSerial::end(void) { - usart_disable(this->usart_device); -} - -/* - * I/O - */ - -int HardwareSerial::read(void) { - if(usart_data_available(usart_device) > 0) { - return usart_getc(usart_device); - } else { - return -1; - } -} - -uint32 HardwareSerial::available(void) { - return usart_data_available(this->usart_device); -} - -void HardwareSerial::write(unsigned char ch) { - usart_putc(this->usart_device, ch); -} - -void HardwareSerial::flush(void) { - usart_reset_rx(this->usart_device); -} diff --git a/STM32F3/cores/maple/wirish/HardwareSerial.h b/STM32F3/cores/maple/wirish/HardwareSerial.h deleted file mode 100644 index 260a99e..0000000 --- a/STM32F3/cores/maple/wirish/HardwareSerial.h +++ /dev/null @@ -1,102 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/HardwareSerial.h - * @brief Wirish serial port interface. - */ - -#ifndef _WIRISH_HARDWARESERIAL_H_ -#define _WIRISH_HARDWARESERIAL_H_ - -#include - -#include -#include - -/* - * IMPORTANT: - * - * This class documented "by hand" (i.e., not using Doxygen) in the - * leaflabs-docs/ repository. - * - * If you alter the public HardwareSerial interface, you MUST update - * the documentation accordingly. - */ - -struct usart_dev; - -class HardwareSerial : public Print { -public: - HardwareSerial(struct usart_dev *usart_device, - uint8 tx_pin, - uint8 rx_pin); - - /* Set up/tear down */ - void begin(uint32 baud); - void end(void); - - /* I/O */ - uint32 available(void); - int read(void); - void flush(void); - virtual void write(unsigned char); - using Print::write; - - /* Pin accessors */ - int txPin(void) { return this->tx_pin; } - int rxPin(void) { return this->rx_pin; } - - /* Escape hatch into libmaple */ - /* FIXME [0.0.13] documentation */ - struct usart_dev* c_dev(void) { return this->usart_device; } -private: - struct usart_dev *usart_device; - uint8 tx_pin; - uint8 rx_pin; -}; - -#if BOARD_HAVE_USART1 -extern HardwareSerial Serial1; -#endif -#if BOARD_HAVE_USART2 -extern HardwareSerial Serial2; -#endif -#if BOARD_HAVE_USART3 -extern HardwareSerial Serial3; -#endif -#if BOARD_HAVE_UART4 -extern HardwareSerial Serial4; -#endif -#if BOARD_HAVE_UART5 -extern HardwareSerial Serial5; -#endif -#if BOARD_HAVE_USART6 -extern HardwareSerial Serial6; -#endif - -#endif diff --git a/STM32F3/cores/maple/wirish/HardwareTimer.cpp b/STM32F3/cores/maple/wirish/HardwareTimer.cpp deleted file mode 100644 index 4f68ad7..0000000 --- a/STM32F3/cores/maple/wirish/HardwareTimer.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Bryan Newbold. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#include - -#include -#include // for noInterrupts(), interrupts() -#include -#include // for CYCLES_PER_MICROSECOND - -// TODO [0.1.0] Remove deprecated pieces - -/* - * Evil hack to infer this->dev from timerNum in the HardwareTimer - * constructor. See: - * - * http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.2 - * http://yosefk.com/c++fqa/function.html#fqa-33.2 - */ - -extern "C" { - static timer_dev **this_devp; - static rcc_clk_id this_id; - static void set_this_dev(timer_dev *dev) { - if (dev->clk_id == this_id) { - *this_devp = dev; - } - } -} - -/* - * HardwareTimer routines - */ - -HardwareTimer::HardwareTimer(uint8 timerNum) { - rcc_clk_id timerID = (rcc_clk_id)(RCC_TIMER1 + (timerNum - 1)); - this->dev = NULL; - noInterrupts(); // Hack to ensure we're the only ones using - // set_this_dev() and friends. TODO: use a lock. - this_id = timerID; - this_devp = &this->dev; - timer_foreach(set_this_dev); - interrupts(); - ASSERT(this->dev != NULL); -} - -void HardwareTimer::pause(void) { - timer_pause(this->dev); -} - -void HardwareTimer::resume(void) { - timer_resume(this->dev); -} - -uint32 HardwareTimer::getPrescaleFactor(void) { - return timer_get_prescaler(this->dev) + 1; -} - -void HardwareTimer::setPrescaleFactor(uint32 factor) { - timer_set_prescaler(this->dev, (uint16)(factor - 1)); -} - -uint16 HardwareTimer::getOverflow() { - return timer_get_reload(this->dev); -} - -void HardwareTimer::setOverflow(uint16 val) { - timer_set_reload(this->dev, val); -} - -uint16 HardwareTimer::getCount(void) { - return timer_get_count(this->dev); -} - -void HardwareTimer::setCount(uint16 val) { - uint16 ovf = this->getOverflow(); - timer_set_count(this->dev, min(val, ovf)); -} - -#define MAX_RELOAD ((1 << 16) - 1) -uint16 HardwareTimer::setPeriod(uint32 microseconds) { - // Not the best way to handle this edge case? - if (!microseconds) { - this->setPrescaleFactor(1); - this->setOverflow(1); - return this->getOverflow(); - } - - uint32 period_cyc = microseconds * CYCLES_PER_MICROSECOND; - uint16 prescaler = (uint16)(period_cyc / MAX_RELOAD + 1); - uint16 overflow = (uint16)((period_cyc + (prescaler / 2)) / prescaler); - this->setPrescaleFactor(prescaler); - this->setOverflow(overflow); - return overflow; -} - -void HardwareTimer::setMode(int channel, timer_mode mode) { - timer_set_mode(this->dev, (uint8)channel, (timer_mode)mode); -} - -uint16 HardwareTimer::getCompare(int channel) { - return timer_get_compare(this->dev, (uint8)channel); -} - -void HardwareTimer::setCompare(int channel, uint16 val) { - uint16 ovf = this->getOverflow(); - timer_set_compare(this->dev, (uint8)channel, min(val, ovf)); -} - -void HardwareTimer::attachInterrupt(int channel, voidFuncPtr handler) { - timer_attach_interrupt(this->dev, (uint8)channel, handler); -} - -void HardwareTimer::detachInterrupt(int channel) { - timer_detach_interrupt(this->dev, (uint8)channel); -} - -void HardwareTimer::refresh(void) { - timer_generate_update(this->dev); -} - -/* -- Deprecated predefined instances -------------------------------------- */ - -HardwareTimer Timer1(1); -HardwareTimer Timer2(2); -HardwareTimer Timer3(3); -HardwareTimer Timer4(4); -#ifdef STM32_HIGH_DENSITY -HardwareTimer Timer5(5); -HardwareTimer Timer6(6); -HardwareTimer Timer7(7); -HardwareTimer Timer8(8); -#endif diff --git a/STM32F3/cores/maple/wirish/HardwareTimer.h b/STM32F3/cores/maple/wirish/HardwareTimer.h deleted file mode 100644 index 22aa010..0000000 --- a/STM32F3/cores/maple/wirish/HardwareTimer.h +++ /dev/null @@ -1,337 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Bryan Newbold. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @brief Wirish timer class. - */ - -#ifndef _WIRISH_HARDWARETIMER_H_ -#define _WIRISH_HARDWARETIMER_H_ - -// TODO [0.1.0] Remove deprecated pieces, pick a better API - -#include - -/** Timer mode. */ -typedef timer_mode TimerMode; - -/** - * @brief Interface to one of the 16-bit timer peripherals. - */ -class HardwareTimer { -private: - timer_dev *dev; - -public: - /** - * @brief Construct a new HardwareTimer instance. - * @param timerNum number of the timer to control. - */ - HardwareTimer(uint8 timerNum); - - /** - * @brief Stop the counter, without affecting its configuration. - * - * @see HardwareTimer::resume() - */ - void pause(void); - - /** - * @brief Resume a paused timer, without affecting its configuration. - * - * The timer will resume counting and firing interrupts as - * appropriate. - * - * Note that there is some function call overhead associated with - * using this method, so using it in concert with - * HardwareTimer::pause() is not a robust way to align multiple - * timers to the same count value. - * - * @see HardwareTimer::pause() - */ - void resume(void); - - /** - * @brief Get the timer's prescale factor. - * @return Timer prescaler, from 1 to 65,536. - * @see HardwareTimer::setPrescaleFactor() - */ - uint32 getPrescaleFactor(); - - /** - * @brief Set the timer's prescale factor. - * - * The new value won't take effect until the next time the counter - * overflows. You can force the counter to reset using - * HardwareTimer::refresh(). - * - * @param factor The new prescale value to set, from 1 to 65,536. - * @see HardwareTimer::refresh() - */ - void setPrescaleFactor(uint32 factor); - - /** - * @brief Get the timer overflow value. - * @see HardwareTimer::setOverflow() - */ - uint16 getOverflow(); - - /** - * @brief Set the timer overflow (or "reload") value. - * - * The new value won't take effect until the next time the counter - * overflows. You can force the counter to reset using - * HardwareTimer::refresh(). - * - * @param val The new overflow value to set - * @see HardwareTimer::refresh() - */ - void setOverflow(uint16 val); - - /** - * @brief Get the current timer count. - * - * @return The timer's current count value - */ - uint16 getCount(void); - - /** - * @brief Set the current timer count. - * - * @param val The new count value to set. If this value exceeds - * the timer's overflow value, it is truncated to the - * overflow value. - */ - void setCount(uint16 val); - - /** - * @brief Set the timer's period in microseconds. - * - * Configures the prescaler and overflow values to generate a timer - * reload with a period as close to the given number of - * microseconds as possible. - * - * @param microseconds The desired period of the timer. This must be - * greater than zero. - * @return The new overflow value. - */ - uint16 setPeriod(uint32 microseconds); - - /** - * @brief Configure a timer channel's mode. - * @param channel Timer channel, from 1 to 4 - * @param mode Mode to set - */ - void setMode(int channel, timer_mode mode); - - /** - * @brief Get the compare value for the given channel. - * @see HardwareTimer::setCompare() - */ - uint16 getCompare(int channel); - - /** - * @brief Set the compare value for the given channel. - * - * @param channel the channel whose compare to set, from 1 to 4. - * @param compare The compare value to set. If greater than this - * timer's overflow value, it will be truncated to - * the overflow value. - * - * @see timer_mode - * @see HardwareTimer::setMode() - * @see HardwareTimer::attachInterrupt() - */ - void setCompare(int channel, uint16 compare); - - /** - * @brief Attach an interrupt handler to the given channel. - * - * This interrupt handler will be called when the timer's counter - * reaches the given channel compare value. - * - * @param channel the channel to attach the ISR to, from 1 to 4. - * @param handler The ISR to attach to the given channel. - * @see voidFuncPtr - */ - void attachInterrupt(int channel, voidFuncPtr handler); - - /** - * @brief Remove the interrupt handler attached to the given - * channel, if any. - * - * The handler will no longer be called by this timer. - * - * @param channel the channel whose interrupt to detach, from 1 to 4. - * @see HardwareTimer::attachInterrupt() - */ - void detachInterrupt(int channel); - - /** - * @brief Reset the counter, and update the prescaler and overflow - * values. - * - * This will reset the counter to 0 in upcounting mode (the - * default). It will also update the timer's prescaler and - * overflow, if you have set them up to be changed using - * HardwareTimer::setPrescaleFactor() or - * HardwareTimer::setOverflow(). - * - * @see HardwareTimer::setPrescaleFactor() - * @see HardwareTimer::setOverflow() - */ - void refresh(void); - - /* Escape hatch */ - - /** - * @brief Get a pointer to the underlying libmaple timer_dev for - * this HardwareTimer instance. - */ - timer_dev* c_dev(void) { return this->dev; } - -/* -- The rest of this file is deprecated. --------------------------------- */ - - /** @brief Deprecated; use setMode(channel, mode) instead. */ - void setChannelMode(int channel, timer_mode mode) { - setMode(channel, mode); - } - - /** @brief Deprecated; use setMode(TIMER_CH1, mode) instead. */ - void setChannel1Mode(timer_mode mode) { setMode(TIMER_CH1, mode); } - - /** @brief Deprecated; use setMode(TIMER_CH2, mode) instead. */ - void setChannel2Mode(timer_mode mode) { setMode(TIMER_CH2, mode); } - - /** @brief Deprecated; use setMode(TIMER_CH3, mode) instead. */ - void setChannel3Mode(timer_mode mode) { setMode(TIMER_CH3, mode); } - - /** @brief Deprecated; use setMode(TIMER_CH4, mode) instead. */ - void setChannel4Mode(timer_mode mode) { setMode(TIMER_CH4, mode); } - - /** @brief Deprecated; use return getCompare(TIMER_CH1) instead. */ - uint16 getCompare1() { return getCompare(TIMER_CH1); } - - /** @brief Deprecated; use return getCompare(TIMER_CH2) instead. */ - uint16 getCompare2() { return getCompare(TIMER_CH2); } - - /** @brief Deprecated; use return getCompare(TIMER_CH3) instead. */ - uint16 getCompare3() { return getCompare(TIMER_CH3); } - - /** @brief Deprecated; use return getCompare(TIMER_CH4) instead. */ - uint16 getCompare4() { return getCompare(TIMER_CH4); } - - /** @brief Deprecated; use setCompare(TIMER_CH1, compare) instead. */ - void setCompare1(uint16 compare) { setCompare(TIMER_CH1, compare); } - - /** @brief Deprecated; use setCompare(TIMER_CH2, compare) instead. */ - void setCompare2(uint16 compare) { setCompare(TIMER_CH2, compare); } - - /** @brief Deprecated; use setCompare(TIMER_CH3, compare) instead. */ - void setCompare3(uint16 compare) { setCompare(TIMER_CH3, compare); } - - /** @brief Deprecated; use setCompare(TIMER_CH4, compare) instead. */ - void setCompare4(uint16 compare) { setCompare(TIMER_CH4, compare); } - - /** @brief Deprecated; use attachInterrupt(TIMER_CH1, handler) instead. */ - void attachCompare1Interrupt(voidFuncPtr handler) { - attachInterrupt(TIMER_CH1, handler); - } - - /** @brief Deprecated; use attachInterrupt(TIMER_CH2, handler) instead. */ - void attachCompare2Interrupt(voidFuncPtr handler) { - attachInterrupt(TIMER_CH2, handler); - } - - /** @brief Deprecated; use attachInterrupt(TIMER_CH3, handler) instead. */ - void attachCompare3Interrupt(voidFuncPtr handler) { - attachInterrupt(TIMER_CH3, handler); - } - - /** @brief Deprecated; use attachInterrupt(TIMER_CH4, handler) instead. */ - void attachCompare4Interrupt(voidFuncPtr handler) { - attachInterrupt(TIMER_CH4, handler); - } - - /** @brief Deprecated; use detachInterrupt(TIMER_CH1) instead. */ - void detachCompare1Interrupt(void) { detachInterrupt(TIMER_CH1); } - - /** @brief Deprecated; use detachInterrupt(TIMER_CH2) instead. */ - void detachCompare2Interrupt(void) { detachInterrupt(TIMER_CH2); } - - /** @brief Deprecated; use detachInterrupt(TIMER_CH3) instead. */ - void detachCompare3Interrupt(void) { detachInterrupt(TIMER_CH3); } - - /** @brief Deprecated; use detachInterrupt(TIMER_CH4) instead. */ - void detachCompare4Interrupt(void) { detachInterrupt(TIMER_CH4); } - - /** @brief Deprecated; use refresh() instead. */ - void generateUpdate(void) { refresh(); } -}; - -/** @brief Deprecated; use TIMER_OUTPUT_COMPARE instead. */ -#define TIMER_OUTPUTCOMPARE TIMER_OUTPUT_COMPARE - -/** - * @brief Deprecated. - * - * Pre-instantiated timer. - */ -extern HardwareTimer Timer1; -/** - * @brief Deprecated. - * - * Pre-instantiated timer. - */ -extern HardwareTimer Timer2; -/** - * @brief Deprecated. - * - * Pre-instantiated timer. - */ -extern HardwareTimer Timer3; -/** - * @brief Deprecated. - * - * Pre-instantiated timer. - */ -extern HardwareTimer Timer4; -#if (STM32_MCU_SERIES == STM32_SERIES_F1) && defined(STM32_HIGH_DENSITY) -/** - * @brief Deprecated. - * - * Pre-instantiated timer. - */ -extern HardwareTimer Timer5; -/** - * @brief Deprecated. - * - * Pre-instantiated timer. - */ -extern HardwareTimer Timer8; -#endif - -#endif diff --git a/STM32F3/cores/maple/wirish/Print.cpp b/STM32F3/cores/maple/wirish/Print.cpp deleted file mode 100644 index 9a8808d..0000000 --- a/STM32F3/cores/maple/wirish/Print.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Print.cpp - Base class that provides print() and println() - * Copyright (c) 2008 David A. Mellis. All right reserved. - * Copyright (c) 2011 LeafLabs, LLC. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - * Modified 23 November 2006 by David A. Mellis - * Modified 12 April 2011 by Marti Bolivar - */ - -#include - -#include -#include - -#ifndef LLONG_MAX -/* - * Note: - * - * At time of writing (12 April 2011), the limits.h that came with the - * newlib we distributed didn't include LLONG_MAX. Because we're - * staying away from using templates (see /notes/coding_standard.rst, - * "Language Features and Compiler Extensions"), this value was - * copy-pasted from a println() of the value - * - * std::numeric_limits::max(). - */ -#define LLONG_MAX 9223372036854775807LL -#endif - -/* - * Public methods - */ - -void Print::write(const char *str) { - while (*str) { - write(*str++); - } -} - -void Print::write(const void *buffer, uint32 size) { - uint8 *ch = (uint8*)buffer; - while (size--) { - write(*ch++); - } -} - -void Print::print(uint8 b, int base) { - print((uint64)b, base); -} - -void Print::print(char c) { - write(c); -} - -void Print::print(const char str[]) { - write(str); -} - -void Print::print(int n, int base) { - print((long long)n, base); -} - -void Print::print(unsigned int n, int base) { - print((unsigned long long)n, base); -} - -void Print::print(long n, int base) { - print((long long)n, base); -} - -void Print::print(unsigned long n, int base) { - print((unsigned long long)n, base); -} - -void Print::print(long long n, int base) { - if (n < 0) { - print('-'); - n = -n; - } - printNumber(n, base); -} - -void Print::print(unsigned long long n, int base) { - printNumber(n, base); -} - -void Print::print(double n, int digits) { - printFloat(n, digits); -} - -void Print::println(void) { - print('\r'); - print('\n'); -} - -void Print::println(char c) { - print(c); - println(); -} - -void Print::println(const char c[]) { - print(c); - println(); -} - -void Print::println(uint8 b, int base) { - print(b, base); - println(); -} - -void Print::println(int n, int base) { - print(n, base); - println(); -} - -void Print::println(unsigned int n, int base) { - print(n, base); - println(); -} - -void Print::println(long n, int base) { - print((long long)n, base); - println(); -} - -void Print::println(unsigned long n, int base) { - print((unsigned long long)n, base); - println(); -} - -void Print::println(long long n, int base) { - print(n, base); - println(); -} - -void Print::println(unsigned long long n, int base) { - print(n, base); - println(); -} - -void Print::println(double n, int digits) { - print(n, digits); - println(); -} - -/* - * Private methods - */ - -void Print::printNumber(unsigned long long n, uint8 base) { - unsigned char buf[CHAR_BIT * sizeof(long long)]; - unsigned long i = 0; - - if (n == 0) { - print('0'); - return; - } - - while (n > 0) { - buf[i++] = n % base; - n /= base; - } - - for (; i > 0; i--) { - print((char)(buf[i - 1] < 10 ? - '0' + buf[i - 1] : - 'A' + buf[i - 1] - 10)); - } -} - -/* According to snprintf(), - * - * nextafter((double)numeric_limits::max(), 0.0) ~= 9.22337e+18 - * - * This slightly smaller value was picked semi-arbitrarily. */ -#define LARGE_DOUBLE_TRESHOLD (9.1e18) - -/* THIS FUNCTION SHOULDN'T BE USED IF YOU NEED ACCURATE RESULTS. - * - * This implementation is meant to be simple and not occupy too much - * code size. However, printing floating point values accurately is a - * subtle task, best left to a well-tested library function. - * - * See Steele and White 2003 for more details: - * - * http://kurtstephens.com/files/p372-steele.pdf - */ -void Print::printFloat(double number, uint8 digits) { - // Hackish fail-fast behavior for large-magnitude doubles - if (abs(number) >= LARGE_DOUBLE_TRESHOLD) { - if (number < 0.0) { - print('-'); - } - print(""); - return; - } - - // Handle negative numbers - if (number < 0.0) { - print('-'); - number = -number; - } - - // Simplistic rounding strategy so that e.g. print(1.999, 2) - // prints as "2.00" - double rounding = 0.5; - for (uint8 i = 0; i < digits; i++) { - rounding /= 10.0; - } - number += rounding; - - // Extract the integer part of the number and print it - long long int_part = (long long)number; - double remainder = number - int_part; - print(int_part); - - // Print the decimal point, but only if there are digits beyond - if (digits > 0) { - print("."); - } - - // Extract digits from the remainder one at a time - while (digits-- > 0) { - remainder *= 10.0; - int to_print = (int)remainder; - print(to_print); - remainder -= to_print; - } -} diff --git a/STM32F3/cores/maple/wirish/Print.h b/STM32F3/cores/maple/wirish/Print.h deleted file mode 100644 index 52203ea..0000000 --- a/STM32F3/cores/maple/wirish/Print.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Print.h - Base class that provides print() and println() - * Copyright (c) 2008 David A. Mellis. All right reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA. - * - * Modified 12 April 2011 by Marti Bolivar - */ - -#ifndef _WIRISH_PRINT_H_ -#define _WIRISH_PRINT_H_ - -#include - -enum { - BIN = 2, - OCT = 8, - DEC = 10, - HEX = 16 -}; - -class Print { -public: - virtual void write(uint8 ch) = 0; - virtual void write(const char *str); - virtual void write(const void *buf, uint32 len); - void print(char); - void print(const char[]); - void print(uint8, int=DEC); - void print(int, int=DEC); - void print(unsigned int, int=DEC); - void print(long, int=DEC); - void print(unsigned long, int=DEC); - void print(long long, int=DEC); - void print(unsigned long long, int=DEC); - void print(double, int=2); - void println(void); - void println(char); - void println(const char[]); - void println(uint8, int=DEC); - void println(int, int=DEC); - void println(unsigned int, int=DEC); - void println(long, int=DEC); - void println(unsigned long, int=DEC); - void println(long long, int=DEC); - void println(unsigned long long, int=DEC); - void println(double, int=2); -private: - void printNumber(unsigned long long, uint8); - void printFloat(double, uint8); -}; - -#endif diff --git a/STM32F3/cores/maple/wirish/bit_constants.h b/STM32F3/cores/maple/wirish/bit_constants.h deleted file mode 100644 index 4638f76..0000000 --- a/STM32F3/cores/maple/wirish/bit_constants.h +++ /dev/null @@ -1,579 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @brief BIT[n] and binary literal defines, for Arduino - * compatibility. - */ - -#ifndef _WIRISH_BIT_CONSTANTS_H_ -#define _WIRISH_BIT_CONSTANTS_H_ - -#define BIT0 (1 << 0) -#define BIT1 (1 << 1) -#define BIT2 (1 << 2) -#define BIT3 (1 << 3) -#define BIT4 (1 << 4) -#define BIT5 (1 << 5) -#define BIT6 (1 << 6) -#define BIT7 (1 << 7) -#define BIT8 (1 << 8) -#define BIT9 (1 << 9) -#define BIT10 (1 << 10) -#define BIT11 (1 << 11) -#define BIT12 (1 << 12) -#define BIT13 (1 << 13) -#define BIT14 (1 << 14) -#define BIT15 (1 << 15) -#define BIT16 (1 << 16) -#define BIT17 (1 << 17) -#define BIT18 (1 << 18) -#define BIT19 (1 << 19) -#define BIT20 (1 << 20) -#define BIT21 (1 << 21) -#define BIT22 (1 << 22) -#define BIT23 (1 << 23) -#define BIT24 (1 << 24) -#define BIT25 (1 << 25) -#define BIT26 (1 << 26) -#define BIT27 (1 << 27) -#define BIT28 (1 << 28) -#define BIT29 (1 << 29) -#define BIT30 (1 << 30) -#define BIT31 (1 << 31) - -#define B0 0 -#define B00 0 -#define B000 0 -#define B0000 0 -#define B00000 0 -#define B000000 0 -#define B0000000 0 -#define B00000000 0 -#define B1 1 -#define B01 1 -#define B001 1 -#define B0001 1 -#define B00001 1 -#define B000001 1 -#define B0000001 1 -#define B00000001 1 -#define B10 2 -#define B010 2 -#define B0010 2 -#define B00010 2 -#define B000010 2 -#define B0000010 2 -#define B00000010 2 -#define B11 3 -#define B011 3 -#define B0011 3 -#define B00011 3 -#define B000011 3 -#define B0000011 3 -#define B00000011 3 -#define B100 4 -#define B0100 4 -#define B00100 4 -#define B000100 4 -#define B0000100 4 -#define B00000100 4 -#define B101 5 -#define B0101 5 -#define B00101 5 -#define B000101 5 -#define B0000101 5 -#define B00000101 5 -#define B110 6 -#define B0110 6 -#define B00110 6 -#define B000110 6 -#define B0000110 6 -#define B00000110 6 -#define B111 7 -#define B0111 7 -#define B00111 7 -#define B000111 7 -#define B0000111 7 -#define B00000111 7 -#define B1000 8 -#define B01000 8 -#define B001000 8 -#define B0001000 8 -#define B00001000 8 -#define B1001 9 -#define B01001 9 -#define B001001 9 -#define B0001001 9 -#define B00001001 9 -#define B1010 10 -#define B01010 10 -#define B001010 10 -#define B0001010 10 -#define B00001010 10 -#define B1011 11 -#define B01011 11 -#define B001011 11 -#define B0001011 11 -#define B00001011 11 -#define B1100 12 -#define B01100 12 -#define B001100 12 -#define B0001100 12 -#define B00001100 12 -#define B1101 13 -#define B01101 13 -#define B001101 13 -#define B0001101 13 -#define B00001101 13 -#define B1110 14 -#define B01110 14 -#define B001110 14 -#define B0001110 14 -#define B00001110 14 -#define B1111 15 -#define B01111 15 -#define B001111 15 -#define B0001111 15 -#define B00001111 15 -#define B10000 16 -#define B010000 16 -#define B0010000 16 -#define B00010000 16 -#define B10001 17 -#define B010001 17 -#define B0010001 17 -#define B00010001 17 -#define B10010 18 -#define B010010 18 -#define B0010010 18 -#define B00010010 18 -#define B10011 19 -#define B010011 19 -#define B0010011 19 -#define B00010011 19 -#define B10100 20 -#define B010100 20 -#define B0010100 20 -#define B00010100 20 -#define B10101 21 -#define B010101 21 -#define B0010101 21 -#define B00010101 21 -#define B10110 22 -#define B010110 22 -#define B0010110 22 -#define B00010110 22 -#define B10111 23 -#define B010111 23 -#define B0010111 23 -#define B00010111 23 -#define B11000 24 -#define B011000 24 -#define B0011000 24 -#define B00011000 24 -#define B11001 25 -#define B011001 25 -#define B0011001 25 -#define B00011001 25 -#define B11010 26 -#define B011010 26 -#define B0011010 26 -#define B00011010 26 -#define B11011 27 -#define B011011 27 -#define B0011011 27 -#define B00011011 27 -#define B11100 28 -#define B011100 28 -#define B0011100 28 -#define B00011100 28 -#define B11101 29 -#define B011101 29 -#define B0011101 29 -#define B00011101 29 -#define B11110 30 -#define B011110 30 -#define B0011110 30 -#define B00011110 30 -#define B11111 31 -#define B011111 31 -#define B0011111 31 -#define B00011111 31 -#define B100000 32 -#define B0100000 32 -#define B00100000 32 -#define B100001 33 -#define B0100001 33 -#define B00100001 33 -#define B100010 34 -#define B0100010 34 -#define B00100010 34 -#define B100011 35 -#define B0100011 35 -#define B00100011 35 -#define B100100 36 -#define B0100100 36 -#define B00100100 36 -#define B100101 37 -#define B0100101 37 -#define B00100101 37 -#define B100110 38 -#define B0100110 38 -#define B00100110 38 -#define B100111 39 -#define B0100111 39 -#define B00100111 39 -#define B101000 40 -#define B0101000 40 -#define B00101000 40 -#define B101001 41 -#define B0101001 41 -#define B00101001 41 -#define B101010 42 -#define B0101010 42 -#define B00101010 42 -#define B101011 43 -#define B0101011 43 -#define B00101011 43 -#define B101100 44 -#define B0101100 44 -#define B00101100 44 -#define B101101 45 -#define B0101101 45 -#define B00101101 45 -#define B101110 46 -#define B0101110 46 -#define B00101110 46 -#define B101111 47 -#define B0101111 47 -#define B00101111 47 -#define B110000 48 -#define B0110000 48 -#define B00110000 48 -#define B110001 49 -#define B0110001 49 -#define B00110001 49 -#define B110010 50 -#define B0110010 50 -#define B00110010 50 -#define B110011 51 -#define B0110011 51 -#define B00110011 51 -#define B110100 52 -#define B0110100 52 -#define B00110100 52 -#define B110101 53 -#define B0110101 53 -#define B00110101 53 -#define B110110 54 -#define B0110110 54 -#define B00110110 54 -#define B110111 55 -#define B0110111 55 -#define B00110111 55 -#define B111000 56 -#define B0111000 56 -#define B00111000 56 -#define B111001 57 -#define B0111001 57 -#define B00111001 57 -#define B111010 58 -#define B0111010 58 -#define B00111010 58 -#define B111011 59 -#define B0111011 59 -#define B00111011 59 -#define B111100 60 -#define B0111100 60 -#define B00111100 60 -#define B111101 61 -#define B0111101 61 -#define B00111101 61 -#define B111110 62 -#define B0111110 62 -#define B00111110 62 -#define B111111 63 -#define B0111111 63 -#define B00111111 63 -#define B1000000 64 -#define B01000000 64 -#define B1000001 65 -#define B01000001 65 -#define B1000010 66 -#define B01000010 66 -#define B1000011 67 -#define B01000011 67 -#define B1000100 68 -#define B01000100 68 -#define B1000101 69 -#define B01000101 69 -#define B1000110 70 -#define B01000110 70 -#define B1000111 71 -#define B01000111 71 -#define B1001000 72 -#define B01001000 72 -#define B1001001 73 -#define B01001001 73 -#define B1001010 74 -#define B01001010 74 -#define B1001011 75 -#define B01001011 75 -#define B1001100 76 -#define B01001100 76 -#define B1001101 77 -#define B01001101 77 -#define B1001110 78 -#define B01001110 78 -#define B1001111 79 -#define B01001111 79 -#define B1010000 80 -#define B01010000 80 -#define B1010001 81 -#define B01010001 81 -#define B1010010 82 -#define B01010010 82 -#define B1010011 83 -#define B01010011 83 -#define B1010100 84 -#define B01010100 84 -#define B1010101 85 -#define B01010101 85 -#define B1010110 86 -#define B01010110 86 -#define B1010111 87 -#define B01010111 87 -#define B1011000 88 -#define B01011000 88 -#define B1011001 89 -#define B01011001 89 -#define B1011010 90 -#define B01011010 90 -#define B1011011 91 -#define B01011011 91 -#define B1011100 92 -#define B01011100 92 -#define B1011101 93 -#define B01011101 93 -#define B1011110 94 -#define B01011110 94 -#define B1011111 95 -#define B01011111 95 -#define B1100000 96 -#define B01100000 96 -#define B1100001 97 -#define B01100001 97 -#define B1100010 98 -#define B01100010 98 -#define B1100011 99 -#define B01100011 99 -#define B1100100 100 -#define B01100100 100 -#define B1100101 101 -#define B01100101 101 -#define B1100110 102 -#define B01100110 102 -#define B1100111 103 -#define B01100111 103 -#define B1101000 104 -#define B01101000 104 -#define B1101001 105 -#define B01101001 105 -#define B1101010 106 -#define B01101010 106 -#define B1101011 107 -#define B01101011 107 -#define B1101100 108 -#define B01101100 108 -#define B1101101 109 -#define B01101101 109 -#define B1101110 110 -#define B01101110 110 -#define B1101111 111 -#define B01101111 111 -#define B1110000 112 -#define B01110000 112 -#define B1110001 113 -#define B01110001 113 -#define B1110010 114 -#define B01110010 114 -#define B1110011 115 -#define B01110011 115 -#define B1110100 116 -#define B01110100 116 -#define B1110101 117 -#define B01110101 117 -#define B1110110 118 -#define B01110110 118 -#define B1110111 119 -#define B01110111 119 -#define B1111000 120 -#define B01111000 120 -#define B1111001 121 -#define B01111001 121 -#define B1111010 122 -#define B01111010 122 -#define B1111011 123 -#define B01111011 123 -#define B1111100 124 -#define B01111100 124 -#define B1111101 125 -#define B01111101 125 -#define B1111110 126 -#define B01111110 126 -#define B1111111 127 -#define B01111111 127 -#define B10000000 128 -#define B10000001 129 -#define B10000010 130 -#define B10000011 131 -#define B10000100 132 -#define B10000101 133 -#define B10000110 134 -#define B10000111 135 -#define B10001000 136 -#define B10001001 137 -#define B10001010 138 -#define B10001011 139 -#define B10001100 140 -#define B10001101 141 -#define B10001110 142 -#define B10001111 143 -#define B10010000 144 -#define B10010001 145 -#define B10010010 146 -#define B10010011 147 -#define B10010100 148 -#define B10010101 149 -#define B10010110 150 -#define B10010111 151 -#define B10011000 152 -#define B10011001 153 -#define B10011010 154 -#define B10011011 155 -#define B10011100 156 -#define B10011101 157 -#define B10011110 158 -#define B10011111 159 -#define B10100000 160 -#define B10100001 161 -#define B10100010 162 -#define B10100011 163 -#define B10100100 164 -#define B10100101 165 -#define B10100110 166 -#define B10100111 167 -#define B10101000 168 -#define B10101001 169 -#define B10101010 170 -#define B10101011 171 -#define B10101100 172 -#define B10101101 173 -#define B10101110 174 -#define B10101111 175 -#define B10110000 176 -#define B10110001 177 -#define B10110010 178 -#define B10110011 179 -#define B10110100 180 -#define B10110101 181 -#define B10110110 182 -#define B10110111 183 -#define B10111000 184 -#define B10111001 185 -#define B10111010 186 -#define B10111011 187 -#define B10111100 188 -#define B10111101 189 -#define B10111110 190 -#define B10111111 191 -#define B11000000 192 -#define B11000001 193 -#define B11000010 194 -#define B11000011 195 -#define B11000100 196 -#define B11000101 197 -#define B11000110 198 -#define B11000111 199 -#define B11001000 200 -#define B11001001 201 -#define B11001010 202 -#define B11001011 203 -#define B11001100 204 -#define B11001101 205 -#define B11001110 206 -#define B11001111 207 -#define B11010000 208 -#define B11010001 209 -#define B11010010 210 -#define B11010011 211 -#define B11010100 212 -#define B11010101 213 -#define B11010110 214 -#define B11010111 215 -#define B11011000 216 -#define B11011001 217 -#define B11011010 218 -#define B11011011 219 -#define B11011100 220 -#define B11011101 221 -#define B11011110 222 -#define B11011111 223 -#define B11100000 224 -#define B11100001 225 -#define B11100010 226 -#define B11100011 227 -#define B11100100 228 -#define B11100101 229 -#define B11100110 230 -#define B11100111 231 -#define B11101000 232 -#define B11101001 233 -#define B11101010 234 -#define B11101011 235 -#define B11101100 236 -#define B11101101 237 -#define B11101110 238 -#define B11101111 239 -#define B11110000 240 -#define B11110001 241 -#define B11110010 242 -#define B11110011 243 -#define B11110100 244 -#define B11110101 245 -#define B11110110 246 -#define B11110111 247 -#define B11111000 248 -#define B11111001 249 -#define B11111010 250 -#define B11111011 251 -#define B11111100 252 -#define B11111101 253 -#define B11111110 254 -#define B11111111 255 - -#endif /* _BIT_CONSTANTS_H_ */ diff --git a/STM32F3/cores/maple/wirish/bits.h b/STM32F3/cores/maple/wirish/bits.h deleted file mode 100644 index 0a63c58..0000000 --- a/STM32F3/cores/maple/wirish/bits.h +++ /dev/null @@ -1,35 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/* Note: Use of this header file is deprecated. Use bit_constants.h - instead. */ - -#ifndef _WIRISH_BITS_H_ -#define _WIRISH_BITS_H_ - -#include - -#endif diff --git a/STM32F3/cores/maple/wirish/boards.cpp b/STM32F3/cores/maple/wirish/boards.cpp deleted file mode 100644 index a693fa6..0000000 --- a/STM32F3/cores/maple/wirish/boards.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/boards.cpp - * @brief init() and board routines. - * - * This file is mostly interesting for the init() function, which - * configures Flash, the core clocks, and a variety of other available - * peripherals on the board so the rest of Wirish doesn't have to turn - * things on before using them. - * - * Prior to returning, init() calls boardInit(), which allows boards - * to perform any initialization they need to. This file includes a - * weak no-op definition of boardInit(), so boards that don't need any - * special initialization don't have to define their own. - * - * How init() works is chip-specific. See the boards_setup.cpp files - * under e.g. wirish/stm32f1/, wirish/stmf32f2 for the details, but be - * advised: their contents are unstable, and can/will change without - * notice. - */ - -#include -#include -#include -#include -#include -#include "boards_private.h" - -static void setup_flash(void); -static void setup_clocks(void); -static void setup_nvic(void); -static void setup_adcs(void); -static void setup_timers(void); - -/* - * Exported functions - */ - -void init(void) { - setup_flash(); - setup_clocks(); - setup_nvic(); - systick_init(SYSTICK_RELOAD_VAL); - wirish::priv::board_setup_gpio(); - setup_adcs(); - setup_timers(); - wirish::priv::board_setup_usb(); - wirish::priv::series_init(); - boardInit(); -} - -/* Provide a default no-op boardInit(). */ -__weak void boardInit(void) { -} - -/* You could farm this out to the files in boards/ if e.g. it takes - * too long to test on boards with lots of pins. */ -bool boardUsesPin(uint8 pin) { - for (int i = 0; i < BOARD_NR_USED_PINS; i++) { - if (pin == boardUsedPins[i]) { - return true; - } - } - return false; -} - -/* - * Auxiliary routines - */ - -static void setup_flash(void) { - // Turn on as many Flash "go faster" features as - // possible. flash_enable_features() just ignores any flags it - // can't support. - flash_enable_features(FLASH_PREFETCH | FLASH_ICACHE | FLASH_DCACHE); - // Configure the wait states, assuming we're operating at "close - // enough" to 3.3V. - flash_set_latency(FLASH_SAFE_WAIT_STATES); -} - -static void setup_clocks(void) { - // Turn on HSI. We'll switch to and run off of this while we're - // setting up the main PLL. - rcc_turn_on_clk(RCC_CLK_HSI); - - // Turn off and reset the clock subsystems we'll be using, as well - // as the clock security subsystem (CSS). Note that resetting CFGR - // to its default value of 0 implies a switch to HSI for SYSCLK. - RCC_BASE->CFGR = 0x00000000; - rcc_disable_css(); - rcc_turn_off_clk(RCC_CLK_PLL); - rcc_turn_off_clk(RCC_CLK_HSE); - wirish::priv::board_reset_pll(); - // Clear clock readiness interrupt flags and turn off clock - // readiness interrupts. - RCC_BASE->CIR = 0x00000000; - - // Enable HSE, and wait until it's ready. - rcc_turn_on_clk(RCC_CLK_HSE); - while (!rcc_is_clk_ready(RCC_CLK_HSE)) - ; - - // Configure AHBx, APBx, etc. prescalers and the main PLL. - wirish::priv::board_setup_clock_prescalers(); - rcc_configure_pll(&wirish::priv::w_board_pll_cfg); - - // Enable the PLL, and wait until it's ready. - rcc_turn_on_clk(RCC_CLK_PLL); - while(!rcc_is_clk_ready(RCC_CLK_PLL)) - ; - - // Finally, switch to the now-ready PLL as the main clock source. - rcc_switch_sysclk(RCC_CLKSRC_PLL); -} - -/* - * These addresses are where usercode starts when a bootloader is - * present. If no bootloader is present, the user NVIC usually starts - * at the Flash base address, 0x08000000. - */ -#define USER_ADDR_ROM 0x08005000 -#define USER_ADDR_RAM 0x20000C00 -extern char __text_start__; - -static void setup_nvic(void) { -#ifdef VECT_TAB_FLASH - nvic_init(USER_ADDR_ROM, 0); -#elif defined VECT_TAB_RAM - nvic_init(USER_ADDR_RAM, 0); -#elif defined VECT_TAB_BASE - nvic_init((uint32)0x08000000, 0); -#elif defined VECT_TAB_ADDR - // A numerically supplied value - nvic_init((uint32)VECT_TAB_ADDR, 0); -#else - // Use the __text_start__ value from the linker script; this - // should be the start of the vector table. - nvic_init((uint32)&__text_start__, 0); -#endif -} - -static void adc_default_config(const adc_dev *dev) { - adc_enable_single_swstart(dev); - adc_set_sample_rate(dev, wirish::priv::w_adc_smp); -} - -static void setup_adcs(void) { - adc_set_prescaler(wirish::priv::w_adc_pre); - adc_foreach(adc_default_config); -} - -static void timer_default_config(timer_dev *dev) { - timer_adv_reg_map *regs = (dev->regs).adv; - const uint16 full_overflow = 0xFFFF; - const uint16 half_duty = 0x8FFF; - - timer_init(dev); - timer_pause(dev); - - regs->CR1 = TIMER_CR1_ARPE; - regs->PSC = 1; - regs->SR = 0; - regs->DIER = 0; - regs->EGR = TIMER_EGR_UG; - switch (dev->type) { - case TIMER_ADVANCED: - regs->BDTR = TIMER_BDTR_MOE | TIMER_BDTR_LOCK_OFF; - // fall-through - case TIMER_GENERAL: - timer_set_reload(dev, full_overflow); - for (uint8 channel = 1; channel <= 4; channel++) { - if (timer_has_cc_channel(dev, channel)) { - timer_set_compare(dev, channel, half_duty); - timer_oc_set_mode(dev, channel, TIMER_OC_MODE_PWM_1, - TIMER_OC_PE); - } - } - // fall-through - case TIMER_BASIC: - break; - } - - timer_generate_update(dev); - timer_resume(dev); -} - -static void setup_timers(void) { - timer_foreach(timer_default_config); -} diff --git a/STM32F3/cores/maple/wirish/boards.h b/STM32F3/cores/maple/wirish/boards.h deleted file mode 100644 index 6676a02..0000000 --- a/STM32F3/cores/maple/wirish/boards.h +++ /dev/null @@ -1,173 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Bryan Newbold. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/boards.h - * @author Bryan Newbold , - * Marti Bolivar - * @brief init() and board-specific pin information. - */ - -#ifndef _WIRISH_BOARDS_H_ -#define _WIRISH_BOARDS_H_ - -#include -#include -#include - -/* Set of all possible pin names; not all boards have all these (note - * that we use the Dx convention since all of the Maple's pins are - * "digital" pins (e.g. can be used with digitalRead() and - * digitalWrite()), but not all of them are connected to ADCs. */ -enum { - D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15, D16, - D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30, D31, - D32, D33, D34, D35, D36, D37, D38, D39, D40, D41, D42, D43, D44, D45, D46, - D47, D48, D49, D50, D51, D52, D53, D54, D55, D56, D57, D58, D59, D60, D61, - D62, D63, D64, D65, D66, D67, D68, D69, D70, D71, D72, D73, D74, D75, D76, - D77, D78, D79, D80, D81, D82, D83, D84, D85, D86, D87, D88, D89, D90, D91, - D92, D93, D94, D95, D96, D97, D98, D99, D100, D101, D102, D103, D104, D105, - D106, D107, D108, D109, D110, D111, }; - -/** - * @brief Maps each Maple pin to a corresponding stm32_pin_info. - * @see stm32_pin_info - */ -extern const stm32_pin_info PIN_MAP[]; - -/** - * @brief Pins capable of PWM output. - * - * Its length is BOARD_NR_PWM_PINS. - */ -extern const uint8 boardPWMPins[]; - -/** - * @brief Array of pins capable of analog input. - * - * Its length is BOARD_NR_ADC_PINS. - */ -extern const uint8 boardADCPins[]; - -/** - * @brief Pins which are connected to external hardware. - * - * For example, on Maple boards, it always at least includes - * BOARD_LED_PIN. Its length is BOARD_NR_USED_PINS. - */ -extern const uint8 boardUsedPins[]; - -/** - * @brief Generic board initialization function. - * - * This function is called before main(). It ensures that the clocks - * and peripherals are configured properly for use with wirish, then - * calls boardInit(). - * - * @see boardInit() - */ -void init(void); - -/** - * @brief Board-specific initialization function. - * - * This function is called from init() after all generic board - * initialization has been performed. Each board is required to - * define its own. - * - * @see init() - */ -extern void boardInit(void); - -/** - * @brief Test if a pin is used for a special purpose on your board. - * @param pin Pin to test - * @return true if the given pin is in boardUsedPins, and false otherwise. - * @see boardUsedPins - */ -bool boardUsesPin(uint8 pin); - -/* - * Derived and default board definitions - */ - -#define CLOCK_SPEED_MHZ CYCLES_PER_MICROSECOND -#define CLOCK_SPEED_HZ (CLOCK_SPEED_MHZ * 1000000UL) - -#ifndef SYSTICK_RELOAD_VAL -#define SYSTICK_RELOAD_VAL (1000 * CYCLES_PER_MICROSECOND - 1) -#endif - -#ifndef BOARD_BUTTON_PRESSED_LEVEL -#define BOARD_BUTTON_PRESSED_LEVEL HIGH -#endif - -/** - * @brief Does the board break out a USART/UART's RX and TX pins? - * - * BOARD_HAVE_USART(n) is nonzero iff USARTn is available (n must be - * an integer literal, 1 through 6). Also see BOARD_HAVE_USART1, ..., - * BOARD_HAVE_UART4 (sic), etc. - */ -#define BOARD_HAVE_USART(n) (defined(BOARD_USART##n##_TX_PIN) && \ - defined(BOARD_USART##n##_RX_PIN)) -/** Feature test: nonzero iff the board has USART1. */ -#define BOARD_HAVE_USART1 BOARD_HAVE_USART(1) -/** Feature test: nonzero iff the board has USART2, 0 otherwise. */ -#define BOARD_HAVE_USART2 BOARD_HAVE_USART(2) -/** Feature test: nonzero iff the board has USART3, 0 otherwise. */ -#define BOARD_HAVE_USART3 BOARD_HAVE_USART(3) -/** Feature test: nonzero iff the board has UART4, 0 otherwise. */ -#define BOARD_HAVE_UART4 BOARD_HAVE_USART(4) -/** Feature test: nonzero iff the board has UART5, 0 otherwise. */ -#define BOARD_HAVE_UART5 BOARD_HAVE_USART(5) -/** Feature test: nonzero iff the board has USART6, 0 otherwise. */ -#define BOARD_HAVE_USART6 BOARD_HAVE_USART(6) - -/** - * @brief Does the board break out a SPI peripheral's pins? - * - * BOARD_HAVE_SPI(n) is nonzero iff SPIn is available (n must be an - * integer literal: 1, 2, or 3). Also see BOARD_HAVE_SPI1, - * BOARD_HAVE_SPI2, BOARD_HAVE_SPI3. */ -#define BOARD_HAVE_SPI(n) (defined(BOARD_SPI##n##_NSS_PIN) && \ - defined(BOARD_SPI##n##_SCK_PIN) && \ - defined(BOARD_SPI##n##_MISO_PIN) && \ - defined(BOARD_SPI##n##_MOSI_PIN)) -/** Feature test: nonzero iff the board has SPI1. */ -#define BOARD_HAVE_SPI1 BOARD_HAVE_SPI(1) -/** Feature test: nonzero iff the board has SPI2. */ -#define BOARD_HAVE_SPI2 BOARD_HAVE_SPI(2) -/** Feature test: nonzero iff the board has SPI3. */ -#define BOARD_HAVE_SPI3 BOARD_HAVE_SPI(3) - -/** - * @brief Feature test: nonzero iff the board has SerialUSB. - */ -#define BOARD_HAVE_SERIALUSB (defined(BOARD_USB_DISC_DEV) && \ - defined(BOARD_USB_DISC_BIT)) - -#endif diff --git a/STM32F3/cores/maple/wirish/boards_private.h b/STM32F3/cores/maple/wirish/boards_private.h deleted file mode 100644 index 49867ca..0000000 --- a/STM32F3/cores/maple/wirish/boards_private.h +++ /dev/null @@ -1,71 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/boards_private.h - * @author Marti Bolivar - * @brief Private board support header. - * - * This file declares chip-specific variables and functions which - * determine how init() behaves. It is not part of the public Wirish - * API, and can change without notice. - */ - -#ifndef _WIRISH_BOARDS_PRIVATE_H_ -#define _WIRISH_BOARDS_PRIVATE_H_ - -#include -#include - -/* Makes the PIN_MAP rows more human-readable. */ -#define PMAP_ROW(gpio_dev, gpio_bit, timer_dev, timer_ch, adc_dev, adc_ch) \ - { gpio_dev, timer_dev, adc_dev, gpio_bit, timer_ch, adc_ch } - -namespace wirish { - namespace priv { - - /* - * Chip-specific initialization data - */ - - extern rcc_pll_cfg w_board_pll_cfg; - extern adc_prescaler w_adc_pre; - extern adc_smp_rate w_adc_smp; - - /* - * Chip-specific initialization routines and helper functions. - */ - - void board_reset_pll(void); - void board_setup_clock_prescalers(void); - void board_setup_gpio(void); - void board_setup_usb(void); - void series_init(void); - - } -} - -#endif diff --git a/STM32F3/cores/maple/wirish/cxxabi-compat.cpp b/STM32F3/cores/maple/wirish/cxxabi-compat.cpp deleted file mode 100644 index 516b112..0000000 --- a/STM32F3/cores/maple/wirish/cxxabi-compat.cpp +++ /dev/null @@ -1,6 +0,0 @@ -/* We compile with nodefaultlibs, so we need to provide an error - * handler for an empty pure virtual function */ -extern "C" void __cxa_pure_virtual(void) { - while(1) - ; -} diff --git a/STM32F3/cores/maple/wirish/ext_interrupts.cpp b/STM32F3/cores/maple/wirish/ext_interrupts.cpp deleted file mode 100644 index 1195ea9..0000000 --- a/STM32F3/cores/maple/wirish/ext_interrupts.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/ext_interrupts.cpp - * @brief Wiring-like interface for external interrupts - */ - -#include - -#include -#include - -#include - -static inline exti_trigger_mode exti_out_mode(ExtIntTriggerMode mode); - -void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode) { - if (pin >= BOARD_NR_GPIO_PINS || !handler) { - return; - } - - exti_trigger_mode outMode = exti_out_mode(mode); - - exti_attach_interrupt((exti_num)(PIN_MAP[pin].gpio_bit), - gpio_exti_port(PIN_MAP[pin].gpio_device), - handler, - outMode); -} - -void attachInterrupt(uint8 pin, voidArgumentFuncPtr handler, void *arg, - ExtIntTriggerMode mode) { - if (pin >= BOARD_NR_GPIO_PINS || !handler) { - return; - } - - exti_trigger_mode outMode = exti_out_mode(mode); - - exti_attach_callback((exti_num)(PIN_MAP[pin].gpio_bit), - gpio_exti_port(PIN_MAP[pin].gpio_device), - handler, - arg, - outMode); -} - -void detachInterrupt(uint8 pin) { - if (pin >= BOARD_NR_GPIO_PINS) { - return; - } - - exti_detach_interrupt((exti_num)(PIN_MAP[pin].gpio_bit)); -} - -static inline exti_trigger_mode exti_out_mode(ExtIntTriggerMode mode) { - switch (mode) { - case RISING: - return EXTI_RISING; - case FALLING: - return EXTI_FALLING; - case CHANGE: - return EXTI_RISING_FALLING; - } - // Can't happen - ASSERT(0); - return (exti_trigger_mode)0; -} diff --git a/STM32F3/cores/maple/wirish/ext_interrupts.h b/STM32F3/cores/maple/wirish/ext_interrupts.h deleted file mode 100644 index ce1ca03..0000000 --- a/STM32F3/cores/maple/wirish/ext_interrupts.h +++ /dev/null @@ -1,128 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/ext_interrupts.h - * @brief Wiring-like external interrupt prototypes and types. - */ - -#ifndef _WIRISH_EXT_INTERRUPTS_H_ -#define _WIRISH_EXT_INTERRUPTS_H_ - -#include -#include - -/** - * The kind of transition on an external pin which should trigger an - * interrupt. - */ -typedef enum ExtIntTriggerMode { - RISING, /**< To trigger an interrupt when the pin transitions LOW - to HIGH */ - FALLING, /**< To trigger an interrupt when the pin transitions - HIGH to LOW */ - CHANGE /**< To trigger an interrupt when the pin transitions from - LOW to HIGH or HIGH to LOW (i.e., when the pin - changes). */ -} ExtIntTriggerMode; - -/** - * @brief Registers an interrupt handler on a pin. - * - * The interrupt will be triggered on a given transition on the pin, - * as specified by the mode parameter. The handler runs in interrupt - * context. The new handler will replace whatever handler is - * currently registered for the pin, if any. - * - * @param pin Pin number - * @param handler Function to run upon external interrupt trigger. - * The handler should take no arguments, and have void - * return type. - * @param mode Type of transition to trigger on, e.g. falling, rising, etc. - * - * @sideeffect Registers a handler - * @see detachInterrupt() - */ -void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode); - -/** - * @brief Registers an interrupt handler on a pin. - * - * The interrupt will be triggered on a given transition on the pin, - * as specified by the mode parameter. The handler runs in interrupt - * context. The new handler will replace whatever handler is - * currently registered for the pin, if any. - * - * @param pin Pin number - * @param handler Static class member function to run upon external interrupt - * trigger. The handler should take 1 argument and return void - * @param arg Argument that the handler will be passed when it's called. One - * use of this is to pass the specific instance of the class that - * will handle the interrupt. - * @param mode Type of transition to trigger on, e.g. falling, rising, etc. - * - * @sideeffect Registers a handler - * @see detachInterrupt() - */ -void attachInterrupt(uint8 pin, voidArgumentFuncPtr handler, void *arg, - ExtIntTriggerMode mode); - -/** - * @brief Disable any registered external interrupt. - * @param pin Maple pin number - * @sideeffect unregisters external interrupt handler - * @see attachInterrupt() - */ -void detachInterrupt(uint8 pin); - -/** - * Re-enable interrupts. - * - * Call this after noInterrupts() to re-enable interrupt handling, - * after you have finished with a timing-critical section of code. - * - * @see noInterrupts() - */ -static __always_inline void interrupts() { - nvic_globalirq_enable(); -} - -/** - * Disable interrupts. - * - * After calling this function, all user-programmable interrupts will - * be disabled. You can call this function before a timing-critical - * section of code, then call interrupts() to re-enable interrupt - * handling. - * - * @see interrupts() - */ -static __always_inline void noInterrupts() { - nvic_globalirq_disable(); -} - -#endif - diff --git a/STM32F3/cores/maple/wirish/io.h b/STM32F3/cores/maple/wirish/io.h deleted file mode 100644 index 08bbc06..0000000 --- a/STM32F3/cores/maple/wirish/io.h +++ /dev/null @@ -1,222 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/io.h - * @brief Wiring-style pin I/O interface. - */ - -#ifndef _WIRISH_IO_H_ -#define _WIRISH_IO_H_ - -#include -#include - -/** - * Specifies a GPIO pin behavior. - * @see pinMode() - */ -typedef enum WiringPinMode { - OUTPUT, /**< Basic digital output: when the pin is HIGH, the - voltage is held at +3.3v (Vcc) and when it is LOW, it - is pulled down to ground. */ - - OUTPUT_OPEN_DRAIN, /**< In open drain mode, the pin indicates - "low" by accepting current flow to ground - and "high" by providing increased - impedance. An example use would be to - connect a pin to a bus line (which is pulled - up to a positive voltage by a separate - supply through a large resistor). When the - pin is high, not much current flows through - to ground and the line stays at positive - voltage; when the pin is low, the bus - "drains" to ground with a small amount of - current constantly flowing through the large - resistor from the external supply. In this - mode, no current is ever actually sourced - from the pin. */ - - INPUT, /**< Basic digital input. The pin voltage is sampled; when - it is closer to 3.3v (Vcc) the pin status is high, and - when it is closer to 0v (ground) it is low. If no - external circuit is pulling the pin voltage to high or - low, it will tend to randomly oscillate and be very - sensitive to noise (e.g., a breath of air across the pin - might cause the state to flip). */ - - INPUT_ANALOG, /**< This is a special mode for when the pin will be - used for analog (not digital) reads. Enables ADC - conversion to be performed on the voltage at the - pin. */ - - INPUT_PULLUP, /**< The state of the pin in this mode is reported - the same way as with INPUT, but the pin voltage - is gently "pulled up" towards +3.3v. This means - the state will be high unless an external device - is specifically pulling the pin down to ground, - in which case the "gentle" pull up will not - affect the state of the input. */ - - INPUT_PULLDOWN, /**< The state of the pin in this mode is reported - the same way as with INPUT, but the pin voltage - is gently "pulled down" towards 0v. This means - the state will be low unless an external device - is specifically pulling the pin up to 3.3v, in - which case the "gentle" pull down will not - affect the state of the input. */ - - INPUT_FLOATING, /**< Synonym for INPUT. */ - - PWM, /**< This is a special mode for when the pin will be used for - PWM output (a special case of digital output). */ - - PWM_OPEN_DRAIN, /**< Like PWM, except that instead of alternating - cycles of LOW and HIGH, the voltage on the pin - consists of alternating cycles of LOW and - floating (disconnected). */ -} WiringPinMode; - -/** - * Configure behavior of a GPIO pin. - * - * @param pin Number of pin to configure. - * @param mode Mode corresponding to desired pin behavior. - * @see WiringPinMode - */ -void pinMode(uint8 pin, WiringPinMode mode); - -#define HIGH 0x1 -#define LOW 0x0 - -/** - * Writes a (digital) value to a pin. The pin must have its - * mode set to OUTPUT or OUTPUT_OPEN_DRAIN. - * - * @param pin Pin to write to. - * @param value Either LOW (write a 0) or HIGH (write a 1). - * @see pinMode() - */ -void digitalWrite(uint8 pin, uint8 value); - -/** - * Read a digital value from a pin. The pin must have its mode set to - * one of INPUT, INPUT_PULLUP, and INPUT_PULLDOWN. - * - * @param pin Pin to read from. - * @return LOW or HIGH. - * @see pinMode() - */ -uint32 digitalRead(uint8 pin); - -/** - * Read an analog value from pin. This function blocks during ADC - * conversion, and has 12 bits of resolution. The pin must have its - * mode set to INPUT_ANALOG. - * - * @param pin Pin to read from. - * @return Converted voltage, in the range 0--4095, (i.e. a 12-bit ADC - * conversion). - * @see pinMode() - */ -uint16 analogRead(uint8 pin); - -/** - * Toggles the digital value at the given pin. - * - * The pin must have its mode set to OUTPUT. - * - * @param pin the pin to toggle. If the pin is HIGH, set it LOW. If - * it is LOW, set it HIGH. - * - * @see pinMode() - */ -void togglePin(uint8 pin); - -/** - * Toggle the LED. - * - * If the LED is on, turn it off. If it is off, turn it on. - * - * The LED must its mode set to OUTPUT. This can be accomplished - * portably over all LeafLabs boards by calling pinMode(BOARD_LED_PIN, - * OUTPUT) before calling this function. - * - * @see pinMode() - */ -static inline void toggleLED() { - togglePin(BOARD_LED_PIN); -} - -/** - * If the button is currently pressed, waits until the button is no - * longer being pressed, and returns true. Otherwise, returns false. - * - * The button pin must have its mode set to INPUT. This can be - * accomplished portably over all LeafLabs boards by calling - * pinMode(BOARD_BUTTON_PIN, INPUT). - * - * @see pinMode() - */ -uint8 isButtonPressed(uint8 pin=BOARD_BUTTON_PIN, - uint32 pressedLevel=BOARD_BUTTON_PRESSED_LEVEL); - -/** - * Wait until the button is pressed and released, timing out if no - * press occurs. - * - * The button pin must have its mode set to INPUT. This can be - * accomplished portably over all LeafLabs boards by calling - * pinMode(BOARD_BUTTON_PIN, INPUT). - * - * @param timeout_millis Number of milliseconds to wait until the - * button is pressed. If timeout_millis is left out (or 0), wait - * forever. - * - * @return true, if the button was pressed; false, if the timeout was - * reached. - * - * @see pinMode() - */ -uint8 waitForButtonPress(uint32 timeout_millis=0); - -/** - * Shift out a byte of data, one bit at a time. - * - * This function starts at either the most significant or least - * significant bit in a byte value, and shifts out each byte in order - * onto a data pin. After each bit is written to the data pin, a - * separate clock pin is pulsed to indicate that the new bit is - * available. - * - * @param dataPin Pin to shift data out on - * @param clockPin Pin to pulse after each bit is shifted out - * @param bitOrder Either MSBFIRST (big-endian) or LSBFIRST (little-endian). - * @param value Value to shift out - */ -void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, uint8 value); - -#endif diff --git a/STM32F3/cores/maple/wirish/main.cxx b/STM32F3/cores/maple/wirish/main.cxx deleted file mode 100644 index 9c0b9cc..0000000 --- a/STM32F3/cores/maple/wirish/main.cxx +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 LeafLabs LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -// Force init to be called *first*, i.e. before static object allocation. -// Otherwise, statically allocated objects that need libmaple may fail. - __attribute__(( constructor )) void premain() { - init(); -} - -int main(void) { - setup(); - - while (1) { - loop(); - } - return 0; -} diff --git a/STM32F3/cores/maple/wirish/pwm.cpp b/STM32F3/cores/maple/wirish/pwm.cpp deleted file mode 100644 index 44884cd..0000000 --- a/STM32F3/cores/maple/wirish/pwm.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/pwm.cpp - * @brief Wiring-style pwmWrite(). - */ - -#include - -#include -#include - -#include - -void pwmWrite(uint8 pin, uint16 duty_cycle) { - if (pin >= BOARD_NR_GPIO_PINS) { - return; - } - timer_dev *dev = PIN_MAP[pin].timer_device; - uint8 cc_channel = PIN_MAP[pin].timer_channel; - ASSERT(dev && cc_channel); - timer_set_compare(dev, cc_channel, duty_cycle); -} diff --git a/STM32F3/cores/maple/wirish/pwm.h b/STM32F3/cores/maple/wirish/pwm.h deleted file mode 100644 index 6631d42..0000000 --- a/STM32F3/cores/maple/wirish/pwm.h +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/pwm.h - * @brief Wiring-style PWM interface. - */ - -#ifndef _WIRISH_PWM_H_ -#define _WIRISH_PWM_H_ - -#include - -/** - * As a convenience, analogWrite is an alias of pwmWrite to ease - * porting Arduino code. However, period and duty will have to be - * recalibrated. - */ -#define analogWrite pwmWrite - -/** - * Set the PWM duty on the given pin. - * - * User code is expected to determine and honor the maximum value - * (based on the configured period). - * - * @param pin PWM output pin - * @param duty_cycle Duty cycle to set. - */ -void pwmWrite(uint8 pin, uint16 duty_cycle); - -#endif - diff --git a/STM32F3/cores/maple/wirish/rules.mk b/STM32F3/cores/maple/wirish/rules.mk deleted file mode 100644 index 539e966..0000000 --- a/STM32F3/cores/maple/wirish/rules.mk +++ /dev/null @@ -1,66 +0,0 @@ -# Standard things -sp := $(sp).x -dirstack_$(sp) := $(d) -d := $(dir) -BUILDDIRS += $(BUILD_PATH)/$(d) - -# Add board directory and MCU-specific directory to BUILDDIRS. These -# are in subdirectories, but they're logically part of the Wirish -# submodule. -ifeq ($(MCU_SERIES), stm32f3) -WIRISH_BOARD_PATH := boards/$(MCU_F3_LINE) -else -WIRISH_BOARD_PATH := boards/$(BOARD) -endif -BUILDDIRS += $(BUILD_PATH)/$(d)/$(WIRISH_BOARD_PATH) -BUILDDIRS += $(BUILD_PATH)/$(d)/$(MCU_SERIES) - -# Safe includes for Wirish. -WIRISH_INCLUDES := -I$(d)/include -I$(d)/$(WIRISH_BOARD_PATH)/include - -# Local flags. Add -I$(d) to allow for private includes. -CFLAGS_$(d) := $(LIBMAPLE_INCLUDES) $(WIRISH_INCLUDES) -I$(d) - -# Local rules and targets -sSRCS_$(d) := start.S -cSRCS_$(d) := start_c.c -cSRCS_$(d) += syscalls.c -cSRCS_$(d) += $(MCU_SERIES)/util_hooks.c -cppSRCS_$(d) := boards.cpp -cppSRCS_$(d) += cxxabi-compat.cpp -cppSRCS_$(d) += ext_interrupts.cpp -cppSRCS_$(d) += HardwareSerial.cpp -cppSRCS_$(d) += HardwareTimer.cpp -cppSRCS_$(d) += Print.cpp -cppSRCS_$(d) += pwm.cpp -ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),stm32f1 stm32f3)) # TODO port USB serial to F2 -cppSRCS_$(d) += usb_serial.cpp -cppSRCS_$(d) += HardwareSPI.cpp -endif -cppSRCS_$(d) += wirish_analog.cpp -cppSRCS_$(d) += wirish_digital.cpp -cppSRCS_$(d) += wirish_math.cpp -cppSRCS_$(d) += wirish_shift.cpp -cppSRCS_$(d) += wirish_time.cpp -cppSRCS_$(d) += $(MCU_SERIES)/boards_setup.cpp -cppSRCS_$(d) += $(MCU_SERIES)/wirish_digital.cpp -cppSRCS_$(d) += $(MCU_SERIES)/wirish_debug.cpp -cppSRCS_$(d) += $(WIRISH_BOARD_PATH)/board.cpp - -sFILES_$(d) := $(sSRCS_$(d):%=$(d)/%) -cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%) -cppFILES_$(d) := $(cppSRCS_$(d):%=$(d)/%) - -OBJS_$(d) := $(sFILES_$(d):%.S=$(BUILD_PATH)/%.o) \ - $(cFILES_$(d):%.c=$(BUILD_PATH)/%.o) \ - $(cppFILES_$(d):%.cpp=$(BUILD_PATH)/%.o) -DEPS_$(d) := $(OBJS_$(d):%.o=%.d) - -$(OBJS_$(d)): TGT_CFLAGS := $(CFLAGS_$(d)) - -TGT_BIN += $(OBJS_$(d)) - -# Standard things --include $(DEPS_$(d)) -d := $(dirstack_$(sp)) -sp := $(basename $(sp)) diff --git a/STM32F3/cores/maple/wirish/stm32f3/boards_setup.cpp b/STM32F3/cores/maple/wirish/stm32f3/boards_setup.cpp deleted file mode 100644 index 6984419..0000000 --- a/STM32F3/cores/maple/wirish/stm32f3/boards_setup.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*****************************************************************************/ - -/** - * @file wirish/stm32f3/boards_setup.cpp - * @author Marti Bolivar , - * Hanspeter Portner - * @brief STM32F3 chip setup. - * - * This file controls how init() behaves on the STM32F3. Be very - * careful when changing anything here. Many of these values depend - * upon each other. - */ - -#include "boards_private.h" - -#include -#include - -#include -#include -#include -#include - -// Allow boards to provide a PLL multiplier. This is useful for -// e.g. STM32F300 value line MCUs, which use slower multipliers. -// (We're leaving the default to RCC_PLLMUL_9 for now, since that -// works for F303 performance line MCUs, which is all that LeafLabs -// currently officially supports). -#ifndef BOARD_RCC_PLLMUL -#define BOARD_RCC_PLLMUL RCC_PLLMUL_9 -#endif - -namespace wirish { - namespace priv { - - static stm32f3_rcc_pll_data pll_data = {.pll_mul=BOARD_RCC_PLLMUL, .pclk_prediv=RCC_PREDIV_PCLK_DIV_1}; - __weak rcc_pll_cfg w_board_pll_cfg = {RCC_PLLSRC_HSE, &pll_data}; - __weak adc_prescaler w_adc_pre = ADC_PRE_PCLK_DIV_1; - __weak adc_smp_rate w_adc_smp = ADC_SMPR_181_5; - - __weak void board_reset_pll(void) { - // TODO - } - - __weak void board_setup_clock_prescalers(void) { - rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_1); - rcc_set_prescaler(RCC_PRESCALER_APB1, RCC_APB1_HCLK_DIV_2); - rcc_set_prescaler(RCC_PRESCALER_APB2, RCC_APB2_HCLK_DIV_1); - } - - __weak void board_setup_gpio(void) { - gpio_init_all(); - } - - __weak void board_setup_usb(void) { - SerialUSB.begin(); - } - - __weak void series_init(void) { - /* We need SYSCFG for external interrupts */ - syscfg_init(); - - /* enable floating point unit */ - fpu_enable(); - } - } -} diff --git a/STM32F3/cores/maple/wirish/stm32f3/f3_wirish_digital.cpp b/STM32F3/cores/maple/wirish/stm32f3/f3_wirish_digital.cpp deleted file mode 100644 index 50cda60..0000000 --- a/STM32F3/cores/maple/wirish/stm32f3/f3_wirish_digital.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/* - * STM32F3 implementations for basic GPIO functionality. - */ - -#include - -#include -#include - -#include - -void pinMode(uint8 pin, WiringPinMode w_mode) { - if (pin >= BOARD_NR_GPIO_PINS) { - return; - } - - gpio_pin_mode mode; - // People always do the silly pin-toggle speed benchmark, so let's - // accomodate them: - unsigned flags = GPIO_MODEF_SPEED_HIGH; - bool pwm = false; - switch(w_mode) { - case OUTPUT: - mode = GPIO_MODE_OUTPUT; - break; - case OUTPUT_OPEN_DRAIN: - mode = GPIO_MODE_OUTPUT; - flags |= GPIO_MODEF_TYPE_OD; - break; - case INPUT: - case INPUT_FLOATING: - mode = GPIO_MODE_INPUT; - break; - case INPUT_ANALOG: - mode = GPIO_MODE_ANALOG; - break; - case INPUT_PULLUP: - mode = GPIO_MODE_INPUT; - flags |= GPIO_MODEF_PUPD_PU; - break; - case INPUT_PULLDOWN: - mode = GPIO_MODE_INPUT; - flags |= GPIO_MODEF_PUPD_PD; - break; - case PWM: - mode = GPIO_MODE_AF; - pwm = true; - break; - case PWM_OPEN_DRAIN: - mode = GPIO_MODE_AF; - flags |= GPIO_MODEF_TYPE_OD; - pwm = true; - break; - default: - ASSERT(0); // Can't happen - return; - } - - const stm32_pin_info *info = &PIN_MAP[pin]; - - if (pwm) { - /* If enabling PWM, tell the timer to do PWM, and tell the pin - * to listen to the right timer. */ - ASSERT(info->timer_device != NULL); - if (info->timer_device == NULL) { - return; - } - gpio_af timer_af = timer_get_af(info->timer_device); - timer_set_mode(info->timer_device, info->timer_channel, TIMER_PWM); - gpio_set_af(info->gpio_device, info->gpio_bit, timer_af); - } - gpio_set_modef(info->gpio_device, info->gpio_bit, mode, flags); -} diff --git a/STM32F3/cores/maple/wirish/stm32f3/util_hooks.c b/STM32F3/cores/maple/wirish/stm32f3/util_hooks.c deleted file mode 100644 index 2387cf7..0000000 --- a/STM32F3/cores/maple/wirish/stm32f3/util_hooks.c +++ /dev/null @@ -1,45 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/* - * STM32F3 implementations for libmaple util.c hooks - * FIXME these are just minimal stubs - */ - -#include - -/* - * Disables all peripheral interrupts. Called by __error() with global - * interrupts disabled. - */ -void __lm_error(void) { - nvic_irq_disable_all(); -} - -/* - * Enable the error USART for writing. - */ -/* usart_dev* __lm_enable_error_usart(void) { (TODO) } */ diff --git a/STM32F3/cores/maple/wirish/stm32f3/wirish_debug.cpp b/STM32F3/cores/maple/wirish/stm32f3/wirish_debug.cpp deleted file mode 100644 index 6a6e1c1..0000000 --- a/STM32F3/cores/maple/wirish/stm32f3/wirish_debug.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/stm32f3/wirish_debug.cpp - * @brief High level debug port configuration - */ - -#include -#include -#include - -void disableDebugPorts(void) { - // BOARD_JTMS_SWDIO_PIN-BOARD_JTDI_PIN and BOARD_JTDO_PIN-BOARD_NJTRST_PIN are in system alternate function mode on - // reset, to support JTAG. Just put them in input mode to release - // them. - gpio_set_modef(PIN_MAP[BOARD_JTMS_SWDIO_PIN].gpio_device, PIN_MAP[BOARD_JTMS_SWDIO_PIN].gpio_bit, - GPIO_MODE_INPUT, GPIO_MODEF_PUPD_NONE); - gpio_set_modef(PIN_MAP[BOARD_JTCK_SWCLK_PIN].gpio_device, PIN_MAP[BOARD_JTCK_SWCLK_PIN].gpio_bit, - GPIO_MODE_INPUT, GPIO_MODEF_PUPD_NONE); - gpio_set_modef(PIN_MAP[BOARD_JTDI_PIN].gpio_device, PIN_MAP[BOARD_JTDI_PIN].gpio_bit, - GPIO_MODE_INPUT, GPIO_MODEF_PUPD_NONE); - gpio_set_modef(PIN_MAP[BOARD_JTDO_PIN].gpio_device, PIN_MAP[BOARD_JTDO_PIN].gpio_bit, - GPIO_MODE_INPUT, GPIO_MODEF_PUPD_NONE); - gpio_set_modef(PIN_MAP[BOARD_NJTRST_PIN].gpio_device, PIN_MAP[BOARD_NJTRST_PIN].gpio_bit, - GPIO_MODE_INPUT, GPIO_MODEF_PUPD_NONE); -} - -void enableDebugPorts(void) { - // Put BOARD_JTMS_SWDIO_PIN-BOARD_JTDI_PIN and BOARD_JTDO_PIN-BOARD_NJTRST_PIN back in system AF mode. - gpio_set_modef(PIN_MAP[BOARD_JTMS_SWDIO_PIN].gpio_device, PIN_MAP[BOARD_JTMS_SWDIO_PIN].gpio_bit, - GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - gpio_set_modef(PIN_MAP[BOARD_JTCK_SWCLK_PIN].gpio_device, PIN_MAP[BOARD_JTCK_SWCLK_PIN].gpio_bit, - GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - gpio_set_modef(PIN_MAP[BOARD_JTDI_PIN].gpio_device, PIN_MAP[BOARD_JTDI_PIN].gpio_bit, - GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - gpio_set_modef(PIN_MAP[BOARD_JTDO_PIN].gpio_device, PIN_MAP[BOARD_JTDO_PIN].gpio_bit, - GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - gpio_set_modef(PIN_MAP[BOARD_NJTRST_PIN].gpio_device, PIN_MAP[BOARD_NJTRST_PIN].gpio_bit, - GPIO_MODE_AF, GPIO_MODEF_TYPE_PP); - - gpio_set_af(PIN_MAP[BOARD_JTMS_SWDIO_PIN].gpio_device, PIN_MAP[BOARD_JTMS_SWDIO_PIN].gpio_bit, GPIO_AF_0); - gpio_set_af(PIN_MAP[BOARD_JTCK_SWCLK_PIN].gpio_device, PIN_MAP[BOARD_JTCK_SWCLK_PIN].gpio_bit, GPIO_AF_0); - gpio_set_af(PIN_MAP[BOARD_JTDI_PIN].gpio_device, PIN_MAP[BOARD_JTDI_PIN].gpio_bit, GPIO_AF_0); - gpio_set_af(PIN_MAP[BOARD_JTDO_PIN].gpio_device, PIN_MAP[BOARD_JTDO_PIN].gpio_bit, GPIO_AF_0); - gpio_set_af(PIN_MAP[BOARD_NJTRST_PIN].gpio_device, PIN_MAP[BOARD_NJTRST_PIN].gpio_bit, GPIO_AF_0); -} diff --git a/STM32F3/cores/maple/wirish/syscalls.c b/STM32F3/cores/maple/wirish/syscalls.c deleted file mode 100644 index a3b6d2c..0000000 --- a/STM32F3/cores/maple/wirish/syscalls.c +++ /dev/null @@ -1,175 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/syscalls.c - * @brief newlib stubs - * - * Low level system routines used by newlib for basic I/O and memory - * allocation. You can override most of these. - */ - -#include - -#include -#include - -/* If CONFIG_HEAP_START (or CONFIG_HEAP_END) isn't defined, then - * assume _lm_heap_start (resp. _lm_heap_end) is appropriately set by - * the linker */ -#ifndef CONFIG_HEAP_START -extern char _lm_heap_start; -#define CONFIG_HEAP_START ((caddr_t)&_lm_heap_start) -#endif -#ifndef CONFIG_HEAP_END -extern char _lm_heap_end; -#define CONFIG_HEAP_END ((caddr_t)&_lm_heap_end) -#endif - -/* - * _sbrk -- Increment the program break. - * - * Get incr bytes more RAM (for use by the heap). malloc() and - * friends call this function behind the scenes. - */ -caddr_t _sbrk(int incr) { - static caddr_t pbreak = NULL; /* current program break */ - caddr_t ret; - - if (pbreak == NULL) { - pbreak = CONFIG_HEAP_START; - } - - if ((CONFIG_HEAP_END - pbreak < incr) || - (pbreak - CONFIG_HEAP_START < -incr)) { - errno = ENOMEM; - return (caddr_t)-1; - } - - ret = pbreak; - pbreak += incr; - return ret; -} - -__weak int _open(const char *path, int flags, ...) { - return 1; -} - -__weak int _close(int fd) { - return 0; -} - -__weak int _fstat(int fd, struct stat *st) { - st->st_mode = S_IFCHR; - return 0; -} - -__weak int _isatty(int fd) { - return 1; -} - -__weak int isatty(int fd) { - return 1; -} - -__weak int _lseek(int fd, off_t pos, int whence) { - return -1; -} - -__weak unsigned char getch(void) { - return 0; -} - - -__weak int _read(int fd, char *buf, size_t cnt) { - *buf = getch(); - - return 1; -} - -__weak void putch(unsigned char c) { -} - -__weak void cgets(char *s, int bufsize) { - char *p; - int c; - int i; - - for (i = 0; i < bufsize; i++) { - *(s+i) = 0; - } -// memset(s, 0, bufsize); - - p = s; - - for (p = s; p < s + bufsize-1;) { - c = getch(); - switch (c) { - case '\r' : - case '\n' : - putch('\r'); - putch('\n'); - *p = '\n'; - return; - - case '\b' : - if (p > s) { - *p-- = 0; - putch('\b'); - putch(' '); - putch('\b'); - } - break; - - default : - putch(c); - *p++ = c; - break; - } - } - return; -} - -__weak int _write(int fd, const char *buf, size_t cnt) { - int i; - - for (i = 0; i < cnt; i++) - putch(buf[i]); - - return cnt; -} - -/* Override fgets() in newlib with a version that does line editing */ -__weak char *fgets(char *s, int bufsize, void *f) { - cgets(s, bufsize); - return s; -} - -__weak void _exit(int exitcode) { - while (1) - ; -} diff --git a/STM32F3/cores/maple/wirish/usb_serial.cpp b/STM32F3/cores/maple/wirish/usb_serial.cpp deleted file mode 100644 index d21766f..0000000 --- a/STM32F3/cores/maple/wirish/usb_serial.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @brief USB virtual serial terminal - */ - -#include - -#include -#include - -#include -#include -#include - -#include - -/* - * Hooks used for bootloader reset signalling - */ - -#if BOARD_HAVE_SERIALUSB -static void rxHook(unsigned, void*); -static void ifaceSetupHook(unsigned, void*); -#endif - -/* - * USBSerial interface - */ - -#define USB_TIMEOUT 50 - -USBSerial::USBSerial(void) { -#if !BOARD_HAVE_SERIALUSB - ASSERT(0); -#endif -} - -void USBSerial::begin(void) { -#if BOARD_HAVE_SERIALUSB - usb_cdcacm_enable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT); - usb_cdcacm_set_hooks(USB_CDCACM_HOOK_RX, rxHook); - usb_cdcacm_set_hooks(USB_CDCACM_HOOK_IFACE_SETUP, ifaceSetupHook); -#endif -} - -void USBSerial::end(void) { -#if BOARD_HAVE_SERIALUSB - usb_cdcacm_disable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT); - usb_cdcacm_remove_hooks(USB_CDCACM_HOOK_RX | USB_CDCACM_HOOK_IFACE_SETUP); -#endif -} - -void USBSerial::write(uint8 ch) { - this->write(&ch, 1); -} - -void USBSerial::write(const char *str) { - this->write(str, strlen(str)); -} - -void USBSerial::write(const void *buf, uint32 len) { - if (!this->isConnected() || !buf) { - return; - } - - uint32 txed = 0; - uint32 old_txed = 0; - uint32 start = millis(); - - uint32 sent = 0; - - while (txed < len && (millis() - start < USB_TIMEOUT)) { - sent = usb_cdcacm_tx((const uint8*)buf + txed, len - txed); - txed += sent; - if (old_txed != txed) { - start = millis(); - } - old_txed = txed; - } - - - if (sent == USB_CDCACM_TX_EPSIZE) { - while (usb_cdcacm_is_transmitting() != 0) { - } - /* flush out to avoid having the pc wait for more data */ - usb_cdcacm_tx(NULL, 0); - } -} - -uint32 USBSerial::available(void) { - return usb_cdcacm_data_available(); -} - -uint32 USBSerial::read(void *buf, uint32 len) { - if (!buf) { - return 0; - } - - uint32 rxed = 0; - while (rxed < len) { - rxed += usb_cdcacm_rx((uint8*)buf + rxed, len - rxed); - } - - return rxed; -} - -/* Blocks forever until 1 byte is received */ -uint8 USBSerial::read(void) { - uint8 b; - this->read(&b, 1); - return b; -} - -uint8 USBSerial::pending(void) { - return usb_cdcacm_get_pending(); -} - -uint8 USBSerial::isConnected(void) { - return usb_is_connected(USBLIB) && usb_is_configured(USBLIB); -} - -uint8 USBSerial::getDTR(void) { - return usb_cdcacm_get_dtr(); -} - -uint8 USBSerial::getRTS(void) { - return usb_cdcacm_get_rts(); -} - -#if BOARD_HAVE_SERIALUSB -USBSerial SerialUSB; -#endif - -/* - * Bootloader hook implementations - */ - -#if BOARD_HAVE_SERIALUSB - -enum reset_state_t { - DTR_UNSET, - DTR_HIGH, - DTR_NEGEDGE, - DTR_LOW -}; - -static reset_state_t reset_state = DTR_UNSET; - -static void ifaceSetupHook(unsigned hook, void *requestvp) { - uint8 request = *(uint8*)requestvp; - - // Ignore requests we're not interested in. - if (request != USB_CDCACM_SET_CONTROL_LINE_STATE) { - return; - } - - // We need to see a negative edge on DTR before we start looking - // for the in-band magic reset byte sequence. - uint8 dtr = usb_cdcacm_get_dtr(); - switch (reset_state) { - case DTR_UNSET: - reset_state = dtr ? DTR_HIGH : DTR_LOW; - break; - case DTR_HIGH: - reset_state = dtr ? DTR_HIGH : DTR_NEGEDGE; - break; - case DTR_NEGEDGE: - reset_state = dtr ? DTR_HIGH : DTR_LOW; - break; - case DTR_LOW: - reset_state = dtr ? DTR_HIGH : DTR_LOW; - break; - } -} - -#define RESET_DELAY 100000 -static void wait_reset(void) { - delay_us(RESET_DELAY); - nvic_sys_reset(); -} - -#define STACK_TOP 0x20000800 -#define EXC_RETURN 0xFFFFFFF9 -#define DEFAULT_CPSR 0x61000000 -static void rxHook(unsigned hook, void *ignored) { - /* FIXME this is mad buggy; we need a new reset sequence. E.g. NAK - * after each RX means you can't reset if any bytes are waiting. */ - if (reset_state == DTR_NEGEDGE) { - reset_state = DTR_LOW; - - if (usb_cdcacm_data_available() >= 4) { - // The magic reset sequence is "1EAF". - static const uint8 magic[4] = {'1', 'E', 'A', 'F'}; - uint8 chkBuf[4]; - - // Peek at the waiting bytes, looking for reset sequence, - // bailing on mismatch. - usb_cdcacm_peek(chkBuf, 4); - for (unsigned i = 0; i < sizeof(magic); i++) { - if (chkBuf[i] != magic[i]) { - return; - } - } - - // Got the magic sequence -> reset, presumably into the bootloader. - // Return address is wait_reset, but we must set the thumb bit. - uintptr_t target = (uintptr_t)wait_reset | 0x1; - asm volatile("mov r0, %[stack_top] \n\t" // Reset stack - "mov sp, r0 \n\t" - "mov r0, #1 \n\t" - "mov r1, %[target_addr] \n\t" - "mov r2, %[cpsr] \n\t" - "push {r2} \n\t" // Fake xPSR - "push {r1} \n\t" // PC target addr - "push {r0} \n\t" // Fake LR - "push {r0} \n\t" // Fake R12 - "push {r0} \n\t" // Fake R3 - "push {r0} \n\t" // Fake R2 - "push {r0} \n\t" // Fake R1 - "push {r0} \n\t" // Fake R0 - "mov lr, %[exc_return] \n\t" - "bx lr" - : - : [stack_top] "r" (STACK_TOP), - [target_addr] "r" (target), - [exc_return] "r" (EXC_RETURN), - [cpsr] "r" (DEFAULT_CPSR) - : "r0", "r1", "r2"); - /* Can't happen. */ - ASSERT_FAULT(0); - } - } -} - -#endif // BOARD_HAVE_SERIALUSB diff --git a/STM32F3/cores/maple/wirish/usb_serial.h b/STM32F3/cores/maple/wirish/usb_serial.h deleted file mode 100644 index f36671b..0000000 --- a/STM32F3/cores/maple/wirish/usb_serial.h +++ /dev/null @@ -1,67 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @brief Wirish USB virtual serial port (SerialUSB). - */ - -#ifndef _WIRISH_USB_SERIAL_H_ -#define _WIRISH_USB_SERIAL_H_ - -#include -#include - -/** - * @brief Virtual serial terminal. - */ -class USBSerial : public Print { -public: - USBSerial(void); - - void begin(void); - void end(void); - - uint32 available(void); - - uint32 read(void *buf, uint32 len); - uint8 read(void); - - void write(uint8); - void write(const char *str); - void write(const void*, uint32); - - uint8 getRTS(); - uint8 getDTR(); - uint8 isConnected(); - uint8 pending(); -}; - -#if BOARD_HAVE_SERIALUSB -extern USBSerial SerialUSB; -#endif - -#endif - diff --git a/STM32F3/cores/maple/wirish/wirish.h b/STM32F3/cores/maple/wirish/wirish.h deleted file mode 100644 index f1884b5..0000000 --- a/STM32F3/cores/maple/wirish/wirish.h +++ /dev/null @@ -1,77 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @brief Main include file for the Wirish core. - * - * Includes most of Wirish, and (transitively or otherwise) - * substantial pieces of libmaple proper. - */ - -#ifndef _WIRISH_WIRISH_H_ -#define _WIRISH_WIRISH_H_ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#if (STM32_MCU_SERIES == STM32_SERIES_F1) || (STM32_MCU_SERIES == STM32_SERIES_F3) /* FIXME [0.0.13?] port to F2 */ -#include -#endif -#include -#include -#include -#include - -#include - -#include - -/* Wiring macros and bit defines */ - -#define true 0x1 -#define false 0x0 - -#define LSBFIRST 0 -#define MSBFIRST 1 - -#define lowByte(w) ((w) & 0xFF) -#define highByte(w) (((w) >> 8) & 0xFF) -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) -#define bitSet(value, bit) ((value) |= (1UL << (bit))) -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : \ - bitClear(value, bit)) -#define bit(b) (1UL << (b)) - -#endif - diff --git a/STM32F3/cores/maple/wirish/wirish_analog.cpp b/STM32F3/cores/maple/wirish/wirish_analog.cpp deleted file mode 100644 index 91ca0e2..0000000 --- a/STM32F3/cores/maple/wirish/wirish_analog.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2011, 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/wirish_analog.cpp - * @brief Wiring-style analogRead() implementation. - */ - -#include -#include -#include - -/* Unlike Wiring and Arduino, this assumes that the pin's mode is set - * to INPUT_ANALOG. That's faster, but it does require some extra work - * on the user's part. Not too much, we think ;). */ -uint16 analogRead(uint8 pin) { - const adc_dev *dev = PIN_MAP[pin].adc_device; - if (dev == NULL) { - return 0; - } - - return adc_read(dev, PIN_MAP[pin].adc_channel); -} diff --git a/STM32F3/cores/maple/wirish/wirish_debug.h b/STM32F3/cores/maple/wirish/wirish_debug.h deleted file mode 100644 index 4edfd27..0000000 --- a/STM32F3/cores/maple/wirish/wirish_debug.h +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/wirish_debug.h - * @brief High level debug port configuration - */ - -#ifndef _WIRISH_WIRISH_DEBUG_H_ -#define _WIRISH_WIRISH_DEBUG_H_ - -#include - -/** - * @brief Disable the JTAG and Serial Wire (SW) debug ports. - * - * You can call this function in order to use the JTAG and SW debug - * pins as ordinary GPIOs. - * - * @see enableDebugPorts() - */ -void disableDebugPorts(void); - -/** - * @brief Enable the JTAG and Serial Wire (SW) debug ports. - * - * After you call this function, the JTAG and SW debug pins will no - * longer be usable as GPIOs. - * - * @see disableDebugPorts() - */ -void enableDebugPorts(void); - -#endif diff --git a/STM32F3/cores/maple/wirish/wirish_digital.cpp b/STM32F3/cores/maple/wirish/wirish_digital.cpp deleted file mode 100644 index 2711a33..0000000 --- a/STM32F3/cores/maple/wirish/wirish_digital.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/* - * Arduino-compatible digital I/O implementation. - */ - -#include - -#include -#include - -#include -#include - -uint32 digitalRead(uint8 pin) { - if (pin >= BOARD_NR_GPIO_PINS) { - return 0; - } - - return gpio_read_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit) ? - HIGH : LOW; -} - -void digitalWrite(uint8 pin, uint8 val) { - if (pin >= BOARD_NR_GPIO_PINS) { - return; - } - - gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, val); -} - -void togglePin(uint8 pin) { - if (pin >= BOARD_NR_GPIO_PINS) { - return; - } - - gpio_toggle_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit); -} - -#define BUTTON_DEBOUNCE_DELAY 1 - -uint8 isButtonPressed(uint8 pin, uint32 pressedLevel) { - if (digitalRead(pin) == pressedLevel) { - delay(BUTTON_DEBOUNCE_DELAY); - while (digitalRead(pin) == pressedLevel) - ; - return true; - } - return false; -} - -uint8 waitForButtonPress(uint32 timeout) { - uint32 start = millis(); - uint32 time; - if (timeout == 0) { - while (!isButtonPressed()) - ; - return true; - } - do { - time = millis(); - /* properly handle wrap-around */ - if ((start > time && time + (0xffffffffU - start) > timeout) || - time - start > timeout) { - return false; - } - } while (!isButtonPressed()); - return true; -} diff --git a/STM32F3/cores/maple/wirish/wirish_math.cpp b/STM32F3/cores/maple/wirish/wirish_math.cpp deleted file mode 100644 index 1443b3c..0000000 --- a/STM32F3/cores/maple/wirish/wirish_math.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Modified by LeafLabs, LLC. - * - * Part of the Wiring project - http://wiring.org.co Copyright (c) - * 2004-06 Hernando Barragan Modified 13 August 2006, David A. Mellis - * for Arduino - http://www.arduino.cc/ - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include -#include - -void randomSeed(unsigned int seed) { - if (seed != 0) { - srand(seed); - } -} - -long random(long howbig) { - if (howbig == 0) { - return 0; - } - - return rand() % howbig; -} - -long random(long howsmall, long howbig) { - if (howsmall >= howbig) { - return howsmall; - } - - long diff = howbig - howsmall; - return random(diff) + howsmall; -} - diff --git a/STM32F3/cores/maple/wirish/wirish_math.h b/STM32F3/cores/maple/wirish/wirish_math.h deleted file mode 100644 index 39f16a0..0000000 --- a/STM32F3/cores/maple/wirish/wirish_math.h +++ /dev/null @@ -1,151 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/wirish_math.h - * @brief Includes ; provides Wiring-compatible math routines. - */ - -#ifndef _WIRISH_WIRISH_MATH_H_ -#define _WIRISH_WIRISH_MATH_H_ - -#include - -/** - * @brief Initialize the pseudo-random number generator. - * @param seed the number used to initialize the seed; cannot be zero. - */ -void randomSeed(unsigned int seed); - -/** - * @brief Generate a pseudo-random number with upper bound. - * @param max An upper bound on the returned value, exclusive. - * @return A pseudo-random number in the range [0,max). - * @see randomSeed() - */ -long random(long max); - -/** - * @brief Generate a pseudo-random number with lower and upper bounds. - * @param min Lower bound on the returned value, inclusive. - * @param max Upper bound on the returned value, exclusive. - * @return A pseudo-random number in the range [min, max). - * @see randomSeed() - */ -long random(long min, long max); - -/** - * @brief Remap a number from one range to another. - * - * That is, a value equal to fromStart gets mapped to toStart, a value - * of fromEnd to toEnd, and other values are mapped proportionately. - * - * Does not constrain value to lie within [fromStart, fromEnd]. - * - * If a "start" value is larger than its corresponding "end", the - * ranges are reversed, so map(n, 1, 10, 10, 1) would reverse the - * range [1,10]. - * - * Negative numbers may appear as any argument. - * - * @param value the value to map. - * @param fromStart the beginning of the value's current range. - * @param fromEnd the end of the value's current range. - * @param toStart the beginning of the value's mapped range. - * @param toEnd the end of the value's mapped range. - * @return the mapped value. - */ -static inline long map(long value, long fromStart, long fromEnd, - long toStart, long toEnd) { - return (value - fromStart) * (toEnd - toStart) / (fromEnd - fromStart) + - toStart; -} - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 - -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) -#define radians(deg) ((deg)*DEG_TO_RAD) -#define degrees(rad) ((rad)*RAD_TO_DEG) -#define sq(x) ((x)*(x)) - -/* undefine stdlib's abs if encountered */ -#ifdef abs -#undef abs -#endif -#define abs(x) (((x) > 0) ? (x) : -(x)) - -/* Following are duplicate declarations (with Doxygen comments) for - * some of the math.h functions; this is for the convenience of the - * Sphinx docs. - */ - -/** - * Compute the cosine of an angle, in radians. - * @param x The radian measure of the angle. - * @return The cosine of x. This value will be between -1 and 1. - */ -double cos(double x); - -/** - * Compute the sine of an angle, in radians. - * @param x The radian measure of the angle. - * @return The sine of x. This value will be between -1 and 1. - */ -double sin(double x); - -/** - * Compute the tangent of an angle, in radians. - * @param x The radian measure of the angle. - * @return The tangent of x. There are no limits on the return value - * of this function. - */ -double tan(double x); - -/** - * Compute the square root of a number. - * @param x The number whose square root to find. This value cannot - * be negative. - * @return The square root of x. The return value is never negative. - */ -double sqrt(double x); - -/** - * Compute an exponentiation. - * @param x the base. This value cannot be zero if y <= 0. This value - * cannot be negative if y is not an integral value. - * @param y the exponent. - * @return x raised to the power y. - */ -double pow(double x, double y); - -#endif diff --git a/STM32F3/cores/maple/wirish/wirish_shift.cpp b/STM32F3/cores/maple/wirish/wirish_shift.cpp deleted file mode 100644 index a032d50..0000000 --- a/STM32F3/cores/maple/wirish/wirish_shift.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2012 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#include - -void shiftOut(uint8 dataPin, uint8 clockPin, uint8 bitOrder, uint8 value) { - digitalWrite(clockPin, LOW); - for (int i = 0; i < 8; i++) { - int bit = bitOrder == LSBFIRST ? i : (7 - i); - digitalWrite(dataPin, (value >> bit) & 0x1); - togglePin(clockPin); - togglePin(clockPin); - } -} diff --git a/STM32F3/cores/maple/wirish/wirish_time.cpp b/STM32F3/cores/maple/wirish/wirish_time.cpp deleted file mode 100644 index 9ce934b..0000000 --- a/STM32F3/cores/maple/wirish/wirish_time.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @brief Delay implementation. - */ - -#include - -#include -#include - -void delay(unsigned long ms) { - uint32 i; - for (i = 0; i < ms; i++) { - delayMicroseconds(1000); - } -} - -void delayMicroseconds(uint32 us) { - delay_us(us); -} diff --git a/STM32F3/cores/maple/wirish/wirish_time.h b/STM32F3/cores/maple/wirish/wirish_time.h deleted file mode 100644 index eb6c68f..0000000 --- a/STM32F3/cores/maple/wirish/wirish_time.h +++ /dev/null @@ -1,95 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/wirish_time.h - * @brief Timing and delay functions. - */ - -#ifndef _WIRISH_WIRISH_TIME_H_ -#define _WIRISH_WIRISH_TIME_H_ - -#include -#include - -#include - -/** - * Returns time (in milliseconds) since the beginning of program - * execution. On overflow, restarts at 0. - * @see micros() - */ -static inline uint32 millis(void) { - return systick_uptime(); -} - -/** - * Returns time (in microseconds) since the beginning of program - * execution. On overflow, restarts at 0. - * @see millis() - */ -static inline uint32 micros(void) { - uint32 ms; - uint32 cycle_cnt; - - do { - ms = millis(); - cycle_cnt = systick_get_count(); - } while (ms != millis()); - -#define US_PER_MS 1000 - /* SYSTICK_RELOAD_VAL is 1 less than the number of cycles it - * actually takes to complete a SysTick reload */ - return ((ms * US_PER_MS) + - (SYSTICK_RELOAD_VAL + 1 - cycle_cnt) / CYCLES_PER_MICROSECOND); -#undef US_PER_MS -} - -/** - * Delay for at least the given number of milliseconds. - * - * Interrupts, etc. may cause the actual number of milliseconds to - * exceed ms. However, this function will return no less than ms - * milliseconds from the time it is called. - * - * @param ms the number of milliseconds to delay. - * @see delayMicroseconds() - */ -void delay(unsigned long ms); - -/** - * Delay for at least the given number of microseconds. - * - * Interrupts, etc. may cause the actual number of microseconds to - * exceed us. However, this function will return no less than us - * microseconds from the time it is called. - * - * @param us the number of microseconds to delay. - * @see delay() - */ -void delayMicroseconds(uint32 us); - -#endif diff --git a/STM32F3/cores/maple/wirish/wirish_types.h b/STM32F3/cores/maple/wirish/wirish_types.h deleted file mode 100644 index fce895e..0000000 --- a/STM32F3/cores/maple/wirish/wirish_types.h +++ /dev/null @@ -1,68 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/include/wirish/wirish_types.h - * @author Marti Bolivar - * @brief Wirish library type definitions. - */ - -#ifndef _WIRISH_WIRISH_TYPES_H_ -#define _WIRISH_WIRISH_TYPES_H_ - -#include -#include -#include -#include - -/** - * Invalid stm32_pin_info adc_channel value. - * @see stm32_pin_info - */ -#define ADCx 0xFF - -/** - * @brief Stores STM32-specific information related to a given Maple pin. - * @see PIN_MAP - */ -typedef struct stm32_pin_info { - gpio_dev *gpio_device; /**< Maple pin's GPIO device */ - timer_dev *timer_device; /**< Pin's timer device, if any. */ - const adc_dev *adc_device; /**< ADC device, if any. */ - uint8 gpio_bit; /**< Pin's GPIO port bit. */ - uint8 timer_channel; /**< Timer channel, or 0 if none. */ - uint8 adc_channel; /**< Pin ADC channel, or ADCx if none. */ -} stm32_pin_info; - -/** - * Variable attribute, instructs the linker to place the marked - * variable in Flash instead of RAM. */ -#define __FLASH__ __attr_flash - -typedef uint8 boolean; -typedef uint8 byte; - -#endif diff --git a/STM32F3/examples/Blinkf3/Blinkf3.ino b/STM32F3/examples/Blinkf3/Blinkf3.ino deleted file mode 100644 index 2bcb929..0000000 --- a/STM32F3/examples/Blinkf3/Blinkf3.ino +++ /dev/null @@ -1,38 +0,0 @@ -/* - Blink - Turns on an LED on for one second, then off for one second, repeatedly. - - Most Arduinos have an on-board LED you can control. On the Uno and - Leonardo, it is attached to digital pin 13. If you're unsure what - pin the on-board LED is connected to on your Arduino model, check - the documentation at http://arduino.cc - - This example code is in the public domain. - - modified 8 May 2014 - by Scott Fitzgerald - - modified for stm32f3discovery - 2015/02 by Frank-Michael Krause - */ - - -// the setup function runs once when you press reset or power the board -void setup() { - // initialize pins PE8, PE9 as an output. - pinMode(PE8, OUTPUT); - pinMode(PE9, OUTPUT); - Serial2.begin(9600); - Serial2.println("Hello world"); - -} - -// the loop function runs over and over again forever -void loop() { - digitalWrite(PE8, HIGH); // turn the LED on (HIGH is the voltage level) - digitalWrite(PE9, LOW); // turn the LED off by making the voltage LOW - delay(100); // wait for a second - digitalWrite(PE8, LOW); // turn the LED off by making the voltage LOW - digitalWrite(PE9, HIGH); // turn the LED on (HIGH is the voltage level) - delay(300); // wait for a second -} diff --git a/STM32F3/examples/f3_buttondemo/f3_buttondemo.ino b/STM32F3/examples/f3_buttondemo/f3_buttondemo.ino deleted file mode 100644 index c6a9c0d..0000000 --- a/STM32F3/examples/f3_buttondemo/f3_buttondemo.ino +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - - -/* - * This demo shows how to handle the blue button of the stm32f3discovery board - * - * Dieses Beispiel zeigt, wie die blaue Taste des Boards abgefragt werden kann. - * Es wird eine LED ein- bzw. ausgeschaltet. - */ - - -void setup() // Init-Funktion -{ - // BOARD_LED_PIN ist PE10 - pinMode(BOARD_LED_PIN, OUTPUT); - - // BOARD_BUTTTON_PIN ist PA0 - pinMode(BOARD_BUTTON_PIN, INPUT); - -} - - -void loop() -{ - if (isButtonPressed()) - togglePin(BOARD_LED_PIN); -} - - - diff --git a/STM32F3/examples/f3_functionTimer/f3_functionTimer.ino b/STM32F3/examples/f3_functionTimer/f3_functionTimer.ino deleted file mode 100644 index ca8fce9..0000000 --- a/STM32F3/examples/f3_functionTimer/f3_functionTimer.ino +++ /dev/null @@ -1,144 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - - -#include -#include - -/* - * Demo program function timer - * - * You can define functions register those functions at the timer system - * to be called after the time in ms given at timer start - * - * - there are 10 timers with id from 0 to 9 - * - the id has to be given at timer start - * - there can only be running one instance of a timer id at one time - * - at each timer start another function can be registered - * - time resolution is 5ms - * - * The registered function will be executed in interrupt context. - * Therefore the timer funtion shall be execute very fast. - * - * If using functtion timer and ultrasonic sensors in parallel the measurement results of - * the sensors can be slightly wrong. - * - * This demo controls three LEDs with different blinking rythms - */ - - -/* - * Demoprogramm fuer Funktions-Timer - * - * Es koennen Funktionen definiert und dem Timersystem-uebergeben werden, - * die nach einer uebergebenen Zeit aufgerufen werden. - * - * - Jeder Timer hat eine id zwischen 0 und 9, die beim Start angegeben werden muss. - * - Es kann nur ein Timer pro Id zu gleichen Zeit laufen - * - Es kann bei jedem Start eines Timers eine andere Funktion uebergeben werden. - * - * Die uebergebene Funktion wird im Interrupt-Kontext ausgefuehrt und unterbricht das - * normal in setup/loop ausgefuehrte Programm an beliebiger Stelle. - * Es ist darauf zu achten, dass die Timerfuntion moeglichst kurz, d.h. schnell ausfuehrbar, ist. - * - * Die parallele Ausfuehrung von Funktionstimern kann die Messergebnisse von Ultraschallsensoren - * leicht verfaelschen! - * - * Das Demoprogramm steuert drei LEDs mit unterschiedlichen Blink-Zeiten an. - * - */ - - - -// 500ms Bink mit Steuerung ueber Timer-Id 0 -#define LED PE9 -int LEDState = 0; -void TimerFunction(int arg) -{ - if (LEDState) - LEDState = 0; - else - LEDState = 1; - digitalWrite(LED, LEDState); - timerStart(0, 500, TimerFunction, 0 ); // restart Timer -} - - -// 900ms Bink mit Steuerung ueber Timer-Id 1 -#define LED1 PE10 -int LED1State = 0; -void Timer1Function(int arg) -{ - if (LED1State) - LED1State = 0; - else - LED1State = 1; - digitalWrite(LED1, LED1State); - timerStart(1, 900, Timer1Function, 0 ); // restart Timer -} - - -// 1300ms Bink mit Steuerung ueber Timer-Id 2 -#define LED2 PE11 -int LED2State = 0; -void Timer2Function(int arg) -{ - if (LED2State) - LED2State = 0; - else - LED2State = 1; - digitalWrite(LED2, LED2State); - timerStart(2, 1300, Timer2Function, 0 ); // restart Timer -} - - - - -void setup() -{ - pinMode(LED, OUTPUT); - pinMode(LED1, OUTPUT); - pinMode(LED2, OUTPUT); - - // Timer-System initialisieren - timerInit(); - - // Timer starten - timerStart(0, 500, TimerFunction, 0 ); - timerStart(1, 900, Timer1Function, 0 ); - timerStart(2, 1300, Timer2Function, 0 ); -} - -void loop() -{ - // Die Programmabarbeitung erfolgt komplett im Interrupt, - // daher muss in loop nichts getan werden - while (1) - ; -} - - - diff --git a/STM32F3/examples/f3_gyrodemo/f3_gyrodemo.ino b/STM32F3/examples/f3_gyrodemo/f3_gyrodemo.ino deleted file mode 100644 index 8e3ca2b..0000000 --- a/STM32F3/examples/f3_gyrodemo/f3_gyrodemo.ino +++ /dev/null @@ -1,100 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#include - -#include -#include - - - -/** - * Dieses Beispiel benutzt die Z-Achse des Gyro-Sensors, um eine Drehung des Boards - * zu messen und anzuzeigen. - * Wenn das Board um seine Z-Achse gedreht wird, so zeigt die jeweils aktive LED - * immer in die gleiche Richtung. - * Mit der Zeit ändert sich die angezeigte Richtung, da die Messwerte kleine - * Fehler haben, die sich mit der Zeit aufsummieren und das Programm keine - * Kalibrierung und Fehlerkorrektur enthält. Die Größe des Fehlers ist von - * Board zu Board unterschiedlich. - * - */ - -// Array mit den LED-Pins -int leds[] = { PE9, PE10, PE11, PE12, PE13, PE14, PE15, PE8 }; - - -void setup() // Init-Funktion -{ - // Die 8 LED-Pins auf Ausgang setzen - pinMode (leds[0], OUTPUT); - pinMode (leds[1], OUTPUT); - pinMode (leds[2], OUTPUT); - pinMode (leds[3], OUTPUT); - pinMode (leds[4], OUTPUT); - pinMode (leds[5], OUTPUT); - pinMode (leds[6], OUTPUT); - pinMode (leds[7], OUTPUT); - - // SPI1-Interface initialisieren - gyroSpiInit(); - - // den Gyrochip initialisieren - gyroInit(); - - // Gyro aktivieren - gyroStart(); -} - - -int led_idx; - -void loop() -{ - // Auslesen der Gyro-Messwerte und Berechnen des aktuellen Drehwinkels - gyroUpdate(); - - // Wenn der Winkel 360° überschreitet oder 0° unterschreitet - // werden 360° abgezogen bzw. addiert - if (winkelz>360) - winkelz -= 360; - else if (winkelz<0) - winkelz += 360; - - // aktuell aktive LED abschalten - digitalWrite(leds[led_idx], LOW); - - // anhand des Winkels die neue Aktive LED bestimmen. - // Dazu wird mit Dreisatz der Winkel (0..360) auf die LED (0..7) abgebildet - led_idx = (winkelz*8)/360; - - // aktive LED anschalten - digitalWrite(leds[led_idx], HIGH); - - delay(50); -} - - - diff --git a/STM32F3/examples/f3_lsm303demo/f3_lsm303demo.ino b/STM32F3/examples/f3_lsm303demo/f3_lsm303demo.ino deleted file mode 100644 index 63251aa..0000000 --- a/STM32F3/examples/f3_lsm303demo/f3_lsm303demo.ino +++ /dev/null @@ -1,111 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#include -#include -#include - -#include -#include - - -/** - * Dieses Beispiel wertet die x und y Werte des Beschleunigungssensors aus - * und zeigt über die 8 LEDs an, in welche Richtung das Board gekippt wurde. - * Die z-Komponente wird nicht ausgewertet. - */ - - -// Array mit den LED-Pins -int leds[] = { PE9, PE10, PE11, PE12, PE13, PE14, PE15, PE8 }; - - -void setup() // Init-Funktion -{ - // Die 8 LED-Pins auf Ausgang setzen - pinMode (leds[0], OUTPUT); - pinMode (leds[1], OUTPUT); - pinMode (leds[2], OUTPUT); - pinMode (leds[3], OUTPUT); - pinMode (leds[4], OUTPUT); - pinMode (leds[5], OUTPUT); - pinMode (leds[6], OUTPUT); - pinMode (leds[7], OUTPUT); - - // I2C-Interface initialisieren, mit dem der - // Beschleunigungssensor verbunden ist - i2c_master_enable(I2C1, 0); - - // Beschleunigungssensor initialisieren - lsm303Init(); - -} - -// Speicher für die aktuell aktive LED -int led_idx; - -void loop() -{ - float winkel; - - // Beschleunigungssensor lesen - readAccValues(); - - // Winkel entsprechend der gemessenen x und y Komponente - // berechnen - // atan2 gibt den Winkel im Bogenmass zurueck, 2*Pi entsprechen 360° - winkel = atan2(accy*-1.0,accx*1.0); - - // Umrechnung des Winkels auf die 8 LEDs, aus denen der Vollkreis (2*Pi) - // besteht (Dreisatz, Umrechnung mit 4 und Pi) - winkel = (winkel*4)/3.14; - - // Falls der Winkel negativ ist, eine Vollkreis-Wert hinzurechnen - // für unser Beispiel 8 - if (winkel<0) - winkel += 8; - - // alte aktive LED ausschalten - digitalWrite(leds[led_idx], LOW); - - // der Ganzzahl-Anteil des Winkels ist der Index der neuen LED - // Das (int) vor winkel führt die Umwandlung der Kommanzahl in einen Integer-Wert - // durch. Das nennt man einen Type-Cast. Der ist hier nötig, da eine - // float Variable nicht direkt einer Integervariable zugewiesen werden kann - led_idx = (int)winkel; - - // nochmal prüfen, ob der neue Led-Index nicht zu groß ist - // wenn ja auf maximalwert setzen - if (led_idx>7) - led_idx=7; - - // neue LED anschalten - digitalWrite(leds[led_idx], HIGH); - - delay(50); -} - - - diff --git a/STM32F3/examples/f3_ultrasonic/f3_ultrasonic.ino b/STM32F3/examples/f3_ultrasonic/f3_ultrasonic.ino deleted file mode 100644 index aa8bc5c..0000000 --- a/STM32F3/examples/f3_ultrasonic/f3_ultrasonic.ino +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#include -#include -#include - -/* - * Demoprogramm für den Betrieb von Ultraschallsensoren über Interrupts. - * - * Diese Betriebsart hat den Vorteil, dass während der Messung (die einige 10ms dauern kann) - * andere Dinge erledigt werden können. - * - * Es kann ständig im Hintergrund gemessen werden und der letzte gültige oder der aktuelle - * Messwert per Funktion abgefragt werden. - * - * Außerdem kann eine Callbackfunktion pro Sensor registriert werden, die nach einer erfolgten - * Messung aufgerufen wird. ZU beachten ist, dass diese Funktion im Interrupt-Kontext aufgerufen wird - * und daher möglichst kurz (d.h. schnell abarbeitbar) sein. - * Bei Debug-Ausgaben in der Handler-Funktion können sich die Ausgaben in Ausgaben aus loop() heraus "hineindrängeln" - * - */ - - -//----------------- Ultraschall ----------------------- -// 3x HC-SR04 - -#define US1_ECHO PD4 -#define US1_TRIGGER PB4 - -#define US2_ECHO PD5 -#define US2_TRIGGER PB5 - -#define US3_ECHO PD6 -#define US3_TRIGGER PB8 - - - -void UsHandler(int id, int entfernung) -{ - Print2Number("Sensor", id, entfernung); -} - - -void setup() -{ - delay(150); - debugInit(); - debugSetTimeStamp(DDEBUG_TIME_STAMP_ON); - - // Ultraschallsensoren definieren - addUSSensor(0, US1_TRIGGER, US1_ECHO, 220); - addUSSensor(1, US2_TRIGGER, US2_ECHO, 220); - addUSSensor(2, US3_TRIGGER, US3_ECHO); - - UsAttachHandler(0, UsHandler); - UsSetMessPause(100); // Pause von 100 ms nach jeder Messung - // damit die Ausgabe im Terminal nicht zu schnell wird - // Im Normalfall würde keine so lange Pause programmiert werden. - // Die Pause ist nur nötig, wenn festgestellt wird, dass sich - // die Sensoren gegenseitig durch nachfolgende mehrfache Echos beeinflussen. - // Das ist Umgebungsabhängig. - - debugPrint("activate Sensor 0 ---------------"); - aktiviereUSSensor(0); - PrintUsSensorList(); - debugPrint("activate Sensor 1 ---------------"); - aktiviereUSSensor(1); - PrintUsSensorList(); - - debugPrint("activate Sensor 2 ---------------"); - aktiviereUSSensor(2); - PrintUsSensorList(); - - // ab jetzt wird im Hintergrund gemessen - - delay(1000); - debugPrint("deactivate Sensor 2 ---------------"); - deaktiviereUSSensor(2); - PrintUsSensorList(); - - delay(1000); - debugPrint("deactivate Sensor 1 ---------------"); - deaktiviereUSSensor(1); - PrintUsSensorList(); - - delay(1000); - debugPrint("deactivate Sensor 0 ---------------"); - deaktiviereUSSensor(0); - PrintUsSensorList(); - - delay(1000); - debugPrint("activate Sensor 0 ---------------"); - aktiviereUSSensor(0); - PrintUsSensorList(); - - delay(1000); - debugPrint("activate Sensor 1 ---------------"); - aktiviereUSSensor(1); - PrintUsSensorList(); - - - debugPrint("Programm gestartet"); -} - -void loop() -{ - Print2Number("Sensor 1", UsLetzterGueltigerMesswert(1), UsLetzterGueltigerMesswertAlter(1)); - delay(300); -} - - - - diff --git a/STM32F3/libraries/gyro/gyro.cpp b/STM32F3/libraries/gyro/gyro.cpp deleted file mode 100644 index ef3722c..0000000 --- a/STM32F3/libraries/gyro/gyro.cpp +++ /dev/null @@ -1,337 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @brief functions for accessing l3g20 gyro on stm32f3discovery board - * - * SPI1 is set up to be a master - * at 9 MHz (SPI_1_125MHZ), - * 8 Bit - * MSB first in/out (MSBFIRST) - * MODE 0 // following the datasheet it should be MODE 3 but 0 is working too - * - * Pin PE3 is used as slave select, as defined for SPI1 in board.h - * - * There is no interrupt support because I was not able to get out any int2-output of the chip - * - */ - -#include -#include "l3gd20.h" -#include "../ringbuffer/ringbuffer.h" -#include "gyro.h" - - -#define NSS PE3 -#define GYRO_FIFO_WATERMARK 10 - -HardwareSPI spi1(1); -static uint8 gyroValuesSingle[6]; - -static int GYRO_BIAS_X = -75; -static int GYRO_BIAS_Y = 94; -static int GYRO_BIAS_Z = 0; - -float winkelx, winkely, winkelz; -int gyroxRaw, gyroyRaw, gyrozRaw; // bei jedem Update wird ein Datensatz der gelesenen - // Werte in den Raw-Variablen gespeichert um den Bias prüfen zu - // können - -#define RB_SIZE 256 -#define GYRO_AVERAGE_X 120 -#define GYRO_AVERAGE_Y 120 -#define GYRO_AVERAGE_Z 120 - -static int rbvx[RB_SIZE]; -static int rbvy[RB_SIZE]; -static int rbvz[RB_SIZE]; -static RingBufferAverage rbx(RB_SIZE, rbvx, NULL, GYRO_AVERAGE_X); -static RingBufferAverage rby(RB_SIZE, rbvy, NULL, GYRO_AVERAGE_Y); -static RingBufferAverage rbz(RB_SIZE, rbvz, NULL, GYRO_AVERAGE_Z); - -static int averageActiveX = 0; -static int averageActiveY = 0; -static int averageActiveZ = 0; - -void readGyroValues() -{ - int j; - digitalWrite(NSS, LOW); - spi1.transfer(0xA8|0x40); - - for (j=0; j<6; j++) - gyroValuesSingle[j] = spi1.transfer(0); - - digitalWrite(NSS, HIGH); -} - -uint8 gyroReadRegister(uint8 reg) -{ - digitalWrite(NSS, LOW); - spi1.transfer(reg|0x80); - - uint8 val = spi1.transfer(0); - - digitalWrite(NSS, HIGH); - return val; -} - -void gyroWriteRegister(uint8 reg, uint8 val) -{ - digitalWrite(NSS, LOW); - spi1.transfer(reg); - spi1.transfer(val); - digitalWrite(NSS, HIGH); -} - -/** - * Initialisiert das spi1 interface des stm32f3discovery - */ -void gyroSpiInit() -{ - spi1.begin(SPI_9MHZ, MSBFIRST, 0); - /* NSS is usually active LOW, so initialize it HIGH */ - pinMode(NSS, OUTPUT); - digitalWrite(NSS, HIGH); -} - -#define GYRO_OP_PARAMS (GYRO_ODR_190|GYRO_LP_BW1|GYRO_ENABLE) - -/** - * konfiguriert den Gyro. - * der Gyro ist nach dem Aufruf der Funktion aktiv. Wird er nicht mehr benötigt, kann er - * mir gyroStop() wieder deaktiviert werden. Für eine Reaktivierung kann die Funktion - * gyroStart() verwendet werden. - * - * Im aktiven Zustand muss im Abstand von höchstens 120ms die Funktion gyroUpdate() - * aufgerufen werden. - * - * Die globalen Variablen winkelx, winkely und winkelz enthalten den jeweils aktuellen winkel. - * Die Funktion gyroResetWinkel setzt die globalen Variablen wieder auf 0. - */ -void gyroInit() -{ - /* Initialize SPI */ - // gyroSpiInit(); --> called aus dem Anwendungsmodul, - // da an SPI1 noch weitere Geräte betrieben werden - - // Initialize GyroChip - // 190Hz data Rate, 50Hz Bandwidth - gyroWriteRegister(GYRO_REG_CTRL_REG1, GYRO_OP_PARAMS); - - // CTRL_REG2 --> no High Pass --> nothing to change - - // enable Watermark interrupt on INT2 --> not working no int pulse - // gyroWriteRegister(GYRO_REG_CTRL_REG3, GYRO_I2_EN|GYRO_I2_WTM); - - // set resolution to 500 dps - gyroWriteRegister(GYRO_REG_CTRL_REG4, GYRO_FULL_SCALE_500); - - // enable FIFO, Output after second LP-Filter, no HP - gyroWriteRegister(GYRO_REG_CTRL_REG5, GYRO_FIFO_ENABLE|GYRO_OUT_SELECT2); - //gyroWriteRegister(GYRO_REG_CTRL_REG5, GYRO_OUT_SELECT2); - - //Fifomode and watermark - gyroWriteRegister(GYRO_REG_FIFO_CTRL, GYRO_FIFO_MODE_STREAM|GYRO_FIFO_WATERMARK); -} - -/** - * Es werden 1000 Werte eingelesen (ca. 5,5s) und aus den Werten die Drift-Kompensations- - * werte gemittelt. Der Gyro darf während der Zeit nicht bewegt werden. - */ -void gyroCalibrate() { - int count = 0; - int sumx=0,sumy=0,sumz=0; - - #ifdef DEBUG_GYRO - SerialUSB.print("Biaswerte ermitteln "); - #endif - while (count < 1000) - { - delay(100); - uint8 anz = gyroReadRegister(GYRO_REG_FIFO_SRC) & 0x1F; - for (int i=0; i -#include -#include "lsm303reg.h" -#include "../ringbuffer/ringbuffer.h" -#include "lsm303.h" - -#define ACC_FIFO_WATERMARK 10 - -static int ACC_BIAS_X; -static int ACC_BIAS_Y; -static int ACC_BIAS_Z; - - -int accx, accy, accz; - -#define RB_SIZE 64 -#define ACC_AVERAGE_X 60 -#define ACC_AVERAGE_Y 60 -#define ACC_AVERAGE_Z 60 - -static int rbvx[RB_SIZE]; -static long unsigned int rbtx[RB_SIZE]; -static int rbvy[RB_SIZE]; -static long unsigned int rbty[RB_SIZE]; -static int rbvz[RB_SIZE]; -static long unsigned int rbtz[RB_SIZE]; -static RingBuffer rbx(RB_SIZE, rbvx, rbtx); -static RingBuffer rby(RB_SIZE, rbvy, rbty); -static RingBuffer rbz(RB_SIZE, rbvz, rbtz); - -//static int averageActiveX = 0; -//static int averageActiveY = 0; -//static int averageActiveZ = 0; - - -static uint8 write_msg_data[3]; -static i2c_msg write_msg; - -static uint8 read_msg_data[7]; -static i2c_msg read_msg; - - -void readAccValues() -{ - int16 *p; - write_msg_data[0] = LSM303_REG_OUT_X_L_A|LSM303_READ_MULTI_BYTES; // 0x80 -> AutoIncrement address on read - write_msg.length = 1; - i2c_master_xfer(I2C1, &write_msg, 1, 0); - - read_msg.length = 6; - i2c_master_xfer(I2C1, &read_msg, 1, 2); - - p = (int16*)read_msg_data; - accx = *p++ - ACC_BIAS_X; - accy = *p++ - ACC_BIAS_Y; - accz = *p++ - ACC_BIAS_Z; -} - -uint8 accReadRegister(uint8 reg) -{ - write_msg_data[0] = reg; - write_msg.length = 1; - i2c_master_xfer(I2C1, &write_msg, 1, 0); - - read_msg.length = 1; - i2c_master_xfer(I2C1, &read_msg, 1, 2); - - return read_msg_data[0]; -} - -void accWriteRegister(uint8 reg, uint8 val) -{ - write_msg_data[0] = reg; - write_msg_data[1] = val; - write_msg.length = 2; - i2c_master_xfer(I2C1, &write_msg, 1, 0); -} - - -void lsm303I2CInit() -{ - //i2c_master_enable(I2C1, 0); - // Aktivierung des I2C-Busses muss im Hauptprogramm erfolgen, - // da mehrere Komponenten das I2C-Interface benutzen können - // und eine mehrfache Initialisierung nicht funktioniert - - write_msg.addr = LSM303_ADDR_A; - write_msg.flags = 0; // write, 7 bit address - write_msg.length = sizeof(write_msg_data); - write_msg.xferred = 0; - write_msg.data = write_msg_data; - - read_msg.addr = LSM303_ADDR_A; - read_msg.flags = I2C_MSG_READ; - read_msg.length = sizeof(read_msg_data); - read_msg.xferred = 0; - read_msg.data = read_msg_data; - -} - -/** - * Initialisiert und aktiviert den Beschleunigungssensor - * Aktivierung des I2C-Busses muss im Hauptprogramm erfolgen, - * da mehrere Komponenten das I2C-Interface benutzen können - * und eine mehrfache Initialisierung nicht funktioniert - */ -void lsm303Init() -{ - /* Initialize I2C Transfer-Strukturen für den lsm303*/ - lsm303I2CInit(); - - // Initialize ACC-Chip - // 50Hz data Rate - accWriteRegister(LSM303_REG_CTRL_REG1_A, LSM303_A_ODR_50HZ|LSM303_A_ALL_AXIS_EN); - - // CTRL_REG2 --> no High Pass --> nothing to change - - // enable Watermark interrupt on INT2 --> not working no int pulse - // gyroWriteRegister(GYRO_REG_CTRL_REG3, GYRO_I2_EN|GYRO_I2_WTM); - - // sensitivity 2G is default - - // enable FIFO ? - - //Fifomode and watermark -} - - -void accCalibrate() { - int count = 0; - int sumx=0,sumy=0,sumz=0; - - #ifdef DEBUG_ACC - SerialUSB.print("Biaswerte ermitteln "); - #endif - while (count < 100) - { - delay(3); - readAccValues(); - sumx += accx; - sumy += accy; - sumz += accz; - #ifdef DEBUG_ACC - SerialUSB.print("*"); - #endif - count += 1; - } - ACC_BIAS_X = sumx/count; - ACC_BIAS_Y = sumy/count; - ACC_BIAS_Z = sumz/count; - - #ifdef DEBUG_ACC - SerialUSB.println(""); - SerialUSB.print("ACC-BIAS "); - SerialUSB.print(ACC_BIAS_X); SerialUSB.print(" "); - SerialUSB.print(ACC_BIAS_Y); SerialUSB.print(" "); - SerialUSB.println(ACC_BIAS_Z); - #endif -} - - - -void accUpdate() -{ - //uint8 gyroFifoStatus = gyroReadRegister(GYRO_REG_FIFO_SRC); - //uint8 anz = gyroFifoStatus & 0x1F; - - #ifdef DEBUG_ACC -// SerialUSB.print("fifo anz = "); -// SerialUSB.print(anz); -// SerialUSB.print(" "); - #endif - - readAccValues(); - - rbx.addValue(accx); - rby.addValue(accy); - rbz.addValue(accz); - - #ifdef DEBUG_ACC - SerialUSB.print(accx); SerialUSB.print(" "); - SerialUSB.print(accy); SerialUSB.print(" "); - SerialUSB.print(accz); SerialUSB.print(" "); - SerialUSB.println(""); - #endif -} - -void accStart() -{ - rbx.reset(); - rby.reset(); - rbz.reset(); -} - -void accStop() -{ -} - diff --git a/STM32F3/libraries/lsm303/lsm303.h b/STM32F3/libraries/lsm303/lsm303.h deleted file mode 100644 index 78a9d16..0000000 --- a/STM32F3/libraries/lsm303/lsm303.h +++ /dev/null @@ -1,77 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#ifndef LSM303_H -#define LSM303_H - - -#define ACC_AXIS_X 1 -#define ACC_AXIS_Y 2 -#define ACC_AXIS_Z 3 - - -/** - * Initialisiert das spi1 interface des stm32f3discovery und konfiguriert den Gyro. - * der Gyro ist nach dem Aufruf der Funktion aktiv. Wird er nicht mehr benötigt, kann er - * mir gyroStop() wieder deaktiviert werden. Für eine Reaktivierung kann die Funktion - * gyroStart() verwendet werden. - * - * Im aktiven Zustand muss im Abstand von höchstens 120ms die Funktion gyroUpdate() - * aufgerufen werden. - * - * Die globalen Variablen winkelx, winkely und winkelz enthalten den jeweils aktuellen winkel. - * Die Funktion gyroResetWinkel setzt die globalen Variablen wieder auf 0. - */ -extern void lsm303Init(); - - -/** - */ -extern void lsm303Calibrate(); - - -/** - */ -extern void accUpdate(); - -/** - */ -extern void accStart(); - -/** - * Versetzt den Beschleunigungssensor in den Power Down mode - */ -extern void accStop(); - - -//---------------------------------------------------------------------------------- -// gobale Variablen - -extern int accx, accy, accz; - - -extern void readAccValues(); - -#endif diff --git a/STM32F3/libraries/lsm303/lsm303reg.h b/STM32F3/libraries/lsm303/lsm303reg.h deleted file mode 100644 index 7bf3f80..0000000 --- a/STM32F3/libraries/lsm303/lsm303reg.h +++ /dev/null @@ -1,131 +0,0 @@ -#ifndef __LSM303REG_H_ -#define __LSM303REG_H_ - -#define LSM303_ADDR_A (0x32>>1) -#define LSM303_ADDR_M (0x3C>>1) - -#define LSM303_REG_CTRL_REG1_A 0x20 -#define LSM303_REG_CTRL_REG2_A 0x21 -#define LSM303_REG_CTRL_REG3_A 0x22 -#define LSM303_REG_CTRL_REG4_A 0x23 -#define LSM303_REG_CTRL_REG5_A 0x24 -#define LSM303_REG_CTRL_REG6_A 0x25 -#define LSM303_REG_REFERENCE_A 0x26 -#define LSM303_REG_STATUS_A 0x27 -#define LSM303_REG_OUT_X_L_A 0x28 -#define LSM303_REG_OUT_X_H_A 0x29 -#define LSM303_REG_OUT_Y_L_A 0x2A -#define LSM303_REG_OUT_Y_H_A 0x2B -#define LSM303_REG_OUT_Z_L_A 0x2C -#define LSM303_REG_OUT_Z_H_A 0x2D -#define LSM303_REG_FIFO_CTRL_A 0x2E -#define LSM303_REG_FIFO_SRC_A 0x2F -#define LSM303_REG_INT1_CFG_A 0x30 -#define LSM303_REG_INT1_SRC_A 0x31 -#define LSM303_REG_INT1_THS_A 0x32 -#define LSM303_REG_INT1_DUARATION_A 0x33 -#define LSM303_REG_INT2_CFG_A 0x34 -#define LSM303_REG_INT2_SRC_A 0x35 -#define LSM303_REG_INT2_THS_A 0x36 -#define LSM303_REG_INT2_DURATION_A 0x37 -#define LSM303_REG_CLICK_CFG_A 0x38 -#define LSM303_REG_CLICK_SRC_A 0x39 -#define LSM303_REG_CLICK_THS_A 0x3A -#define LSM303_REG_TIME_LIMIT_A 0x3B -#define LSM303_REG_TIME_LATENCY_A 0x3C -#define LSM303_REG_TIME_WINDOW_A 0x3D - -#define LSM303_READ_MULTI_BYTES 0x80 - - -//================================================================== -// CTRL_REG1 - -#define LSM303_A_ODR_1HZ 0x10 -#define LSM303_A_ODR_10HZ 0x20 -#define LSM303_A_ODR_25HZ 0x30 -#define LSM303_A_ODR_50HZ 0x40 -#define LSM303_A_ODR_100HZ 0x50 -#define LSM303_A_ODR_200HZ 0x60 -#define LSM303_A_ODR_400HZ 0x70 -#define LSM303_A_ODR_1620HZ 0x80 -#define LSM303_A_ODR_1344Hz 0x90 - -#define LSM303_A_LOWPOWER_EN 0x08 -#define LSM303_A_X_EN 0x01 -#define LSM303_A_Y_EN 0x02 -#define LSM303_A_Z_EN 0x04 -#define LSM303_A_ALL_AXIS_EN 0x07 - - -//================================================================== -// CTRL_REG2 - HP-Filter config - -//================================================================== -// CTRL_REG3 - Int1 config - -#define LSM303_A_I1_CLICK 0x80 -#define LSM303_A_I1_AOI1 0x40 -#define LSM303_A_I1_AOI2 0x20 -#define LSM303_A_I1_DRDY1 0x10 -#define LSM303_A_I1_DRDY2 0x08 -#define LSM303_A_I1_WTM 0x04 -#define LSM303_A_I1_OVERRUN 0x02 - - -//================================================================== -// CTRL_REG4 - Sensitivity, Endianess and SPI config - -#define LSM303_A_FS_2G 0x00 // default -#define LSM303_A_FS_4G 0x10 -#define LSM303_A_FS_8G 0x20 -#define LSM303_A_FS_16G 0x30 - - - -//================================================================== -// CTRL_REG5 - Fifo and other - -#define LSM303_A_FIFO_EN 0x40 - -//================================================================== -// CTRL_REG6 - INT2 config - -//================================================================== -// FIFO_CTRL - -#define LSM303_A_FIFO_MODE_BYPASS 0b00000000 -#define LSM303_A_FIFO_MODE_FIFO 0b01000000 -#define LSM303_A_FIFO_MODE_STREAM 0b10000000 -#define LSM303_A_FIFO_MODE_TRIGGER 0b11000000 - -#define LSM303_A_FIFO_TR 0b00100000 - - -//================================================================== -//================================================================== -//================================================================== -// Magnetometer register -//================================================================== -//================================================================== -//================================================================== - -#define LSM303_REG_CRA_M 0x00 -#define LSM303_REG_CRB_M 0x01 -#define LSM303_REG_MR_M 0x02 -#define LSM303_REG_OUTX_H_M 0x03 -#define LSM303_REG_OUTX_L_M 0x04 -#define LSM303_REG_OUTY_H_M 0x05 -#define LSM303_REG_OUTY_L_M 0x06 -#define LSM303_REG_OUTZ_H_M 0x07 -#define LSM303_REG_OUTZ_L_M 0x08 -#define LSM303_REG_Mg_M 0x09 -#define LSM303_REG_IRA_M 0x0A -#define LSM303_REG_IRB_M 0x0B -#define LSM303_REG_IRC_M 0x0C -#define LSM303_REG_TEMP_H_M 0x31 -#define LSM303_REG_TEMP_L_M 0x32 - - -#endif - diff --git a/STM32F3/libraries/ringbuffer/ringbuffer.cpp b/STM32F3/libraries/ringbuffer/ringbuffer.cpp deleted file mode 100644 index 852b2de..0000000 --- a/STM32F3/libraries/ringbuffer/ringbuffer.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#include "ringbuffer.h" - -#ifdef WIN32 - -int tmcnt=10; - -unsigned long millis() { return tmcnt++; } -#define NULL 0 - -#else -#include -#endif - - -RingBuffer::RingBuffer(int _size, int *_values, unsigned long *_timeStamps) -{ - size = _size; // muss ZweierPotenz sein - values = _values; // Pointer auf Speicher für Werte - timeStamps = _timeStamps; // optional Pointer auf Speicher für ms timestamps - mask = 0; - int t = size/2; - while (t) - { - mask = (mask<<1)|1; - t = t/2; - } - reset(); -} - - -void RingBuffer::addValue(int value) -{ - values[wrIdx] = value; - - if (timeStamps != NULL) - timeStamps[wrIdx] = millis(); - - if (anz < size) - anz++; - - wrIdx++; - wrIdx &= mask; -} - - -void RingBuffer::reset() -{ - anz = 0; - wrIdx = 0; - rdIdx = 0; - - for (int i=0; i anz) - return 0; - - rdIdx = (wrIdx - distance) & mask; - - lastRead = 0; - - return 1; -} - - -/* - * Setzt rdIdx auf den ersten Wert, für den der zugehörige timeStamp mindestens zurückliegt, - * Es wird das Alter des betreffenden Wertes in ms zurückgegeben - * = wird zurückgegeben, wenn kein Wert mindestens so alt wie gefordert ist oder keine timestamps vorhanden sind - */ -int RingBuffer::setReadIdxDt(int ms) -{ - if (timeStamps == NULL) // keine timeStamps vorhanden - return 0; - - unsigned long aktTime = millis(); - unsigned long dt=0; - int count = 0; - rdIdx = (wrIdx - 1)&mask; // auf letzten eingetragenen Wert setzen - - lastRead = 0; - - while (count ms) - return dt; - count++; - - rdIdx = (rdIdx-1)&mask; - } - - return 0; -} - - -/* - * gibt Wert für rdIdx zurück und incrementiert rdIdx, solange rdIdx < (wrIdx-1) - * ACHTUNG: wird wrPtr erreicht, so wird immer wieder der letzte Wert zurückgegeben! - */ -int RingBuffer::getValue() -{ - int ret = values[rdIdx]; - - if (((rdIdx+1)&mask) == wrIdx) - lastRead = 1; - else - rdIdx = (rdIdx+1)&mask; - - return ret; -} - -/* - * gibt Wert für rdIdx zurück, trägt den zugehörigen timestamp - * in time ein und incrementiert rdIdx, solange rdIdx < wrIdx - * ACHTUNG: wird wrPtr erreicht, so wird immer wieder der letzte Wert zurückgegeben! - */ -int RingBuffer::getValue(unsigned long *time) -{ - int ret = values[rdIdx]; - if ((time != NULL) && (timeStamps!=NULL)) - *time = timeStamps[rdIdx]; - - if (((rdIdx+1)&mask) == wrIdx) - lastRead = 1; - else - rdIdx = (rdIdx+1)&mask; - - return ret; -} - - -/* - * gibt den Wert von rdIdx-1 zurück und decrementiert rdIdx wenn rdIdx-1 != wrIdx - * - */ -int RingBuffer::getPreviousValue() -{ - int idx = (rdIdx-1)&mask; - int ret = values[idx]; - if (idx != wrIdx) // rdIdx darf nicht kleiner als wrIdx werden - rdIdx = idx; - else - lastRead = 1; - return ret; -} - - -/* -`* decrementiert rdPtr und gibt den zugehörigen Wert zurück - */ -int RingBuffer::getPreviousValue(unsigned long *time) -{ - int idx = (rdIdx-1)&mask; - int ret = values[idx]; - rdIdx = (rdIdx-1)&mask; - if ((time != NULL) && (timeStamps!=NULL)) - *time = timeStamps[idx]; - if (idx != wrIdx) // rdIdx darf nicht kleiner als wrIdx werden - rdIdx = idx; - else - lastRead = 1; - return ret; -} - - -int RingBuffer::getPreviousValueDt(unsigned long *dt) -{ - int idx = (rdIdx-1)&mask; - int ret = values[idx]; - if ((dt != NULL) && (timeStamps!=NULL)) - { - unsigned long aktTime = millis(); - *dt = aktTime - timeStamps[idx]; - } - if (idx != wrIdx) // rdIdx darf nicht kleiner als wrIdx werden - rdIdx = idx; - else - lastRead = 1; - return ret; -} - - -/* - * gibt eins zurück, sobald der älteste Wert mit einer PreviousValue-Funktion - * gelesen wurde - * wird durch jeden Aufruf einer SetReadIdx-Funktion zurückgesetzt - */ -int RingBuffer::lastValueRead() -{ - return lastRead; -} - - -/* - * gibt 1 zurück, wenn rdPtr != wrPtr - * gibt 0 zurück, wenn rdPtr == wrPtr - * - * --> funktioniert nur, wenn zuvor SetReadIdx() aufgerufen wurde - */ -int RingBuffer::valueAvailable() -{ - return !lastRead; -} - - -int RingBuffer::getValueAt(int idx) -{ - return values[(wrIdx+idx)&mask]; -} - - -int RingBuffer::getValueAt(int idx, unsigned long *time) -{ - int valueIdx = (wrIdx+idx)&mask; - if ((time != NULL) && (timeStamps!=NULL)) - *time = timeStamps[valueIdx]; - return values[valueIdx]; -} - - -int RingBuffer::getPreviousValueAt(int idx) -{ - return values[(wrIdx-1-idx)&mask]; -} - - -int RingBuffer::getPreviousValueAt(int idx, unsigned long *time) -{ - int valueIdx = (wrIdx-1-idx)&mask; - if ((time != NULL) && (timeStamps!=NULL)) - *time = timeStamps[valueIdx]; - return values[valueIdx]; -} - -//***************************************************************** - - -RingBufferAverage::RingBufferAverage(int _size, int *_values, unsigned long *_timeStamps, int _averageSize):RingBuffer(_size, _values, _timeStamps) -{ - averageSize = _averageSize; - averageSum = 0; -} - -void RingBufferAverage::addValue(int val) -{ - RingBuffer::addValue(val); - averageSum += val; - if (anz > averageSize) - averageSum -= getPreviousValueAt(averageSize); -} - - -void RingBufferAverage::reset() -{ - RingBuffer::reset(); - averageSum = 0; -} - - -void RingBufferAverage::setAverageLen(int len) -{ - averageSize = len; - reset(); -} - -int RingBufferAverage::getAverage() -{ - if (anz>averageSize) - return averageSum/averageSize; - return averageSum/anz; -} - - -int RingBufferAverage::getAverageSum() -{ - return averageSum; -} - - diff --git a/STM32F3/libraries/ringbuffer/ringbuffer.h b/STM32F3/libraries/ringbuffer/ringbuffer.h deleted file mode 100644 index 3fce4c2..0000000 --- a/STM32F3/libraries/ringbuffer/ringbuffer.h +++ /dev/null @@ -1,155 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#ifndef RINGBUFFER_H_ -#define RINGBUFFER_H_ - -class RingBuffer { -public: - int size; // muss ZweierPotenz sein - int *values; // Pointer auf Speicher für Werte - unsigned long *timeStamps; // optional Pointer auf Speicher für ms timestamps - int rdIdx; // Leseindex - Benutzung optional - int wrIdx; // Schreibindex - int mask; - - int anz; // Aktuelle Anzahl an Werten im Puffer - int lastRead; // wird auf eins gesetz, wenn letzter vorhandener Wert gelesen wurde - - - RingBuffer(int _size, int *_values, unsigned long *_timeStamps); - - /* - * fügt einen Wert zum Ringpuffer hinzu und erzeugt einen zugehörigen Timestamp - * wenn timeStamps != NULL ist - */ - void addValue(int val); - - /* - * setzt rdIdx auf distance Werte vor den letzten Wert (wrPtr-1) - * Mit getValue können die letzten Werte bis zum letzten wert abgefragt werden - * - * gibt 1 zurück, wenn genügend Werte im Puffer sind - * gibt 0 zurück, wenn noch nicht genügend Werte im Puffer sind oder distance - * größer als die Pufferlänge ist - */ - int setReadIdx(int distance); - - /* - * Setzt rdIdx auf den ersten Wert, für den der zugehörige timeStamp mindestens zurückliegt, - * Es wird das Alter des betreffenden Wertes in ms zurückgegeben - * = wird zurückgegeben, wenn kein Wert mindestens so alt wie gefordert ist oder keine timestamps vorhanden sind - */ - int setReadIdxDt(int ms); - - /* - * gibt Wert für rdIdx zurück und incrementiert rdIdx, solange rdIdx < wrIdx - * ACHTUNG: wird wrPtr erreicht, so wird immer wieder der letzte Wert zurückgegeben! - */ - int getValue(); - - /* - * gibt Wert für rdIdx zurück, trägt den zugehörigen timestamp - * in time ein und incrementiert rdIdx, solange rdIdx < wrIdx - * ACHTUNG: wird wrPtr erreicht, so wird immer wieder der letzte Wert zurückgegeben! - */ - int getValue(unsigned long *time); - - /* - * gibt 1 zurück, wenn rdPtr != wrPtr - * gibt 0 zurück, wenn rdPtr == wrPtr - * - * --> funktioniert nur, wenn zuvor SetReadIdx() aufgerufen wurde - */ - int valueAvailable(); - - /* - * Setzt den Ringbuffer zurück - */ - void reset(); - - /* - `* decrementiert rdPtr und gibt den zugehörigen Wert zurück - */ - int getPreviousValue(); - int getPreviousValue(unsigned long *time); - - /* - `* decrementiert rdPtr und gibt den zugehörigen Wert zurück - * schreibt Zeiitdifferenz zur aktuellen Zeit in dt - */ - int getPreviousValueDt(unsigned long *dt); - - - /* - * gibt eins zurück, sobald der älteste Wert mit einer PreviousValue-Funktion - * gelesen wurde - * wird durch jeden Aufruf einer SetReadIdx-Funktion zurückgesetzt - */ - int lastValueRead(); - - /* - * Diese Funktion erlaubt den Zugriff auf den Ringbuffer wie auf ein Array. - * Der älteste Wert hat immer den Index 0, der aktuellste Wert den Index size-1 - * Der rdIdx des Puffers wird nicht verändert. - */ - int getValueAt(int idx); - int getValueAt(int idx, unsigned long *time); - - /* - * Diese Funktion erlaubt den Zugriff auf den Ringbuffer wie auf ein Array. - * Der neueste Wert hat immer den Index 0, der älteste Wert den Index size-1 - * Der rdIdx des Puffers wird nicht verändert. - */ - int getPreviousValueAt(int idx); - int getPreviousValueAt(int idx, unsigned long *time); - - -}; - - - -class RingBufferAverage : public RingBuffer -{ -public: - int averageSize; - int averageSum; - - RingBufferAverage(int _size, int *_values, unsigned long *_timeStamps, int _averageSize); - - void setAverageLen(int len); - - void addValue(int val); - void reset(); - - int getAverage(); - int getAverageSum(); - - -}; - - -#endif /* RINGBUFFER_H_ */ diff --git a/STM32F3/libraries/roboter/debug.cpp b/STM32F3/libraries/roboter/debug.cpp deleted file mode 100644 index fa0a3e7..0000000 --- a/STM32F3/libraries/roboter/debug.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#include -#include "debug.h" - -#define DEBUG - -#ifndef DEBUGPORTID -#define DEBUGPORTID 2 -// TX-PIN ist PA2 -#endif - -#ifndef DEBUGPORT -#if DEBUGPORTID == 0 - #define DEBUGPORT SerialUSB -#endif -#if DEBUGPORTID == 1 - #define DEBUGPORT Serial1 -#endif -#if DEBUGPORTID == 2 - #define DEBUGPORT Serial2 -#endif -#if DEBUGPORTID == 3 - #define DEBUGPORT Serial3 -#endif -#endif - - -void debugInit() -{ -#ifdef DEBUG -#if (DEBUGPORTID != 0) - DEBUGPORT.begin(57600); -#endif - DEBUGPORT.println("Debug Init"); -#endif -} - - -static int printTimeStamp = 0; - -void debugSetTimeStamp(int OnOff) { - printTimeStamp = OnOff; -} - -static inline void addTimeStamp() { - if (printTimeStamp) { - DEBUGPORT.print(millis()); - DEBUGPORT.print(" "); - } -} - -void debugPrint(const char *s) -{ -#ifdef DEBUG - addTimeStamp(); - DEBUGPORT.println(s); -#endif -} - -void PrintNumber(const char *name, int num) -{ -#ifdef DEBUG - addTimeStamp(); - DEBUGPORT.print(name); - DEBUGPORT.print(" "); - DEBUGPORT.println(num); -#endif -} - -void PrintNumber(const char *name, byte num) -{ -#ifdef DEBUG - addTimeStamp(); - DEBUGPORT.print(name); - DEBUGPORT.print(" "); - DEBUGPORT.println(num); -#endif -} - -void PrintNumber(const char *name, float num) -{ -#ifdef DEBUG - addTimeStamp(); - DEBUGPORT.print(name); - DEBUGPORT.print(" "); - DEBUGPORT.println(num); -#endif -} - - - -void Print2Number(const char *name, int num1, int num2) -{ -#ifdef DEBUG - addTimeStamp(); - DEBUGPORT.print(name); - DEBUGPORT.print(" "); - DEBUGPORT.print(num1); - DEBUGPORT.print("\t"); - DEBUGPORT.println(num2); -#endif -} - -void Print2Number(const char *name, byte num1, byte num2) -{ -#ifdef DEBUG - addTimeStamp(); - DEBUGPORT.print(name); - DEBUGPORT.print(" "); - DEBUGPORT.print(num1); - DEBUGPORT.print("\t"); - DEBUGPORT.println(num2); -#endif -} - -void Print2Number(const char *name, float num1, float num2) -{ -#ifdef DEBUG - addTimeStamp(); - DEBUGPORT.print(name); - DEBUGPORT.print(" "); - DEBUGPORT.print(num1); - DEBUGPORT.print("\t"); - DEBUGPORT.println(num2); -#endif -} - -void PrintArray(const char *name, int len, int *arr) -{ -#ifdef DEBUG - int i; - addTimeStamp(); - DEBUGPORT.print(name); - for (i=0; i -#include -#include -#include "eeprom.h" -#include "debug.h" - - -/* - Source Code fuer 24C128 EEPROM (16Kbyte) -* - __ __ - A0 -| |- VCC - A1 -| |- WP --> unconnected low: write enabled - A2 -| |- SCL - VSS -|_____|- SDA - - -*/ - -#define EEPROM_I2C_BASE_ADDR (0xA0>>1) -#define EEPROM_I2C_ADDR(mem_addr) EEPROM_I2C_BASE_ADDR -#define EEPROM_I2C_CHANNEL I2C1 - -#define EEPROM_MAX_BUF 3 - -static uint8 msg_wr_data[EEPROM_MAX_BUF]; -static i2c_msg msg[2]; -static uint8 msg_rd_data[EEPROM_MAX_BUF]; - - -static void writeDataByte(int device_address, byte memory_address, byte data) -// write one byte of data 'data' to eeprom memory address 'memory_address' to chip with I2C address 'device_address' -{ -/* Arduino Code - Wire.beginTransmission(device_address); // device address - Wire.write(memory_address ); // memory address - Wire.write(data); // data to send - Wire.endTransmission(); // end - delay(10); -*/ - msg[0].addr = device_address; - msg[0].flags = 0; // write, 7 bit address - msg[0].xferred = 0; - msg[0].length = 3; - msg[0].data = msg_wr_data; - - msg_wr_data[0] = (memory_address>>8)&0xFF; - msg_wr_data[1] = memory_address&0xFF; - msg_wr_data[2] = data; - - i2c_master_xfer(EEPROM_I2C_CHANNEL, msg, 1, 10); - - delay(10); -} - - -static byte readDataByte(int device_address, byte memory_address) -// reads one byte of data from memory location 'memory_address' in chip at I2C address 'device_address' -{ - -/* Arduino Code - byte result; // return value - Wire.beginTransmission(device_address); // device address - Wire.write(memory_address); // memory address - Wire.endTransmission(); // end - Wire.requestFrom(device_address,1); // get one byte of data from device - if (Wire.available()) - result = Wire.read(); - return result; // return the read data byte - delay(10); -*/ - msg[0].addr = device_address; - msg[0].flags = 0; // write, 7 bit address - msg[0].xferred = 0; - msg[0].length = 2; - msg[0].data = msg_wr_data; - - msg_wr_data[0] = (memory_address>>8)&0xFF; - msg_wr_data[1] = memory_address&0xFF; - - msg[1].addr = device_address; - msg[1].flags = I2C_MSG_READ; - msg[1].xferred = 0; - msg[1].length = 1; - msg[1].data = msg_rd_data; - - i2c_master_xfer(EEPROM_I2C_CHANNEL, msg, 2, 10); - return msg_rd_data[0]; -} - -//--------------------------------------------------------------------------------- -int eepromWriteBytes(int addr, int len, unsigned char *pData) -{ - for (int i = 0; i -#include "functiontimer.h" -#include "debug.h" - - -//#define TMR_DEBUG - -typedef void (*tmrFuncPtr)(int arg); - - -typedef struct timerDaten { - struct timerDaten *pNext; - struct timerDaten *pPrev; - int time; - int state; - int arg; - int id; - tmrFuncPtr handler; -}TimerData_t; - - -TimerData_t timerArray[TIMER_ANZAHL]; -TimerData_t *pNextTimer = NULL; - - - -#define TIMEOUT_RATE 5000 // in microseconds - -HardwareTimer timer(2); - - -static void timeoutHandler() { - if (pNextTimer) { - pNextTimer->time -= 5; - if (pNextTimer->time <= 0) { -#ifdef TMR_DEBUG - PrintNumber("to", pNextTimer->id); -#endif - TimerData_t *p = pNextTimer; - pNextTimer = pNextTimer->pNext; - if (pNextTimer) - pNextTimer->pPrev = NULL; - p->state = 0; - //p->pNext = NULL; - //p->pPrev = NULL; - p->handler(p->arg); - } - } -} - -static bool timerInitialized = false; - -void timerInit() { - if (timerInitialized == false) { - for (int i=0; i= TIMER_ANZAHL) - return; - if (timerArray[id].state) // is already running? - return; - - TimerData_t *pNew = timerArray + id; - pNew->time = ms+5; - pNew->state = 1; - pNew->handler = handler; - pNew->pNext = NULL; - pNew->pPrev = NULL; - pNew->arg = arg; - if (pNextTimer == NULL) { - pNextTimer = pNew; -#ifdef TMR_DEBUG - PrintNumber("st", id); -#endif - } - else { -#ifdef TMR_DEBUG - Print2Number("sta", id, ms); -#endif - noInterrupts(); - TimerData_t *p = pNextTimer; - TimerData_t *last = NULL; - while (p) { - if (pNew->time < p->time) // vorher einhaengen - break; - else - pNew->time -= p->time; - last = p; - p = p->pNext; - } - - if (p==NULL) { - // hinter Last mit Restzeit einhängen - last->pNext = pNew; - pNew->pPrev = last; -#ifdef TMR_DEBUG - debugPrint("at end"); -#endif - } - else { // vor p einhängen und p->time um pNew->time verkleinern - p->time -= pNew->time; - pNew->pNext = p; - - if (p==pNextTimer) { - pNextTimer = pNew; - p->pPrev = pNew; -#ifdef TMR_DEBUG - PrintNumber("at begin", p->id); -#endif - } - else { - pNew->pPrev = p->pPrev; - p->pPrev = pNew; - if (pNew->pPrev) - pNew->pPrev->pNext = pNew; -#ifdef TMR_DEBUG - Print2Number("between", pNew->pPrev->id, pNew->pNext->id); -#endif - } - } - interrupts(); - } -#ifdef TMR_DEBUG - PrintTimerList(); -#endif -} - - -void timerStop(int id) { - if (id < 0) - return; - if (id>= TIMER_ANZAHL) - return; - if (timerArray[id].state==0) // is timer running? - return; - - TimerData_t *pTimer = timerArray + id; - noInterrupts(); - if (pTimer->pNext == NULL) { - // ist letzter in der queue - if (pTimer->pPrev == NULL) { - // ist einziger Timer - pTimer->state = 0; - pNextTimer = NULL; - } - else { - pTimer->pPrev->pNext = NULL; - pTimer->pPrev = NULL; - pTimer->state = 0; - } - } - else { - // Restzeit des zu löschenden Timers auf den nächsten in der Queue addieren - pTimer->pNext->time += pTimer->time; - if (pTimer == pNextTimer) {// erster Timer in der queue - pNextTimer = pTimer->pNext; - pTimer->pNext->pPrev = NULL; - pTimer->pNext = NULL; - } - else { - TimerData_t *pPrev = pTimer->pPrev; - pPrev->pNext = pTimer->pNext; - pTimer->pNext->pPrev = pPrev; - pTimer->pNext = NULL; - pTimer->pPrev = NULL; - } - } - interrupts(); - -} - - -void PrintTimerList() { - TimerData_t *p = pNextTimer; - - while (p) { - Print2Number("tmr",p->id, p->time); - if (p->pNext) - PrintNumber(" nxt", p->pNext->id); - if (p->pPrev) - PrintNumber(" prv", p->pPrev->id); - p = p->pNext; - } -} diff --git a/STM32F3/libraries/roboter/functiontimer.h b/STM32F3/libraries/roboter/functiontimer.h deleted file mode 100644 index 1a31f88..0000000 --- a/STM32F3/libraries/roboter/functiontimer.h +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - /* - * Das Timer-Modul stellt Funktionen bereit, mit denen andere Funktionen - * später aufgerufen werden können. Diese Funktionen sollten eine - * kurze Laufzeit haben, da sie im Interrupt aufgerufen werden. - * - * - Die Timer arbeiten mit einer Auflösung von 5 ms. - * - Es können maximal 10 Timer gleichzeitig aktiv sein. - * - Stoppen eines Timers ist möglich - * - */ - -#ifndef FUNCTION_TIMER_H_ -#define FUNCTION_TIMER_H_ - -#define TIMER_ANZAHL 10 - -typedef void (*tmrFuncPtr)(int arg); - -extern void timerInit(); -extern void timerStart(int id, int ms, tmrFuncPtr handler, int arg); -extern void timerStop(int id); - - - - -#endif /* TIMER_H_ */ diff --git a/STM32F3/libraries/roboter/motor.cpp b/STM32F3/libraries/roboter/motor.cpp deleted file mode 100644 index 57b6171..0000000 --- a/STM32F3/libraries/roboter/motor.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#include -#include "motor.h" -#include "../gyro/gyro.h" -#include "debug.h" - - -#define TB6612 - -#define MOTOR_ANZ 3 - - -typedef struct { - int dir; - int pwm; - int sensor; - int led; -} MotorPins_t; - -static MotorPins_t mpins[MOTOR_ANZ]; - -#define IDX_A 0 -#define IDX_B 1 -#define IDX_C 2 - -// Umwandlung MotorIds to Index, wenn nur ein Motor addressiert ist -#define MIDX(id) ((id&OUT_A)?IDX_A:(id&OUT_B)?IDX_B:IDX_C) - - -static volatile int RadCount0; -void CountRad0() -{ - RadCount0++; -} - -static volatile int RadCount1; -void CountRad1() -{ - RadCount1++; -} - -static volatile int RadCount2; -void CountRad2() -{ - RadCount2++; -} - - -void InitMotor(int id, int PinDir, int PinPWM, int PinSensor, int PinLED) -{ - MotorPins_t *p = mpins+MIDX(id); - p->dir = PinDir; - p->pwm = PinPWM; - p->sensor = PinSensor; - p->led = PinLED; - - pinMode (p->pwm, PWM); - pinMode (p->dir, OUTPUT); - analogWrite(p->pwm, 0); - - if (p->sensor != -1) - { - if (p->led != -1) - pinMode(p->led, OUTPUT); - - pinMode(p->sensor, INPUT); - } -} - - -static inline void RadSensorAn(int motor) -{ - MotorPins_t *p = mpins; - - for (int idx=0; idxled != -1) - digitalWrite(p->led, HIGH); - if (p->sensor != -1) { - if (idx == 0) - attachInterrupt(p->sensor, CountRad0, CHANGE); - else if (idx == 1) - attachInterrupt(p->sensor, CountRad1, CHANGE); - else - attachInterrupt(p->sensor, CountRad2, CHANGE); - } - } - p++; - } - delayMicroseconds(50); // Damit ggf. ein Interrupt beim Einschalten ausgeführt wird -} - - -static inline void RadSensoren(int motor) -{ - MotorPins_t *p = mpins; - - for (int idx=0; idxled != -1) - digitalWrite(p->led, LOW); - if (p->sensor != -1) { - detachInterrupt(p->sensor); - } - } - p++; - } -} - - -void OnFwd(int Motor, int Geschwindigkeit) -{ - if(Geschwindigkeit>0) - Geschwindigkeit+=13; - else if(Geschwindigkeit<0) - Geschwindigkeit-=13; - - MotorPins_t *p = mpins; - Geschwindigkeit = constrain(Geschwindigkeit,-100, 100); // Geschwindigkeit auf Bereich -100 ... +100 begrenzen - Geschwindigkeit = (65535*Geschwindigkeit)/100; - PrintNumber("v ",Geschwindigkeit ); - - for (int i=0; i0) - { - digitalWrite(p->dir, HIGH); - v = Geschwindigkeit; - } - else - { - digitalWrite(p->dir, LOW); - v = -Geschwindigkeit; - } - analogWrite(p->pwm, v); - #endif - } - p++; - } -} - - -void OnRev(int m, int v) -{ - OnFwd(m, -v); -} - -void Off(int Motor) -{ - MotorPins_t *p = mpins; - for (int i=0; ipwm, 0); -#endif - } - p++; - } -} - - - -#if 0 - -// gyro-Funktionen nicht in diesem Modul - -void DreheRechts(int v, int Winkel) -{ - gyroResetWinkel(); - OnFwd(OUT_A, v); - OnFwd(OUT_B, -v); - while (winkelz>=-Winkel) - gyroUpdate(); - Off (OUT_AB); - -} - - -void DreheLinks(int v, int Winkel) -{ - gyroResetWinkel(); - OnFwd(OUT_A, -v); - OnFwd(OUT_B, v); - while (winkelz<=Winkel) - gyroUpdate(); - Off (OUT_AB); - -} - - -void FahreVor(int v, int Strecke) -{ - RadSensorenAn(); - RadCountR = 0; // 0 Setzen erst NACH Einschalten des Sensors, eventuell kommt schon ein Interrupt -// RadCountL = 0; - OnFwd(OUT_AB, v); - while (Strecke>RadCountR) - { -// PrintNumber("RC", RadCountR); -// delay (1); - } - Off(OUT_AB); - RadSensorenAus(); -} - -#endif - - -#if 0 -void TestRadSensoren() -{ - RadSensorenAn(); - RadCountR = 0; - RadCountL = 0; - OnFwd(OUT_AB,10); - while(1) - { - lcd.clear(); - lcd.setCursor(0,0); - lcd.print(RadCountL); - lcd.setCursor(4,0); - lcd.print(RadCountR); - delay(300); - } -} - -#endif diff --git a/STM32F3/libraries/roboter/motor.h b/STM32F3/libraries/roboter/motor.h deleted file mode 100644 index c63470e..0000000 --- a/STM32F3/libraries/roboter/motor.h +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - /* - * Das Modul Motor stellt Funktionen und Makros zur Steuerung der - * Fahrmotoren zur verfügung sowie Funktionen zur Steuerung und - * Abfrage der Wegsensoren. - */ - -#ifndef MOTOR_H_ -#define MOTOR_H_ - -#define OUT_A 1 -#define OUT_B 2 -#define OUT_C 4 -#define OUT_AB (OUT_A|OUT_B) -#define OUT_BC (OUT_B|OUT_C) -#define OUT_AC (OUT_A|OUT_C) -#define OUT_ABC (OUT_A|OUT_B|OUT_C) - - -extern void InitMotor(int id, int PinDir, int PinPWM, int PinSensor, int PinLED); - -extern void OnFwd(int Motor, int Geschwindigkeit); -extern void OnRev(int Motor, int Geschwindigkeit); -extern void Off (int Motor); - -#if 0 -extern void DreheRechts(int v, int Winkel); -extern void DreheLinks(int v, int Winkel); - -extern void FahreVor(int v, int Strecke); -#endif - - -#endif /* MOTOR_H_ */ diff --git a/STM32F3/libraries/roboter/sound.cpp b/STM32F3/libraries/roboter/sound.cpp deleted file mode 100644 index 09ca894..0000000 --- a/STM32F3/libraries/roboter/sound.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#include -#include "sound.h" - - -/* todo */ \ No newline at end of file diff --git a/STM32F3/libraries/roboter/sound.h b/STM32F3/libraries/roboter/sound.h deleted file mode 100644 index 54c5723..0000000 --- a/STM32F3/libraries/roboter/sound.h +++ /dev/null @@ -1,33 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#ifndef SOUND_H_ -#define SOUND_H_ - - - - -#endif /* SOUND_H_ */ diff --git a/STM32F3/libraries/roboter/ultraschall.cpp b/STM32F3/libraries/roboter/ultraschall.cpp deleted file mode 100644 index 871c6ac..0000000 --- a/STM32F3/libraries/roboter/ultraschall.cpp +++ /dev/null @@ -1,536 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ -#include -#include "ultraschall.h" -#include "debug.h" - -/* - * Für jeden Ultraschallsensor gibt es eine Struktur USSensor, die im Array USSensoren - * angelegt wird. - * Für jeden Sensor muss einmal die Funktion addUSSensor() mit den richtigen Anschluss - * Pins aufgerufen werden. - * - * Zum Messen muss ein Sensor aktiviert werden. Es können alle Sensoren aktiv sein. - * Sie werden dann abwechselnd für Messungen getriggert. Nicht mehr benötigte Sensoren - * sollten deaktiviert werden. - * Im aktiven Zustand wird durch die Funktion UltraschallMessen() die Messung - * jeweils eines aktiven Sensors gestartet, wenn keine Messung aktiv ist. - * UltraschallMessen() koordiniert nur die Messungen (es darf immer nur ein - * Ultraschallsensor aktiv sein) und wartet nicht, bis die Messung erfolgt ist. - * UltraschallMessen sollte alle 25ms oder kürzer aufgerufen werden, - * wenn Ultraschallmesswerte benötigt werden. - * --> ggf. Aktivieren der nächsten Messung im Interrupt? --> testen - * - * Das Messen selbst erfolgt asynchron zur Programmausführung. Eine spezielle - * Messroutine wird aufgerufen, wenn der Echo-Pin des Sensors seinen Zustand ändert. - * Diese Routine trägt die gemessene Entfernung und einen Zeitstempel in die Sensor- - * struktur ein und setzt ein Flag in der Struktur, dass ein neuer Messwert zur - * Verfügung steht. - * - * Mit der Funktion UltraschallMessenFertig(id) kann abgefragt werden, ob ein neuer - * Messwert vorliegt. Dieser kann mit UltraschallMesswert(id) abgefragt werden. - * Mit UltraschallMesswertAlter(id) kann abgefragt werden, wie alt der ausgelesene - * Messwert ist. Alternativ zu den Funktionsaufrufen können die Werte auch direkt aus - * den Sensorstrukturen ausgelesen werden. - * - * Alternativ zum automatischen Messen im Hintergrund kann statt UltraschallMessen() - * die Funktion UltraschallMessenEinzel(id) aufgerufen werden. Diese Funktion blockiert - * solange bis ein Messwert vorliegt (max. 50ms falls kein Wert ermittelt werden kann) - * und gibt diesen zurück. Eine Aktivierung des Sensors ist nicht erforderlich. - * Eventuell laufende Messungen werden abgebrochen. Eine noch laufende Messung wird - * jedoch zu Ende geführt. - * - * Zeitüberwachung: - * Es kann eine maximale Laufzeit für das zu erwartende Echo gesetzt werden (z.B. 30ms). - * Für diese Laufzeit wird ein Timer mit eigenem Interrupt gestartet. - * Gestoppt wird der Timer, wenn die Echo-Interrupt-Funktion vor Ablauf des Timers ausgeführt wird - * (der Echo-Puls ist in diesem Fall innerhalb des zulässigen Zeitfensters gekommen. - * Läuft der Timer ab, ist die aktuelle Messung ungültig und es wird versucht eine neue Messung - * mit dem nächsten Sensor zu starten. - * Eine Messung kann nur gestartet werden, wenn der Echo-Pin auf LOW ist. - * Gibt es keinen Sensor, der bei Startanforderung echo==LOW hat, so wird nichts unternommen und - * auf die nächste fallende Flanke einer Echo-Leitung (Interrupt) gewartet. Die fallende Flanke startet - * dann eine neue Messung per Interrupt. - * Gibt es einen Sensor, der bereit für eine neue Messung ist, so wird bei diesem die Messung - * gestartet. - * Damit das funktioniert, muss für jeden Echo-Pin eine eigene Interrupt-Funktion attached werden. - * - * Wenn auf die Zeitüberwachung verzeichtet wird blockiert eine ungültige Messung weitere Messungen - * anderer Sensoren um die Zeit bis zum HIGH-LOW-Übergang des Echopins - * --> bei nur einem Sensor ist eine Zeitüberwachung nicht nötig, da kein Neustart einer Messung - * stattfinden kann bevor der Echo-Pin wieder Low ist. - * - * HC-SR04: Wenn kein Echo kommt, wird das ECHO-Signal nach ca. 235ms (entspricht ca. 4m) wieder nach - * LOW gezogen. - * - * Um das Suchen nach einem messbereiten Sensor zu vereinfachen werden die aktiven Sensorstrukturen in einer - * doppelt verketteten Liste verwaltet. - * - * Der Aufruf von micros() im Interrupt funktioniert nicht sicher, deshalb muss die Timing-Information auf anderm Wege - * beschafft werden: - * Eigener Hardwaretimer für Ultraschallsensoren (ist auch schneller bei der Vewaltung) - * - */ - - -#define IDLE_CHECK_TMO 25 // ms - -// global state -#define US_GLOBAL_IDLE 0 -#define US_GLOBAL_MESSUNG_AKTIV 1 - -static int state = US_GLOBAL_IDLE; - -// Prototypen -static void TimerIntRangeTimeout(); -static void TimerIntWaitIdle(); -static inline void startMessung(); -static void USInt(); - -// globale Variablen -USSensor USSensoren[MAX_US_SENSOR]; - -// static Variablen -static USSensor *pAktiverSensor = NULL; -static int SensorAktivAnzahl=0; -static int MessPause = 0; - - -//-------------------------------------------------------------------------- -// Timer-Funktionen -//-------------------------------------------------------------------------- - -static HardwareTimer usTimer(15); -static int usTimerCount; // Beim Starten wird sofort ein Interrupt ausgelöst, - // der ausgeblendet werden muss - - -static void startUsTimer(int ms, voidFuncPtr handler) -{ - usTimer.pause(); - - // Set up period - usTimer.setPeriod(ms*1000); // in microseconds - - usTimerCount = 1; - - // Set up an interrupt on channel 1S - usTimer.setChannel1Mode(TIMER_OUTPUT_COMPARE); - usTimer.setCompare(TIMER_CH1, 1); // Interrupt 1 count after each update - usTimer.attachCompare1Interrupt(handler); - - // Refresh the timer's count, prescale, and overflow - usTimer.refresh(); - - // Start the timer counting - usTimer.resume(); -} - - -static void stopUsTimer() { - usTimer.pause(); -} - -//-------------------------------------------------------------------------- - - - -/** - * Startet die Messung beim nächsten IDLE-Sensor. - * Wenn keine Messung aktiv ist (US_GLOBAL_IDLE) und kein Sensor gefunden wird, - * wird der IDLE-Wait-Timer gestartet - */ -static inline void startMessung() -{ - if (state != US_GLOBAL_IDLE) - return; // Es kann keine Messung gestartet werden - - int anz = SensorAktivAnzahl; - - while (anz) { - pAktiverSensor = pAktiverSensor->pNext; // erstmal auf den nächsten Sensor stellen - if (pAktiverSensor->state==US_IDLE) - { - //PrintNumber(" nis", pAktiverSensor->id); - // nur wenn EchoPin Low ist, kann die nächste Messung erfolgen - if (digitalRead(pAktiverSensor->echoPin) == LOW) { - state = US_GLOBAL_MESSUNG_AKTIV; // globalen Zustand setzen - pAktiverSensor->state = US_ACTIVE; - //PrintNumber("sel", pAktiverSensor->id); - digitalWrite(pAktiverSensor->triggerPin, HIGH); - delayMicroseconds(10); // FIXME: funktioniert das im Interrupt ??? - // sollte gehen, ist eine Assemblerschleife - // muss aber mal gemessen werden!! - digitalWrite(pAktiverSensor->triggerPin, LOW); - attachInterrupt(pAktiverSensor->echoPin, USInt, CHANGE); - return; - } - //else - //PrintNumber("ns2", pAktiverSensor->id); - } - //else - // PrintNumber("ns1", pAktiverSensor->id); - - anz--; - } - startUsTimer(IDLE_CHECK_TMO, TimerIntWaitIdle); -} - -// Interrupt-Routinen - -/** - * Interrupt-Routine für Echo-Pin - */ -static void USInt() -{ - int time = usTimer.getCount(); - int pin = digitalRead(pAktiverSensor->echoPin); - if (pin==HIGH) - { - if (pAktiverSensor->state == US_ACTIVE) { - startUsTimer(pAktiverSensor->maxTime, TimerIntRangeTimeout); - //PrintNumber(" eh",pSensor->id); - } - } - else - { - stopUsTimer(); - detachInterrupt(pAktiverSensor->echoPin); - pAktiverSensor->entfernung = time/pAktiverSensor->timerTicksPerCm; - //Print2Number("usi", pAktiverSensor->id, pAktiverSensor->entfernung); - pAktiverSensor->messZeit = millis(); - pAktiverSensor->lastValidRange = pAktiverSensor->entfernung; - pAktiverSensor->lastValidTime = pAktiverSensor->messZeit; - pAktiverSensor->neuerMesswert = 1; - pAktiverSensor->state = US_IDLE; - state = US_GLOBAL_IDLE; - if (pAktiverSensor->handler) - pAktiverSensor->handler(pAktiverSensor->id, pAktiverSensor->entfernung); - if (MessPause) - startUsTimer(MessPause, TimerIntWaitIdle); - else - startMessung(); - } -} - -static void TimerIntWaitIdle() { - if (usTimerCount) - usTimerCount--; - else { - //debugPrint("twi"); - stopUsTimer(); - startMessung(); - } -} - -static void TimerIntRangeTimeout() { - if (usTimerCount) - usTimerCount--; - else { - stopUsTimer(); - if (pAktiverSensor) { - detachInterrupt(pAktiverSensor->echoPin); - //debugPrint(" tmo"); - if (pAktiverSensor->state == US_ACTIVE) { - pAktiverSensor->state = US_IDLE; - state = US_GLOBAL_IDLE; // Es kann eine Messung mit einem anderen Sensor gestartet werden - pAktiverSensor->entfernung = ENTFERNUNG_INVALID; - pAktiverSensor->messZeit = millis(); - if (pAktiverSensor->handler) - pAktiverSensor->handler(pAktiverSensor->id, pAktiverSensor->entfernung); - startMessung(); - } - else - { - if (state == US_GLOBAL_IDLE) - startMessung(); - } - } - } -} - - -//----------------------------------------------------------------- -// extern aufrufbare Funktionen -//----------------------------------------------------------------- - -/** - * Definiert und initialisiert einen Ultraschallsensor - * maxRange in cm - */ -void addUSSensor(int id, int trigger, int echo, int maxRange) -{ - if ((id < 0) || (id >= MAX_US_SENSOR)) - return; - USSensor *pSensor = &USSensoren[id]; - pSensor->triggerPin = trigger; - pSensor->echoPin = echo; - pSensor->enabled = 0; - pSensor->state = US_IDLE; - pSensor->id = id; - pSensor->maxTime = (maxRange*US_ROUNDTRIP_CM)/1000; - - // Timer-Wertebereich für maxRange ermitteln - usTimer.setPeriod(pSensor->maxTime*1000); // in microseconds - pSensor->timerTicksPerCm = usTimer.getOverflow()/maxRange; - - // pins initialisieren - pinMode(trigger, OUTPUT); - pinMode(echo, INPUT); -} - -/** - * aktiviert einen Sensor zum Messen im Hintergrund - */ -void aktiviereUSSensor(int id) -{ - if (USSensoren[id].enabled) // ist bereits enabled - return; - - USSensoren[id].enabled = 1; - - if (pAktiverSensor == NULL) { // ist der erste Sensor - pAktiverSensor = USSensoren + id; - pAktiverSensor->pNext = pAktiverSensor; // zeigt auf sich selbst! - pAktiverSensor->pPrev = pAktiverSensor; - SensorAktivAnzahl = 1; - // Über den Timer wird erreicht, dass die Messung gestartet wird. - startUsTimer(IDLE_CHECK_TMO, TimerIntWaitIdle); - } - else { - noInterrupts(); - USSensor *pSensor = USSensoren + id; - pSensor->state = US_IDLE; - - pSensor->pNext = pAktiverSensor->pNext; - pSensor->pPrev = pAktiverSensor; - pAktiverSensor->pNext->pPrev = pSensor; - pAktiverSensor->pNext = pSensor; - - SensorAktivAnzahl++; - interrupts(); - } -} - - -void UsAttachHandler(int id, usFuncPtr fkt){ - USSensoren[id].handler = fkt; -} - - -void UsSetMessPause(int ms) { - MessPause = ms; -} - - -/** - * deaktiviert einen Sensor - */ -void deaktiviereUSSensor(int id) -{ - /* - * Problem: - * für den aktuellen Sensor könnte aktuell eine Messung laufen! - */ - if (!USSensoren[id].enabled) - return; - - noInterrupts(); - USSensor *pSensor = USSensoren + id; - pSensor->enabled = 0; - pSensor->neuerMesswert = 0; - - if (SensorAktivAnzahl>1) { - pSensor->pPrev->pNext = pSensor->pNext; - pSensor->pNext->pPrev = pSensor->pPrev; - if (pAktiverSensor == pSensor) - pAktiverSensor = pSensor->pNext; - } - else - pAktiverSensor = NULL; - - SensorAktivAnzahl--; - - if (pSensor->state == US_ACTIVE) { - detachInterrupt(pSensor->echoPin); - pSensor->state = US_IDLE; - state = US_GLOBAL_IDLE; - - if (SensorAktivAnzahl) - // Über den Timer wird erreicht, dass eine neue Messung gestartet wird. - startUsTimer(IDLE_CHECK_TMO, TimerIntWaitIdle); - } - interrupts(); -} - -/** - * gibt 1 zurück, wenn ein neuer Messwert vorliegt. - * Es wird nur einmal eine 1 zurückgegeben, das Flag wird beim Auslesen zurückgesetzt - */ -int UltraschallMessenFertig(int id) -{ - if (USSensoren[id].neuerMesswert) - { - USSensoren[id].neuerMesswert = 0; - return 1; - } - return 0; -} - - -/** - * gibt aktuellstes Messergebnis zurück - */ -int16 UsAktuellerMesswert(int id) -{ - return USSensoren[id].entfernung; -} - -/** - * Gibt das Alter der aktuellsten Messung in ms zurück - */ -int UsAktuellerMesswertAlter(int id) -{ - return (millis() - USSensoren[id].messZeit); -} - -/** - * gibt den letzten gueltigen Wert zurück - */ -int16 UsLetzterGueltigerMesswert(int id) -{ - return USSensoren[id].lastValidRange; -} - -/** - * Gibt das Alter der letzten Messung in ms zurück - */ -int UsLetzterGueltigerMesswertAlter(int id) -{ - return (millis() - USSensoren[id].lastValidTime); -} - - -/** - * ----------------------------------------------------------- - * blockierende Messung - * ----------------------------------------------------------- - */ -int16 UltraschallMessenEinzel(int id) -{ - uint32 t1; - uint32 t2=0; - if ((id<0) || (id >= MAX_US_SENSOR)) - return ENTFERNUNG_INVALID; - - // alle Sensoren deaktivieren - for (int i=0; iechoPin) == HIGH ) - { - t2 = micros(); - if (t2-t1 > 100000) // Wenn 100ms lang kein LOW am Echo-Pin Fehler zurückgeben - return ERROR_SENSOR_BUSY; - } - - // trigger-Impuls generieren - digitalWrite(pSensor->triggerPin, HIGH); - delayMicroseconds(10); - digitalWrite(pSensor->triggerPin, LOW); - - // auf HIGH am Echo-Pin warten - t1 = micros(); - - while (digitalRead(pSensor->echoPin) == LOW ) - { - t2 = micros(); - if (t2-t1 > 1000) - return ERROR_NO_SENSOR; // kein LOW-HIGH-Übergang innerhalb 1ms detektiert -> Fehler - } - t1 = micros(); - - // auf LOW am Echo-Pin warten - while (digitalRead(pSensor->echoPin) == HIGH ) - { - t2 = micros(); - if ((t2-t1) > (uint32)(pSensor->maxTime*1000)) - return ENTFERNUNG_INVALID; // Messentfernung größer maxRange - } - - return (t2-t1)/US_ROUNDTRIP_CM; -} - - -//------------------------------------------------------------------------ -void PrintUsSensorList() { - USSensor *pSensor = pAktiverSensor; - - for (int i = 0; i < SensorAktivAnzahl; i++){ - if (pSensor == NULL) - return; - PrintNumber("Sensor", pSensor->id); - if (pSensor->pNext == NULL) - debugPrint(" next NULL"); - else - PrintNumber(" next", pSensor->pNext->id); - if (pSensor->pPrev == NULL) - debugPrint(" prev NULL"); - else - PrintNumber(" prev", pSensor->pPrev->id); - pSensor = pSensor->pNext; - } -} - -#if 0 -// Timer Test-Funktionen - -static void testHandler() { - debugPrint("usi"); - - if (usTimerCount) - usTimerCount--; - else { - stopUsTimer(); - debugPrint("---"); - startUsTimer(300, testHandler); - } -} - -void TestUsTimer() { - startUsTimer(100, testHandler); -} - -int GetUsTimerCount() { - return usTimer.getCount(); -} -#endif - diff --git a/STM32F3/libraries/roboter/ultraschall.h b/STM32F3/libraries/roboter/ultraschall.h deleted file mode 100644 index a03af40..0000000 --- a/STM32F3/libraries/roboter/ultraschall.h +++ /dev/null @@ -1,156 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2015 Frank-Michael Krause - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -#ifndef ULTRASCHALL_H_ -#define ULTRASCHALL_H_ - -#define US_IDLE 0 -#define US_ACTIVE 1 - - -#define US_ROUNDTRIP_CM 57 // Microseconds (uS) it takes sound to travel round-trip 1cm (2cm total), uses integer to save compiled code space. - -typedef void (*usFuncPtr)(int id, int entfernung); - -typedef struct USSensor_s { - int8 id; - int triggerPin; - int echoPin; - int8 enabled; - int8 state; // IDLE, ACTIVE - int8 neuerMesswert; - int16 maxTime; //Zeit für maximal zu messende Entfernung in ms - int timerTicksPerCm; - int16 entfernung; // in cm - uint32 messZeit; // Systemzeit der Messung in ms - int16 lastValidRange; - uint32 lastValidTime; -// uint32 startZeit; // Startzeit der aktuellen Messung - usFuncPtr handler; - struct USSensor_s *pNext; - struct USSensor_s *pPrev; -} USSensor; - -#define MAX_US_SENSOR 4 - -#define ENTFERNUNG_INVALID -1 -#define ERROR_NO_SENSOR -2 -#define ERROR_SENSOR_BUSY -3 - -extern USSensor USSensoren[MAX_US_SENSOR]; - - -/***************************************************** - * Funktionen zur Initialisierung - ****************************************************/ - -/** - * id: Index zwischen 0 und MAX_US_SENSOR-1 - * trigger: IO-Pin, der mit dem Trigger-Eingang des Sensors verbunden ist - * echo: IO-Pin, der mit dem Echo-Ausgang des Sensors verbunden ist. - * !!! der Echo-IO-Pin muss 5V tolerant sein oder mit einem - * Spannungsteiler versehen werden. - * maxRange: Maximal zu messende Entfernung in cm; optional - */ -extern void addUSSensor(int id, int trigger, int echo, int maxRange=150); - -/** - * setzt die Zeit der Pause, die nach erfolgreicher Messung vor der nächsten - * Messung eingefügt wird. - * Default ist 0, d.h. keine Pause - */ -extern void UsSetMessPause(int ms); - - - -/***************************************************** - * Funktionen für blockierende Messung - * Bei Aufruf der blockierenden Einzelmessfunktion werden - * alle über Interrupt akktivierten Sensoren deaktiviert - * - * gibt Entfernung in cm zurück - * bzw. die Fehlerwerte - * ENTFERNUNG_INVALID -1 - * ERROR_NO_SENSOR -2 - * ERROR_SENSOR_BUSY -3 - *****************************************************/ -extern int16 UltraschallMessenEinzel(int id); - - - - -/***************************************************** - * Funktionen für nicht blockierende, interrupt-basierte Messung - * - * Durch Zustandsvariablen gesteuert werden auf allen aktiven Sensoren - * immer wieder abwechselnd Messungen angestossen. - * Die Messergebnisse werden in Variablen der Sensorstruktur abgelegt - * und können über Funktionen aus dem Hauptptogramm abgefragt werden. - * - * Es kann pro Sensor eine Handler-Funktion registriert werden, - * die aufgerufen wird, sobald ein neuer Messwert vorliegt. - *****************************************************/ - - -extern void aktiviereUSSensor(int id); -extern void deaktiviereUSSensor(int id); - -extern void UsAttachHandler(int id, usFuncPtr fkt); - - -/** - * gibt das Ergebnis der letzten Messung zurück. - * Kann ENTFERNUNG_INVALID sein. - */ -extern int16 UsAktuellerMesswert(int id); - -/** - * gibt das Alter des letzen Messergebnisses in ms an. - */ -extern int UsAktuellerMesswertAlter(int id); - -/** - * gibt den letzten Messwert des Sensors zurück, der nicht - * ENTFERNUNG_INVALID ist. - */ -extern int16 UsLetzterGueltigerMesswert(int id); - - -/** - * gibt das Alter des letzen gültigen Messergebnisses in ms an. - */ -extern int UsLetzterGueltigerMesswertAlter(int id); - - - -/***************************************************** - * Debug-Funktionen - ****************************************************/ - -extern void PrintUsSensorList(); - - -#endif /* ULTRASCHALL_H_ */ diff --git a/STM32F3/platform.txt b/STM32F3/platform.txt deleted file mode 100644 index 60d4042..0000000 --- a/STM32F3/platform.txt +++ /dev/null @@ -1,144 +0,0 @@ -# -# -# For more info: -# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification - -name=STM32F3 boards -version=0.1.0 - -# compiler variables -# ---------------------- -#build.gcc_ver=gcc-arm-none-eabi-4.8.3-2014q1 - -compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ -compiler.c.cmd=arm-none-eabi-gcc -compiler.c.flags=-c -g {build.flags.optimize} -w -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin} -compiler.c.elf.cmd=arm-none-eabi-g++ -compiler.c.elf.flags={build.flags.optimize} -Wl,--gc-sections {build.flags.ldspecs} -compiler.S.cmd=arm-none-eabi-gcc -compiler.S.flags=-c -g -x assembler-with-cpp -MMD -compiler.cpp.cmd=arm-none-eabi-g++ -compiler.cpp.flags=-c -g {build.flags.optimize} -w -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_{build.variant} -D{build.vect} -DERROR_LED_PORT={build.error_led_port} -DERROR_LED_PIN={build.error_led_pin} -compiler.ar.cmd=arm-none-eabi-ar -compiler.ar.flags=rcs -compiler.objcopy.cmd=arm-none-eabi-objcopy -compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 -compiler.elf2hex.flags=-O binary -compiler.elf2hex.cmd=arm-none-eabi-objcopy -compiler.ldflags={build.flags.ldspecs} -compiler.size.cmd=arm-none-eabi-size -compiler.define=-DARDUINO= - -# this can be overriden in boards.txt -build.cpu_flags= -build.hs_flag= -build.common_flags= -build.extra_flags= {build.cpu_flags} {build.hs_flag} {build.common_flags} - -# These can be overridden in platform.local.txt -compiler.c.extra_flags= -compiler.c.elf.extra_flags="-L{build.variant.path}/ld" -compiler.cpp.extra_flags= -compiler.S.extra_flags= -compiler.ar.extra_flags= -compiler.elf2hex.extra_flags= - - - -compiler.libs.c.flags="-I{build.core.path}/libmaple" "-I{build.core.path}/libmaple/include" "-I{build.core.path}/libmaple/stm32f3/include" "-I{build.core.path}/libmaple/usb" "-I{build.core.path}/libmaple/usb/usb_lib" "-I{build.core.path}/wirish/include" "-I{build.core.path}/wirish" -#compiler.libs.c.flags="-I{build.system.path}/libmaple" "-I{build.system.path}/libmaple/include" "-I{build.system.path}/libmaple/stm32f1/include" "-I{build.system.path}/libmaple/usb/stm32f1" "-I{build.system.path}/libmaple/usb/usb_lib" "-I{build.system.path}/wirish/include" - - -#compiler.libs.c.flags="-I{build.core.path}/libmaple" -I{build.core.path}/libmaple/usbF4 -I{build.core.path}/libmaple/usbF4/STM32_USB_Device_Library/Core/inc -I{build.core.path}/libmaple/usbF4/STM32_USB_Device_Library/Class/cdc/inc -I{build.core.path}/libmaple/usbF4/STM32_USB_OTG_Driver/inc -I{build.core.path}/libmaple/usbF4/VCP - - - -# USB Flags -# --------- -## build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' - -# Default usb manufacturer will be replaced at compile time using -# numeric vendor ID if available or by board's specific value. -## build.usb_manufacturer="Unknown" - - -# build patterns -# --------------------- - -## Compile c files -recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {compiler.libs.c.flags} {includes} "{source_file}" -o "{object_file}" - -## Compile c++ files -recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.cpu_flags} {build.hs_flag} {build.common_flags} {compiler.libs.c.flags} {includes} "{source_file}" -o "{object_file}" - -## Compile S files -recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.cpu_flags} {build.hs_flag} {build.common_flags} {compiler.libs.c.flags} {includes} "{source_file}" -o "{object_file}" -#recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" "{source_file}" -o "{object_file}" - -## Create archives -recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" - -## Combine gc-sections, archives, and objects -##recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{archive_file_path}" -Wl,--end-group -#-Wl,--entry=__start__ -#recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group {object_files} "{build.variant.path}/{build.variant_system_lib}" "{archive_file_path}" -Wl,--end-group -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group {object_files} -Wl,--whole-archive "{archive_file_path}" -Wl,--no-whole-archive -Wl,--end-group - -## Create eeprom -recipe.objcopy.eep.pattern= - -## Create hex -recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin" - -## Compute size -recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" -#recipe.size.regex=\.text\s+([0-9]+).* -recipe.size.regex=^(?:\.text|\.rodata|\.ARM.exidx)\s+([0-9]+).* -recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).* - -# Uploader tools -# ------------------- - -# Upload using Maple bootloader over DFU -tools.maple_upload.cmd=maple_upload -tools.maple_upload.cmd.windows=maple_upload.bat -#tools.maple_upload.cmd.linux= -tools.maple_upload.path={runtime.hardware.path}/tools/win -tools.maple_upload.path.macosx={runtime.hardware.path}/tools/macosx - -tools.maple_upload.upload.params.verbose=-d -tools.maple_upload.upload.params.quiet= -tools.maple_upload.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin" - -# Generic STM32 upload via serial to Serial Port 1 (pins PA9 and PA10) - note. Boot0 line needs to high on board reset to enable upload via serial -# at the end of the upload the program is automatically run, without the board being reset - -tools.serial_upload.cmd=serial_upload -tools.serial_upload.cmd.windows=serial_upload.bat -#tools.serial_upload.cmd.linux= -tools.serial_upload.path={runtime.hardware.path}/tools/win - -tools.serial_upload.upload.params.verbose=-d -tools.serial_upload.upload.params.quiet= -tools.serial_upload.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin" - -# -tools.upload_router.cmd=upload_router -tools.upload_router.cmd.windows=upload_router.bat -#tools.upload_router.cmd.linux= -tools.upload_router.path={runtime.hardware.path}/tools/win - -tools.upload_router.upload.params.verbose=-d -tools.upload_router.upload.params.quiet= -tools.upload_router.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}" {upload.protocol} {build.debuggingMode} "{runtime.ide.path}/hardware/tools/{build.gcc_ver}/bin/" - -# STLINK/V2 - -tools.stlink.cmd=stlink -tools.stlink.cmd.windows=stlink_upload.bat -#tools.stlink.cmd.linux= -tools.stlink.path={runtime.hardware.path}/tools/win -tools.stlink.upload.params.verbose=-d -tools.stlink.upload.params.quiet= -tools.stlink.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin" - diff --git a/STM32F3/variants/discovery_f3/board/board.h b/STM32F3/variants/discovery_f3/board/board.h deleted file mode 100644 index 6b04a8b..0000000 --- a/STM32F3/variants/discovery_f3/board/board.h +++ /dev/null @@ -1,138 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/boards/48F3/include/board/board.h - * @author F3-port: Hanspeter Portner - * @brief F303xx board header (F303CB, F303CC, F303RB, F303RC, F303VB, F303VC). - * - * See wirish/boards/maple/include/board/board.h for more information - * on these definitions. - */ - -#ifndef _BOARD_F303xx_H_ -#define _BOARD_F303xx_H_ - -#include - -#define CYCLES_PER_MICROSECOND (F_CPU / 1000000U) -#define SYSTICK_RELOAD_VAL (F_CPU/1000) - 1 /* takes a cycle to reload */ - -enum { - PC13, PC14, PC15, - PF0, PF1, - PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, - PB0, PB1, PB2, - PB10, PB11, PB12, PB13, PB14, PB15, - PA8, PA9, PA10, PA11, PA12, PA13, PA14, PA15, - PB3, PB4, PB5, PB6, PB7, PB8, PB9, -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) - PC0, PC1, PC2, PC3, - PF4, - PC4, PC5, PC6, PC7, PC8, PC9, PC10, PC11, PC12, - PD2, -# if defined(STM32_XL_DENSITY) - PE2, PE3, PE4, PE5, PE6, - PF9, PF10, - PF2, - PE7, PE8, PE9, PE10, PE11, PE12, PE13, PE14, PE15, - PD8, PD9, PD10, PD11, PD12, PD13, PD14, PD15, - PF6, - PD0, PD1, - PD3, PD4, PD5, PD6, PD7, - PE0, PE1, -# endif -#endif -}; - -#define BOARD_USART1_TX_PIN PA9 /* also PB6 */ -#define BOARD_USART1_RX_PIN PA10 /* also PB7 */ - -#define BOARD_USART2_TX_PIN PA2 /* also PA14, PB3 */ -#define BOARD_USART2_RX_PIN PA3 /* also PA15, PB4 */ - -#define BOARD_USART3_TX_PIN PB10 -#define BOARD_USART3_RX_PIN PB11 - -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) -# define BOARD_UART4_TX_PIN PC10 -# define BOARD_UART4_RX_PIN PC11 - -# define BOARD_UART5_TX_PIN PC12 -# define BOARD_UART5_RX_PIN PD2 -#endif - -#define BOARD_NR_SPI 3 - -#define BOARD_SPI1_NSS_PIN PA4 -#define BOARD_SPI1_SCK_PIN PA5 -#define BOARD_SPI1_MISO_PIN PA6 -#define BOARD_SPI1_MOSI_PIN PA7 - -#define BOARD_SPI2_NSS_PIN PB12 -#define BOARD_SPI2_SCK_PIN PB13 -#define BOARD_SPI2_MISO_PIN PB14 -#define BOARD_SPI2_MOSI_PIN PB15 - -#define BOARD_SPI3_NSS_PIN PA15 -#define BOARD_SPI3_SCK_PIN PB3 -#define BOARD_SPI3_MISO_PIN PB4 -#define BOARD_SPI3_MOSI_PIN PB5 - -#define BOARD_JTMS_SWDIO_PIN PA13 -#define BOARD_JTCK_SWCLK_PIN PA14 -#define BOARD_JTDI_PIN PA15 -#define BOARD_JTDO_PIN PB3 -#define BOARD_NJTRST_PIN PB4 - -#if defined(STM32_MEDIUM_DENSITY) -# define BOARD_NR_USARTS 3 -# define BOARD_NR_GPIO_PINS 37 -# define BOARD_NR_PWM_PINS 28 -# define BOARD_NR_ADC_PINS 15 -# define BOARD_NR_USED_PINS 4 -#elif defined(STM32_HIGH_DENSITY) -# define BOARD_NR_USARTS 5 -# define BOARD_NR_GPIO_PINS 52 -# define BOARD_NR_PWM_PINS 32 -# define BOARD_NR_ADC_PINS 22 -# define BOARD_NR_USED_PINS 4 -#elif defined(STM32_XL_DENSITY) -# define BOARD_NR_USARTS 5 -# define BOARD_NR_GPIO_PINS 87 -# define BOARD_NR_PWM_PINS 53 -# define BOARD_NR_ADC_PINS 39 -# define BOARD_NR_USED_PINS 7 -#endif - -/* redefine the following ones to match your hardware design */ -#define BOARD_BUTTON_PIN PA0 -#define BOARD_LED_PIN PE10 - -#define BOARD_USB_DISC_DEV GPIOA -#define BOARD_USB_DISC_BIT 13 - -#endif diff --git a/STM32F3/variants/discovery_f3/discovery_f3.cpp b/STM32F3/variants/discovery_f3/discovery_f3.cpp deleted file mode 100644 index c3c2542..0000000 --- a/STM32F3/variants/discovery_f3/discovery_f3.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2013 OpenMusicKontrollers. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wirish/boards/48F3/board.c - * @author F3-port: Hanspeter Portner - * @brief F303xx board file (F303CB, F303CC, F303RB, F303RC, F303VB, F303VC). - */ - -#include "board/board.h" - -#include "libmaple/gpio.h" -#include "libmaple/timer.h" - -#include "wirish/wirish_debug.h" -#include "wirish/wirish_types.h" - -/* Since we want the Serial Wire/JTAG pins as GPIOs, disable both SW - * and JTAG debug support on the packages with low pin-count (e.g. MEDIUM_DENSITY), - * unless configured otherwise. */ -void boardInit(void) { -#if defined(STM32_MEDIUM_DENSITY) - //disableDebugPorts(); -#endif - enableDebugPorts(); - -} - -extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS] = { - [PC13]= {GPIOC, NULL, NULL, 13, 0, ADCx}, /* PC13 */ - [PC14]= {GPIOC, NULL, NULL, 14, 0, ADCx}, /* PC14 */ /* OSC32_IN */ - [PC15]= {GPIOC, NULL, NULL, 15, 0, ADCx}, /* PC15 */ /* OSC32_OUT */ - - [PF0] = {GPIOF, NULL, NULL, 0, 0, ADCx}, /* PF0 */ /* OSC_IN */ - [PF1] = {GPIOF, NULL, NULL, 1, 0, ADCx}, /* PF1 */ /* OSC_OUT */ - - [PA0] = {GPIOA, TIMER2, ADC1, 0, 1, 1}, /* PA0 */ - [PA1] = {GPIOA, TIMER2, ADC1, 1, 2, 2}, /* PA1 */ - [PA2] = {GPIOA, TIMER2, ADC1, 2, 3, 3}, /* PA2 */ /* also TIMER15 CH1 */ - [PA3] = {GPIOA, TIMER2, ADC1, 3, 4, 4}, /* PA3 */ /* also TIMER15 CH2 */ - [PA4] = {GPIOA, TIMER3, ADC2, 4, 2, 1}, /* PA4 */ - [PA5] = {GPIOA, NULL, ADC2, 5, 0, 2}, /* PA5 */ - [PA6] = {GPIOA, TIMER3, ADC2, 6, 1, 3}, /* PA6 */ /* also TIMER16 CH1 */ - [PA7] = {GPIOA, TIMER3, ADC2, 7, 2, 4}, /* PA7 */ /* also TIMER17 CH1 */ - - [PB0] = {GPIOB, TIMER3, ADC3, 0, 3, 12}, /* PB0 */ - [PB1] = {GPIOB, TIMER3, ADC3, 1, 4, 1}, /* PB1 */ - [PB2] = {GPIOB, NULL, ADC2, 2, 0, 12}, /* PB2 */ - - [PB10]= {GPIOB, TIMER2, NULL, 10, 3, ADCx}, /* PB10 */ - [PB11]= {GPIOB, TIMER2, NULL, 11, 4, ADCx}, /* PB11 */ - [PB12]= {GPIOB, NULL, ADC4, 12, 0, 3}, /* PB12 */ - [PB13]= {GPIOB, NULL, ADC3, 13, 0, 5}, /* PB13 */ - [PB14]= {GPIOB, TIMER15,ADC4, 14, 1, 4}, /* PB14 */ - [PB15]= {GPIOB, TIMER15,ADC4, 15, 2, 5}, /* PB15 */ - - [PA8] = {GPIOA, TIMER1, NULL, 8, 1, ADCx}, /* PA8 */ - [PA9] = {GPIOA, TIMER1, NULL, 9, 2, ADCx}, /* PA9 */ /* also TIMER2_CH3 */ - [PA10]= {GPIOA, TIMER1, NULL, 10, 3, ADCx}, /* PA10 */ /* also TIMER2 CH4 */ - [PA11]= {GPIOA, TIMER4, NULL, 11, 1, ADCx}, /* PA11 */ /* also TIMER1 CH4 */ - [PA12]= {GPIOA, TIMER4, NULL, 12, 2, ADCx}, /* PA12 */ /* also TIMER16 CH1 */ - [PA13]= {GPIOA, TIMER4, NULL, 13, 3, ADCx}, /* PA13 */ - [PA14]= {GPIOA, TIMER8, NULL, 14, 2, ADCx}, /* PA14 */ - [PA15]= {GPIOA, TIMER8, NULL, 15, 1, ADCx}, /* PA15 */ - - [PB3] = {GPIOB, TIMER2, NULL, 3, 2, ADCx}, /* PB3 */ - [PB4] = {GPIOB, TIMER3, NULL, 4, 1, ADCx}, /* PB4 */ /* also TIMER16 CH1 */ - [PB5] = {GPIOB, TIMER3, NULL, 5, 2, ADCx}, /* PB5 */ /* also TIMER17 CH1 */ - [PB6] = {GPIOB, TIMER4, NULL, 6, 1, ADCx}, /* PB6 */ /* also TIMER8 CH1 */ - [PB7] = {GPIOB, TIMER4, NULL, 7, 2, ADCx}, /* PB7 */ /* also TIMER3 CH4 */ - [PB8] = {GPIOB, TIMER4, NULL, 8, 3, ADCx}, /* PB8 */ /* also TIMER16 CH1 */ - [PB9] = {GPIOB, TIMER4, NULL, 9, 4, ADCx}, /* PB9 */ /* also TIMER17 CH1 */ - -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) - [PC0] = {GPIOC, NULL, ADC1, 0, 0, 6}, /* PC0 */ - [PC1] = {GPIOC, NULL, ADC1, 1, 0, 7}, /* PC1 */ - [PC2] = {GPIOC, NULL, ADC1, 2, 0, 8}, /* PC2 */ - [PC3] = {GPIOC, NULL, ADC1, 3, 0, 9}, /* PC3 */ - - [PF4] = {GPIOF, NULL, ADC1, 4, 0, 5}, /* PF4 */ - - [PC4] = {GPIOC, NULL, ADC2, 4, 0, 5}, /* PC4 */ - [PC5] = {GPIOC, NULL, ADC2, 5, 0, 11}, /* PC5 */ - [PC6] = {GPIOC, TIMER8, NULL, 6, 1, ADCx}, /* PC6 */ /* also TIMER3_CH1 */ - [PC7] = {GPIOC, TIMER8, NULL, 7, 2, ADCx}, /* PC7 */ /* also TIMER3_CH2 */ - [PC8] = {GPIOC, TIMER8, NULL, 8, 3, ADCx}, /* PC8 */ /* also TIMER3_CH3 */ - [PC9] = {GPIOC, TIMER8, NULL, 9, 4, ADCx}, /* PC9 */ /* also TIMER3_CH4 */ - [PC10]= {GPIOC, NULL, NULL, 10, 0, ADCx}, /* PC10 */ - [PC11]= {GPIOC, NULL, NULL, 11, 0, ADCx}, /* PC11 */ - [PC12]= {GPIOC, NULL, NULL, 12, 0, ADCx}, /* PC12 */ - - [PD2] = {GPIOD, NULL, NULL, 2, 0, ADCx}, /* PD2 */ - -# if defined(STM32_XL_DENSITY) - [PE2] = {GPIOE, TIMER3, NULL, 2, 1, ADCx}, /* PE2 */ - [PE3] = {GPIOE, TIMER3, NULL, 3, 2, ADCx}, /* PE3 */ - [PE4] = {GPIOE, TIMER3, NULL, 4, 3, ADCx}, /* PE4 */ - [PE5] = {GPIOE, TIMER3, NULL, 5, 4, ADCx}, /* PE5 */ - [PE6] = {GPIOE, NULL, NULL, 6, 0, ADCx}, /* PE6 */ - - [PF9] = {GPIOF,TIMER15, NULL, 9, 1, ADCx}, /* PF9 */ - [PF10]= {GPIOF,TIMER15, NULL, 10, 2, ADCx}, /* PF10 */ - - [PF2] = {GPIOF, NULL, ADC1, 2, 0, 10}, /* PF2 */ - - [PE7] = {GPIOE, NULL, ADC3, 7, 0, 13}, /* PE7 */ - [PE8] = {GPIOE, NULL, ADC3, 8, 0, 6}, /* PE8 */ - [PE9] = {GPIOE, TIMER1, ADC3, 9, 1, 2}, /* PE9 */ - [PE10]= {GPIOE, NULL, ADC3, 10, 0, 14}, /* PE10 */ - [PE11]= {GPIOE, TIMER1, ADC3, 11, 2, 15}, /* PE11 */ - [PE12]= {GPIOE, NULL, ADC3, 12, 0, 15}, /* PE12 */ - [PE13]= {GPIOE, TIMER1, ADC3, 13, 3, 3}, /* PE13 */ - [PE14]= {GPIOE, TIMER1, ADC4, 14, 4, 1}, /* PE14 */ - [PE15]= {GPIOE, NULL, ADC4, 15, 0, 2}, /* PE15 */ - - [PD8] = {GPIOD, NULL, ADC4, 8, 0, 12}, /* PD8 */ - [PD9] = {GPIOD, NULL, ADC4, 9, 0, 13}, /* PD0 */ - [PD10]= {GPIOD, NULL, ADC3, 10, 0, 7}, /* PD10 */ - [PD11]= {GPIOD, NULL, ADC3, 11, 0, 8}, /* PD11 */ - [PD12]= {GPIOD, TIMER4, ADC3, 12, 1, 9}, /* PD12 */ - [PD13]= {GPIOD, TIMER4, ADC3, 13, 2, 10}, /* PD13 */ - [PD14]= {GPIOD, TIMER4, ADC3, 14, 3, 11}, /* PD14 */ - [PD15]= {GPIOD, TIMER4, NULL, 15, 4, ADCx}, /* PD15 */ - - [PF6] = {GPIOF, TIMER4, NULL, 6, 4, ADCx}, /* PF6 */ - - [PD0] = {GPIOD, NULL, NULL, 0, 0, ADCx}, /* PD0 */ - [PD1] = {GPIOD, TIMER8, NULL, 1, 4, ADCx}, /* PD1 */ - - [PD3] = {GPIOD, NULL, NULL, 3, 0, ADCx}, /* PD3 */ - [PD4] = {GPIOD, TIMER2, NULL, 4, 2, ADCx}, /* PD4 */ - [PD5] = {GPIOD, NULL, NULL, 5, 0, ADCx}, /* PD5 */ - [PD6] = {GPIOD, TIMER2, NULL, 6, 4, ADCx}, /* PD6 */ - [PD7] = {GPIOD, TIMER2, NULL, 7, 3, ADCx}, /* PD7 */ - - [PE0] = {GPIOE,TIMER16, NULL, 0, 1, ADCx}, /* PE0 */ - [PE1] = {GPIOE,TIMER17, NULL, 1, 1, ADCx}, /* PE1 */ -# endif -#endif -}; - -extern const uint8 boardPWMPins[BOARD_NR_PWM_PINS] __FLASH__ = { - PA0, PA1, PA2, PA3, PA4, PA6, PA7, PB0, PB1, PB10, PB11, PB14, PB15, PA8, PA9, PA10, PA11, PA12, PA13, PA14, PA15, PB3, PB4, PB5, PB6, PB7, PB8, PB9, -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) - PC6, PC7, PC8, PC9, -# if defined(STM32_XL_DENSITY) - PE2, PE3, PE4, PE5, PF9, PF10, PE9, PE11, PE13, PE14, PD12, PD13, PD14, PD15, PF6, PD1, PD4, PD6, PD7, PE0, PE1, -# endif -#endif -}; - -extern const uint8 boardADCPins[BOARD_NR_ADC_PINS] __FLASH__ = { - PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PB0, PB1, PB2, PB12, PB13, PB14, PB15, -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) - PC0, PC1, PC2, PC3, PF4, PC4, PC5, -# if defined(STM32_XL_DENSITY) - PF2, PE7, PE8, PE9, PE10, PE11, PE12, PE13, PE14, PE15, PD8, PD9, PD10, PD11, PD12, PD13, PD14, -# endif -#endif -}; - -#define OSC_IN PF0 -#define OSC_OUT PF1 - -#define USB_DM PA11 -#define USB_DP PA12 - -extern const uint8 boardUsedPins[BOARD_NR_USED_PINS] __FLASH__ = { - OSC_IN, OSC_OUT, USB_DP, USB_DM,PB3, PA13, PA14 -}; diff --git a/STM32F3/variants/discovery_f3/ld/common.inc b/STM32F3/variants/discovery_f3/ld/common.inc deleted file mode 100644 index 49aaf6f..0000000 --- a/STM32F3/variants/discovery_f3/ld/common.inc +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Linker script for libmaple. - * - * Original author "lanchon" from ST forums, with modifications by LeafLabs. - */ - -OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") - -/* - * Configure other libraries we want in the link. - * - * libgcc, libc, and libm are common across supported toolchains. - * However, some toolchains require additional archives which aren't - * present everywhere (e.g. ARM's gcc-arm-embedded releases). - * - * To hack around this, we let the build system specify additional - * archives by putting the right extra_libs.inc (in a directory under - * toolchains/) in our search path. - */ -GROUP(libgcc.a libc.a libm.a) -INCLUDE extra_libs.inc - -/* - * These force the linker to search for vector table symbols. - * - * These symbols vary by STM32 family (and also within families). - * It's up to the build system to configure the link's search path - * properly for the target MCU. - */ -INCLUDE vector_symbols.inc - -/* STM32 vector table. */ -EXTERN(__stm32_vector_table) - -/* C runtime initialization function. */ -EXTERN(start_c) - -/* main entry point */ -EXTERN(main) - -/* Initial stack pointer value. */ -EXTERN(__msp_init) -PROVIDE(__msp_init = ORIGIN(ram) + LENGTH(ram)); - -/* Reset vector and chip reset entry point */ -EXTERN(__start__) -ENTRY(__start__) -PROVIDE(__exc_reset = __start__); - -/* Heap boundaries, for libmaple */ -EXTERN(_lm_heap_start); -EXTERN(_lm_heap_end); - -SECTIONS -{ - .text : - { - __text_start__ = .; - /* - * STM32 vector table. Leave this here. Yes, really. - */ - *(.stm32.interrupt_vector) - - /* - * Program code and vague linking - */ - *(.text .text.* .gnu.linkonce.t.*) - *(.plt) - *(.gnu.warning) - *(.glue_7t) *(.glue_7) *(.vfp11_veneer) - - *(.ARM.extab* .gnu.linkonce.armextab.*) - *(.gcc_except_table) - *(.eh_frame_hdr) - *(.eh_frame) - - . = ALIGN(4); - KEEP(*(.init)) - - . = ALIGN(4); - __preinit_array_start = .; - KEEP (*(.preinit_array)) - __preinit_array_end = .; - - . = ALIGN(4); - __init_array_start = .; - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array)) - __init_array_end = .; - - . = ALIGN(0x4); - KEEP (*crtbegin.o(.ctors)) - KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*crtend.o(.ctors)) - - . = ALIGN(4); - KEEP(*(.fini)) - - . = ALIGN(4); - __fini_array_start = .; - KEEP (*(.fini_array)) - KEEP (*(SORT(.fini_array.*))) - __fini_array_end = .; - - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*crtend.o(.dtors)) - } > REGION_TEXT - - /* - * End of text - */ - .text.align : - { - . = ALIGN(8); - __text_end__ = .; - } > REGION_TEXT - - /* - * .ARM.exidx exception unwinding; mandated by ARM's C++ ABI - */ - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > REGION_RODATA - __exidx_end = .; - - /* - * .data - */ - .data : - { - . = ALIGN(8); - __data_start__ = .; - - *(.got.plt) *(.got) - *(.data .data.* .gnu.linkonce.d.*) - - . = ALIGN(8); - __data_end__ = .; - } > REGION_DATA AT> REGION_RODATA - - /* - * Read-only data - */ - .rodata : - { - *(.rodata .rodata.* .gnu.linkonce.r.*) - /* .USER_FLASH: We allow users to allocate into Flash here */ - *(.USER_FLASH) - /* ROM image configuration; for C startup */ - . = ALIGN(4); - _lm_rom_img_cfgp = .; - LONG(LOADADDR(.data)); - /* - * Heap: Linker scripts may choose a custom heap by overriding - * _lm_heap_start and _lm_heap_end. Otherwise, the heap is in - * internal SRAM, beginning after .bss, and growing towards - * the stack. - * - * I'm shoving these here naively; there's probably a cleaner way - * to go about this. [mbolivar] - */ - _lm_heap_start = DEFINED(_lm_heap_start) ? _lm_heap_start : _end; - _lm_heap_end = DEFINED(_lm_heap_end) ? _lm_heap_end : __msp_init; - } > REGION_RODATA - - /* - * .bss - */ - .bss : - { - . = ALIGN(8); - __bss_start__ = .; - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - . = ALIGN (8); - __bss_end__ = .; - _end = __bss_end__; - } > REGION_BSS - - /* - * .ccm - */ - .ccm (NOLOAD) : - { - . = ALIGN(4); - *(.CCM) - . = ALIGN(4); - } > REGION_CCM - - /* - * Debugging sections - */ - .stab 0 (NOLOAD) : { *(.stab) } - .stabstr 0 (NOLOAD) : { *(.stabstr) } - /* DWARF debug sections. - * Symbols in the DWARF debugging sections are relative to the beginning - * of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } - - .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } - .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) } - /DISCARD/ : { *(.note.GNU-stack) } -} diff --git a/STM32F3/variants/discovery_f3/ld/extra_libs.inc b/STM32F3/variants/discovery_f3/ld/extra_libs.inc deleted file mode 100644 index dd2c84f..0000000 --- a/STM32F3/variants/discovery_f3/ld/extra_libs.inc +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Extra archives needed by ARM's GCC ARM Embedded arm-none-eabi- - * releases (https://launchpad.net/gcc-arm-embedded/). - */ - -/* This is for the provided newlib. */ -GROUP(libnosys.a) diff --git a/STM32F3/variants/discovery_f3/ld/flash.ld b/STM32F3/variants/discovery_f3/ld/flash.ld deleted file mode 100644 index 2fa9035..0000000 --- a/STM32F3/variants/discovery_f3/ld/flash.ld +++ /dev/null @@ -1,28 +0,0 @@ -/* - * libmaple linker script for "Flash" builds. - * - * A Flash build puts .text (and .rodata) in Flash, and - * .data/.bss/heap (of course) in SRAM, but offsets the sections by - * enough space to store the Maple bootloader, which lives in low - * Flash and uses low memory. - */ - -/* - * This pulls in the appropriate MEMORY declaration from the right - * subdirectory of stm32/mem/ (the environment must call ld with the - * right include directory flags to make this happen). Boards can also - * use this file to use any of libmaple's memory-related hooks (like - * where the heap should live). - */ - -INCLUDE mem-flash.inc - -/* Provide memory region aliases for common.inc */ -REGION_ALIAS("REGION_TEXT", rom); -REGION_ALIAS("REGION_DATA", ram); -REGION_ALIAS("REGION_BSS", ram); -REGION_ALIAS("REGION_RODATA", rom); -REGION_ALIAS("REGION_CCM", ccm); - -/* Let common.inc handle the real work. */ -INCLUDE common.inc diff --git a/STM32F3/variants/discovery_f3/ld/jtag.ld b/STM32F3/variants/discovery_f3/ld/jtag.ld deleted file mode 100644 index cf08b20..0000000 --- a/STM32F3/variants/discovery_f3/ld/jtag.ld +++ /dev/null @@ -1,33 +0,0 @@ -/* - * libmaple linker script for "JTAG" builds. - * - * A "JTAG" build puts .text (and .rodata) in Flash, and - * .data/.bss/heap (of course) in SRAM, but links starting at the - * Flash and SRAM starting addresses (0x08000000 and 0x20000000 - * respectively). This will wipe out a Maple bootloader if there's one - * on the board, so only use this if you know what you're doing. - * - * Of course, a "JTAG" build is perfectly usable for upload over SWD, - * the system memory bootloader, etc. The name is just a historical - * artifact. - */ - -/* - * This pulls in the appropriate MEMORY declaration from the right - * subdirectory of stm32/mem/ (the environment must call ld with the - * right include directory flags to make this happen). Boards can also - * use this file to use any of libmaple's memory-related hooks (like - * where the heap should live). - */ - -INCLUDE mem-jtag.inc - -/* Provide memory region aliases for common.inc */ -REGION_ALIAS("REGION_TEXT", rom); -REGION_ALIAS("REGION_DATA", ram); -REGION_ALIAS("REGION_BSS", ram); -REGION_ALIAS("REGION_RODATA", rom); -REGION_ALIAS("REGION_CCM", ccm); - -/* Let common.inc handle the real work. */ -INCLUDE common.inc diff --git a/STM32F3/variants/discovery_f3/ld/mem-flash.inc b/STM32F3/variants/discovery_f3/ld/mem-flash.inc deleted file mode 100644 index a683808..0000000 --- a/STM32F3/variants/discovery_f3/ld/mem-flash.inc +++ /dev/null @@ -1,6 +0,0 @@ -MEMORY -{ - ccm (rwx) : ORIGIN = 0x10000000, LENGTH = 8K - ram (rwx) : ORIGIN = 0x20000C00, LENGTH = 37K - rom (rx) : ORIGIN = 0x08005000, LENGTH = 236K -} diff --git a/STM32F3/variants/discovery_f3/ld/mem-jtag.inc b/STM32F3/variants/discovery_f3/ld/mem-jtag.inc deleted file mode 100644 index 9fb4452..0000000 --- a/STM32F3/variants/discovery_f3/ld/mem-jtag.inc +++ /dev/null @@ -1,6 +0,0 @@ -MEMORY -{ - ccm (rwx) : ORIGIN = 0x10000000, LENGTH = 8K - ram (rwx) : ORIGIN = 0x20000000, LENGTH = 40K - rom (rx) : ORIGIN = 0x08000000, LENGTH = 256K -} diff --git a/STM32F3/variants/discovery_f3/ld/mem-ram.inc b/STM32F3/variants/discovery_f3/ld/mem-ram.inc deleted file mode 100644 index 08d7608..0000000 --- a/STM32F3/variants/discovery_f3/ld/mem-ram.inc +++ /dev/null @@ -1,6 +0,0 @@ -MEMORY -{ - ccm (rwx) : ORIGIN = 0x10000000, LENGTH = 8K - ram (rwx) : ORIGIN = 0x20000C00, LENGTH = 37K - rom (rx) : ORIGIN = 0x08005000, LENGTH = 0K -} diff --git a/STM32F3/variants/discovery_f3/ld/names.inc b/STM32F3/variants/discovery_f3/ld/names.inc deleted file mode 100644 index 6d7ff6e..0000000 --- a/STM32F3/variants/discovery_f3/ld/names.inc +++ /dev/null @@ -1,78 +0,0 @@ -EXTERN(__cs3_stack) -EXTERN(__cs3_reset) -EXTERN(__exc_nmi) -EXTERN(__exc_hardfault) -EXTERN(__exc_memmanage) -EXTERN(__exc_busfault) -EXTERN(__exc_usagefault) -EXTERN(__stm32reservedexception7) -EXTERN(__stm32reservedexception8) -EXTERN(__stm32reservedexception9) -EXTERN(__stm32reservedexception10) -EXTERN(__exc_svc) -EXTERN(__exc_debug_monitor) -EXTERN(__stm32reservedexception13) -EXTERN(__exc_pendsv) -EXTERN(__exc_systick) - -EXTERN(__irq_wwdg) -EXTERN(__irq_pvd) -EXTERN(__irq_tamper) -EXTERN(__irq_rtc) -EXTERN(__irq_flash) -EXTERN(__irq_rcc) -EXTERN(__irq_exti0) -EXTERN(__irq_exti1) -EXTERN(__irq_exti2) -EXTERN(__irq_exti3) -EXTERN(__irq_exti4) -EXTERN(__irq_dma1_channel1) -EXTERN(__irq_dma1_channel2) -EXTERN(__irq_dma1_channel3) -EXTERN(__irq_dma1_channel4) -EXTERN(__irq_dma1_channel5) -EXTERN(__irq_dma1_channel6) -EXTERN(__irq_dma1_channel7) -EXTERN(__irq_adc) -EXTERN(__irq_usb_hp_can_tx) -EXTERN(__irq_usb_lp_can_rx0) -EXTERN(__irq_can_rx1) -EXTERN(__irq_can_sce) -EXTERN(__irq_exti9_5) -EXTERN(__irq_tim1_brk) -EXTERN(__irq_tim1_up) -EXTERN(__irq_tim1_trg_com) -EXTERN(__irq_tim1_cc) -EXTERN(__irq_tim2) -EXTERN(__irq_tim3) -EXTERN(__irq_tim4) -EXTERN(__irq_i2c1_ev) -EXTERN(__irq_i2c1_er) -EXTERN(__irq_i2c2_ev) -EXTERN(__irq_i2c2_er) -EXTERN(__irq_spi1) -EXTERN(__irq_spi2) -EXTERN(__irq_usart1) -EXTERN(__irq_usart2) -EXTERN(__irq_usart3) -EXTERN(__irq_exti15_10) -EXTERN(__irq_rtcalarm) -EXTERN(__irq_usbwakeup) - -EXTERN(__irq_tim8_brk) -EXTERN(__irq_tim8_up) -EXTERN(__irq_tim8_trg_com) -EXTERN(__irq_tim8_cc) -EXTERN(__irq_adc3) -EXTERN(__irq_fsmc) -EXTERN(__irq_sdio) -EXTERN(__irq_tim5) -EXTERN(__irq_spi3) -EXTERN(__irq_uart4) -EXTERN(__irq_uart5) -EXTERN(__irq_tim6) -EXTERN(__irq_tim7) -EXTERN(__irq_dma2_channel1) -EXTERN(__irq_dma2_channel2) -EXTERN(__irq_dma2_channel3) -EXTERN(__irq_dma2_channel4_5) diff --git a/STM32F3/variants/discovery_f3/ld/ram.ld b/STM32F3/variants/discovery_f3/ld/ram.ld deleted file mode 100644 index 0484423..0000000 --- a/STM32F3/variants/discovery_f3/ld/ram.ld +++ /dev/null @@ -1,27 +0,0 @@ -/* - * libmaple linker script for RAM builds. - * - * A Flash build puts .text, .rodata, and .data/.bss/heap (of course) - * in SRAM, but offsets the sections by enough space to store the - * Maple bootloader, which uses low memory. - */ - -/* - * This pulls in the appropriate MEMORY declaration from the right - * subdirectory of stm32/mem/ (the environment must call ld with the - * right include directory flags to make this happen). Boards can also - * use this file to use any of libmaple's memory-related hooks (like - * where the heap should live). - */ - -INCLUDE mem-ram.inc - -/* Provide memory region aliases for common.inc */ -REGION_ALIAS("REGION_TEXT", ram); -REGION_ALIAS("REGION_DATA", ram); -REGION_ALIAS("REGION_BSS", ram); -REGION_ALIAS("REGION_RODATA", ram); -REGION_ALIAS("REGION_CCM", ccm); - -/* Let common.inc handle the real work. */ -INCLUDE common.inc diff --git a/STM32F3/variants/discovery_f3/ld/vector_symbols.inc b/STM32F3/variants/discovery_f3/ld/vector_symbols.inc deleted file mode 100644 index a9d18f4..0000000 --- a/STM32F3/variants/discovery_f3/ld/vector_symbols.inc +++ /dev/null @@ -1,98 +0,0 @@ -EXTERN(__msp_init) -EXTERN(__exc_reset) -EXTERN(__exc_nmi) -EXTERN(__exc_hardfault) -EXTERN(__exc_memmanage) -EXTERN(__exc_busfault) -EXTERN(__exc_usagefault) -EXTERN(__stm32reservedexception7) -EXTERN(__stm32reservedexception8) -EXTERN(__stm32reservedexception9) -EXTERN(__stm32reservedexception10) -EXTERN(__exc_svc) -EXTERN(__exc_debug_monitor) -EXTERN(__stm32reservedexception13) -EXTERN(__exc_pendsv) -EXTERN(__exc_systick) -EXTERN(__irq_wwdg) -EXTERN(__irq_pvd) -EXTERN(__irq_tamp_stamp) -EXTERN(__irq_rtc_wkup) -EXTERN(__irq_flash) -EXTERN(__irq_rcc) -EXTERN(__irq_exti0) -EXTERN(__irq_exti1) -EXTERN(__irq_exti2) -EXTERN(__irq_exti3) -EXTERN(__irq_exti4) -EXTERN(__irq_dma1_ch1) -EXTERN(__irq_dma1_ch2) -EXTERN(__irq_dma1_ch3) -EXTERN(__irq_dma1_ch4) -EXTERN(__irq_dma1_ch5) -EXTERN(__irq_dma1_ch6) -EXTERN(__irq_dma1_ch7) -EXTERN(__irq_adc1_2) -EXTERN(__irq_usb_hp_can_tx) -EXTERN(__irq_usb_lp_can_rx0) -EXTERN(__irq_can_rx1) -EXTERN(__irq_can_sce) -EXTERN(__irq_exti9_5) -EXTERN(__irq_tim1_brk_tim15) -EXTERN(__irq_tim1_up_tim16) -EXTERN(__irq_tim1_trg_com_tim17) -EXTERN(__irq_tim1_cc) -EXTERN(__irq_tim2) -EXTERN(__irq_tim3) -EXTERN(__irq_tim4) -EXTERN(__irq_i2c1_ev) -EXTERN(__irq_i2c1_er) -EXTERN(__irq_i2c2_ev) -EXTERN(__irq_i2c2_er) -EXTERN(__irq_spi1) -EXTERN(__irq_spi2) -EXTERN(__irq_usart1) -EXTERN(__irq_usart2) -EXTERN(__irq_usart3) -EXTERN(__irq_exti15_10) -EXTERN(__irq_rtc_alarm) -EXTERN(__irq_usb_wkup) -EXTERN(__irq_tim8_brk) -EXTERN(__irq_tim8_up) -EXTERN(__irq_tim8_trg_com) -EXTERN(__irq_tim8_cc) -EXTERN(__irq_adc3) -EXTERN(__stm32reservedexception48) -EXTERN(__stm32reservedexception49) -EXTERN(__stm32reservedexception50) -EXTERN(__irq_spi3) -EXTERN(__irq_uart4) -EXTERN(__irq_uart5) -EXTERN(__irq_tim6_dacunder) -EXTERN(__irq_tim7) -EXTERN(__irq_dma2_ch1) -EXTERN(__irq_dma2_ch2) -EXTERN(__irq_dma2_ch3) -EXTERN(__irq_dma2_ch4) -EXTERN(__irq_dma2_ch5) -EXTERN(__irq_adc4) -EXTERN(__stm32reservedexception62) -EXTERN(__stm32reservedexception63) -EXTERN(__irq_comp123) -EXTERN(__irq_comp456) -EXTERN(__irq_comp7) -EXTERN(__stm32reservedexception67) -EXTERN(__stm32reservedexception68) -EXTERN(__stm32reservedexception69) -EXTERN(__stm32reservedexception70) -EXTERN(__stm32reservedexception71) -EXTERN(__stm32reservedexception72) -EXTERN(__stm32reservedexception73) -EXTERN(__irq_usb_hp) -EXTERN(__irq_usb_lp) -EXTERN(__irq_usb_wkup2) -EXTERN(__stm32reservedexception77) -EXTERN(__stm32reservedexception78) -EXTERN(__stm32reservedexception79) -EXTERN(__stm32reservedexception80) -EXTERN(__irq_fpu) diff --git a/STM32F3/variants/discovery_f3/stm32_isrs.S b/STM32F3/variants/discovery_f3/stm32_isrs.S deleted file mode 100644 index f236387..0000000 --- a/STM32F3/variants/discovery_f3/stm32_isrs.S +++ /dev/null @@ -1,331 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/* STM32F3 performance line ISR weak declarations */ - -#include - - .thumb - -/* Default handler for all non-overridden interrupts and exceptions */ - .globl __default_handler - .type __default_handler, %function - -__default_handler: - b . - - .weak __exc_nmi - .globl __exc_nmi - .set __exc_nmi, __default_handler - .weak __exc_hardfault - .globl __exc_hardfault - .set __exc_hardfault, __default_handler - .weak __exc_memmanage - .globl __exc_memmanage - .set __exc_memmanage, __default_handler - .weak __exc_busfault - .globl __exc_busfault - .set __exc_busfault, __default_handler - .weak __exc_usagefault - .globl __exc_usagefault - .set __exc_usagefault, __default_handler - .weak __stm32reservedexception7 - .globl __stm32reservedexception7 - .set __stm32reservedexception7, __default_handler - .weak __stm32reservedexception8 - .globl __stm32reservedexception8 - .set __stm32reservedexception8, __default_handler - .weak __stm32reservedexception9 - .globl __stm32reservedexception9 - .set __stm32reservedexception9, __default_handler - .weak __stm32reservedexception10 - .globl __stm32reservedexception10 - .set __stm32reservedexception10, __default_handler - .weak __exc_svc - .globl __exc_svc - .set __exc_svc, __default_handler - .weak __exc_debug_monitor - .globl __exc_debug_monitor - .set __exc_debug_monitor, __default_handler - .weak __stm32reservedexception13 - .globl __stm32reservedexception13 - .set __stm32reservedexception13, __default_handler - .weak __exc_pendsv - .globl __exc_pendsv - .set __exc_pendsv, __default_handler - .weak __exc_systick - .globl __exc_systick - .set __exc_systick, __default_handler - .weak __irq_wwdg - .globl __irq_wwdg - .set __irq_wwdg, __default_handler - .weak __irq_pvd - .globl __irq_pvd - .set __irq_pvd, __default_handler - .weak __irq_tamp_stamp - .globl __irq_tamp_stamp - .set __irq_tamp_stamp, __default_handler - .weak __irq_rtc_wkup - .globl __irq_rtc_wkup - .set __irq_rtc_wkup, __default_handler - .weak __irq_flash - .globl __irq_flash - .set __irq_flash, __default_handler - .weak __irq_rcc - .globl __irq_rcc - .set __irq_rcc, __default_handler - .weak __irq_exti0 - .globl __irq_exti0 - .set __irq_exti0, __default_handler - .weak __irq_exti1 - .globl __irq_exti1 - .set __irq_exti1, __default_handler - .weak __irq_exti2 - .globl __irq_exti2 - .set __irq_exti2, __default_handler - .weak __irq_exti3 - .globl __irq_exti3 - .set __irq_exti3, __default_handler - .weak __irq_exti4 - .globl __irq_exti4 - .set __irq_exti4, __default_handler - .weak __irq_dma1_ch1 - .globl __irq_dma1_ch1 - .set __irq_dma1_ch1, __default_handler - .weak __irq_dma1_ch2 - .globl __irq_dma1_ch2 - .set __irq_dma1_ch2, __default_handler - .weak __irq_dma1_ch3 - .globl __irq_dma1_ch3 - .set __irq_dma1_ch3, __default_handler - .weak __irq_dma1_ch4 - .globl __irq_dma1_ch4 - .set __irq_dma1_ch4, __default_handler - .weak __irq_dma1_ch5 - .globl __irq_dma1_ch5 - .set __irq_dma1_ch5, __default_handler - .weak __irq_dma1_ch6 - .globl __irq_dma1_ch6 - .set __irq_dma1_ch6, __default_handler - .weak __irq_dma1_ch7 - .globl __irq_dma1_ch7 - .set __irq_dma1_ch7, __default_handler - .weak __irq_adc1_2 - .globl __irq_adc1_2 - .set __irq_adc1_2, __default_handler - .weak __irq_usb_hp_can_tx - .globl __irq_usb_hp_can_tx - .set __irq_usb_hp_can_tx, __default_handler - .weak __irq_usb_lp_can_rx0 - .globl __irq_usb_lp_can_rx0 - .set __irq_usb_lp_can_rx0, __default_handler - .weak __irq_can_rx1 - .globl __irq_can_rx1 - .set __irq_can_rx1, __default_handler - .weak __irq_can_sce - .globl __irq_can_sce - .set __irq_can_sce, __default_handler - .weak __irq_exti9_5 - .globl __irq_exti9_5 - .set __irq_exti9_5, __default_handler - .weak __irq_tim1_brk_tim15 - .globl __irq_tim1_brk_tim15 - .set __irq_tim1_brk_tim15, __default_handler - .weak __irq_tim1_up_tim16 - .globl __irq_tim1_up_tim16 - .set __irq_tim1_up_tim16, __default_handler - .weak __irq_tim1_trg_com_tim17 - .globl __irq_tim1_trg_com_tim17 - .set __irq_tim1_trg_com_tim17, __default_handler - .weak __irq_tim1_cc - .globl __irq_tim1_cc - .set __irq_tim1_cc, __default_handler - .weak __irq_tim2 - .globl __irq_tim2 - .set __irq_tim2, __default_handler - .weak __irq_tim3 - .globl __irq_tim3 - .set __irq_tim3, __default_handler - .weak __irq_tim4 - .globl __irq_tim4 - .set __irq_tim4, __default_handler - .weak __irq_i2c1_ev - .globl __irq_i2c1_ev - .set __irq_i2c1_ev, __default_handler - .weak __irq_i2c1_er - .globl __irq_i2c1_er - .set __irq_i2c1_er, __default_handler - .weak __irq_i2c2_ev - .globl __irq_i2c2_ev - .set __irq_i2c2_ev, __default_handler - .weak __irq_i2c2_er - .globl __irq_i2c2_er - .set __irq_i2c2_er, __default_handler - .weak __irq_spi1 - .globl __irq_spi1 - .set __irq_spi1, __default_handler - .weak __irq_spi2 - .globl __irq_spi2 - .set __irq_spi2, __default_handler - .weak __irq_usart1 - .globl __irq_usart1 - .set __irq_usart1, __default_handler - .weak __irq_usart2 - .globl __irq_usart2 - .set __irq_usart2, __default_handler - .weak __irq_usart3 - .globl __irq_usart3 - .set __irq_usart3, __default_handler - .weak __irq_exti15_10 - .globl __irq_exti15_10 - .set __irq_exti15_10, __default_handler - .weak __irq_rtc_alarm - .globl __irq_rtc_alarm - .set __irq_rtc_alarm, __default_handler - .weak __irq_usb_wkup - .globl __irq_usb_wkup - .set __irq_usb_wkup, __default_handler - - .weak __irq_tim8_brk - .globl __irq_tim8_brk - .set __irq_tim8_brk, __default_handler - .weak __irq_tim8_up - .globl __irq_tim8_up - .set __irq_tim8_up, __default_handler - .weak __irq_tim8_trg_com - .globl __irq_tim8_trg_com - .set __irq_tim8_trg_com, __default_handler - .weak __irq_tim8_cc - .globl __irq_tim8_cc - .set __irq_tim8_cc, __default_handler - .weak __irq_adc3 - .globl __irq_adc3 - .set __irq_adc3, __default_handler - .weak __stm32reservedexception48 - .globl __stm32reservedexception48 - .set __stm32reservedexception48, __default_handler - .weak __stm32reservedexception49 - .globl __stm32reservedexception49 - .set __stm32reservedexception49, __default_handler - .weak __stm32reservedexception50 - .globl __stm32reservedexception50 - .set __stm32reservedexception50, __default_handler - .weak __irq_spi3 - .globl __irq_spi3 - .set __irq_spi3, __default_handler - .weak __irq_uart4 - .globl __irq_uart4 - .set __irq_uart4, __default_handler - .weak __irq_uart5 - .globl __irq_uart5 - .set __irq_uart5, __default_handler - .weak __irq_tim6_dacunder - .globl __irq_tim6_dacunder - .set __irq_tim6_dac, __default_handler - .weak __irq_tim7 - .globl __irq_tim7 - .set __irq_tim7, __default_handler - .weak __irq_dma2_ch1 - .globl __irq_dma2_ch1 - .set __irq_dma2_ch1, __default_handler - .weak __irq_dma2_ch2 - .globl __irq_dma2_ch2 - .set __irq_dma2_ch2, __default_handler - .weak __irq_dma2_ch3 - .globl __irq_dma2_ch3 - .set __irq_dma2_ch3, __default_handler - .weak __irq_dma2_ch4 - .globl __irq_dma2_ch4 - .set __irq_dma2_ch4, __default_handler - .weak __irq_dma2_ch5 - .globl __irq_dma2_ch5 - .set __irq_dma2_ch5, __default_handler - .weak __irq_adc4 - .globl __irq_adc4 - .set __irq_adc4, __default_handler - .weak __stm32reservedexception62 - .globl __stm32reservedexception62 - .set __stm32reservedexception62, __default_handler - .weak __stm32reservedexception63 - .globl __stm32reservedexception63 - .set __stm32reservedexception63, __default_handler - .weak __irq_comp123 - .globl __irq_comp123 - .set __irq_comp123, __default_handler - .weak __irq_comp456 - .globl __irq_comp456 - .set __irq_comp456, __default_handler - .weak __irq_comp7 - .globl __irq_comp7 - .set __irq_comp7, __default_handler - .weak __stm32reservedexception67 - .globl __stm32reservedexception67 - .set __stm32reservedexception67, __default_handler - .weak __stm32reservedexception68 - .globl __stm32reservedexception68 - .set __stm32reservedexception68, __default_handler - .weak __stm32reservedexception69 - .globl __stm32reservedexception69 - .set __stm32reservedexception69, __default_handler - .weak __stm32reservedexception70 - .globl __stm32reservedexception70 - .set __stm32reservedexception70, __default_handler - .weak __stm32reservedexception71 - .globl __stm32reservedexception71 - .set __stm32reservedexception71, __default_handler - .weak __stm32reservedexception72 - .globl __stm32reservedexception72 - .set __stm32reservedexception72, __default_handler - .weak __stm32reservedexception73 - .globl __stm32reservedexception73 - .set __stm32reservedexception73, __default_handler - .weak __irq_usb_hp - .globl __irq_usb_hp - .set __irq_usb_hp, __default_handler - .weak __irq_usb_lp - .globl __irq_usb_lp - .set __irq_usb_lp, __default_handler - .weak __irq_usb_wkup2 - .globl __irq_usb_wkup2 - .set __irq_usb_wkup2, __default_handler - .weak __stm32reservedexception77 - .globl __stm32reservedexception77 - .set __stm32reservedexception77, __default_handler - .weak __stm32reservedexception78 - .globl __stm32reservedexception78 - .set __stm32reservedexception78, __default_handler - .weak __stm32reservedexception79 - .globl __stm32reservedexception79 - .set __stm32reservedexception79, __default_handler - .weak __stm32reservedexception80 - .globl __stm32reservedexception80 - .set __stm32reservedexception80, __default_handler - .weak __irq_fpu - .globl __irq_fpu - .set __irq_fpu, __default_handler - .weak __reserved - .globl __reserved - .set __reserved, __default_handler diff --git a/STM32F3/variants/discovery_f3/stm32_vector_table.S b/STM32F3/variants/discovery_f3/stm32_vector_table.S deleted file mode 100644 index f68fa4b..0000000 --- a/STM32F3/variants/discovery_f3/stm32_vector_table.S +++ /dev/null @@ -1,134 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ /* STM32F3 performance line vector table */ #include - .section ".stm32.interrupt_vector" - - .globl __stm32_vector_table - .type __stm32_vector_table, %object - -__stm32_vector_table: -/* CM4 core interrupts */ - .long __msp_init - .long __exc_reset - .long __exc_nmi - .long __exc_hardfault - .long __exc_memmanage - .long __exc_busfault - .long __exc_usagefault - .long __stm32reservedexception7 - .long __stm32reservedexception8 - .long __stm32reservedexception9 - .long __stm32reservedexception10 - .long __exc_svc - .long __exc_debug_monitor - .long __stm32reservedexception13 - .long __exc_pendsv - .long __exc_systick -/* Peripheral interrupts */ - .long __irq_wwdg - .long __irq_pvd - .long __irq_tamp_stamp - .long __irq_rtc_wkup - .long __irq_flash - .long __irq_rcc - .long __irq_exti0 - .long __irq_exti1 - .long __irq_exti2 - .long __irq_exti3 - .long __irq_exti4 - .long __irq_dma1_ch1 - .long __irq_dma1_ch2 - .long __irq_dma1_ch3 - .long __irq_dma1_ch4 - .long __irq_dma1_ch5 - .long __irq_dma1_ch6 - .long __irq_dma1_ch7 - .long __irq_adc1_2 - .long __irq_usb_hp_can_tx - .long __irq_usb_lp_can_rx0 - .long __irq_can_rx1 - .long __irq_can_sce - .long __irq_exti9_5 - .long __irq_tim1_brk_tim15 - .long __irq_tim1_up_tim16 - .long __irq_tim1_trg_com_tim17 - .long __irq_tim1_cc - .long __irq_tim2 - .long __irq_tim3 - .long __irq_tim4 - .long __irq_i2c1_ev - .long __irq_i2c1_er - .long __irq_i2c2_ev - .long __irq_i2c2_er - .long __irq_spi1 - .long __irq_spi2 - .long __irq_usart1 - .long __irq_usart2 - .long __irq_usart3 - .long __irq_exti15_10 - .long __irq_rtc_alarm - .long __irq_usb_wkup - - .long __irq_tim8_brk - .long __irq_tim8_up - .long __irq_tim8_trg_com - .long __irq_tim8_cc - .long __irq_adc3 - .long __stm32reservedexception48 - .long __stm32reservedexception49 - .long __stm32reservedexception50 - .long __irq_spi3 - .long __irq_uart4 - .long __irq_uart5 - .long __irq_tim6_dacunder - .long __irq_tim7 - .long __irq_dma2_ch1 - .long __irq_dma2_ch2 - .long __irq_dma2_ch3 - .long __irq_dma2_ch4 - .long __irq_dma2_ch5 - .long __irq_adc4 - .long __stm32reservedexception62 - .long __stm32reservedexception63 - .long __irq_comp123 - .long __irq_comp456 - .long __irq_comp7 - .long __stm32reservedexception67 - .long __stm32reservedexception68 - .long __stm32reservedexception69 - .long __stm32reservedexception70 - .long __stm32reservedexception71 - .long __stm32reservedexception72 - .long __stm32reservedexception73 - .long __irq_usb_hp - .long __irq_usb_lp - .long __irq_usb_wkup2 - .long __stm32reservedexception77 - .long __stm32reservedexception78 - .long __stm32reservedexception79 - .long __stm32reservedexception80 - .long __irq_fpu - - .size __stm32_vector_table, . - __stm32_vector_table diff --git a/STM32F3/variants/discovery_f3/wirish/start.S b/STM32F3/variants/discovery_f3/wirish/start.S deleted file mode 100644 index 8b181aa..0000000 --- a/STM32F3/variants/discovery_f3/wirish/start.S +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/* - * This file is a modified version of a file obtained from - * CodeSourcery Inc. (now part of Mentor Graphics Corp.), in which the - * following text appeared: - * - * The authors hereby grant permission to use, copy, modify, distribute, - * and license this software and its documentation for any purpose, provided - * that existing copyright notices are retained in all copies and that this - * notice is included verbatim in any distributions. No written agreement, - * license, or royalty fee is required for any of the authorized uses. - * Modifications to this software may be copyrighted by their authors - * and need not follow the licensing terms described here, provided that - * the new terms are clearly indicated on the first page of each file where - * they apply. - */ - - .text - .code 16 - .thumb_func - - .globl __start__ - .type __start__, %function -__start__: - .fnstart - ldr r1,=__msp_init - mov sp,r1 - ldr r1,=start_c - bx r1 - .pool - .cantunwind - .fnend diff --git a/STM32F3/variants/discovery_f3/wirish/start_c.c b/STM32F3/variants/discovery_f3/wirish/start_c.c deleted file mode 100644 index 655fefb..0000000 --- a/STM32F3/variants/discovery_f3/wirish/start_c.c +++ /dev/null @@ -1,95 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2011 LeafLabs, LLC. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/* - * This file is a modified version of a file obtained from - * CodeSourcery Inc. (now part of Mentor Graphics Corp.), in which the - * following text appeared: - * - * Copyright (c) 2006, 2007 CodeSourcery Inc - * - * The authors hereby grant permission to use, copy, modify, distribute, - * and license this software and its documentation for any purpose, provided - * that existing copyright notices are retained in all copies and that this - * notice is included verbatim in any distributions. No written agreement, - * license, or royalty fee is required for any of the authorized uses. - * Modifications to this software may be copyrighted by their authors - * and need not follow the licensing terms described here, provided that - * the new terms are clearly indicated on the first page of each file where - * they apply. - */ - -#include - -extern void __libc_init_array(void); - -extern int main(int, char**, char**); - -extern void exit(int) __attribute__((noreturn, weak)); - -/* The linker must ensure that these are at least 4-byte aligned. */ -extern char __data_start__, __data_end__; -extern char __bss_start__, __bss_end__; - -struct rom_img_cfg { - int *img_start; -}; - -extern char _lm_rom_img_cfgp; - -void __attribute__((noreturn)) start_c(void) { - struct rom_img_cfg *img_cfg = (struct rom_img_cfg*)&_lm_rom_img_cfgp; - int *src = img_cfg->img_start; - int *dst = (int*)&__data_start__; - int exit_code; - - /* Initialize .data, if necessary. */ - if (src != dst) { - int *end = (int*)&__data_end__; - while (dst < end) { - *dst++ = *src++; - } - } - - /* Zero .bss. */ - dst = (int*)&__bss_start__; - while (dst < (int*)&__bss_end__) { - *dst++ = 0; - } - - /* Run initializers. */ - __libc_init_array(); - - /* Jump to main. */ - exit_code = main(0, 0, 0); - if (exit) { - exit(exit_code); - } - - /* If exit is NULL, make sure we don't return. */ - for (;;) - continue; -}