From d44f856baffd72742d2287f75df5c2c5dff07a73 Mon Sep 17 00:00:00 2001 From: AJM Date: Fri, 21 May 2010 19:09:35 -0400 Subject: Finalized the libmaple changes required by newboot. Added setupUSB() to wirish init this involved some some changes to copy-to-ide, WProgram.h, and the makefile. Separated the reset.py from the wait.py so that the program closes the serial port correctly. --- Makefile | 9 +++- copy-to-ide | 50 +++++++++++----------- notes/45-maple.rules | 1 + reset.py | 21 --------- wait.py | 7 +++ wirish/WProgram.h | 2 - wirish/comm/HardwareUsb.cpp | 102 -------------------------------------------- wirish/comm/HardwareUsb.h | 54 ----------------------- wirish/wirish.c | 2 + 9 files changed, 41 insertions(+), 207 deletions(-) create mode 100755 wait.py delete mode 100644 wirish/comm/HardwareUsb.cpp delete mode 100644 wirish/comm/HardwareUsb.h diff --git a/Makefile b/Makefile index 379013c..b85e28e 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ OD := arm-none-eabi-objdump ARCH = $(shell uname -m) OS = $(shell uname) +VENDOR_ID = 1EAF +PRODUCT_ID = 0003 + ifeq ($(OS),Linux) DFU = dfu-util else @@ -195,11 +198,13 @@ jtag: $(BUILD_PATH)/main.bin @echo "JTAG build" program_ram: ram -# ./reset.py - $(DFU) -a0 -d 0110:1001 -D build/main.bin -R + ./reset.py + ./wait.py + $(DFU) -a0 -d $(VENDOR_ID):$(PRODUCT_ID) -D build/main.bin -R program_flash: flash ./reset.py + ./wait.py $(DFU) -a1 -d 0110:1001 -D build/main.bin -R program_jtag: jtag diff --git a/copy-to-ide b/copy-to-ide index e4d5bd0..7c1565b 100755 --- a/copy-to-ide +++ b/copy-to-ide @@ -40,28 +40,28 @@ FILES="LICENSE ./libmaple/adc.c ./libmaple/flash.c ./libmaple/gpio.c - ./wirish/usb/usb_lib/usb_core.c - ./wirish/usb/usb_lib/usb_core.h - ./wirish/usb/usb_lib/usb_def.h - ./wirish/usb/usb_lib/usb_init.c - ./wirish/usb/usb_lib/usb_init.h - ./wirish/usb/usb_lib/usb_int.c - ./wirish/usb/usb_lib/usb_int.h - ./wirish/usb/usb_lib/usb_lib.h - ./wirish/usb/usb_lib/usb_mem.c - ./wirish/usb/usb_lib/usb_mem.h - ./wirish/usb/usb_lib/usb_regs.c - ./wirish/usb/usb_lib/usb_regs.h - ./wirish/usb/usb_lib/usb_type.h - ./wirish/usb/descriptors.c - ./wirish/usb/descriptors.h - ./wirish/usb/usb_callbacks.h - ./wirish/usb/usb_callbacks.c - ./wirish/usb/usb_config.h - ./wirish/usb/usb.h - ./wirish/usb/usb.c - ./wirish/usb/usb_hardware.c - ./wirish/usb/usb_hardware.h + ./libmaple/usb/usb_lib/usb_core.c + ./libmaple/usb/usb_lib/usb_core.h + ./libmaple/usb/usb_lib/usb_def.h + ./libmaple/usb/usb_lib/usb_init.c + ./libmaple/usb/usb_lib/usb_init.h + ./libmaple/usb/usb_lib/usb_int.c + ./libmaple/usb/usb_lib/usb_int.h + ./libmaple/usb/usb_lib/usb_lib.h + ./libmaple/usb/usb_lib/usb_mem.c + ./libmaple/usb/usb_lib/usb_mem.h + ./libmaple/usb/usb_lib/usb_regs.c + ./libmaple/usb/usb_lib/usb_regs.h + ./libmaple/usb/usb_lib/usb_type.h + ./libmaple/usb/descriptors.c + ./libmaple/usb/descriptors.h + ./libmaple/usb/usb_callbacks.h + ./libmaple/usb/usb_callbacks.c + ./libmaple/usb/usb_config.h + ./libmaple/usb/usb.h + ./libmaple/usb/usb.c + ./libmaple/usb/usb_hardware.c + ./libmaple/usb/usb_hardware.h ./wirish/bits.h ./wirish/ext_interrupts.c ./wirish/ext_interrupts.h @@ -85,9 +85,7 @@ FILES="LICENSE ./wirish/comm/HardwareSerial.cpp ./wirish/comm/HardwareSerial.h ./wirish/comm/HardwareSPI.cpp - ./wirish/comm/HardwareSPI.h - ./wirish/comm/HardwareUsb.cpp - ./wirish/comm/HardwareUsb.h" + ./wirish/comm/HardwareSPI.h" # First see if this folder exists if !(test -d $DEST/lanchon-stm32) @@ -105,7 +103,7 @@ cp -v $FILES $DEST # if a working directory already exists, copy in there too so we # dont have to rebuild the ide just to change the lib out -if (test -d $DEST_WORD) +if (test -d $WORK_DEST) then # Then copy over linker files cp -v stm32conf/* $WORK_DEST diff --git a/notes/45-maple.rules b/notes/45-maple.rules index e1d3638..e3032b9 100644 --- a/notes/45-maple.rules +++ b/notes/45-maple.rules @@ -2,5 +2,6 @@ BUS!="usb", ACTION!="add", SUBSYSTEM!=="usb_device", GOTO="maple_rules_end" SYSFS{idProduct}=="1001", SYSFS{idVendor}=="0110", MODE="664", GROUP="plugdev" SYSFS{idProduct}=="1002", SYSFS{idVendor}=="0110", MODE="664", GROUP="plugdev" +SYSFS{idProduct}=="0003", SYSFS{idVendor}=="1EAF", MODE="664", GROUP="plugdev" LABEL="maple_rules_end" diff --git a/reset.py b/reset.py index a7447d0..1a4d515 100755 --- a/reset.py +++ b/reset.py @@ -13,27 +13,6 @@ ser.setDTR(0) # toggle DTR ser.setDTR(1) -# Some versions of python seem to throw an IOError on this line. -# I have no idea why and don't have any time to look at it. -# Just catch it for now. -# -# Error msg: -# -# Traceback (most recent call last): -# File "./reset.py", line 15, in -# ser.setDTR(0) -# File "/usr/lib/python2.6/dist-packages/serial/serialposix.py", line 388, in setDTR -# fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_DTR_str) -# IOError: [Errno 84] Invalid or incomplete multibyte or wide character - -try: - ser.setDTR(0) -except IOError: - print "IOError caught" - # close ser.close() -time.sleep(1) - -print "Done" diff --git a/wait.py b/wait.py new file mode 100755 index 0000000..3347089 --- /dev/null +++ b/wait.py @@ -0,0 +1,7 @@ +#!/usr/bin/python + +import time + +time.sleep(1) + +print "Done" diff --git a/wirish/WProgram.h b/wirish/WProgram.h index 6f0b913..36a9e6d 100644 --- a/wirish/WProgram.h +++ b/wirish/WProgram.h @@ -24,9 +24,7 @@ #include "wirish.h" #include "HardwareSerial.h" -#include "HardwareUsb.h" #include "math.h" -#include "usb.h" void setup(); void loop(); diff --git a/wirish/comm/HardwareUsb.cpp b/wirish/comm/HardwareUsb.cpp deleted file mode 100644 index 4398e96..0000000 --- a/wirish/comm/HardwareUsb.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* ***************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Andrew Meyer. - * - * 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 Wiring like serial api to USB virtual COM - */ - -#include "wirish.h" -#include "HardwareUsb.h" -#include "bootVect.h" -#include "usb.h" - -HardwareUsb::HardwareUsb(void) { - mapleVectTable = (BootVectTable*)(BOOTLOADER_VECT_TABLE); - mapleVectTable->serial_tx_cb = usb_tx_cb; - mapleVectTable->serial_rx_cb = usb_rx_cb; - mapleVectTable->usb_local_obj_ptr = this; - rx_buffer_offset_in = 0; - rx_buffer_offset_out = 0; -} - -uint8 HardwareUsb::read(void) { - uint8 outVal = rx_buffer[rx_buffer_offset_out++]; - -#if 1 - if (rx_buffer_offset_out == rx_buffer_offset_in) { - flush(); - } -#endif - - return outVal; -} - -uint8 HardwareUsb::available(void) { - ASSERT(rx_buffer_offset_out >= 0); - // return rx_buffer_offset+1; - // return usb_serialGetRecvLen(); - return rx_buffer_offset_in - rx_buffer_offset_out; -} - -void HardwareUsb::flush(void) { - rx_buffer_offset_in = 0; - rx_buffer_offset_out = 0; -} - -void HardwareUsb::write(unsigned char ch) { - usb_serialWriteChar(ch); -} - -void HardwareUsb::begin(void) { - /* placeholder for usb<->uart linking */ -} - -void HardwareUsb::usb_rx_cb(void) { - BootVectTable *vectTable = (BootVectTable*)(BOOTLOADER_VECT_TABLE); - HardwareUsb *thisPtr = (HardwareUsb*) vectTable->usb_local_obj_ptr; - - uint8 numBytes = usb_serialGetRecvLen(); - -#if 0 - /* ONE-SHOT-TO-READ Version (buffer cleared on next recv interrupt */ - usb_copyRecvBuffer(thisPtr->rx_buffer,numBytes); - thisPtr->rx_buffer_offset_in = numBytes; - thisPtr->rx_buffer_offset_out = 0; -#else - /* FIFO DISCARD OVERFLOW VERSION */ - if ((thisPtr->rx_buffer_offset_in + numBytes) > (USB_SERIAL_BUF_SIZE)) { - numBytes = USB_SERIAL_BUF_SIZE - thisPtr->rx_buffer_offset_in; - } - - if (numBytes > 0) { - ASSERT(thisPtr->rx_buffer_offset_in <= USB_SERIAL_BUF_SIZE); - usb_copyRecvBuffer(&(thisPtr->rx_buffer[thisPtr->rx_buffer_offset_in]),numBytes); - thisPtr->rx_buffer_offset_in += numBytes; - } -#endif -} - -void HardwareUsb::usb_tx_cb(void) { - /* placeholder for when serial dumps exceed buflen */ -} diff --git a/wirish/comm/HardwareUsb.h b/wirish/comm/HardwareUsb.h deleted file mode 100644 index ee13f40..0000000 --- a/wirish/comm/HardwareUsb.h +++ /dev/null @@ -1,54 +0,0 @@ -/* ***************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Andrew Meyer. - * - * 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 Wiring like serial api to USB virtual COM - */ - -#ifndef _HARDWAREUSB_H_ -#define _HARDWAREUSB_H_ - -#include "Print.h" -#include "bootVect.h" -#include "usb.h" - -class HardwareUsb : public Print { - private: - BootVectTable* mapleVectTable; - static void usb_rx_cb(void); - static void usb_tx_cb(void); - unsigned char rx_buffer[USB_SERIAL_BUF_SIZE]; - int8 rx_buffer_offset_out; - int8 rx_buffer_offset_in; - public: - HardwareUsb(void); - void begin(); - uint8 available(void); - uint8 read(void); - void flush(void); - virtual void write(unsigned char); - using Print::write; -}; - -#endif //_HARDWAREUSB_H diff --git a/wirish/wirish.c b/wirish/wirish.c index 3cfc12e..e21f792 100644 --- a/wirish/wirish.c +++ b/wirish/wirish.c @@ -31,6 +31,7 @@ #include "systick.h" #include "gpio.h" #include "nvic.h" +#include "usb.h" void init(void) { rcc_init(); @@ -42,4 +43,5 @@ void init(void) { timer_init(2, 1); timer_init(3, 1); timer_init(4, 1); + setupUSB(); } -- cgit v1.2.3