From d7228094fd54d5f7572c03e115b22fd23d335995 Mon Sep 17 00:00:00 2001 From: Noe Brun <44475654+noebrun@users.noreply.github.com> Date: Tue, 26 Nov 2019 13:51:16 +0100 Subject: [PATCH 1/8] missing source file for cdc_msc to compile --- examples/device/cdc_msc/ses/nrf5x/nrf5x.emProject | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/device/cdc_msc/ses/nrf5x/nrf5x.emProject b/examples/device/cdc_msc/ses/nrf5x/nrf5x.emProject index 55c5a4ec4..fa5534635 100644 --- a/examples/device/cdc_msc/ses/nrf5x/nrf5x.emProject +++ b/examples/device/cdc_msc/ses/nrf5x/nrf5x.emProject @@ -60,6 +60,7 @@ + From 26dcc19b186a85f6ee8d1d94bb672e34865f56e9 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Fri, 29 Nov 2019 18:14:23 +0800 Subject: [PATCH 2/8] valentyusb: eptri: don't double-advance read buffer Due to an error, we were double-advancing the FIFO buffer. The end result was that the second half of most reads were getting ignored. This wasn't found during earlier testing because only 64-byte buffers were tested. This corrects this error by avoiding double-advancing the buffer. Signed-off-by: Sean Cross --- src/portable/valentyusb/eptri/dcd_eptri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/portable/valentyusb/eptri/dcd_eptri.c b/src/portable/valentyusb/eptri/dcd_eptri.c index e555fb0b1..67e0c59aa 100644 --- a/src/portable/valentyusb/eptri/dcd_eptri.c +++ b/src/portable/valentyusb/eptri/dcd_eptri.c @@ -226,7 +226,7 @@ static void process_rx(void) { test_buffer[total_read] = c; #endif total_read++; - if ((rx_buffer_offset[rx_ep] + current_offset) < rx_buffer_max[rx_ep]) { + if (current_offset < rx_buffer_max[rx_ep]) { #if LOG_USB usb_log[usb_log_offset].data[usb_log[usb_log_offset].size++] = c; #endif From 4a1f7d024315a8a280cf2ab1c5ba0c0d0c80fb7d Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Fri, 29 Nov 2019 16:25:08 +0100 Subject: [PATCH 3/8] Fix mynewt osal queue definition Queue table has pointers instead of data os_event structs. This resulted in crashes when elements were put to queue and overwritten variables that were just after mpool desiged for queue. --- src/osal/osal_mynewt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osal/osal_mynewt.h b/src/osal/osal_mynewt.h index da7977d39..e47e140c1 100644 --- a/src/osal/osal_mynewt.h +++ b/src/osal/osal_mynewt.h @@ -98,7 +98,7 @@ static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) // role device/host is used by OS NONE for mutex (disable usb isr) only #define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \ static _type _name##_##buf[_depth];\ - static struct os_event* _name##_##evbuf[_depth];\ + static struct os_event _name##_##evbuf[_depth];\ osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf, .evbuf = _name##_##evbuf};\ typedef struct From 96a9eca6a041c8a7e9e86792f06abd0ef5a187a3 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 11 Dec 2019 14:03:36 +0700 Subject: [PATCH 4/8] move VBUS sense out of dcd_synosys to bsp --- hw/bsp/feather_stm32f405/feather_stm32f405.c | 10 +++- hw/bsp/pyboardv11/pyboardv11.c | 24 +++++--- hw/bsp/stm32f207nucleo/stm32f207nucleo.c | 24 ++++++-- hw/bsp/stm32f407disco/stm32f407disco.c | 18 ++++-- hw/bsp/stm32f411disco/stm32f411disco.c | 23 +++++--- hw/bsp/stm32f412disco/stm32f412disco.c | 17 ++++-- hw/bsp/stm32f767nucleo/stm32f767nucleo.c | 3 + hw/bsp/stm32h743nucleo/stm32h743nucleo.c | 58 ++++++++++++-------- hw/bsp/stm32l476disco/stm32l476disco.c | 22 +++++--- src/portable/st/synopsys/dcd_synopsys.c | 8 +-- 10 files changed, 136 insertions(+), 71 deletions(-) diff --git a/hw/bsp/feather_stm32f405/feather_stm32f405.c b/hw/bsp/feather_stm32f405/feather_stm32f405.c index aec779ea3..e8b15b513 100644 --- a/hw/bsp/feather_stm32f405/feather_stm32f405.c +++ b/hw/bsp/feather_stm32f405/feather_stm32f405.c @@ -152,9 +152,6 @@ void board_init(void) GPIO_InitStruct.Alternate = UART_GPIO_AF; HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct); - // Enable USB OTG clock - __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); - // USB Pin Init // PA9- VUSB, PA10- ID, PA11- DM, PA12- DP @@ -179,6 +176,13 @@ void board_init(void) GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + // Enable USB OTG clock + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; } //--------------------------------------------------------------------+ diff --git a/hw/bsp/pyboardv11/pyboardv11.c b/hw/bsp/pyboardv11/pyboardv11.c index 2d4c732cc..7452eef71 100644 --- a/hw/bsp/pyboardv11/pyboardv11.c +++ b/hw/bsp/pyboardv11/pyboardv11.c @@ -38,6 +38,14 @@ #define BUTTON_PIN GPIO_PIN_3 #define BUTTON_STATE_ACTIVE 1 + +// enable all LED, Button, Uart, USB clock +static void all_rcc_clk_enable(void) +{ + __HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D- + __HAL_RCC_GPIOB_CLK_ENABLE(); // LED, Button +} + /** * @brief System Clock Configuration * The system Clock is configured as follow : @@ -107,14 +115,11 @@ void board_init(void) // Notify runtime of frequency change. SystemCoreClockUpdate(); - __HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+/D- - __HAL_RCC_GPIOB_CLK_ENABLE(); // button, LED + all_rcc_clk_enable(); GPIO_InitTypeDef GPIO_InitStruct; // LED - __HAL_RCC_GPIOD_CLK_ENABLE(); - GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; @@ -130,12 +135,8 @@ void board_init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FAST; HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct); - // Enable USB OTG clock - __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); - // USB Pin Init // PA9- VUSB, PA10- ID, PA11- DM, PA12- DP - __HAL_RCC_GPIOA_CLK_ENABLE(); /* Configure DM DP Pins */ GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; @@ -158,6 +159,13 @@ void board_init(void) GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + // Enable USB OTG clock + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; } //--------------------------------------------------------------------+ diff --git a/hw/bsp/stm32f207nucleo/stm32f207nucleo.c b/hw/bsp/stm32f207nucleo/stm32f207nucleo.c index de0b4753b..a09f26cfb 100644 --- a/hw/bsp/stm32f207nucleo/stm32f207nucleo.c +++ b/hw/bsp/stm32f207nucleo/stm32f207nucleo.c @@ -38,6 +38,14 @@ #define BUTTON_STATE_ACTIVE 1 +// enable all LED, Button, Uart, USB clock +static void all_rcc_clk_enable(void) +{ + __HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D- + __HAL_RCC_GPIOB_CLK_ENABLE(); // LED + __HAL_RCC_GPIOC_CLK_ENABLE(); // Button +} + /** * @brief System Clock Configuration * The system Clock is configured as follow : @@ -91,21 +99,22 @@ void board_init(void) #endif SystemClock_Config(); - - // Notify runtime of frequency change. SystemCoreClockUpdate(); - // LED - __HAL_RCC_GPIOB_CLK_ENABLE(); + all_rcc_clk_enable(); + GPIO_InitTypeDef GPIO_InitStruct; + + // LED GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct); + board_led_write(false); + // Button - __HAL_RCC_GPIOC_CLK_ENABLE(); GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; @@ -113,7 +122,6 @@ void board_init(void) HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct); /* Configure DM DP Pins */ - __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12); GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; @@ -136,6 +144,10 @@ void board_init(void) /* Enable USB FS Clocks */ __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; } //--------------------------------------------------------------------+ diff --git a/hw/bsp/stm32f407disco/stm32f407disco.c b/hw/bsp/stm32f407disco/stm32f407disco.c index b80c5c1b3..42cb613c8 100644 --- a/hw/bsp/stm32f407disco/stm32f407disco.c +++ b/hw/bsp/stm32f407disco/stm32f407disco.c @@ -37,6 +37,14 @@ #define BUTTON_PIN GPIO_PIN_0 #define BUTTON_STATE_ACTIVE 1 + +// enable all LED, Button, Uart, USB clock +static void all_rcc_clk_enable(void) +{ + __HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D-, Button + __HAL_RCC_GPIOD_CLK_ENABLE(); // LED +} + /** * @brief System Clock Configuration * The system Clock is configured as follow : @@ -102,14 +110,12 @@ void board_init(void) #endif SystemClock_Config(); - - // Notify runtime of frequency change. SystemCoreClockUpdate(); + all_rcc_clk_enable(); GPIO_InitTypeDef GPIO_InitStruct; // LED - __HAL_RCC_GPIOD_CLK_ENABLE(); GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; @@ -119,7 +125,6 @@ void board_init(void) board_led_write(false); // Button - __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; @@ -129,7 +134,6 @@ void board_init(void) // USB Pin Init // PA9- VUSB, PA10- ID, PA11- DM, PA12- DP /* Configure DM DP Pins */ - __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; @@ -153,6 +157,10 @@ void board_init(void) // Enable USB OTG clock __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; } //--------------------------------------------------------------------+ diff --git a/hw/bsp/stm32f411disco/stm32f411disco.c b/hw/bsp/stm32f411disco/stm32f411disco.c index d8d79d2f0..9d9c30715 100644 --- a/hw/bsp/stm32f411disco/stm32f411disco.c +++ b/hw/bsp/stm32f411disco/stm32f411disco.c @@ -37,6 +37,13 @@ #define BUTTON_PIN GPIO_PIN_0 #define BUTTON_STATE_ACTIVE 1 +// enable all LED, Button, Uart, USB clock +static void all_rcc_clk_enable(void) +{ + __HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D-, Button + __HAL_RCC_GPIOD_CLK_ENABLE(); // LED +} + /** * @brief System Clock Configuration * The system Clock is configured as follow : @@ -102,14 +109,12 @@ void board_init(void) #endif SystemClock_Config(); - - // Notify runtime of frequency change. SystemCoreClockUpdate(); + all_rcc_clk_enable(); GPIO_InitTypeDef GPIO_InitStruct; // LED - __HAL_RCC_GPIOD_CLK_ENABLE(); GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; @@ -119,19 +124,14 @@ void board_init(void) board_led_write(false); // Button - __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct); - // Enable USB OTG clock - __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); - /* Configure USB FS GPIOs */ /* Configure USB D+ D- Pins */ - __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; @@ -152,6 +152,13 @@ void board_init(void) GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + // Enable USB OTG clock + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; } //--------------------------------------------------------------------+ diff --git a/hw/bsp/stm32f412disco/stm32f412disco.c b/hw/bsp/stm32f412disco/stm32f412disco.c index 8d93013c1..10778bcfc 100644 --- a/hw/bsp/stm32f412disco/stm32f412disco.c +++ b/hw/bsp/stm32f412disco/stm32f412disco.c @@ -38,6 +38,14 @@ #define BUTTON_PIN GPIO_PIN_0 #define BUTTON_STATE_ACTIVE 1 + +// enable all LED, Button, Uart, USB clock +static void all_rcc_clk_enable(void) +{ + __HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D-, Button + __HAL_RCC_GPIOE_CLK_ENABLE(); // LED +} + /** * @brief System Clock Configuration * The system Clock is configured as follow : @@ -114,9 +122,8 @@ static void SystemClock_Config(void) void board_init(void) { SystemClock_Config(); - - // Notify runtime of frequency change. SystemCoreClockUpdate(); + all_rcc_clk_enable(); #if CFG_TUSB_OS == OPT_OS_NONE // 1ms tick timer @@ -129,7 +136,6 @@ void board_init(void) GPIO_InitTypeDef GPIO_InitStruct; // LED - __HAL_RCC_GPIOE_CLK_ENABLE(); GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; @@ -139,7 +145,6 @@ void board_init(void) board_led_write(false); // Button - __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; @@ -148,7 +153,6 @@ void board_init(void) /* Configure USB FS GPIOs */ /* Configure USB D+ D- Pins */ - __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; @@ -179,6 +183,9 @@ void board_init(void) // Enable USB OTG clock __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN; } //--------------------------------------------------------------------+ diff --git a/hw/bsp/stm32f767nucleo/stm32f767nucleo.c b/hw/bsp/stm32f767nucleo/stm32f767nucleo.c index 13966438f..7367c56b8 100644 --- a/hw/bsp/stm32f767nucleo/stm32f767nucleo.c +++ b/hw/bsp/stm32f767nucleo/stm32f767nucleo.c @@ -189,6 +189,9 @@ void board_init(void) /* Enable USB FS Clocks */ __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN; } //--------------------------------------------------------------------+ diff --git a/hw/bsp/stm32h743nucleo/stm32h743nucleo.c b/hw/bsp/stm32h743nucleo/stm32h743nucleo.c index f7e46a158..b7071ed64 100644 --- a/hw/bsp/stm32h743nucleo/stm32h743nucleo.c +++ b/hw/bsp/stm32h743nucleo/stm32h743nucleo.c @@ -30,10 +30,23 @@ #include "stm32h7xx.h" #include "stm32h7xx_hal_conf.h" -#define LED_PORT GPIOB -#define LED_PIN GPIO_PIN_0 -#define BUTTON_PORT GPIOC -#define BUTTON_PIN GPIO_PIN_13 +#define LED_PORT GPIOB +#define LED_PIN GPIO_PIN_0 +#define LED_STATE_ON 1 + +#define BUTTON_PORT GPIOC +#define BUTTON_PIN GPIO_PIN_13 +#define BUTTON_STATE_ACTIVE 1 + +// enable all LED, Button, Uart, USB clock +static void all_rcc_clk_enable(void) +{ + __HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D- + __HAL_RCC_GPIOB_CLK_ENABLE(); // LED + __HAL_RCC_GPIOC_CLK_ENABLE(); // Button +// __HAL_RCC_GPIOD_CLK_ENABLE(); // Uart tx, rx +// __HAL_RCC_USART3_CLK_ENABLE(); // Uart module +} /* PWR, RCC, GPIO (All): AHB4 (D3 domain) USB{1,2} OTG_{H,F}S: AHB1 (D2 domain) @@ -127,14 +140,27 @@ void board_init(void) #endif SystemClock_Config(); - SystemCoreClockUpdate(); + all_rcc_clk_enable(); GPIO_InitTypeDef GPIO_InitStruct; + // LED + GPIO_InitStruct.Pin = LED_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct); + + // Button + GPIO_InitStruct.Pin = BUTTON_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct); + // USB Pin Init // PA9- VUSB, PA10- ID, PA11- DM, PA12- DP - __HAL_RCC_GPIOA_CLK_ENABLE(); /* Configure DM DP Pins */ GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; @@ -158,27 +184,13 @@ void board_init(void) GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - // LED - __HAL_RCC_GPIOB_CLK_ENABLE(); - - GPIO_InitStruct.Pin = LED_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct); - - // Button - __HAL_RCC_GPIOC_CLK_ENABLE(); - GPIO_InitStruct.Pin = BUTTON_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct); - // https://community.st.com/s/question/0D50X00009XkYZLSA3/stm32h7-nucleo-usb-fs-cdc // TODO: Board init actually works fine without this line. HAL_PWREx_EnableUSBVoltageDetector(); __HAL_RCC_USB2_OTG_FS_CLK_ENABLE(); + + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN; } //--------------------------------------------------------------------+ diff --git a/hw/bsp/stm32l476disco/stm32l476disco.c b/hw/bsp/stm32l476disco/stm32l476disco.c index a4cad68bb..ac4ef365c 100644 --- a/hw/bsp/stm32l476disco/stm32l476disco.c +++ b/hw/bsp/stm32l476disco/stm32l476disco.c @@ -38,6 +38,16 @@ #define BUTTON_PIN GPIO_PIN_0 #define BUTTON_STATE_ACTIVE 1 + +// enable all LED, Button, Uart, USB clock +static void all_rcc_clk_enable(void) +{ + __HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D-, Button + __HAL_RCC_GPIOB_CLK_ENABLE(); // LED + __HAL_RCC_GPIOC_CLK_ENABLE(); // VBUS pin +} + + /** * @brief System Clock Configuration * The system Clock is configured as follow : @@ -117,6 +127,8 @@ void board_init(void) #endif SystemClock_Config(); + SystemCoreClockUpdate(); + all_rcc_clk_enable(); /* Enable Power Clock*/ __HAL_RCC_PWR_CLK_ENABLE(); @@ -124,13 +136,9 @@ void board_init(void) /* Enable USB power on Pwrctrl CR2 register */ HAL_PWREx_EnableVddUSB(); - // Notify runtime of frequency change. - SystemCoreClockUpdate(); - GPIO_InitTypeDef GPIO_InitStruct; // LED - __HAL_RCC_GPIOB_CLK_ENABLE(); GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; @@ -140,7 +148,6 @@ void board_init(void) board_led_write(false); // Button - __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; @@ -149,7 +156,6 @@ void board_init(void) // USB /* Configure DM DP Pins */ - __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12); GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; @@ -158,7 +164,6 @@ void board_init(void) HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Configure VBUS Pin */ - __HAL_RCC_GPIOC_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_11; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; @@ -166,6 +171,9 @@ void board_init(void) /* Enable USB FS Clock */ __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN; } //--------------------------------------------------------------------+ diff --git a/src/portable/st/synopsys/dcd_synopsys.c b/src/portable/st/synopsys/dcd_synopsys.c index 7929b6916..b25cfccae 100644 --- a/src/portable/st/synopsys/dcd_synopsys.c +++ b/src/portable/st/synopsys/dcd_synopsys.c @@ -207,12 +207,8 @@ void dcd_init (uint8_t rhport) USB_OTG_GINTMSK_SOFM | USB_OTG_GINTMSK_RXFLVLM /* SB_OTG_GINTMSK_ESUSPM | \ USB_OTG_GINTMSK_USBSUSPM */; - // Enable VBUS hardware sensing, enable pullup, enable peripheral. -#ifdef USB_OTG_GCCFG_VBDEN - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN | USB_OTG_GCCFG_PWRDWN; -#else - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN | USB_OTG_GCCFG_PWRDWN; -#endif + // Enable USB transceiver. + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_PWRDWN; // Soft Connect -> Enable pullup on D+/D-. // This step does not appear to be specified in the programmer's model. From 88bdb12ee506a143e2fa1033c258a0540c0768bd Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 11 Dec 2019 15:19:51 +0700 Subject: [PATCH 5/8] close #204 define HSE_VALUE in _hal_conf instead of board.mk --- hw/bsp/feather_stm32f405/board.mk | 1 - hw/bsp/pyboardv11/board.mk | 1 - hw/bsp/stm32f070rbnucleo/board.mk | 1 - hw/bsp/stm32f072disco/board.mk | 1 - hw/bsp/stm32f103bluepill/board.mk | 1 - hw/bsp/stm32f207nucleo/board.mk | 1 - hw/bsp/stm32f303disco/board.mk | 1 - hw/bsp/stm32f407disco/board.mk | 1 - hw/bsp/stm32f411disco/board.mk | 1 - hw/bsp/stm32f412disco/board.mk | 1 - hw/bsp/stm32f767nucleo/board.mk | 1 - hw/bsp/stm32h743nucleo/board.mk | 1 - hw/bsp/stm32h743nucleo/stm32h7xx_hal_conf.h | 2 +- hw/bsp/stm32l0538disco/board.mk | 1 - hw/bsp/stm32l476disco/board.mk | 1 - 15 files changed, 1 insertion(+), 15 deletions(-) diff --git a/hw/bsp/feather_stm32f405/board.mk b/hw/bsp/feather_stm32f405/board.mk index 1e68737b9..ba84dd3a2 100644 --- a/hw/bsp/feather_stm32f405/board.mk +++ b/hw/bsp/feather_stm32f405/board.mk @@ -7,7 +7,6 @@ CFLAGS += \ -mfpu=fpv4-sp-d16 \ -nostdlib -nostartfiles \ -DSTM32F405xx \ - -DHSE_VALUE=12000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32F4 ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver diff --git a/hw/bsp/pyboardv11/board.mk b/hw/bsp/pyboardv11/board.mk index 0118b54a4..f57f662f8 100644 --- a/hw/bsp/pyboardv11/board.mk +++ b/hw/bsp/pyboardv11/board.mk @@ -7,7 +7,6 @@ CFLAGS += \ -mfpu=fpv4-sp-d16 \ -nostdlib -nostartfiles \ -DSTM32F405xx \ - -DHSE_VALUE=12000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32F4 ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver diff --git a/hw/bsp/stm32f070rbnucleo/board.mk b/hw/bsp/stm32f070rbnucleo/board.mk index 6e52b8141..07d885dcb 100644 --- a/hw/bsp/stm32f070rbnucleo/board.mk +++ b/hw/bsp/stm32f070rbnucleo/board.mk @@ -5,7 +5,6 @@ CFLAGS += \ -mcpu=cortex-m0 \ -mfloat-abi=soft \ -nostdlib -nostartfiles \ - -DHSE_VALUE=8000000 \ -DSTM32F070xB \ -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_STM32F0 diff --git a/hw/bsp/stm32f072disco/board.mk b/hw/bsp/stm32f072disco/board.mk index 5ed87cfa8..cae3b5621 100644 --- a/hw/bsp/stm32f072disco/board.mk +++ b/hw/bsp/stm32f072disco/board.mk @@ -6,7 +6,6 @@ CFLAGS += \ -mfloat-abi=soft \ -nostdlib -nostartfiles \ -DSTM32F072xB \ - -DHSE_VALUE=8000000 \ -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_STM32F0 diff --git a/hw/bsp/stm32f103bluepill/board.mk b/hw/bsp/stm32f103bluepill/board.mk index f464fa298..7c1a7b373 100644 --- a/hw/bsp/stm32f103bluepill/board.mk +++ b/hw/bsp/stm32f103bluepill/board.mk @@ -6,7 +6,6 @@ CFLAGS += \ -mfloat-abi=soft \ -nostdlib -nostartfiles \ -DSTM32F103xB \ - -DHSE_VALUE=8000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32F1 # mcu driver cause following warnings diff --git a/hw/bsp/stm32f207nucleo/board.mk b/hw/bsp/stm32f207nucleo/board.mk index 003a3dd41..2eb92f175 100644 --- a/hw/bsp/stm32f207nucleo/board.mk +++ b/hw/bsp/stm32f207nucleo/board.mk @@ -6,7 +6,6 @@ CFLAGS += \ -mfloat-abi=soft \ -nostdlib -nostartfiles \ -DSTM32F207xx \ - -DHSE_VALUE=8000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32F2 # mcu driver cause following warnings diff --git a/hw/bsp/stm32f303disco/board.mk b/hw/bsp/stm32f303disco/board.mk index fbe034144..61c851031 100644 --- a/hw/bsp/stm32f303disco/board.mk +++ b/hw/bsp/stm32f303disco/board.mk @@ -7,7 +7,6 @@ CFLAGS += \ -mfpu=fpv4-sp-d16 \ -nostdlib -nostartfiles \ -DSTM32F303xC \ - -DHSE_VALUE=8000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32F3 # mcu driver cause following warnings diff --git a/hw/bsp/stm32f407disco/board.mk b/hw/bsp/stm32f407disco/board.mk index 216b51bf9..e80e84bcb 100644 --- a/hw/bsp/stm32f407disco/board.mk +++ b/hw/bsp/stm32f407disco/board.mk @@ -7,7 +7,6 @@ CFLAGS += \ -mfpu=fpv4-sp-d16 \ -nostdlib -nostartfiles \ -DSTM32F407xx \ - -DHSE_VALUE=8000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32F4 ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver diff --git a/hw/bsp/stm32f411disco/board.mk b/hw/bsp/stm32f411disco/board.mk index 63aa76154..5cbe05248 100644 --- a/hw/bsp/stm32f411disco/board.mk +++ b/hw/bsp/stm32f411disco/board.mk @@ -7,7 +7,6 @@ CFLAGS += \ -mfpu=fpv4-sp-d16 \ -nostdlib -nostartfiles \ -DSTM32F411xE \ - -DHSE_VALUE=8000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32F4 ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver diff --git a/hw/bsp/stm32f412disco/board.mk b/hw/bsp/stm32f412disco/board.mk index ddb8402ec..9b54ab55c 100644 --- a/hw/bsp/stm32f412disco/board.mk +++ b/hw/bsp/stm32f412disco/board.mk @@ -7,7 +7,6 @@ CFLAGS += \ -mfpu=fpv4-sp-d16 \ -nostdlib -nostartfiles \ -DSTM32F412Zx \ - -DHSE_VALUE=8000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32F4 # mcu driver cause following warnings diff --git a/hw/bsp/stm32f767nucleo/board.mk b/hw/bsp/stm32f767nucleo/board.mk index 5d9645379..152e0bdbb 100644 --- a/hw/bsp/stm32f767nucleo/board.mk +++ b/hw/bsp/stm32f767nucleo/board.mk @@ -7,7 +7,6 @@ CFLAGS += \ -mfpu=fpv5-d16 \ -nostdlib -nostartfiles \ -DSTM32F767xx \ - -DHSE_VALUE=8000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32F7 # mcu driver cause following warnings diff --git a/hw/bsp/stm32h743nucleo/board.mk b/hw/bsp/stm32h743nucleo/board.mk index cfea7f57b..928ad9a83 100644 --- a/hw/bsp/stm32h743nucleo/board.mk +++ b/hw/bsp/stm32h743nucleo/board.mk @@ -7,7 +7,6 @@ CFLAGS += \ -mfpu=fpv5-d16 \ -nostdlib -nostartfiles \ -DSTM32H743xx \ - -DHSE_VALUE=8000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32H7 # mcu driver cause following warnings diff --git a/hw/bsp/stm32h743nucleo/stm32h7xx_hal_conf.h b/hw/bsp/stm32h743nucleo/stm32h7xx_hal_conf.h index 2a9eb37ae..c58fdf75b 100644 --- a/hw/bsp/stm32h743nucleo/stm32h7xx_hal_conf.h +++ b/hw/bsp/stm32h743nucleo/stm32h7xx_hal_conf.h @@ -111,7 +111,7 @@ * (when HSE is used as system clock source, directly or through the PLL). */ #if !defined (HSE_VALUE) -#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */ +#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ #if !defined (HSE_STARTUP_TIMEOUT) diff --git a/hw/bsp/stm32l0538disco/board.mk b/hw/bsp/stm32l0538disco/board.mk index d81b2d887..241ad5d28 100644 --- a/hw/bsp/stm32l0538disco/board.mk +++ b/hw/bsp/stm32l0538disco/board.mk @@ -6,7 +6,6 @@ CFLAGS += \ -mfloat-abi=soft \ -nostdlib -nostartfiles \ -DSTM32L053xx \ - -DHSE_VALUE=8000000 \ -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_STM32L0 diff --git a/hw/bsp/stm32l476disco/board.mk b/hw/bsp/stm32l476disco/board.mk index 3432ac2e5..dc6b886db 100644 --- a/hw/bsp/stm32l476disco/board.mk +++ b/hw/bsp/stm32l476disco/board.mk @@ -7,7 +7,6 @@ CFLAGS += \ -mfpu=fpv4-sp-d16 \ -nostdlib -nostartfiles \ -DSTM32L476xx \ - -DHSE_VALUE=8000000 \ -DCFG_TUSB_MCU=OPT_MCU_STM32L4 ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32L4xx_HAL_Driver From 9d96b6d66eab8a8dea44db1a2c346f667d22ce21 Mon Sep 17 00:00:00 2001 From: Jeremy Herbert Date: Thu, 12 Dec 2019 09:40:06 +1000 Subject: [PATCH 6/8] Update dcd_stm32_fsdev.c Add a note about pin remapping for the STM32F042Fx --- src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index ec182960e..9e99ea1de 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -30,7 +30,7 @@ /********************************************** * This driver has been tested with the following MCUs: - * - F070, F072, L053 + * - F070, F072, L053, F042F6 * * It also should work with minimal changes for any ST MCU with an "USB A"/"PCD"/"HCD" peripheral. This * covers: @@ -44,6 +44,9 @@ * L4x2, L4x3 1024 byte buffer * * To use this driver, you must: + * - If you are using a device with crystal-less USB, set up the clock recovery system (CRS) + * - Remap pins to be D+/D- on devices that they are shared (for example: F042Fx) + * - This is different to the normal "alternate function" GPIO interface, needs to go through SYSCFG->CFGRx register * - Enable USB clock; Perhaps use __HAL_RCC_USB_CLK_ENABLE(); * - (Optionally configure GPIO HAL to tell it the USB driver is using the USB pins) * - call tusb_init(); From fdce63b268579f4b847980172d113577de28900e Mon Sep 17 00:00:00 2001 From: samveen Date: Mon, 16 Dec 2019 23:01:26 +0530 Subject: [PATCH 7/8] [tusb]fix typo in comment --- src/class/hid/hid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index a3a9ffc88..cb5e60474 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -180,7 +180,7 @@ typedef enum /// Standard HID Boot Protocol Keyboard Report. typedef struct TU_ATTR_PACKED { - uint8_t modifier; /**< Keyboard modifier (KEYBOARD_MODIFER_* masks). */ + uint8_t modifier; /**< Keyboard modifier (KEYBOARD_MODIFIER_* masks). */ uint8_t reserved; /**< Reserved for OEM use, always set to 0. */ uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */ } hid_keyboard_report_t; From ba8a2329700059a52594efdfe8d0f98018e02fc7 Mon Sep 17 00:00:00 2001 From: samveen Date: Tue, 17 Dec 2019 12:47:05 +0530 Subject: [PATCH 8/8] add "`" and "~" to keycode -> ASCII table --- src/class/hid/hid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index cb5e60474..7fa4aa8ab 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -812,7 +812,7 @@ enum {'#' , '~' }, /* 0x32 */ \ {';' , ':' }, /* 0x33 */ \ {'\'' , '\"' }, /* 0x34 */ \ - {0 , 0 }, /* 0x35 */ \ + {'`' , '~' }, /* 0x35 */ \ {',' , '<' }, /* 0x36 */ \ {'.' , '>' }, /* 0x37 */ \ {'/' , '?' }, /* 0x38 */ \