From 46b9f96d4a76198d2cde117bdd6d029caab1c3c0 Mon Sep 17 00:00:00 2001 From: Thibaut VIARD Date: Sat, 28 Apr 2012 20:15:23 +0200 Subject: [PATCH] [sam] intermediate commit --- hardware/arduino/sam/boards.txt | 8 +- hardware/arduino/sam/cores/sam/Arduino.h | 16 +- hardware/arduino/sam/cores/sam/Platform.h | 19 --- hardware/arduino/sam/cores/sam/USB/CDC.cpp | 94 ++++++------ hardware/arduino/sam/cores/sam/USB/HID.cpp | 24 ++- hardware/arduino/sam/cores/sam/USB/USBAPI.h | 20 ++- .../USB/{USBCore.cpp.disabled => USBCore.cpp} | 18 +-- hardware/arduino/sam/cores/sam/USB/USBCore.h | 144 +++++++++--------- .../sam/build_gcc/libarduino_arduino_due_x.mk | 9 +- .../sam/system/libsam/include/uotghs.h | 1 - .../arduino/sam/system/libsam/source/uotghs.c | 18 ++- .../sam/variants/arduino_due_x/variant.h | 3 + 12 files changed, 194 insertions(+), 180 deletions(-) delete mode 100644 hardware/arduino/sam/cores/sam/Platform.h rename hardware/arduino/sam/cores/sam/USB/{USBCore.cpp.disabled => USBCore.cpp} (97%) diff --git a/hardware/arduino/sam/boards.txt b/hardware/arduino/sam/boards.txt index 231d86cc7..5a57940f5 100644 --- a/hardware/arduino/sam/boards.txt +++ b/hardware/arduino/sam/boards.txt @@ -7,10 +7,12 @@ arduino_due_u.upload.maximum_size=49152 arduino_due_u.build.mcu=cortex-m3 arduino_due_u.build.f_cpu=96000000L arduino_due_u.build.core=sam -arduino_due_u.build.extra_flags=-D__SAM3U4E__ -mthumb +arduino_due_u.build.extra_flags=-D__SAM3U4E__ -mthumb arduino_due_u.build.ldscript=linker_scripts/gcc/flash.ld arduino_due_u.build.variant=arduino_due_u arduino_due_u.build.variant_system_lib=libsam_sam3u4e_gcc_rel.a +arduino_due_u.build.vid=0x2341 +arduino_due_u.build.pid=0xcafe ############################################################## @@ -21,7 +23,9 @@ arduino_due_x.upload.maximum_size=49152 arduino_due_x.build.mcu=cortex-m3 arduino_due_x.build.f_cpu=84000000L arduino_due_x.build.core=sam -arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb +arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb arduino_due_x.build.ldscript=linker_scripts/gcc/flash.ld arduino_due_x.build.variant=arduino_due_x arduino_due_x.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a +arduino_due_x.build.vid=0x2341 +arduino_due_x.build.pid=0xcafe diff --git a/hardware/arduino/sam/cores/sam/Arduino.h b/hardware/arduino/sam/cores/sam/Arduino.h index 970ac0ad0..2916de028 100644 --- a/hardware/arduino/sam/cores/sam/Arduino.h +++ b/hardware/arduino/sam/cores/sam/Arduino.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2011 Arduino. All right reserved. + Copyright (c) 2012 Arduino. 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 @@ -8,7 +8,7 @@ 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. + 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 @@ -198,4 +198,16 @@ extern const PinDescription g_APinDescription[] ; // Include board variant #include "variant.h" +#if defined USBCON + #define USB_VID 0x2341 // arduino LLC vid + + #define USB_PID_LEONARDO 0x0034 + #define USB_PID_MICRO 0x0035 + #define USB_PID_DUE 0xcafe + + #include "USBDesc.h" + #include "USBCore.h" + #include "USBAPI.h" +#endif // if defined USBCON + #endif // Arduino_h diff --git a/hardware/arduino/sam/cores/sam/Platform.h b/hardware/arduino/sam/cores/sam/Platform.h deleted file mode 100644 index e334dcad1..000000000 --- a/hardware/arduino/sam/cores/sam/Platform.h +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef __PLATFORM_H__ -#define __PLATFORM_H__ - -#include - -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned long u32; - -#include "Arduino.h" - -#if defined(USBCON) - #include "USBDesc.h" - #include "USBCore.h" - #include "USBAPI.h" -#endif /* if defined(USBCON) */ - -#endif diff --git a/hardware/arduino/sam/cores/sam/USB/CDC.cpp b/hardware/arduino/sam/cores/sam/USB/CDC.cpp index 13a3d3afd..4ad930e89 100644 --- a/hardware/arduino/sam/cores/sam/USB/CDC.cpp +++ b/hardware/arduino/sam/cores/sam/USB/CDC.cpp @@ -1,37 +1,30 @@ - - -/* Copyright (c) 2011, Peter Barrett -** -** Permission to use, copy, modify, and/or distribute this software for -** any purpose with or without fee is hereby granted, provided that the -** above copyright notice and this permission notice appear in all copies. -** -** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL -** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED -** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR -** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES -** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -** SOFTWARE. +/* Copyright (c) 2011, Peter Barrett +** +** Permission to use, copy, modify, and/or distribute this software for +** any purpose with or without fee is hereby granted, provided that the +** above copyright notice and this permission notice appear in all copies. +** +** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +** SOFTWARE. */ +#include "Arduino.h" + #if defined(USBCON) -#include "Platform.h" -#include "USBAPI.h" -#include #ifdef CDC_ENABLED -#if (RAMEND < 1000) -#define SERIAL_BUFFER_SIZE 16 -#else -#define SERIAL_BUFFER_SIZE 64 -#endif +#define CDC_SERIAL_BUFFER_SIZE 64 struct ring_buffer { - unsigned char buffer[SERIAL_BUFFER_SIZE]; + unsigned char buffer[CDC_SERIAL_BUFFER_SIZE]; volatile int head; volatile int tail; }; @@ -40,19 +33,16 @@ ring_buffer cdc_rx_buffer = { { 0 }, 0, 0}; typedef struct { - u32 dwDTERate; - u8 bCharFormat; - u8 bParityType; - u8 bDataBits; - u8 lineState; + uint32_t dwDTERate; + uint8_t bCharFormat; + uint8_t bParityType; + uint8_t bDataBits; + uint8_t lineState; } LineInfo; static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 }; -#define WEAK __attribute__ ((weak)) - -extern const CDCDescriptor _cdcInterface PROGMEM; -const CDCDescriptor _cdcInterface = +static const CDCDescriptor _cdcInterface = { D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1), @@ -70,7 +60,7 @@ const CDCDescriptor _cdcInterface = D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,0) }; -int WEAK CDC_GetInterface(u8* interfaceNum) +int WEAK CDC_GetInterface(uint8_t* interfaceNum) { interfaceNum[0] += 2; // uses 2 return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface)); @@ -78,8 +68,8 @@ int WEAK CDC_GetInterface(u8* interfaceNum) bool WEAK CDC_Setup(Setup& setup) { - u8 r = setup.bRequest; - u8 requestType = setup.bmRequestType; + uint8_t r = setup.bRequest; + uint8_t requestType = setup.bmRequestType; if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType) { @@ -102,24 +92,30 @@ bool WEAK CDC_Setup(Setup& setup) { _usbLineInfo.lineState = setup.wValueL; - // auto-reset into the bootloader is triggered when the port, already + // auto-reset into the bootloader is triggered when the port, already // open at 1200 bps, is closed. this is the signal to start the watchdog // with a relatively long period so it can finish housekeeping tasks // like servicing endpoints before the sketch ends if (1200 == _usbLineInfo.dwDTERate) { // We check DTR state to determine if host port is open (bit 0 of lineState). - if ((_usbLineInfo.lineState & 0x01) == 0) { + if ((_usbLineInfo.lineState & 0x01) == 0) + { +/* TODO, AVR Stuff *(uint16_t *)0x0800 = 0x7777; wdt_enable(WDTO_120MS); - } else { +*/ + } + else + { // Most OSs do some intermediate steps when configuring ports and DTR can // twiggle more than once before stabilizing. // To avoid spurious resets we set the watchdog to 250ms and eventually // cancel if DTR goes back high. - +/* TODO, AVR Stuff wdt_disable(); wdt_reset(); *(uint16_t *)0x0800 = 0x0; +*/ } } return true; @@ -138,12 +134,12 @@ void Serial_::end(void) { } -void Serial_::accept(void) +void Serial_::accept(void) { ring_buffer *buffer = &cdc_rx_buffer; - int c = USB_Recv(CDC_RX); + int c = USB_Recv(CDC_RX); int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; - + // if we should be storing the received character into the location // just before the tail (meaning that the head would advance to the // current location of the tail), we're about to overflow the buffer @@ -180,7 +176,7 @@ int Serial_::read(void) unsigned char c = buffer->buffer[buffer->tail]; buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE; return c; - } + } } void Serial_::flush(void) @@ -190,12 +186,12 @@ void Serial_::flush(void) size_t Serial_::write(uint8_t c) { - /* only try to send bytes if the high-level CDC connection itself + /* only try to send bytes if the high-level CDC connection itself is open (not just the pipe) - the OS should set lineState when the port is opened and clear lineState when the port is closed. bytes sent before the user opens the connection or after the connection is closed are lost - just like with a UART. */ - + // TODO - ZE - check behavior on different OSes and test what happens if an // open connection isn't broken cleanly (cable is yanked out, host dies // or locks up, or host virtual serial port hangs) @@ -214,14 +210,14 @@ size_t Serial_::write(uint8_t c) // This operator is a convenient way for a sketch to check whether the // port has actually been configured and opened by the host (as opposed -// to just being connected to the host). It can be used, for example, in +// to just being connected to the host). It can be used, for example, in // setup() before printing to ensure that an application on the host is // actually ready to receive and display the data. // We add a short delay before returning to fix a bug observed by Federico // where the port is configured (lineState != 0) but not quite opened. Serial_::operator bool() { bool result = false; - if (_usbLineInfo.lineState > 0) + if (_usbLineInfo.lineState > 0) result = true; delay(10); return result; diff --git a/hardware/arduino/sam/cores/sam/USB/HID.cpp b/hardware/arduino/sam/cores/sam/USB/HID.cpp index ae2c04290..f0ef44982 100644 --- a/hardware/arduino/sam/cores/sam/USB/HID.cpp +++ b/hardware/arduino/sam/cores/sam/USB/HID.cpp @@ -1,5 +1,3 @@ - - /* Copyright (c) 2011, Peter Barrett ** ** Permission to use, copy, modify, and/or distribute this software for @@ -16,11 +14,7 @@ ** SOFTWARE. */ -#define USBCON - -#include "Platform.h" -#include "USBAPI.h" -#include "USBDesc.h" +#include "Arduino.h" #if defined(USBCON) #ifdef HID_ENABLED @@ -45,7 +39,7 @@ Keyboard_ Keyboard; #define RAWHID_TX_SIZE 64 #define RAWHID_RX_SIZE 64 -extern const u8 _hidReportDescriptor[] = { +extern const uint8_t _hidReportDescriptor[] = { // Mouse 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 0x09, 0x02, // USAGE (Mouse) @@ -139,12 +133,12 @@ extern const HIDDescriptor _hidInterface = //================================================================================ // Driver -u8 _hid_protocol = 1; -u8 _hid_idle = 1; +uint8_t _hid_protocol = 1; +uint8_t _hid_idle = 1; #define WEAK __attribute__ ((weak)) -int WEAK HID_GetInterface(u8* interfaceNum) +int WEAK HID_GetInterface(uint8_t* interfaceNum) { interfaceNum[0] += 1; // uses 1 return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface)); @@ -155,7 +149,7 @@ int WEAK HID_GetDescriptor(int i) return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor)); } -void WEAK HID_SendReport(u8 id, const void* data, int len) +void WEAK HID_SendReport(uint8_t id, const void* data, int len) { USB_Send(HID_TX, &id, 1); USB_Send(HID_TX | TRANSFER_RELEASE,data,len); @@ -163,8 +157,8 @@ void WEAK HID_SendReport(u8 id, const void* data, int len) bool WEAK HID_Setup(Setup& setup) { - u8 r = setup.bRequest; - u8 requestType = setup.bmRequestType; + uint8_t r = setup.bRequest; + uint8_t requestType = setup.bmRequestType; if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType) { if (HID_GET_REPORT == r) @@ -222,7 +216,7 @@ void Mouse_::click(uint8_t b) void Mouse_::move(signed char x, signed char y, signed char wheel) { - u8 m[4]; + uint8_t m[4]; m[0] = _buttons; m[1] = x; m[2] = y; diff --git a/hardware/arduino/sam/cores/sam/USB/USBAPI.h b/hardware/arduino/sam/cores/sam/USB/USBAPI.h index f06380bf0..bd6b736bf 100644 --- a/hardware/arduino/sam/cores/sam/USB/USBAPI.h +++ b/hardware/arduino/sam/cores/sam/USB/USBAPI.h @@ -1,9 +1,25 @@ +/* + Copyright (c) 2012 Arduino. 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 +*/ #ifndef __USBAPI__ #define __USBAPI__ -#if defined(USBCON) +#if defined __cplusplus && defined USBCON //================================================================================ //================================================================================ @@ -192,4 +208,4 @@ void USB_Flush(uint8_t ep); #endif -#endif /* if defined(USBCON) */ +#endif /* if defined USBCON */ diff --git a/hardware/arduino/sam/cores/sam/USB/USBCore.cpp.disabled b/hardware/arduino/sam/cores/sam/USB/USBCore.cpp similarity index 97% rename from hardware/arduino/sam/cores/sam/USB/USBCore.cpp.disabled rename to hardware/arduino/sam/cores/sam/USB/USBCore.cpp index 4b352afa4..20793afae 100644 --- a/hardware/arduino/sam/cores/sam/USB/USBCore.cpp.disabled +++ b/hardware/arduino/sam/cores/sam/USB/USBCore.cpp @@ -1,5 +1,3 @@ - - /* Copyright (c) 2010, Peter Barrett ** ** Permission to use, copy, modify, and/or distribute this software for @@ -15,17 +13,9 @@ ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ** SOFTWARE. */ -#define USBCON -#include "Platform.h" -#include "USBAPI.h" -#include "USBDesc.h" -#include "USBCore.h" +#include "Arduino.h" - -#if defined(USBCON) - -extern const uint8_t _initEndpoints[] ; const uint8_t _initEndpoints[] = { 0, @@ -366,7 +356,7 @@ void USB_ISR() { if (REQUEST_DEVICE == (requestType & REQUEST_RECIPIENT)) { - InitEndpoints(); + InitEndpoints(_initEndpoints, sizeof(_initEndpoints)/sizeof(_initEndpoints[0])); _usbConfiguration = setup.wValueL; } else @@ -447,7 +437,9 @@ ISR(USB_GEN_vect) uint8_t USBD_Connected(void) { uint8_t f = UDFNUML; + delay(3); + return f != UDFNUML; } @@ -503,5 +495,3 @@ bool USB_::configured() void USB_::poll() { } - -#endif /* if defined(USBCON) */ diff --git a/hardware/arduino/sam/cores/sam/USB/USBCore.h b/hardware/arduino/sam/cores/sam/USB/USBCore.h index 15ed54f37..7462fb5f4 100644 --- a/hardware/arduino/sam/cores/sam/USB/USBCore.h +++ b/hardware/arduino/sam/cores/sam/USB/USBCore.h @@ -127,32 +127,32 @@ // Device typedef struct { - u8 len; // 18 - u8 dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE - u16 usbVersion; // 0x200 - u8 deviceClass; - u8 deviceSubClass; - u8 deviceProtocol; - u8 packetSize0; // Packet 0 - u16 idVendor; - u16 idProduct; - u16 deviceVersion; // 0x100 - u8 iManufacturer; - u8 iProduct; - u8 iSerialNumber; - u8 bNumConfigurations; + uint8_t len; // 18 + uint8_t dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE + uint16_t usbVersion; // 0x200 + uint8_t deviceClass; + uint8_t deviceSubClass; + uint8_t deviceProtocol; + uint8_t packetSize0; // Packet 0 + uint16_t idVendor; + uint16_t idProduct; + uint16_t deviceVersion; // 0x100 + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; } DeviceDescriptor; // Config typedef struct { - u8 len; // 9 - u8 dtype; // 2 - u16 clen; // total length - u8 numInterfaces; - u8 config; - u8 iconfig; - u8 attributes; - u8 maxPower; + uint8_t len; // 9 + uint8_t dtype; // 2 + uint16_t clen; // total length + uint8_t numInterfaces; + uint8_t config; + uint8_t iconfig; + uint8_t attributes; + uint8_t maxPower; } ConfigDescriptor; // String @@ -160,75 +160,75 @@ typedef struct { // Interface typedef struct { - u8 len; // 9 - u8 dtype; // 4 - u8 number; - u8 alternate; - u8 numEndpoints; - u8 interfaceClass; - u8 interfaceSubClass; - u8 protocol; - u8 iInterface; + uint8_t len; // 9 + uint8_t dtype; // 4 + uint8_t number; + uint8_t alternate; + uint8_t numEndpoints; + uint8_t interfaceClass; + uint8_t interfaceSubClass; + uint8_t protocol; + uint8_t iInterface; } InterfaceDescriptor; // Endpoint typedef struct { - u8 len; // 7 - u8 dtype; // 5 - u8 addr; - u8 attr; - u16 packetSize; - u8 interval; + uint8_t len; // 7 + uint8_t dtype; // 5 + uint8_t addr; + uint8_t attr; + uint16_t packetSize; + uint8_t interval; } EndpointDescriptor; // Interface Association Descriptor // Used to bind 2 interfaces together in CDC compostite device typedef struct { - u8 len; // 8 - u8 dtype; // 11 - u8 firstInterface; - u8 interfaceCount; - u8 functionClass; - u8 funtionSubClass; - u8 functionProtocol; - u8 iInterface; + uint8_t len; // 8 + uint8_t dtype; // 11 + uint8_t firstInterface; + uint8_t interfaceCount; + uint8_t functionClass; + uint8_t funtionSubClass; + uint8_t functionProtocol; + uint8_t iInterface; } IADDescriptor; // CDC CS interface descriptor typedef struct { - u8 len; // 5 - u8 dtype; // 0x24 - u8 subtype; - u8 d0; - u8 d1; + uint8_t len; // 5 + uint8_t dtype; // 0x24 + uint8_t subtype; + uint8_t d0; + uint8_t d1; } CDCCSInterfaceDescriptor; typedef struct { - u8 len; // 4 - u8 dtype; // 0x24 - u8 subtype; - u8 d0; + uint8_t len; // 4 + uint8_t dtype; // 0x24 + uint8_t subtype; + uint8_t d0; } CDCCSInterfaceDescriptor4; typedef struct { - u8 len; - u8 dtype; // 0x24 - u8 subtype; // 1 - u8 bmCapabilities; - u8 bDataInterface; + uint8_t len; + uint8_t dtype; // 0x24 + uint8_t subtype; // 1 + uint8_t bmCapabilities; + uint8_t bDataInterface; } CMFunctionalDescriptor; typedef struct { - u8 len; - u8 dtype; // 0x24 - u8 subtype; // 1 - u8 bmCapabilities; + uint8_t len; + uint8_t dtype; // 0x24 + uint8_t subtype; // 1 + uint8_t bmCapabilities; } ACMFunctionalDescriptor; typedef struct @@ -259,15 +259,15 @@ typedef struct typedef struct { - u8 len; // 9 - u8 dtype; // 0x21 - u8 addr; - u8 versionL; // 0x101 - u8 versionH; // 0x101 - u8 country; - u8 desctype; // 0x22 report - u8 descLenL; - u8 descLenH; + uint8_t len; // 9 + uint8_t dtype; // 0x21 + uint8_t addr; + uint8_t versionL; // 0x101 + uint8_t versionH; // 0x101 + uint8_t country; + uint8_t desctype; // 0x22 report + uint8_t descLenL; + uint8_t descLenH; } HIDDescDescriptor; typedef struct diff --git a/hardware/arduino/sam/cores/sam/build_gcc/libarduino_arduino_due_x.mk b/hardware/arduino/sam/cores/sam/build_gcc/libarduino_arduino_due_x.mk index 0283daddd..5867a5f61 100644 --- a/hardware/arduino/sam/cores/sam/build_gcc/libarduino_arduino_due_x.mk +++ b/hardware/arduino/sam/cores/sam/build_gcc/libarduino_arduino_due_x.mk @@ -74,6 +74,9 @@ endif include $(TOOLCHAIN).mk +CFLAGS += -DUSB_VID=0x2341 -DUSB_PID=0xcafe +CPPFLAGS += -DUSB_VID=0x2341 -DUSB_PID=0xcafe + #------------------------------------------------------------------------------- ifdef DEBUG OUTPUT_OBJ=debug @@ -155,12 +158,12 @@ create_output: -@mkdir $(OUTPUT_PATH) 1>NUL 2>&1 $(addprefix $(OUTPUT_PATH)/,$(C_OBJ)): $(OUTPUT_PATH)/%.o: %.c -# @"$(CC)" -v -c $(CFLAGS) $< -o $@ +# "$(CC)" -v -c $(CFLAGS) $< -o $@ @"$(CC)" -c $(CFLAGS) $< -o $@ $(addprefix $(OUTPUT_PATH)/,$(CPP_OBJ)): $(OUTPUT_PATH)/%.o: %.cpp -# @"$(CC)" -c $(CPPFLAGS) $< -o $@ - @"$(CC)" -xc++ -c $(CPPFLAGS) $< -o $@ + "$(CC)" -xc++ -c $(CPPFLAGS) $< -o $@ +# @"$(CC)" -xc++ -c $(CPPFLAGS) $< -o $@ $(addprefix $(OUTPUT_PATH)/,$(A_OBJ)): $(OUTPUT_PATH)/%.o: %.s @"$(AS)" -c $(ASFLAGS) $< -o $@ diff --git a/hardware/arduino/sam/system/libsam/include/uotghs.h b/hardware/arduino/sam/system/libsam/include/uotghs.h index df5f89958..131cfdc95 100644 --- a/hardware/arduino/sam/system/libsam/include/uotghs.h +++ b/hardware/arduino/sam/system/libsam/include/uotghs.h @@ -43,5 +43,4 @@ #define EP_TYPE_ISOCHRONOUS_IN (UOTGHS_DEVEPTCFG_EPSIZE_1024_BYTE | UOTGHS_DEVEPTCFG_EPDIR_IN | UOTGHS_DEVEPTCFG_EPTYPE_ISO | UOTGHS_DEVEPTCFG_EPBK_3_BANK) #define EP_TYPE_ISOCHRONOUS_OUT (UOTGHS_DEVEPTCFG_EPSIZE_1024_BYTE | UOTGHS_DEVEPTCFG_EPTYPE_ISO | UOTGHS_DEVEPTCFG_EPBK_3_BANK) - #endif /* UOTGHS_H_INCLUDED */ diff --git a/hardware/arduino/sam/system/libsam/source/uotghs.c b/hardware/arduino/sam/system/libsam/source/uotghs.c index ab2b5927a..19ddffb23 100644 --- a/hardware/arduino/sam/system/libsam/source/uotghs.c +++ b/hardware/arduino/sam/system/libsam/source/uotghs.c @@ -20,8 +20,24 @@ #if SAM3XA_SERIES -void USBD_InitEndpoints(void) +void USBD_InitEndpoints( uint8_t* puc_EndPoints, uint32_t ul_EndPoints ) { + for (uint8_t i = 1; i < sizeof(_initEndpoints); i++) + { + // Reset Endpoint Fifos + UOTGHS->UOTGHS_DEVEPTISR[i].UDPHS_EPTCLRSTA = UDPHS_EPTCLRSTA_TOGGLESQ | UDPHS_EPTCLRSTA_FRCESTALL; + UOTGHS->UDPHS_EPTRST = 1<UDPHS_EPT[i].UDPHS_EPTCFG = _initEndpoints[i]; + + while( (signed int)UDPHS_EPTCFG_EPT_MAPD != (signed int)((UOTGHS->UDPHS_EPT[i].UDPHS_EPTCFG) & (unsigned int)UDPHS_EPTCFG_EPT_MAPD) ) + ; + UOTGHS->UDPHS_EPT[i].UDPHS_EPTCTLENB = UDPHS_EPTCTLENB_EPT_ENABL; + + // UECFG1X = EP_DOUBLE_64; + } } uint32_t USBD_Init(void) diff --git a/hardware/arduino/sam/variants/arduino_due_x/variant.h b/hardware/arduino/sam/variants/arduino_due_x/variant.h index 34fe2a8ee..a47d4b3e4 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/variant.h +++ b/hardware/arduino/sam/variants/arduino_due_x/variant.h @@ -23,6 +23,9 @@ * Headers *----------------------------------------------------------------------------*/ +// We have native USB on this variant +#define USBCON + #include "Arduino.h" #ifdef __cplusplus #include "UARTClass.h"