Changes for USB driver.

This commit is contained in:
NIIBE Yutaka
2019-05-13 09:37:18 +09:00
parent 79305c3de4
commit 0de43691ab
15 changed files with 64 additions and 58 deletions

View File

@@ -1,3 +1,14 @@
2019-05-13 NIIBE Yutaka <gniibe@fsij.org>
* 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 <gniibe@fsij.org>
* chopstx.c (chopstx_claim_irq): Check INTR before the call.

20
NEWS
View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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 */

View File

@@ -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.

View File

@@ -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 */

View File

@@ -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
*/

View File

@@ -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

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -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

View File

@@ -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).

View File

@@ -29,14 +29,6 @@
#include <stdint.h>
#include <stdlib.h>
#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;

View File

@@ -29,10 +29,6 @@
#include <stdint.h>
#include <stdlib.h>
#ifdef USE_SYS
#include "sys-stm32l4.h"
#endif
#include <mcu/stm32l.h>
#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);