diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 23 | ||||
-rw-r--r-- | examples/vga-leaf.cpp | 4 | ||||
-rw-r--r-- | libmaple/libmaple.h | 4 | ||||
-rw-r--r-- | libmaple/systick.c | 6 | ||||
-rw-r--r-- | libmaple/systick.h | 1 | ||||
-rw-r--r-- | libmaple/usart.c | 38 | ||||
-rw-r--r-- | support/make/build-rules.mk | 3 | ||||
-rw-r--r-- | support/openocd/flash.cfg | 2 | ||||
-rwxr-xr-x | support/scripts/reset.py | 65 | ||||
-rw-r--r-- | wirish/HardwareTimer.cpp | 2 | ||||
-rw-r--r-- | wirish/SystemTick.cpp | 40 | ||||
-rw-r--r-- | wirish/SystemTick.h | 43 | ||||
-rw-r--r-- | wirish/boards.h | 7 | ||||
-rw-r--r-- | wirish/rules.mk | 5 | ||||
-rw-r--r-- | wirish/time.h | 1 | ||||
-rw-r--r-- | wirish/wirish.h | 1 |
17 files changed, 200 insertions, 46 deletions
@@ -3,4 +3,5 @@ main.cpp libmaple.layout tags TAGS +*~ *.swp
\ No newline at end of file @@ -19,9 +19,14 @@ ifeq ($(BOARD), maple_native) endif # Useful paths +ifeq ($(LIB_MAPLE_HOME),) SRCROOT := $(dir) +else +SRCROOT := $(LIB_MAPLE_HOME) +endif BUILD_PATH = build -LIBMAPLE_PATH := libmaple +LIBMAPLE_PATH := $(SRCROOT)/libmaple +SUPPORT_PATH := $(SRCROOT)/support # Useful variables GLOBAL_CFLAGS := -Os -g -mcpu=cortex-m3 -mthumb -march=armv7-m -nostdlib \ @@ -30,14 +35,14 @@ GLOBAL_CFLAGS := -Os -g -mcpu=cortex-m3 -mthumb -march=armv7-m -nostdlib \ GLOBAL_CXXFLAGS := -fno-rtti -fno-exceptions -Wall -DBOARD_$(BOARD) -DMCU_$(MCU) -LDDIR := support/ld +LDDIR := $(SUPPORT_PATH)/ld LDFLAGS = -T$(LDDIR)/$(LDSCRIPT) -L$(LDDIR) \ -mcpu=cortex-m3 -mthumb -Xlinker \ --gc-sections --print-gc-sections --march=armv7-m -Wall # Set up build rules and some useful templates -include support/make/build-rules.mk -include support/make/build-templates.mk +include $(SUPPORT_PATH)/make/build-rules.mk +include $(SUPPORT_PATH)/make/build-templates.mk # Some target specific things ifeq ($(MEMORY_TARGET), ram) @@ -54,22 +59,22 @@ ifeq ($(MEMORY_TARGET), jtag) endif # Set all submodules here -LIBMAPLE_MODULES := libmaple -LIBMAPLE_MODULES += wirish +LIBMAPLE_MODULES := $(SRCROOT)/libmaple +LIBMAPLE_MODULES += $(SRCROOT)/wirish # call each module rules.mk $(foreach m,$(LIBMAPLE_MODULES),$(eval $(call LIBMAPLE_MODULE_template,$(m)))) # Main target -include support/make/build-targets.mk +include $(SUPPORT_PATH)/make/build-targets.mk .PHONY: install sketch clean help debug cscope tags ctags ram flash jtag # Target upload commands -UPLOAD_ram := support/scripts/reset.py && \ +UPLOAD_ram := $(SUPPORT_PATH)/scripts/reset.py && \ sleep 1 && \ $(DFU) -a0 -d $(VENDOR_ID):$(PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R -UPLOAD_flash := support/scripts/reset.py && \ +UPLOAD_flash := $(SUPPORT_PATH)/scripts/reset.py && \ sleep 1 && \ $(DFU) -a1 -d $(VENDOR_ID):$(PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R UPLOAD_jtag := $(OPENOCD) -f support/openocd/flash.cfg diff --git a/examples/vga-leaf.cpp b/examples/vga-leaf.cpp index 16204ba..d1c6d7d 100644 --- a/examples/vga-leaf.cpp +++ b/examples/vga-leaf.cpp @@ -86,7 +86,6 @@ uint8 logo[18][16] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}, }; void setup() { - // Setup our pins pinMode(LED_PIN, OUTPUT); pinMode(VGA_R, OUTPUT); @@ -101,9 +100,8 @@ void setup() { digitalWrite(VGA_V, HIGH); // This gets rid of the majority of the interrupt artifacts; - // a SysTick.end() is required as well SerialUSB.end(); - + SystemTick.end(); // Configure Timer4.pause(); // while we configure diff --git a/libmaple/libmaple.h b/libmaple/libmaple.h index 437566f..3a4042a 100644 --- a/libmaple/libmaple.h +++ b/libmaple/libmaple.h @@ -74,7 +74,7 @@ // Debug port settings (from ASSERT) #define ERROR_LED_PORT GPIOA_BASE #define ERROR_LED_PIN 5 - #define ERROR_USART_NUM 2 + #define ERROR_USART_NUM USART2 #define ERROR_USART_BAUD 9600 #define ERROR_TX_PIN 2 #define ERROR_TX_PORT GPIOA_BASE @@ -113,7 +113,7 @@ #define ERROR_LED_PORT GPIOC_BASE #define ERROR_LED_PIN 15 - #define ERROR_USART_NUM 1 + #define ERROR_USART_NUM USART1 #define ERROR_USART_BAUD 9600 #define ERROR_TX_PIN 10 #define ERROR_TX_PORT GPIOA_BASE diff --git a/libmaple/systick.c b/libmaple/systick.c index 8b0d92a..456ac2f 100644 --- a/libmaple/systick.c +++ b/libmaple/systick.c @@ -52,6 +52,12 @@ void systick_init(uint32 reload_val) { SYSTICK_TICKINT); } +void systick_disable() { + /* clock the system timer with the core clock, but don't turn it on + or enable interrupt. */ + __write(SYSTICK_CSR, SYSTICK_SRC_HCLK); +} + void SysTickHandler(void) { systick_timer_millis++; } diff --git a/libmaple/systick.h b/libmaple/systick.h index 57b724a..86284f8 100644 --- a/libmaple/systick.h +++ b/libmaple/systick.h @@ -43,6 +43,7 @@ extern "C"{ #endif void systick_init(uint32 reload_val); +void systick_disable(); static inline uint32 systick_get_count(void) { return __read(SYSTICK_CNT); diff --git a/libmaple/usart.c b/libmaple/usart.c index d08d3cf..ef54ad0 100644 --- a/libmaple/usart.c +++ b/libmaple/usart.c @@ -33,18 +33,18 @@ #include "nvic.h" #include "usart.h" -#define USART1_BASE 0x40013800 -#define USART2_BASE 0x40004400 -#define USART3_BASE 0x40004800 -#define UART4_BASE 0x40004C00 // High-density devices only (Maple Native) -#define UART5_BASE 0x40005000 // High-density devices only (Maple Native) - -#define USART_UE BIT(13) -#define USART_M BIT(12) -#define USART_TE BIT(3) -#define USART_RE BIT(2) -#define USART_RXNEIE BIT(5) // read data register not empty interrupt enable -#define USART_TC BIT(6) +#define USART1_BASE 0x40013800 +#define USART2_BASE 0x40004400 +#define USART3_BASE 0x40004800 +#define UART4_BASE 0x40004C00 // High-density devices only (Maple Native) +#define UART5_BASE 0x40005000 // High-density devices only (Maple Native) + +#define USART_UE BIT(13) +#define USART_M BIT(12) +#define USART_TE BIT(3) +#define USART_RE BIT(2) +#define USART_RXNEIE BIT(5) // read data register not empty interrupt enable +#define USART_TC BIT(6) /* usart descriptor table */ struct usart_dev usart_dev_table[] = { @@ -63,6 +63,7 @@ struct usart_dev usart_dev_table[] = { .rcc_dev_num = RCC_USART3, .nvic_dev_num = NVIC_USART3 }, + /* #if NR_USART >= 5 [UART4] = { .base = (usart_port*)UART4_BASE, @@ -75,6 +76,7 @@ struct usart_dev usart_dev_table[] = { .nvic_dev_num = NVIC_UART5 }, #endif + */ }; /* usart interrupt handlers */ @@ -148,12 +150,12 @@ void usart_init(uint8 usart_num, uint32 baud) { * @brief Turn off all USARTs. */ void usart_disable_all() { - usart_disable(1); - usart_disable(2); - usart_disable(3); + usart_disable(USART1); + usart_disable(USART2); + usart_disable(USART3); #if NR_USART >= 5 - usart_disable(4); - usart_disable(5); + usart_disable(UART4); + usart_disable(UART5); #endif } @@ -165,7 +167,7 @@ void usart_disable(uint8 usart_num) { usart_port *port = usart_dev_table[usart_num].base; /* TC bit must be high before disabling the usart */ - while ((port->SR & USART_TC) == 0) + while((port->CR1 & USART_UE) && !(port->SR & USART_TC)) ; /* Disable UE */ diff --git a/support/make/build-rules.mk b/support/make/build-rules.mk index 274152c..3892af9 100644 --- a/support/make/build-rules.mk +++ b/support/make/build-rules.mk @@ -23,9 +23,6 @@ ifndef V SILENT_OBJDUMP = @echo ' [OBJDUMP] ' $(OBJDUMP); endif -DFU := dfu-util -OPENOCD := openocd - BUILDDIRS := TGT_BIN := diff --git a/support/openocd/flash.cfg b/support/openocd/flash.cfg index fcd9561..41c6532 100644 --- a/support/openocd/flash.cfg +++ b/support/openocd/flash.cfg @@ -64,7 +64,7 @@ target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNA $_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size 0x5000 -work-area-backup 0 # TODO: native -$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size 0x10000 -work-area-backup 0 +#$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size 0x10000 -work-area-backup 0 flash bank stm32x 0x08000000 0x00020000 0 0 $_TARGETNAME diff --git a/support/scripts/reset.py b/support/scripts/reset.py index cc944ee..9be5607 100755 --- a/support/scripts/reset.py +++ b/support/scripts/reset.py @@ -1,13 +1,69 @@ #!/usr/bin/python -# NOTE: On Mac OSX this script must be run as sudo? - import serial import os +import sys from struct import pack +def get_maple_device_path(file_prefix): + """Try to find the device file for the Maple on OS X; assuming + that it looks like /dev/<file_prefix>*. If there are multiple + possibilities, ask the user what to do. If the user chooses not + to say, returns None.""" + possible_paths = [os.path.join('/dev', x) for x in os.listdir('/dev') \ + if x.startswith(file_prefix)] + if len(possible_paths) == 0: + return None + elif len(possible_paths) == 1: + return possible_paths[0] + else: + print 'Found multiple candidates for the Maple device:' + for (i,p) in enumerate(possible_paths): + print '\t%d. %s' % (i+1, p) + + prompt = 'Enter a number to select one, or q to quit: ' + while True: + resp = raw_input(prompt).strip().lower() + if resp == 'q': return None + + try: + i = int(resp, 10) + except ValueError: + pass + else: + if 0 <= i-1 < len(possible_paths): + return possible_paths[i-1] + + prompt = 'Please enter a number from the list, or q to quit: ' + +os_sysname = os.uname()[0] +if os_sysname == 'Linux': + maple_path = get_maple_device_path('ttyACM') + # fall back on /dev/maple if that doesn't work + if maple_path is None: + maple_path = '/dev/maple' + print 'Could not find Maple serial port; defaulting to /dev/maple.' +elif os_sysname == 'Darwin': + maple_path = get_maple_device_path('tty.usbmodem') +else: + # TODO [mbolivar] what to do for windows, BSD, whatever? + maple_path = '/dev/maple' + +if maple_path is None: + print 'Could not find the Maple serial port for reset.', \ + 'Perhaps this is your first upload, or the board is already', \ + 'in bootloader mode.' + print + print "If your sketch doesn't upload, try putting your Maple", \ + 'into bootloader mode manually by pressing the RESET button', \ + 'then letting it go and quickly pressing button BUT', \ + '(hold for several seconds).' + sys.exit() + +print 'Using %s as Maple serial port' % maple_path + try: - ser = serial.Serial('/dev/maple', baudrate=115200, xonxoff=1) + ser = serial.Serial(maple_path, baudrate=115200, xonxoff=1) ser.open() # try to toggle DTR/RTS (old scheme) @@ -26,5 +82,6 @@ try: ser.close() except: - print "Failed to open the serial port for reset, perhaps this is your first upload or the board was already in bootloader mode" + print 'Failed to open serial port %s for reset.' % maple_path + sys.exit() diff --git a/wirish/HardwareTimer.cpp b/wirish/HardwareTimer.cpp index 5675948..64fa222 100644 --- a/wirish/HardwareTimer.cpp +++ b/wirish/HardwareTimer.cpp @@ -32,7 +32,7 @@ #include "HardwareTimer.h" HardwareTimer::HardwareTimer(uint8 timerNum) { - ASSERT(timerNum < NR_TIMERS); + ASSERT(timerNum <= NR_TIMERS); this->timerNum = timerNum; // Need to remember over flow for bounds checking this->overflow = 0xFFFF; diff --git a/wirish/SystemTick.cpp b/wirish/SystemTick.cpp new file mode 100644 index 0000000..8631a70 --- /dev/null +++ b/wirish/SystemTick.cpp @@ -0,0 +1,40 @@ +/* ***************************************************************************** + * The MIT License + * + * Copyright (c) 2010 Marti F. Bolivar. + * + * 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 "SystemTick.h" +#include "systick.h" +#include "time.h" + +SysTick::SysTick(void) { +} + +void SysTick::begin(void) { + systick_init(MAPLE_RELOAD_VAL); +} + +void SysTick::end(void) { + systick_disable(); +} + +SysTick SystemTick; diff --git a/wirish/SystemTick.h b/wirish/SystemTick.h new file mode 100644 index 0000000..f0dd876 --- /dev/null +++ b/wirish/SystemTick.h @@ -0,0 +1,43 @@ +/* ***************************************************************************** + * The MIT License + * + * Copyright (c) 2010 Marti F. Bolivar. + * + * 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 wrapper class for starting and stopping SysTick interrupts. + */ + +#ifndef _SYSTEMTICK_H_ +#define _SYSTEMTICK_H_ + +#include "systick.h" + +class SysTick { + public: + SysTick(void); + void begin(void); + void end(void); +}; + +extern SysTick SystemTick; + +#endif diff --git a/wirish/boards.h b/wirish/boards.h index 035868a..11d1774 100644 --- a/wirish/boards.h +++ b/wirish/boards.h @@ -75,8 +75,9 @@ typedef struct ExtiInfo { #ifdef BOARD_maple #define CYCLES_PER_MICROSECOND 72 + #define MAPLE_RELOAD_VAL 72000 - static PinMapping PIN_MAP[NR_GPIO_PINS] = { + static __attribute__ ((unused)) PinMapping PIN_MAP[NR_GPIO_PINS] = { {GPIOA_BASE, 3, ADC3, TIMER2_CH4_CCR}, // D0/PA3 {GPIOA_BASE, 2, ADC2, TIMER2_CH3_CCR}, // D1/PA2 {GPIOA_BASE, 0, ADC0, TIMER2_CH1_CCR}, // D2/PA0 @@ -120,7 +121,8 @@ typedef struct ExtiInfo { {GPIOC_BASE, 9, ADC_INVALID, TIMER_INVALID} // D38/PC9 (BUT) }; - static ExtiInfo PIN_TO_EXTI_CHANNEL[NR_GPIO_PINS] = { + static __attribute__ ((unused)) ExtiInfo PIN_TO_EXTI_CHANNEL[NR_GPIO_PINS] = + { {EXTI3, EXTI_CONFIG_PORTA}, // D0/PA3 {EXTI2, EXTI_CONFIG_PORTA}, // D1/PA2 {EXTI0, EXTI_CONFIG_PORTA}, // D2/PA0 @@ -143,6 +145,7 @@ typedef struct ExtiInfo { #ifdef BOARD_maple_native #define CYCLES_PER_MICROSECOND 72 + #define MAPLE_RELOAD_VAL 72000 // TODO: static PinMapping PIN_MAP[NR_GPIO_PINS] = { diff --git a/wirish/rules.mk b/wirish/rules.mk index b2110bd..18d93b2 100644 --- a/wirish/rules.mk +++ b/wirish/rules.mk @@ -24,8 +24,9 @@ cppSRCS_$(d) := wirish_math.cpp \ comm/HardwareSerial.cpp \ comm/HardwareSPI.cpp \ usb_serial.cpp \ - HardwareTimer.cpp \ - cxxabi-compat.cpp + HardwareTimer.cpp \ + cxxabi-compat.cpp \ + SystemTick.cpp cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%) cppFILES_$(d) := $(cppSRCS_$(d):%=$(d)/%) diff --git a/wirish/time.h b/wirish/time.h index 33c04b4..f73d133 100644 --- a/wirish/time.h +++ b/wirish/time.h @@ -38,7 +38,6 @@ extern "C"{ #include "boards.h" #define US_PER_MS 1000 -#define MAPLE_RELOAD_VAL (CYCLES_PER_MICROSECOND * US_PER_MS) extern volatile uint32 systick_timer_millis; diff --git a/wirish/wirish.h b/wirish/wirish.h index 7ede77c..d293901 100644 --- a/wirish/wirish.h +++ b/wirish/wirish.h @@ -45,6 +45,7 @@ #include "HardwareSPI.h" #include "HardwareSerial.h" #include "usb_serial.h" +#include "SystemTick.h" #include "HardwareTimer.h" #endif |