From 0de43691ab8e9456ec2b476cd85ab18a749ffb89 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Mon, 13 May 2019 09:37:18 +0900 Subject: [PATCH] Changes for USB driver. --- ChangeLog | 11 +++++++++++ NEWS | 20 ++++++++++--------- board/board-fst-01-00.h | 2 +- board/board-fst-01.h | 2 +- board/board-maple-mini.h | 4 ++-- board/board-nitrokey-start.h | 2 +- board/board-olimex-stm32-h103.h | 4 ++-- board/board-st-dongle.h | 2 +- board/board-stbee-mini.h | 2 +- board/board-stbee.h | 4 ++-- board/board-stm32-primer2.h | 4 ++-- mcu/ABOUT-SYS | 4 ++-- mcu/ABOUT-USB | 35 +++++++++++++++++++++++++-------- mcu/usb-stm32f103.c | 15 -------------- mcu/usb-stm32l4.c | 11 ----------- 15 files changed, 64 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4ccf7fe..0487c88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2019-05-13 NIIBE Yutaka + + * board/board-maple-mini.h: Assert USB D+ pull-up. + * board/board-olimex-stm32-h103.h: Likewise. + * board/board-stbee.h:Likewise. + * board/board-stm32-primer2.h: Likewise. + + * mcu/usb-stm32f103.c: Don't use usb_lld_sys_init and + usb_lld_sys_shutdown in SYS. + * mcu/usb-stm32l4.c: Ditto. + 2019-05-10 NIIBE Yutaka * chopstx.c (chopstx_claim_irq): Check INTR before the call. diff --git a/NEWS b/NEWS index 4e2321a..4dbcfa4 100644 --- a/NEWS +++ b/NEWS @@ -3,21 +3,23 @@ NEWS - Noteworthy changes * Major changes in Chopstx 1.15 - Released 2019-05-10 + Released 2019-05-1X ** SYS version 4.0 USB initialization/finalization demarcation has been changed. Enabling/disabling USB module is done by USB driver. SYS routines -only handles USB cable config. If a board has a fixed pull-up -resistor, USB driver can omit calling -usb_lld_sys_init/usb_lld_sys_shutdown. +only handles USB cable config. For all boards, USB driver doesn't use +usb_lld_sys_init/usb_lld_sys_shutdown (those routines only makes sense +for USB self powered situation, which Chopstx does not support yet). ** USB driver change -Enabling/disabling USB module is done by USB driver. Only with --DUSE_SYS option, it calls usb_lld_sys_init/usb_lld_sys_shutdown. -Don't forget having -DUSE_SYS to support boards with non-fixed 1K5 -resistor. Despite this change, it should work well with SYS 3.0 -routines. +Enabling/disabling USB module is done by USB driver. It's +responsibility of board configuration to enable external transistor +for pull-up D+-line. + +** Board configuration change +For USB driver change, board-maple-mini.h, board-olimex-stm32-h103.h, +board-stbee.h, and board-stm32-primer2.h were changed. ** Cortex-M4 support Cortex-M4 support has been added. Not supporting use of FPU or DSP, diff --git a/board/board-fst-01-00.h b/board/board-fst-01-00.h index e317453..ee73f35 100644 --- a/board/board-fst-01-00.h +++ b/board/board-fst-01-00.h @@ -19,7 +19,7 @@ * PA0 - input with pull-up. AN0 * PA1 - input with pull-up. AN1 * PA8 - Push pull output 50MHz (LED 1:ON 0:OFF) - * PA10 - Push pull output 50MHz (USB 1:ON 0:OFF) + * PA10 - Push pull output 50MHz (USB 1:ON 0:OFF) default 1 * PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM) * PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP) * ------------------------ Default diff --git a/board/board-fst-01.h b/board/board-fst-01.h index 3b89c66..88c836b 100644 --- a/board/board-fst-01.h +++ b/board/board-fst-01.h @@ -25,7 +25,7 @@ * PA5 - Alternate Push pull output (SPI1_SCK) * PA6 - Alternate Push pull output (SPI1_MISO) * PA7 - Alternate Push pull output (SPI1_MOSI) - * PA10 - Push pull output (USB 1:ON 0:OFF) + * PA10 - Push pull output (USB 1:ON 0:OFF) default 1 * PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM) * PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP) * ------------------------ Default diff --git a/board/board-maple-mini.h b/board/board-maple-mini.h index ac3dc91..6d7fe6d 100644 --- a/board/board-maple-mini.h +++ b/board/board-maple-mini.h @@ -30,11 +30,11 @@ /* * Port B setup. * PB1 - Push pull output 50MHz (LED 1:ON 0:OFF) - * PB9 - Push pull output 50MHz (USB 1:ON 0:OFF) + * PB9 - Push pull output 50MHz (USB 0:ON 1:OFF) default 0 * ------------------------ Default * PBx - input with pull-up */ -#define VAL_GPIO_LED_ODR 0xFFFFFFFF +#define VAL_GPIO_LED_ODR 0xFFFFFDFF #define VAL_GPIO_LED_CRL 0x88888838 /* PB7...PB0 */ #define VAL_GPIO_LED_CRH 0x88888838 /* PB15...PB8 */ diff --git a/board/board-nitrokey-start.h b/board/board-nitrokey-start.h index a033233..cfa8e8a 100644 --- a/board/board-nitrokey-start.h +++ b/board/board-nitrokey-start.h @@ -29,7 +29,7 @@ * PA10 - floating input * PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM) * PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP) - * PA15 - Push pull output (USB_EN 1:ON 0:OFF) + * PA15 - Push pull output (USB_EN 1:ON 0:OFF) default 1 * ------------------------ Default * PA8 - input with pull-up. * PA9 - floating input. diff --git a/board/board-olimex-stm32-h103.h b/board/board-olimex-stm32-h103.h index 348860d..435a02e 100644 --- a/board/board-olimex-stm32-h103.h +++ b/board/board-olimex-stm32-h103.h @@ -20,12 +20,12 @@ * PC1 - input with pull-up. AN11 for NeuG * PC6 - input without pull-up/down * PC7 - input without pull-up/down - * PC11 - Open-drain output 50MHz (USB disconnect). + * PC11 - Open-drain output 50MHz (USB 0:ON 1:OFF) default 0 * PC12 - Push Pull output 50MHz (LED). * ------------------------ Default * PCx - input with pull-up */ -#define VAL_GPIO_LED_ODR 0xFFFFFFFF +#define VAL_GPIO_LED_ODR 0xFFFFF7FF #define VAL_GPIO_LED_CRL 0x44888888 /* PC7...PC0 */ #define VAL_GPIO_LED_CRH 0x88837888 /* PC15...PC8 */ diff --git a/board/board-st-dongle.h b/board/board-st-dongle.h index ef9b4f3..19f717b 100644 --- a/board/board-st-dongle.h +++ b/board/board-st-dongle.h @@ -22,7 +22,7 @@ * PA9 - Push pull output 50MHz (LED 1:ON 0:OFF) * PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM) * PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP) - * PA15 - Push pull output 50MHz (USB 1:ON 0:OFF) + * PA15 - Push pull output 50MHz (USB 1:ON 0:OFF) default 1 * ------------------------ Default * PAx - input with pull-up */ diff --git a/board/board-stbee-mini.h b/board/board-stbee-mini.h index d9ab407..553c784 100644 --- a/board/board-stbee-mini.h +++ b/board/board-stbee-mini.h @@ -52,7 +52,7 @@ * PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM) * PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP) * PA13 - Open Drain output (LED1 0:ON 1:OFF) - * PA14 - Push pull output (USB ENABLE 0:DISABLE 1:ENABLE) + * PA14 - Push pull output (USB 1:ON 0:OFF) default 1 * PA15 - Open Drain output (LED2 0:ON 1:OFF) */ #define VAL_GPIO_LED_ODR 0xFFFFE77F diff --git a/board/board-stbee.h b/board/board-stbee.h index 3cfd248..94ba206 100644 --- a/board/board-stbee.h +++ b/board/board-stbee.h @@ -29,9 +29,9 @@ /* * Port D setup. - * PD3 - Push pull output (USB_DISC 1:USB-DISABLE 0:USB-ENABLE) 2MHz + * PD3 - Push pull output (USB 1:OFF 0:ON) 2MHz default 0 * PD4 - Open Drain output 2MHz (LED1). */ -#define VAL_GPIO_LED_ODR 0xFFFFFFFF +#define VAL_GPIO_LED_ODR 0xFFFFFFF7 #define VAL_GPIO_LED_CRL 0x88862888 /* PD7...PD0 */ #define VAL_GPIO_LED_CRH 0x88888888 /* PD15...PD8 */ diff --git a/board/board-stm32-primer2.h b/board/board-stm32-primer2.h index 4318dd8..b3f59fb 100644 --- a/board/board-stm32-primer2.h +++ b/board/board-stm32-primer2.h @@ -30,11 +30,11 @@ /* * Port D setup. - * PD3 - Push pull output 50MHz (USB 1:ON 0:OFF) + * PD3 - Push pull output 50MHz (USB 0:ON 1:OFF) default 0 * ------------------------ Default * PDx - input with pull-up */ -#define VAL_GPIO_USB_ODR 0xFFFFFFFF +#define VAL_GPIO_USB_ODR 0xFFFFFFF7 #define VAL_GPIO_USB_CRL 0x88883888 /* PD7...PD0 */ #define VAL_GPIO_USB_CRH 0x88888888 /* PD15...PD8 */ diff --git a/mcu/ABOUT-SYS b/mcu/ABOUT-SYS index c5e17fe..b98de6b 100644 --- a/mcu/ABOUT-SYS +++ b/mcu/ABOUT-SYS @@ -9,8 +9,8 @@ This document was written when I was porting Chopstx to Kinetis L. SYS 2.0: Added clock_init, gpio_init SYS 2.1: Added sys_board_id, sys_board_name SYS 3.0: Don't setup NVIC priority by usb_lld_sys_init - SYS 4.0: For USB, only do usb_cable_config, enabling the USB module - is the role of USB driver. + SYS 4.0: For USB, only do usb_cable_config. Enabling/disabling the + USB module is the role of USB driver. * Macro definition by DEFS in Makefile diff --git a/mcu/ABOUT-USB b/mcu/ABOUT-USB index 6b71955..82e6b23 100644 --- a/mcu/ABOUT-USB +++ b/mcu/ABOUT-USB @@ -1,13 +1,32 @@ USB driver in Chopstx Full speed device is assumed. Bus powered system is assumed. +API-wise, self powered system is not supported (yet) by this USB driver. -API-wise, self powered system is not supported (yet). To support self -powered system, we need to define the hardware interface detecting -VBUS voltage. Only after detecting VBUS power, we can enable USB -driver (D+/D- lines). For self powered system, driving D+/D- lines -(by fixed pull-up resistor) violates the USB specification. +The driver can be used without Chopstx. An example can be find in +Gnuk (gnuk/regnual). -This driver can be used without Chopstx. Please supply --DFREE_STANDING when used without Chopstx. An example can be find -in gnuk/regnual. +The USB driver was originally written for STM32F103, which USB +hardware design is considered not mature. Modern USB hardware design +allows crystal-less design, and/or comes with internal 5V->3V3 +regulator, D+-line pull-up support, and VBUS detection. STM32F103 has +nothing. + +To support self powered system, we need to define a hardware interface +for a board detecting VBUS voltage. Only after detecting VBUS power, +we can enable USB driver (D+/D- lines). For self powered system, +driving D+/D- lines by fixed pull-up resistor violates the USB +specification. + +With STM32F103, there is a common hardware practice having a +gate/transistor for pull-up D+ line. If it also supports detecting +VBUS, self powerd system can be supported with the gate/transistor. + +Such a gate/transistor can be also used for the board to ask +re-enumeration of USB device. Asking re-enumeration, it is enough to +have SE0 (Single-Ended Zero) state. + +The USB driver doesn't touch such a gate/transistor. By gpio_init, +the D+-line should be asserted, USB D+ and D- lines should be drived +to 0 (SE0). When the USB module is enabled, it goes into J and K +state (from SE0 state). diff --git a/mcu/usb-stm32f103.c b/mcu/usb-stm32f103.c index f91634d..ac37dcb 100644 --- a/mcu/usb-stm32f103.c +++ b/mcu/usb-stm32f103.c @@ -29,14 +29,6 @@ #include #include -#ifdef USE_SYS -#include "sys-stm32f103.h" -#else -# ifdef FREE_STANDING -# error "Please compile with -DUSE_SYS" -# endif -#endif - #include "stm32f103.h" #include "usb_lld.h" #include "usb_lld_driver.h" @@ -123,9 +115,6 @@ usb_lld_shutdown_chip_specific (void) { RCC->APB1ENR &= ~RCC_APB1ENR_USBEN; RCC->APB1RSTR = RCC_APB1RSTR_USBRST; -#ifdef USE_SYS - usb_lld_sys_shutdown (); -#endif } static void @@ -149,10 +138,6 @@ usb_lld_init_chip_specific (void) wait (5*MHZ); } -#ifdef USE_SYS - usb_lld_sys_init (); -#endif - if ((RCC->APB1ENR & RCC_APB1ENR_USBEN) == 0) { RCC->APB1ENR |= RCC_APB1ENR_USBEN; diff --git a/mcu/usb-stm32l4.c b/mcu/usb-stm32l4.c index b860295..2b67b44 100644 --- a/mcu/usb-stm32l4.c +++ b/mcu/usb-stm32l4.c @@ -29,10 +29,6 @@ #include #include -#ifdef USE_SYS -#include "sys-stm32l4.h" -#endif - #include #include "usb_lld.h" #include "usb_lld_driver.h" @@ -120,9 +116,6 @@ usb_lld_shutdown_chip_specific (void) USB_STM32L4->BCDR &= 0x7fff; /* DP disable */ RCC->APB1ENR1 &= ~(RCC_APB1_1_USB | RCC_APB1_1_CRS); RCC->APB1RSTR1 |= (RCC_APB1_1_USB | RCC_APB1_1_CRS); -#ifdef USE_SYS - usb_lld_sys_shutdown (); -#endif } static void @@ -158,10 +151,6 @@ usb_lld_init_chip_specific (void) wait (5*MHZ); } -#ifdef USE_SYS - usb_lld_sys_init (); -#endif - /* Enable USB clock and CRC clock */ RCC->APB1ENR1 |= (RCC_APB1_1_USB | RCC_APB1_1_CRS); RCC->APB1RSTR1 = (RCC_APB1_1_USB | RCC_APB1_1_CRS);