diff --git a/arch/arm/soc/st_stm32/stm32f1/dts.fixup b/arch/arm/soc/st_stm32/stm32f1/dts.fixup index 7c7771bc44b..08b4f8fe062 100644 --- a/arch/arm/soc/st_stm32/stm32f1/dts.fixup +++ b/arch/arm/soc/st_stm32/stm32f1/dts.fixup @@ -51,4 +51,10 @@ #define CONFIG_SPI_3_NAME ST_STM32_SPI_40003C00_LABEL #define CONFIG_SPI_3_IRQ ST_STM32_SPI_40003C00_IRQ_0 +#define CONFIG_USB_BASE_ADDRESS ST_STM32_USB_40005C00_BASE_ADDRESS +#define CONFIG_USB_IRQ ST_STM32_USB_40005C00_IRQ_USB +#define CONFIG_USB_IRQ_PRI ST_STM32_USB_40005C00_IRQ_USB_PRIORITY +#define CONFIG_USB_NUM_BIDIR_ENDPOINTS ST_STM32_USB_40005C00_NUM_BIDIR_ENDPOINTS +#define CONFIG_USB_RAM_SIZE ST_STM32_USB_40005C00_RAM_SIZE + /* End of SoC Level DTS fixup file */ diff --git a/arch/arm/soc/st_stm32/stm32f1/soc.c b/arch/arm/soc/st_stm32/stm32f1/soc.c index 70b2e36a414..d8028f074b3 100644 --- a/arch/arm/soc/st_stm32/stm32f1/soc.c +++ b/arch/arm/soc/st_stm32/stm32f1/soc.c @@ -27,6 +27,17 @@ uint32_t HAL_GetTick(void) return k_uptime_get_32(); } +/** + * @brief This function provides minimum delay (in milliseconds) based + * on variable incremented. + * @param Delay: specifies the delay time length, in milliseconds. + * @return None + */ +void HAL_Delay(__IO uint32_t Delay) +{ + k_sleep(Delay); +} + /** * @brief Perform basic hardware initialization at boot. * diff --git a/boards/arm/olimexino_stm32/Kconfig.board b/boards/arm/olimexino_stm32/Kconfig.board index c715dab5ebb..f84125e76da 100644 --- a/boards/arm/olimexino_stm32/Kconfig.board +++ b/boards/arm/olimexino_stm32/Kconfig.board @@ -7,3 +7,4 @@ config BOARD_OLIMEXINO_STM32 bool "OLIMEXINO-STM32 Development Board" depends on SOC_STM32F103XB + select USB_DC_STM32_DISCONN_ENABLE if USB diff --git a/boards/arm/olimexino_stm32/Kconfig.defconfig b/boards/arm/olimexino_stm32/Kconfig.defconfig index 467b5099844..c8eeb355d8b 100644 --- a/boards/arm/olimexino_stm32/Kconfig.defconfig +++ b/boards/arm/olimexino_stm32/Kconfig.defconfig @@ -44,4 +44,17 @@ config PWM_STM32_1 endif # PWM +if USB_DC_STM32_DISCONN_ENABLE + +config USB_DC_STM32_DISCONN_GPIO_PORT_NAME + default "GPIOC" + +config USB_DC_STM32_DISCONN_PIN + default 12 + +config USB_DC_STM32_DISCONN_PIN_LEVEL + default 0 + +endif # USB_DC_STM32_DISCONN_ENABLE + endif # BOARD_OLIMEXINO_STM32 diff --git a/boards/arm/olimexino_stm32/doc/olimexino_stm32.rst b/boards/arm/olimexino_stm32/doc/olimexino_stm32.rst index 0d1e04e55e4..f0f8b677a0d 100644 --- a/boards/arm/olimexino_stm32/doc/olimexino_stm32.rst +++ b/boards/arm/olimexino_stm32/doc/olimexino_stm32.rst @@ -45,6 +45,8 @@ hardware features: +-----------+------------+----------------------+ | SPI | on-chip | spi | +-----------+------------+----------------------+ +| USB | on-chip | USB device | ++-----------+------------+----------------------+ Other hardware features are not supported by the Zephyr kernel. @@ -319,6 +321,15 @@ OLIMEXINO-STM32 board has up to 1 I2C. The default I2C mapping for Zephyr is: - I2C2_SCL : PB10 - I2C2_SDA : PB11 +USB +=== + +OLIMEXINO-STM32 board has a USB 2.0 full-speed device interface available +through its mini USB connector. + +- USB_DM : PA11 +- USB_DP : PA12 + Jumpers ======= diff --git a/boards/arm/olimexino_stm32/olimexino_stm32.dts b/boards/arm/olimexino_stm32/olimexino_stm32.dts index 0c483949b98..d0f25a6a98c 100644 --- a/boards/arm/olimexino_stm32/olimexino_stm32.dts +++ b/boards/arm/olimexino_stm32/olimexino_stm32.dts @@ -74,3 +74,7 @@ &spi2 { status = "ok"; }; + +&usb { + status = "ok"; +}; diff --git a/boards/arm/olimexino_stm32/olimexino_stm32.yaml b/boards/arm/olimexino_stm32/olimexino_stm32.yaml index f31785bdff3..d865710ce99 100644 --- a/boards/arm/olimexino_stm32/olimexino_stm32.yaml +++ b/boards/arm/olimexino_stm32/olimexino_stm32.yaml @@ -10,3 +10,4 @@ supported: - gpio - i2c - spi + - usb_device diff --git a/boards/arm/olimexino_stm32/pinmux.c b/boards/arm/olimexino_stm32/pinmux.c index ec3c6b0e9e0..17cb59f4ceb 100644 --- a/boards/arm/olimexino_stm32/pinmux.c +++ b/boards/arm/olimexino_stm32/pinmux.c @@ -45,6 +45,10 @@ static const struct pin_config pinconf[] = { #ifdef CONFIG_PWM_STM32_1 {STM32_PIN_PA8, STM32F1_PINMUX_FUNC_PA8_PWM1_CH1}, #endif /* CONFIG_PWM_STM32_1 */ +#ifdef USB_DC_STM32 + {STM32_PIN_PA11, STM32F1_PINMUX_FUNC_PA11_USB_DM}, + {STM32_PIN_PA12, STM32F1_PINMUX_FUNC_PA12_USB_DP}, +#endif /* USB_DC_STM32 */ }; static int pinmux_stm32_init(struct device *port) diff --git a/drivers/pinmux/stm32/pinmux_stm32f1.h b/drivers/pinmux/stm32/pinmux_stm32f1.h index bf6c0dd74e6..7bd740c5805 100644 --- a/drivers/pinmux/stm32/pinmux_stm32f1.h +++ b/drivers/pinmux/stm32/pinmux_stm32f1.h @@ -27,6 +27,9 @@ #define STM32F1_PINMUX_FUNC_PA7_SPI1_MASTER_MOSI STM32_PIN_SPI_MASTER_MOSI #define STM32F1_PINMUX_FUNC_PA7_SPI1_SLAVE_MOSI STM32_PIN_SPI_SLAVE_MOSI +#define STM32F1_PINMUX_FUNC_PA11_USB_DM STM32_PIN_USB +#define STM32F1_PINMUX_FUNC_PA12_USB_DP STM32_PIN_USB + #define STM32F1_PINMUX_FUNC_PD5_USART2_TX STM32_PIN_USART_TX #define STM32F1_PINMUX_FUNC_PD6_USART2_RX STM32_PIN_USART_RX diff --git a/drivers/usb/device/usb_dc_stm32.c b/drivers/usb/device/usb_dc_stm32.c index 1c8ca03fed1..b6090193a23 100644 --- a/drivers/usb/device/usb_dc_stm32.c +++ b/drivers/usb/device/usb_dc_stm32.c @@ -67,6 +67,14 @@ #define EP_TYPE_INTR PCD_EP_TYPE_INTR #endif +#ifndef CONFIG_USB_NUM_IN_ENDPOINTS +#define CONFIG_USB_NUM_IN_ENDPOINTS 0 +#endif /* CONFIG_USB_NUM_IN_ENDPOINTS */ + +#ifndef CONFIG_USB_NUM_OUT_ENDPOINTS +#define CONFIG_USB_NUM_OUT_ENDPOINTS 0 +#endif /* CONFIG_USB_NUM_OUT_ENDPOINTS */ + /* Total in ep number = bidirectional ep number + in ep number */ #define NUM_IN_EP (CONFIG_USB_NUM_BIDIR_ENDPOINTS + \ CONFIG_USB_NUM_IN_ENDPOINTS) diff --git a/dts/arm/st/stm32f103Xb.dtsi b/dts/arm/st/stm32f103Xb.dtsi index c2548525ffd..38d0b437cc5 100644 --- a/dts/arm/st/stm32f103Xb.dtsi +++ b/dts/arm/st/stm32f103Xb.dtsi @@ -23,5 +23,16 @@ status = "disabled"; label = "SPI_2"; }; + + usb: usb@40005c00 { + compatible = "st,stm32-usb"; + reg = <0x40005c00 0x400>; + interrupts = <20 0>; + interrupt-names = "usb"; + num-bidir-endpoints = <8>; + ram-size = <512>; + status = "disabled"; + label= "USB"; + }; }; }; diff --git a/include/dt-bindings/pinctrl/stm32-pinctrlf1.h b/include/dt-bindings/pinctrl/stm32-pinctrlf1.h index 8fdf44e10a0..b6a7a6b175d 100644 --- a/include/dt-bindings/pinctrl/stm32-pinctrlf1.h +++ b/include/dt-bindings/pinctrl/stm32-pinctrlf1.h @@ -105,5 +105,6 @@ /* Hardware master NSS output enabled */ #define STM32_PIN_SPI_MASTER_NSS_OE (STM32_MODE_OUTPUT | STM32_CNF_ALT_FUNC | STM32_CNF_PUSH_PULL) #define STM32_PIN_SPI_SLAVE_NSS (STM32_MODE_INPUT | STM32_CNF_IN_FLOAT) +#define STM32_PIN_USB (STM32_MODE_INPUT | STM32_CNF_IN_PUPD) #endif /* _STM32_PINCTRLF1_H_ */