4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-31 14:00:22 +08:00

[bsp][nrf5x]added the cherryusb adapter for nrf52840 (#9939)

This commit is contained in:
hydevcode 2025-01-24 23:12:25 +08:00 committed by GitHub
parent 4d4c9660ce
commit 2a18d6873b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 1579 additions and 2 deletions

View File

@ -98,4 +98,13 @@ nimble.uart:
segger:
kconfig:
- CONFIG_PKG_USING_SEGGER_RTT=y
- CONFIG_RT_USING_SERIAL_V2=y
- CONFIG_RT_USING_SERIAL_V2=y
# ------ component CI ------
component.cherryusb_hid_keyboard:
kconfig:
- CONFIG_RT_USING_CHERRYUSB=y
- CONFIG_RT_CHERRYUSB_DEVICE=y
- CONFIG_RT_CHERRYUSB_DEVICE_NRF5X=y
- CONFIG_RT_CHERRYUSB_DEVICE_HID=y
- CONFIG_RT_CHERRYUSB_DEVICE_TEMPLATE_HID_KEYBOARD=y
- CONFIG_RT_USING_MESSAGEQUEUE=y

View File

@ -7,4 +7,10 @@ src = Glob('*.c')
CPPPATH = [cwd]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
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')

View File

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

View File

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

View File

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

View File

@ -2472,7 +2472,7 @@
// <e> NRFX_POWER_ENABLED - nrfx_power - POWER peripheral driver
//==========================================================
#ifndef NRFX_POWER_ENABLED
#define NRFX_POWER_ENABLED 0
#define NRFX_POWER_ENABLED 1
#endif
// <o> NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority

View File

@ -68,6 +68,8 @@ if RT_USING_CHERRYUSB
bool "aic"
config RT_CHERRYUSB_DEVICE_PUSB2
bool "pusb2"
config RT_CHERRYUSB_DEVICE_NRF5X
bool "nrf5x"
endchoice
config RT_CHERRYUSB_DEVICE_CDC_ACM

View File

@ -28,6 +28,8 @@ if GetDepend(['RT_CHERRYUSB_DEVICE']):
if GetDepend(['RT_CHERRYUSB_DEVICE_SPEED_HS']):
CPPDEFINES+=['CONFIG_USB_HS']
if GetDepend(['RT_CHERRYUSB_DEVICE_NRF5X']):
src += Glob('port/nrf5x/usb_dc_nrf5x.c')
if GetDepend(['RT_CHERRYUSB_DEVICE_FSDEV']):
src += Glob('port/fsdev/usb_dc_fsdev.c')
if GetDepend(['RT_CHERRYUSB_DEVICE_DWC2_ST']):

View File

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

File diff suppressed because it is too large Load Diff