-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bsp][nrf5x]added the cherryusb adapter for nrf52840 (#9939)
- Loading branch information
Showing
10 changed files
with
1,579 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
from building import * | ||
|
||
cwd = GetCurrentDir() | ||
|
||
# add general drivers | ||
src = [] | ||
path = [] | ||
|
||
if GetDepend(['RT_USING_CHERRYUSB']): | ||
src += Glob('cherryusb/cherryusb.c') | ||
path += [cwd + '/cherryusb'] | ||
|
||
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path) | ||
|
||
list = os.listdir(cwd) | ||
for item in list: | ||
if os.path.isfile(os.path.join(cwd, item, 'SConscript')): | ||
group = group + SConscript(os.path.join(item, 'SConscript')) | ||
|
||
Return('group') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <rtthread.h> | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include "nrf.h" | ||
#include "nrfx_usbd.h" | ||
#include "nrfx_clock.h" | ||
#include "nrfx_power.h" | ||
|
||
void usb_dc_low_level_post_init(void) | ||
{ | ||
/* Enable interrupt globally */ | ||
NRFX_IRQ_PRIORITY_SET(USBD_IRQn, NRFX_USBD_CONFIG_IRQ_PRIORITY); | ||
NRFX_IRQ_ENABLE(USBD_IRQn); | ||
} | ||
|
||
extern void cherry_usb_hal_nrf_power_event(uint32_t event); | ||
static void power_event_handler(nrfx_power_usb_evt_t event) | ||
{ | ||
cherry_usb_hal_nrf_power_event((uint32_t)event); | ||
} | ||
|
||
void usb_dc_low_level_pre_init(void) | ||
{ | ||
uint32_t usb_reg; | ||
const nrfx_power_usbevt_config_t config = {.handler = power_event_handler}; | ||
nrfx_power_usbevt_init(&config); | ||
nrfx_power_usbevt_enable(); | ||
usb_reg = NRF_POWER->USBREGSTATUS; | ||
|
||
if (usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk) | ||
{ | ||
cherry_usb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED); | ||
} | ||
|
||
if (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk) | ||
{ | ||
cherry_usb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY); | ||
} | ||
} | ||
|
||
void usb_low_clear_pending_irq(void) | ||
{ | ||
NVIC_ClearPendingIRQ(USBD_IRQn); | ||
} | ||
|
||
void usb_low_disable_irq(void) | ||
{ | ||
NVIC_DisableIRQ(USBD_IRQn); | ||
} | ||
|
||
int cherryusb_protocol_stack_init(void) | ||
{ | ||
#ifdef RT_CHERRYUSB_DEVICE_TEMPLATE_CDC_ACM | ||
extern void cdc_acm_init(void); | ||
cdc_acm_init(); | ||
rt_kprintf("cdc acm example started. \r\n"); | ||
#elif defined RT_CHERRYUSB_DEVICE_TEMPLATE_MSC | ||
extern void msc_ram_init(void); | ||
msc_ram_init(); | ||
rt_kprintf("msc ram example started. \r\n"); | ||
#elif defined RT_CHERRYUSB_DEVICE_TEMPLATE_HID_KEYBOARD | ||
extern void hid_keyboard_init(uint8_t busid, uintptr_t reg_base); | ||
hid_keyboard_init(0,NULL); | ||
rt_kprintf("hid keyboard example started. \r\n"); | ||
#endif | ||
} | ||
|
||
INIT_APP_EXPORT(cherryusb_protocol_stack_init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright (c) 2022, sakumisu | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef CHERRYUSB_CONFIG_H | ||
#define CHERRYUSB_CONFIG_H | ||
|
||
|
||
#include <rtthread.h> | ||
|
||
/* ================ USB common Configuration ================ */ | ||
#define CONFIG_USB_PRINTF(...) rt_kprintf(__VA_ARGS__) | ||
#define usb_malloc(size) malloc(size) | ||
#define usb_free(ptr) free(ptr) | ||
|
||
#ifndef CONFIG_USB_DBG_LEVEL | ||
//#define CONFIG_USB_DBG_LEVEL USB_DBG_INFO | ||
#define CONFIG_USB_DBG_LEVEL 3 | ||
#endif | ||
|
||
/* Enable print with color */ | ||
#define CONFIG_USB_PRINTF_COLOR_ENABLE | ||
|
||
/* data align size when use dma */ | ||
#ifndef CONFIG_USB_ALIGN_SIZE | ||
#define CONFIG_USB_ALIGN_SIZE 4 | ||
#endif | ||
|
||
/* attribute data into no cache ram */ | ||
#define USB_NOCACHE_RAM_SECTION __attribute__((section(".noncacheable"))) | ||
|
||
/* ================= USB Device Stack Configuration ================ */ | ||
|
||
/* Ep0 max transfer buffer, specially for receiving data from ep0 out */ | ||
#define CONFIG_USBDEV_REQUEST_BUFFER_LEN 256 | ||
|
||
#ifndef CONFIG_USBDEV_MSC_MAX_LUN | ||
#define CONFIG_USBDEV_MSC_MAX_LUN 1 | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_MSC_MAX_BUFSIZE | ||
#define CONFIG_USBDEV_MSC_MAX_BUFSIZE 512 | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING | ||
#define CONFIG_USBDEV_MSC_MANUFACTURER_STRING "" | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING | ||
#define CONFIG_USBDEV_MSC_PRODUCT_STRING "" | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_MSC_VERSION_STRING | ||
#define CONFIG_USBDEV_MSC_VERSION_STRING "0.01" | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_MSC_PRIO | ||
#define CONFIG_USBDEV_MSC_PRIO 4 | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_MSC_STACKSIZE | ||
#define CONFIG_USBDEV_MSC_STACKSIZE 2048 | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE | ||
#define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156 | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE | ||
#define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1536 | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID | ||
#define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff | ||
#endif | ||
|
||
#ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC | ||
#define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB" | ||
#endif | ||
|
||
#define CONFIG_USBDEV_RNDIS_USING_LWIP | ||
|
||
/* ================ USB HOST Stack Configuration ================== */ | ||
|
||
#define CONFIG_USBHOST_MAX_RHPORTS 1 | ||
#define CONFIG_USBHOST_MAX_EXTHUBS 1 | ||
#define CONFIG_USBHOST_MAX_EHPORTS 4 | ||
#define CONFIG_USBHOST_MAX_INTERFACES 8 | ||
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8 | ||
#define CONFIG_USBHOST_MAX_ENDPOINTS 4 | ||
|
||
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4 | ||
#define CONFIG_USBHOST_MAX_HID_CLASS 4 | ||
#define CONFIG_USBHOST_MAX_MSC_CLASS 2 | ||
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 1 | ||
#define CONFIG_USBHOST_MAX_VIDEO_CLASS 1 | ||
|
||
#define CONFIG_USBHOST_DEV_NAMELEN 16 | ||
|
||
#ifndef CONFIG_USBHOST_PSC_PRIO | ||
#define CONFIG_USBHOST_PSC_PRIO 0 | ||
#endif | ||
#ifndef CONFIG_USBHOST_PSC_STACKSIZE | ||
#define CONFIG_USBHOST_PSC_STACKSIZE 2048 | ||
#endif | ||
|
||
#define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00 | ||
|
||
/* Ep0 max transfer buffer */ | ||
#define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512 | ||
|
||
#ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT | ||
#define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500 | ||
#endif | ||
|
||
#ifndef CONFIG_USBHOST_MSC_TIMEOUT | ||
#define CONFIG_USBHOST_MSC_TIMEOUT 5000 | ||
#endif | ||
|
||
/* ================ USB Device Port Configuration ================*/ | ||
#define CONFIG_USBDEV_MAX_BUS 1 | ||
|
||
#define CONFIG_USBDEV_EP_NUM 8 | ||
#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2 | ||
|
||
/* ================ USB Host Port Configuration ==================*/ | ||
|
||
#define CONFIG_USBHOST_PIPE_NUM 10 | ||
|
||
/* ================ EHCI Configuration ================ */ | ||
|
||
#define CONFIG_USB_EHCI_HCCR_BASE (0x20072000) | ||
#define CONFIG_USB_EHCI_HCOR_BASE (0x20072000 + 0x10) | ||
#define CONFIG_USB_EHCI_FRAME_LIST_SIZE 1024 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Note | ||
|
||
## Support Chip List | ||
|
||
- NRF5x | ||
|
||
## Before Use | ||
|
||
- Your should implement `usb_dc_low_level_pre_init`,`usb_dc_low_level_post_init`,`usb_dc_low_level_deinit`. |
Oops, something went wrong.