From d42a45c1eefd55890c32ebc17de75744ed3a3815 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 18 Aug 2010 14:21:58 +0900 Subject: [PATCH] let device runs with three interfaces. --- README | 15 +++++++++++++++ src/Makefile | 2 +- src/main.c | 7 ++++++- src/usb.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/usb_desc.c | 12 ++++++------ 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/README b/README index f139926..fb52745 100644 --- a/README +++ b/README @@ -15,3 +15,18 @@ Taken from http://github.com/robots/STM32.git * USBCDC Taken from http://github.com/robots/STM32.git + + +HOWTO RUN +================= + +$ openocd -f interface/olimex-jtag-tiny.cfg -f board/olimex_stm32_h103.cfg + +$ arm-none-eabi-gdb --annotate=3 gnuk.elf + +$ telnet localhost 4444 +> reset halt +> flash write_image erase gnuk.elf +> reset +> exit +$ diff --git a/src/Makefile b/src/Makefile index d571251..bc25463 100644 --- a/src/Makefile +++ b/src/Makefile @@ -78,7 +78,7 @@ CSRC = $(PORTSRC) \ $(CHIBIOS)/os/various/syscalls.c \ $(STMUSBSRC) \ $(USBCDCSRC) \ - main.c hw_config.c usb_lld.c usb_desc.c usb_prop.c + main.c hw_config.c usb_lld.c usb_desc.c usb_prop.c usb.c # List ASM source files here ASMSRC = $(PORTASM) \ diff --git a/src/main.c b/src/main.c index a53bf64..368bca0 100644 --- a/src/main.c +++ b/src/main.c @@ -70,7 +70,7 @@ stdout_init (void) stdout.str = NULL; } -static int +int _write (const char *s, int size) { if (size == 0) @@ -160,6 +160,9 @@ static msg_t Thread2 (void *arg) return 0; } +static WORKING_AREA(waUSBThread, 128); +extern msg_t USBThread (void *arg); + /* * Entry point, note, the main() function is already a thread in the system * on entry. @@ -185,6 +188,8 @@ int main(int argc, char **argv) */ chThdCreateStatic (waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL); + chThdCreateStatic (waUSBThread, sizeof(waUSBThread), NORMALPRIO, USBThread, NULL); + while (1) { #if 0 diff --git a/src/usb.c b/src/usb.c index 51f08dd..dbfd5d1 100644 --- a/src/usb.c +++ b/src/usb.c @@ -21,6 +21,37 @@ * */ +#include "ch.h" +#include "hal.h" + +#include "usb_lib.h" +#include "usb_desc.h" +#include "usb_mem.h" +#include "hw_config.h" +#include "usb_istr.h" + +static uint8_t icc_buffer_out[64]; +static uint8_t icc_buffer_in[64]; + +static __IO uint32_t icc_count_out = 0; +static uint32_t icc_count_in = 0; + +void +EP4_IN_Callback(void) +{ +} + +void +EP5_OUT_Callback(void) +{ + /* Get the received data buffer and update the counter */ + icc_count_out = USB_SIL_Read (EP5_OUT, icc_buffer_out); + + /* Enable the receive of data on EP5 */ + SetEPRxValid (ENDP5); +} + +#if 0 #define ICC_POWER_ON 0x62 0 bMessageType 0x62 1 dwLength 0x00000000 @@ -146,3 +177,19 @@ RDR_to_PC_DataBlock PC_to_RDR_XfrBlock RDR_to_PC_DataBlock +#endif + +msg_t +USBThread (void *arg) +{ + while (TRUE) + { + while (icc_count_out == 0) + chThdSleepMilliseconds (1); + + _write ("!\r\n", 3); + icc_count_out = 0; + } + + return 0; +} diff --git a/src/usb_desc.c b/src/usb_desc.c index 4b830f4..c0ca195 100644 --- a/src/usb_desc.c +++ b/src/usb_desc.c @@ -37,7 +37,7 @@ static const uint8_t gnukConfigDescriptor[] = { 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ 0xC0, /* bmAttributes: self powered */ - 0x32, /* MaxPower 0 mA */ + 50, /* MaxPower 100 mA */ /* Interface Descriptor */ 9, /* bLength: Interface Descriptor size */ @@ -53,7 +53,7 @@ static const uint8_t gnukConfigDescriptor[] = { /* ICC Descriptor */ 54, /* bLength: */ 0x21, /* bDescriptorType: USBDESCR_ICC */ - 0x10, 0x01, /* bcdCCID: 1.1 */ + 0x10, 0x01, /* bcdCCID: 1.1 XXX */ 0, /* bMaxSlotIndex: */ 1, /* bVoltageSupport: FIXED VALUE */ 0x02, 0, 0, 0, /* dwProtocols: T=1 */ @@ -67,7 +67,7 @@ static const uint8_t gnukConfigDescriptor[] = { 0, 0, 0, 0, /* dwSynchProtocols: FIXED VALUE */ 0, 0, 0, 0, /* dwMechanical: FIXED VALUE */ 0x40, 0x08, 0x04, 0x00, /* dwFeatures: Short and extended ADPU level */ - 0x0f, 0x01, 0, 0, /* dwMaxCCIDMessageLength: 261+10 */ + 0x0f, 0x01, 0, 0, /* dwMaxCCIDMessageLength: 261+10 XXX */ 0xff, /* bClassGetResponse: */ 0xff, /* bClassEnvelope: */ 0, 0, /* wLCDLayout: FIXED VALUE */ @@ -109,7 +109,7 @@ static const uint8_t gnukConfigDescriptor[] = { 0x24, /* bDescriptorType: CS_INTERFACE */ 0x01, /* bDescriptorSubtype: Call Management Func Desc */ 0x00, /* bmCapabilities: D0+D1 */ - 0x01, /* bDataInterface: 1 */ + 0x02, /* bDataInterface: 1 */ /*ACM Functional Descriptor*/ 4, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ @@ -119,8 +119,8 @@ static const uint8_t gnukConfigDescriptor[] = { 5, /* bFunctionLength */ 0x24, /* bDescriptorType: CS_INTERFACE */ 0x06, /* bDescriptorSubtype: Union func desc */ - 0x00, /* bMasterInterface: Communication class interface */ - 0x01, /* bSlaveInterface0: Data Class Interface */ + 0x01, /* bMasterInterface: Communication class interface */ + 0x02, /* bSlaveInterface0: Data Class Interface */ /*Endpoint 2 Descriptor*/ 7, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */