example update

This commit is contained in:
NIIBE Yutaka
2013-08-21 11:17:11 +09:00
parent 102f30092b
commit 3261453723
6 changed files with 40 additions and 52 deletions

View File

@@ -1,3 +1,11 @@
2013-08-21 Niibe Yutaka <gniibe@fsij.org>
* example-led/sys.c: Update from NeuG.
* example-cdc/sys.c: Likewise.
* example-cdc/usb_stm32f103.c: Likewise.
* example-cdc/usb_lld.h: Likewise.
* example-cdc/usb-cdc.c: Likewise.
2013-08-19 Niibe Yutaka <gniibe@fsij.org> 2013-08-19 Niibe Yutaka <gniibe@fsij.org>
* rules.mk (%.elf): Support OBJS_ADD. * rules.mk (%.elf): Support OBJS_ADD.

View File

@@ -566,7 +566,7 @@ reset (void)
/* Never reach here. */ /* Never reach here. */
/* Artificial entry to refer FT0, FT1, and FT2. */ /* Artificial entry to refer FT0, FT1, and FT2. */
asm volatile ("" asm volatile (""
: : "r" (&FT0), "r" (&FT1), "r" (&FT2)); : : "r" (FT0), "r" (FT1), "r" (FT2));
} }
typedef void (*handler)(void); typedef void (*handler)(void);

View File

@@ -158,6 +158,7 @@ static const uint8_t vcom_string3[28] = {
#define NUM_INTERFACES 2 #define NUM_INTERFACES 2
uint32_t bDeviceState = UNCONNECTED; /* USB device status */ uint32_t bDeviceState = UNCONNECTED; /* USB device status */
uint8_t connected;
void void
usb_cb_device_reset (void) usb_cb_device_reset (void)
@@ -179,11 +180,18 @@ void
usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value, usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value,
uint16_t index, uint16_t len) uint16_t index, uint16_t len)
{ {
(void)req; uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
(void)req_no;
(void)value; if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT)
(void)index; && index == 0 && USB_SETUP_SET (req) && len == 0
(void)len; && req_no == USB_CDC_REQ_SET_CONTROL_LINE_STATE)
{
/* Open/close the connection. */
chopstx_mutex_lock (&usb_mtx);
connected = (value != 0)? 1 : 0;
chopstx_cond_signal (&cnd_usb);
chopstx_mutex_unlock (&usb_mtx);
}
} }
struct line_coding struct line_coding
@@ -192,7 +200,7 @@ struct line_coding
uint8_t format; uint8_t format;
uint8_t paritytype; uint8_t paritytype;
uint8_t datatype; uint8_t datatype;
}; } __attribute__((packed));
static struct line_coding line_coding = { static struct line_coding line_coding = {
115200, /* baud rate: 115200 */ 115200, /* baud rate: 115200 */
@@ -201,51 +209,31 @@ static struct line_coding line_coding = {
0x08 /* bits: 8 */ 0x08 /* bits: 8 */
}; };
uint8_t connected;
static int static int
vcom_port_data_setup (uint8_t req, uint8_t req_no, uint16_t value) vcom_port_data_setup (uint8_t req, uint8_t req_no, uint16_t value, uint16_t len)
{ {
(void)value;
if (USB_SETUP_GET (req)) if (USB_SETUP_GET (req))
{ {
if (req_no == USB_CDC_REQ_GET_LINE_CODING) if (req_no == USB_CDC_REQ_GET_LINE_CODING
&& len == sizeof (line_coding))
{ {
usb_lld_set_data_to_send (&line_coding, sizeof(line_coding)); usb_lld_set_data_to_send (&line_coding, sizeof (line_coding));
return USB_SUCCESS; return USB_SUCCESS;
} }
} }
else /* USB_SETUP_SET (req) */ else /* USB_SETUP_SET (req) */
{ {
if (req_no == USB_CDC_REQ_SET_LINE_CODING) if (req_no == USB_CDC_REQ_SET_LINE_CODING
&& len == sizeof (line_coding))
{ {
usb_lld_set_data_to_recv (&line_coding, sizeof(line_coding)); usb_lld_set_data_to_recv (&line_coding, sizeof (line_coding));
return USB_SUCCESS; return USB_SUCCESS;
} }
else if (req_no == USB_CDC_REQ_SET_CONTROL_LINE_STATE) else if (req_no == USB_CDC_REQ_SET_CONTROL_LINE_STATE)
{
uint8_t connected_saved = connected;
if (value != 0)
{
if (connected == 0)
/* It's Open call */
connected++;
}
else
{
if (connected)
/* Close call */
connected = 0;
}
chopstx_mutex_lock (&usb_mtx);
if (connected != connected_saved)
chopstx_cond_signal (&cnd_usb);
chopstx_mutex_unlock (&usb_mtx);
return USB_SUCCESS; return USB_SUCCESS;
} }
}
return USB_UNSUPPORT; return USB_UNSUPPORT;
} }
@@ -259,7 +247,7 @@ usb_cb_setup (uint8_t req, uint8_t req_no,
(void)len; (void)len;
if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT)) if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT))
if (index == 0) if (index == 0)
return vcom_port_data_setup (req, req_no, value); return vcom_port_data_setup (req, req_no, value, len);
return USB_UNSUPPORT; return USB_UNSUPPORT;
} }

View File

@@ -88,7 +88,6 @@ enum DEVICE_STATE
CONFIGURED CONFIGURED
}; };
extern uint32_t bDeviceState;
extern const uint8_t usb_initial_feature; extern const uint8_t usb_initial_feature;
#define STM32_USB_IRQ_PRIORITY 11 #define STM32_USB_IRQ_PRIORITY 11

View File

@@ -1,16 +1,9 @@
#ifdef FREE_STANDING
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#define NULL 0
#define __IO volatile
#else
#include "ch.h"
#include "hal.h"
#endif
#include "sys.h" #include "sys.h"
#include "usb_lld.h" #include "usb_lld.h"
@@ -90,15 +83,15 @@ static struct DATA_INFO *const data_p = &data_info;
#define PMA_ADDR (0x40006000UL) /* USB_IP Packet Memory Area base address */ #define PMA_ADDR (0x40006000UL) /* USB_IP Packet Memory Area base address */
/* Control register */ /* Control register */
#define CNTR ((__IO uint16_t *)(REG_BASE + 0x40)) #define CNTR ((volatile uint16_t *)(REG_BASE + 0x40))
/* Interrupt status register */ /* Interrupt status register */
#define ISTR ((__IO uint16_t *)(REG_BASE + 0x44)) #define ISTR ((volatile uint16_t *)(REG_BASE + 0x44))
/* Frame number register */ /* Frame number register */
#define FNR ((__IO uint16_t *)(REG_BASE + 0x48)) #define FNR ((volatile uint16_t *)(REG_BASE + 0x48))
/* Device address register */ /* Device address register */
#define DADDR ((__IO uint16_t *)(REG_BASE + 0x4C)) #define DADDR ((volatile uint16_t *)(REG_BASE + 0x4C))
/* Buffer Table address register */ /* Buffer Table address register */
#define BTABLE ((__IO uint16_t *)(REG_BASE + 0x50)) #define BTABLE ((volatile uint16_t *)(REG_BASE + 0x50))
#define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */ #define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */
#define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */ #define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */

View File

@@ -566,7 +566,7 @@ reset (void)
/* Never reach here. */ /* Never reach here. */
/* Artificial entry to refer FT0, FT1, and FT2. */ /* Artificial entry to refer FT0, FT1, and FT2. */
asm volatile ("" asm volatile (""
: : "r" (&FT0), "r" (&FT1), "r" (&FT2)); : : "r" (FT0), "r" (FT1), "r" (FT2));
} }
typedef void (*handler)(void); typedef void (*handler)(void);