drivers: usb: Add nRF52840 USBD driver

* Add usbd_dc_nrfx shim

The shim is based on the previous one usbd_dc_nrf5.
For handling the USBD hardware, tested nrfx_usbd driver from nRF SDK
was used.

Briefly tested examples:
* usb/cdc_acm
* usb/dfu (USB communication only due to flash handling issues)
* usb/hid-mouse
* bluetooth/hci_usb

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
This commit is contained in:
Paweł Zadrożniak 2018-07-06 16:16:47 +02:00 committed by Carles Cufí
commit 68cb7b3e38
7 changed files with 1574 additions and 2319 deletions

View file

@ -261,9 +261,9 @@ lf_already_started:
#if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840) #if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840)
static inline void power_event_cb(nrf_power_event_t event) static inline void power_event_cb(nrf_power_event_t event)
{ {
extern void nrf5_usbd_power_event_callback(nrf_power_event_t event); extern void usb_dc_nrfx_power_event_callback(nrf_power_event_t event);
nrf5_usbd_power_event_callback(event); usb_dc_nrfx_power_event_callback(event);
} }
#endif #endif
@ -414,70 +414,22 @@ DEVICE_AND_API_INIT(clock_nrf5_k32src,
&_k32src_clock_control_api); &_k32src_clock_control_api);
#if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840) #if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840)
static void power_int_enable(bool enable)
void nrf5_power_usb_power_int_enable(bool enable)
{ {
u32_t mask; u32_t mask;
mask = NRF_POWER_INT_USBDETECTED_MASK | mask = NRF_POWER_INT_USBDETECTED_MASK |
NRF_POWER_INT_USBREMOVED_MASK | NRF_POWER_INT_USBREMOVED_MASK |
NRF_POWER_INT_USBPWRRDY_MASK; NRF_POWER_INT_USBPWRRDY_MASK;
if (enable) { if (enable) {
nrf_power_int_enable(mask); nrf_power_int_enable(mask);
irq_enable(POWER_CLOCK_IRQn);
} else { } else {
nrf_power_int_disable(mask); nrf_power_int_disable(mask);
} }
} }
static bool usbregstatus_vbusdet_get(void)
{
return nrf_power_usbregstatus_vbusdet_get();
}
static bool usbregstatus_outrdy_get(void)
{
return nrf_power_usbregstatus_outrdy_get();
}
static const struct usbd_power_nrf5_api usbd_power_api = {
.usb_power_int_enable = power_int_enable,
.vbusdet_get = usbregstatus_vbusdet_get,
.outrdy_get = usbregstatus_outrdy_get,
};
static int usbd_power_init(struct device *dev)
{
irq_enable(POWER_CLOCK_IRQn);
return 0;
}
void nrf5_power_usb_power_int_enable(struct device *dev, bool enable)
{
const struct usbd_power_nrf5_api *api = dev->driver_api;
api->usb_power_int_enable(enable);
}
bool nrf5_power_clock_usb_vbusdet(struct device *dev)
{
const struct usbd_power_nrf5_api *api = dev->driver_api;
return api->vbusdet_get();
}
bool nrf5_power_clock_usb_outrdy(struct device *dev)
{
const struct usbd_power_nrf5_api *api = dev->driver_api;
return api->outrdy_get();
}
DEVICE_AND_API_INIT(usbd_power_nrf5,
CONFIG_USBD_NRF5_NAME,
usbd_power_init,
NULL, NULL,
PRE_KERNEL_2,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&usbd_power_api);
#endif #endif

View file

@ -1,5 +1,5 @@
zephyr_sources_ifdef(CONFIG_USB_DW usb_dc_dw.c) zephyr_sources_ifdef(CONFIG_USB_DW usb_dc_dw.c)
zephyr_sources_ifdef(CONFIG_USB_DC_STM32 usb_dc_stm32.c) zephyr_sources_ifdef(CONFIG_USB_DC_STM32 usb_dc_stm32.c)
zephyr_sources_ifdef(CONFIG_USB_DC_SAM0 usb_dc_sam0.c) zephyr_sources_ifdef(CONFIG_USB_DC_SAM0 usb_dc_sam0.c)
zephyr_sources_ifdef(CONFIG_USB_NRF52840 usb_dc_nrf5.c) zephyr_sources_ifdef(CONFIG_USB_NRF52840 usb_dc_nrfx.c)
zephyr_sources_ifdef(CONFIG_USB_KINETIS usb_dc_kinetis.c) zephyr_sources_ifdef(CONFIG_USB_KINETIS usb_dc_kinetis.c)

View file

@ -53,6 +53,7 @@ config USB_NRF52840
depends on SOC_NRF52840 depends on SOC_NRF52840
select USB_DEVICE_DRIVER select USB_DEVICE_DRIVER
select HAS_DTS_USB select HAS_DTS_USB
select NRFX_USBD
help help
nRF52840 USB Device Controller Driver nRF52840 USB Device Controller Driver

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -48,15 +48,7 @@
#endif #endif
#if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840) #if defined(CONFIG_USB) && defined(CONFIG_SOC_NRF52840)
struct usbd_power_nrf5_api { void nrf5_power_usb_power_int_enable(bool enable);
void (*usb_power_int_enable)(bool enable);
bool (*vbusdet_get)(void);
bool (*outrdy_get)(void);
};
void nrf5_power_usb_power_int_enable(struct device *dev, bool enable);
bool nrf5_power_clock_usb_vbusdet(struct device *dev);
bool nrf5_power_clock_usb_outrdy(struct device *dev);
#endif #endif
#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF5_CLOCK_CONTROL_H_ */ #endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF5_CLOCK_CONTROL_H_ */

View file

@ -111,14 +111,14 @@
#define CONFIG_SPI_3_NRF_MISO_PIN NORDIC_NRF_SPI_4002B000_MISO_PIN #define CONFIG_SPI_3_NRF_MISO_PIN NORDIC_NRF_SPI_4002B000_MISO_PIN
#define CONFIG_SPI_3_NRF_CSN_PIN NORDIC_NRF_SPI_4002B000_CSN_PIN #define CONFIG_SPI_3_NRF_CSN_PIN NORDIC_NRF_SPI_4002B000_CSN_PIN
#define CONFIG_USBD_NRF5_IRQ NORDIC_NRF_USBD_40027000_IRQ_USBD #define CONFIG_USBD_NRF_IRQ NORDIC_NRF_USBD_40027000_IRQ_USBD
#define CONFIG_USBD_NRF5_IRQ_PRI NORDIC_NRF_USBD_40027000_IRQ_USBD_PRIORITY #define CONFIG_USBD_NRF_IRQ_PRI NORDIC_NRF_USBD_40027000_IRQ_USBD_PRIORITY
#define CONFIG_USBD_NRF5_NUM_BIDIR_EP NORDIC_NRF_USBD_40027000_NUM_BIDIR_ENDPOINTS #define CONFIG_USBD_NRF_NUM_BIDIR_EP NORDIC_NRF_USBD_40027000_NUM_BIDIR_ENDPOINTS
#define CONFIG_USBD_NRF5_NUM_IN_EP NORDIC_NRF_USBD_40027000_NUM_IN_ENDPOINTS #define CONFIG_USBD_NRF_NUM_IN_EP NORDIC_NRF_USBD_40027000_NUM_IN_ENDPOINTS
#define CONFIG_USBD_NRF5_NUM_OUT_EP NORDIC_NRF_USBD_40027000_NUM_OUT_ENDPOINTS #define CONFIG_USBD_NRF_NUM_OUT_EP NORDIC_NRF_USBD_40027000_NUM_OUT_ENDPOINTS
#define CONFIG_USBD_NRF5_NUM_ISOIN_EP NORDIC_NRF_USBD_40027000_NUM_ISOIN_ENDPOINTS #define CONFIG_USBD_NRF_NUM_ISOIN_EP NORDIC_NRF_USBD_40027000_NUM_ISOIN_ENDPOINTS
#define CONFIG_USBD_NRF5_NUM_ISOOUT_EP NORDIC_NRF_USBD_40027000_NUM_ISOOUT_ENDPOINTS #define CONFIG_USBD_NRF_NUM_ISOOUT_EP NORDIC_NRF_USBD_40027000_NUM_ISOOUT_ENDPOINTS
#define CONFIG_USBD_NRF5_NAME NORDIC_NRF_USBD_40027000_LABEL #define CONFIG_USBD_NRF_NAME NORDIC_NRF_USBD_40027000_LABEL
#define CONFIG_WDT_0_NAME NORDIC_NRF_WATCHDOG_40010000_LABEL #define CONFIG_WDT_0_NAME NORDIC_NRF_WATCHDOG_40010000_LABEL
#define CONFIG_WDT_NRF_IRQ NORDIC_NRF_WATCHDOG_40010000_IRQ_WDT #define CONFIG_WDT_NRF_IRQ NORDIC_NRF_WATCHDOG_40010000_IRQ_WDT