add usb msc support for nrf52840
This commit is contained in:
parent
a73effa5b6
commit
7fff7f5e70
@ -1 +1 @@
|
||||
Subproject commit 3e66d2d31e21d1ce91bcc4728c929b9bdf3421e8
|
||||
Subproject commit fc139b009f4c49d4fdbf1b80097c94c8dabb1ee1
|
@ -54,6 +54,8 @@ INC += -I./nrfx/drivers/include
|
||||
INC += -I../../lib/mp-readline
|
||||
INC += -I./drivers/bluetooth
|
||||
INC += -I./drivers
|
||||
INC += -I../../lib/tinyusb/src
|
||||
INC += -I./usb
|
||||
|
||||
NRF_DEFINES += -DCONFIG_GPIO_AS_PINRESET
|
||||
|
||||
@ -98,6 +100,7 @@ SRC_HAL = $(addprefix hal/,\
|
||||
SRC_NRFX = $(addprefix nrfx/,\
|
||||
drivers/src/nrfx_spim.c \
|
||||
drivers/src/nrfx_twim.c \
|
||||
drivers/src/nrfx_power.c \
|
||||
)
|
||||
|
||||
SRC_C += \
|
||||
@ -113,6 +116,8 @@ SRC_C += \
|
||||
boards/$(BOARD)/board.c \
|
||||
nrfx/mdk/system_$(MCU_SUB_VARIANT).c \
|
||||
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
|
||||
usb/tusb_descriptors.c \
|
||||
usb/msc_flash.c \
|
||||
lib/oofatfs/ff.c \
|
||||
lib/oofatfs/option/ccsbcs.c \
|
||||
lib/timeutils/timeutils.c \
|
||||
@ -122,6 +127,14 @@ SRC_C += \
|
||||
lib/utils/pyexec.c \
|
||||
lib/libc/string0.c \
|
||||
lib/mp-readline/readline.c \
|
||||
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \
|
||||
lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c \
|
||||
lib/tinyusb/src/common/tusb_fifo.c \
|
||||
lib/tinyusb/src/device/usbd.c \
|
||||
lib/tinyusb/src/device/usbd_desc.c \
|
||||
lib/tinyusb/src/class/msc/msc_device.c \
|
||||
lib/tinyusb/src/class/cdc/cdc_device.c \
|
||||
lib/tinyusb/src/tusb.c \
|
||||
internal_flash.c \
|
||||
|
||||
|
||||
|
@ -27,12 +27,38 @@
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nrf.h"
|
||||
|
||||
#include "nrfx.h"
|
||||
#include "nrfx_power.h"
|
||||
#include "boards/board.h"
|
||||
|
||||
#include "tick.h"
|
||||
#include "tusb.h"
|
||||
|
||||
void board_init(void) {
|
||||
|
||||
// Init USB
|
||||
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
|
||||
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
// TODO support Softdevice config
|
||||
#else
|
||||
// Softdevice is not present, init power module and register tusb power event function
|
||||
// for vusb detect, ready, removed
|
||||
extern void tusb_hal_nrf_power_event(uint32_t event);
|
||||
|
||||
// Power module init
|
||||
const nrfx_power_config_t pwr_cfg = { 0 };
|
||||
nrfx_power_init(&pwr_cfg);
|
||||
|
||||
// USB Power detection
|
||||
const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event };
|
||||
nrfx_power_usbevt_init(&config);
|
||||
|
||||
nrfx_power_usbevt_enable();
|
||||
#endif
|
||||
|
||||
tusb_init();
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
@ -42,3 +68,24 @@ bool board_requests_safe_mode(void) {
|
||||
void reset_board(void) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// tinyusb callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
void tud_mount_cb(uint8_t rhport) {
|
||||
(void) rhport;
|
||||
}
|
||||
|
||||
void tud_umount_cb(uint8_t rhport) {
|
||||
(void) rhport;
|
||||
}
|
||||
|
||||
uint32_t tusb_hal_millis(void)
|
||||
{
|
||||
uint64_t ms;
|
||||
uint32_t us;
|
||||
current_tick(&ms, &us);
|
||||
return (uint32_t) ms;
|
||||
}
|
||||
|
||||
|
@ -21,4 +21,7 @@
|
||||
#define NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY NRF_TWIM_FREQ_400K
|
||||
#define NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT 0
|
||||
|
||||
#define NRFX_POWER_ENABLED 1
|
||||
#define NRFX_POWER_CONFIG_IRQ_PRIORITY 7
|
||||
|
||||
#endif
|
||||
|
@ -51,8 +51,7 @@ void SysTick_Handler(void) {
|
||||
|
||||
void tick_init() {
|
||||
uint32_t ticks_per_ms = common_hal_mcu_processor_get_frequency() / 1000;
|
||||
SysTick_Config(ticks_per_ms);
|
||||
// NVIC_EnableIRQ(SysTick_IRQn);
|
||||
SysTick_Config(ticks_per_ms); // interrupt is enabled
|
||||
}
|
||||
|
||||
void tick_delay(uint32_t us) {
|
||||
|
163
ports/nrf/usb/msc_flash.c
Normal file
163
ports/nrf/usb/msc_flash.c
Normal file
@ -0,0 +1,163 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file msc_flash.c
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2018, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* MACRO TYPEDEF CONSTANT ENUM
|
||||
*------------------------------------------------------------------*/
|
||||
#define MSC_FLASH_ADDR_START 0xAD000
|
||||
#define MSC_FLASH_SIZE (256*1024)
|
||||
#define MSC_FLASH_BLOCK_SIZE 512
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* VARIABLES
|
||||
*------------------------------------------------------------------*/
|
||||
static scsi_sense_fixed_data_t mscd_sense_data =
|
||||
{
|
||||
.response_code = 0x70,
|
||||
.sense_key = 0, // no errors
|
||||
.additional_sense_len = sizeof(scsi_sense_fixed_data_t) - 8
|
||||
};
|
||||
|
||||
static scsi_mode_parameters_t const msc_dev_mode_para =
|
||||
{
|
||||
.mode_data_length = 3,
|
||||
.medium_type = 0,
|
||||
.device_specific_para = 0,
|
||||
.block_descriptor_length = 0
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/*
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
static inline uint32_t lba2addr(uint32_t lba)
|
||||
{
|
||||
return MSC_FLASH_ADDR_START + lba*MSC_FLASH_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// tinyusb callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
int32_t tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize)
|
||||
{
|
||||
// read10 & write10 has their own callback and MUST not be handled here
|
||||
|
||||
void const* ptr = NULL;
|
||||
uint16_t len = 0;
|
||||
|
||||
// most scsi handled is input
|
||||
bool in_xfer = true;
|
||||
|
||||
switch (scsi_cmd[0])
|
||||
{
|
||||
case SCSI_CMD_REQUEST_SENSE:
|
||||
ptr = &mscd_sense_data;
|
||||
len = sizeof(scsi_sense_fixed_data_t);
|
||||
break;
|
||||
|
||||
case SCSI_CMD_MODE_SENSE_6:
|
||||
ptr = &msc_dev_mode_para;
|
||||
len = sizeof(msc_dev_mode_para);
|
||||
break;
|
||||
|
||||
case SCSI_CMD_TEST_UNIT_READY:
|
||||
ptr = NULL;
|
||||
len = 0;
|
||||
break;
|
||||
|
||||
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
ptr = NULL;
|
||||
len = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
// negative is error -> Data stage is STALL, status = failed
|
||||
return -1;
|
||||
}
|
||||
|
||||
// return len must not larger than bufsize
|
||||
TU_ASSERT( bufsize >= len );
|
||||
|
||||
if ( ptr && len )
|
||||
{
|
||||
if(in_xfer)
|
||||
{
|
||||
memcpy(buffer, ptr, len);
|
||||
}else
|
||||
{
|
||||
// SCSI output
|
||||
}
|
||||
}
|
||||
|
||||
//------------- clear sense data if it is not request sense command -------------//
|
||||
if ( SCSI_CMD_REQUEST_SENSE != scsi_cmd[0] )
|
||||
{
|
||||
mscd_sense_data.sense_key = SCSI_SENSEKEY_NONE;
|
||||
mscd_sense_data.additional_sense_code = 0;
|
||||
mscd_sense_data.additional_sense_qualifier = 0;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Tinyusb Flash READ10 & WRITE10
|
||||
*------------------------------------------------------------------*/
|
||||
int32_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
(void) rhport; (void) lun;
|
||||
|
||||
uint32_t addr = lba2addr(lba) + offset;
|
||||
memcpy(buffer, (uint8_t*) addr, bufsize);
|
||||
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
int32_t tud_msc_write10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
(void) rhport; (void) lun;
|
||||
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
193
ports/nrf/usb/nrf_drv_usbd_errata.h
Normal file
193
ports/nrf/usb/nrf_drv_usbd_errata.h
Normal file
@ -0,0 +1,193 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_DRV_USBD_ERRATA_H__
|
||||
#define NRF_DRV_USBD_ERRATA_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
/**
|
||||
* @defgroup nrf_drv_usbd_errata Functions to check if selected PAN is present in current chip
|
||||
* @{
|
||||
* @ingroup nrf_drv_usbd
|
||||
*
|
||||
* Functions here are checking the presence of an error in current chip.
|
||||
* The checking is done at runtime based on the microcontroller version.
|
||||
* This file is subject to removal when nRF51840 prototype support is removed.
|
||||
*/
|
||||
|
||||
#ifndef NRF_DRV_USBD_ERRATA_ENABLE
|
||||
/**
|
||||
* @brief The constant that informs if errata should be enabled at all
|
||||
*
|
||||
* If this constant is set to 0, all the Errata bug fixes will be automatically disabled.
|
||||
*/
|
||||
#define NRF_DRV_USBD_ERRATA_ENABLE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Internal auxiliary function to check if the program is running on NRF52840 chip
|
||||
* @retval true It is NRF52480 chip
|
||||
* @retval false It is other chip
|
||||
*/
|
||||
static inline bool nrf_drv_usbd_errata_type_52840(void)
|
||||
{
|
||||
return ((((*(uint32_t *)0xF0000FE0) & 0xFF) == 0x08) &&
|
||||
(((*(uint32_t *)0xF0000FE4) & 0x0F) == 0x0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Internal auxiliary function to check if the program is running on first sample of
|
||||
* NRF52840 chip
|
||||
* @retval true It is NRF52480 chip and it is first sample version
|
||||
* @retval false It is other chip
|
||||
*/
|
||||
static inline bool nrf_drv_usbd_errata_type_52840_proto1(void)
|
||||
{
|
||||
return ( nrf_drv_usbd_errata_type_52840() &&
|
||||
( ((*(uint32_t *)0xF0000FE8) & 0xF0) == 0x00 ) &&
|
||||
( ((*(uint32_t *)0xF0000FEC) & 0xF0) == 0x00 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Internal auxiliary function to check if the program is running on first final product of
|
||||
* NRF52840 chip
|
||||
* @retval true It is NRF52480 chip and it is first final product
|
||||
* @retval false It is other chip
|
||||
*/
|
||||
static inline bool nrf_drv_usbd_errata_type_52840_fp1(void)
|
||||
{
|
||||
return ( nrf_drv_usbd_errata_type_52840() &&
|
||||
( ((*(uint32_t *)0xF0000FE8) & 0xF0) == 0x20 ) &&
|
||||
( ((*(uint32_t *)0xF0000FEC) & 0xF0) == 0x00 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to check if chip requires errata 104
|
||||
*
|
||||
* Errata: USBD: EPDATA event is not always generated.
|
||||
*
|
||||
* @retval true Errata should be implemented
|
||||
* @retval false Errata should not be implemented
|
||||
*/
|
||||
static inline bool nrf_drv_usbd_errata_104(void)
|
||||
{
|
||||
return NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_proto1();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to check if chip requires errata 154
|
||||
*
|
||||
* Errata: During setup read/write transfer USBD acknowledges setup stage without SETUP task.
|
||||
*
|
||||
* @retval true Errata should be implemented
|
||||
* @retval false Errata should not be implemented
|
||||
*/
|
||||
static inline bool nrf_drv_usbd_errata_154(void)
|
||||
{
|
||||
return NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_proto1();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to check if chip requires errata 166
|
||||
*
|
||||
* Errata: ISO double buffering not functional
|
||||
*
|
||||
* @retval true Errata should be implemented
|
||||
* @retval false Errata should not be implemented
|
||||
*/
|
||||
static inline bool nrf_drv_usbd_errata_166(void)
|
||||
{
|
||||
return NRF_DRV_USBD_ERRATA_ENABLE && true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to check if chip requires errata 171
|
||||
*
|
||||
* Errata: USBD might not reach its active state.
|
||||
*
|
||||
* @retval true Errata should be implemented
|
||||
* @retval false Errata should not be implemented
|
||||
*/
|
||||
static inline bool nrf_drv_usbd_errata_171(void)
|
||||
{
|
||||
return NRF_DRV_USBD_ERRATA_ENABLE && true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to check if chip requires errata 187
|
||||
*
|
||||
* Errata: USB cannot be enabled
|
||||
*
|
||||
* @retval true Errata should be implemented
|
||||
* @retval false Errata should not be implemented
|
||||
*/
|
||||
static inline bool nrf_drv_usbd_errata_187(void)
|
||||
{
|
||||
return NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_fp1();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to check if chip requires errata ???
|
||||
*
|
||||
* Errata: SIZE.EPOUT not writable
|
||||
*
|
||||
* @retval true Errata should be implemented
|
||||
* @retval false Errata should not be implemented
|
||||
*/
|
||||
static inline bool nrf_drv_usbd_errata_sizeepout_rw(void)
|
||||
{
|
||||
return NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_proto1();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to check if chip requires errata 199
|
||||
*
|
||||
* Errata: USBD cannot receive tasks during DMA
|
||||
*
|
||||
* @retval true Errata should be implemented
|
||||
* @retval false Errata should not be implemented
|
||||
*/
|
||||
static inline bool nrf_drv_usb_errata_199(void)
|
||||
{
|
||||
return NRF_DRV_USBD_ERRATA_ENABLE && true;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
#endif /* NRF_DRV_USBD_ERRATA_H__ */
|
125
ports/nrf/usb/tusb_config.h
Normal file
125
ports/nrf/usb/tusb_config.h
Normal file
@ -0,0 +1,125 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file tusb_config.h
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef _TUSB_CONFIG_H_
|
||||
#define _TUSB_CONFIG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// COMMON CONFIGURATION
|
||||
//--------------------------------------------------------------------+
|
||||
#define CFG_TUSB_MCU OPT_MCU_NRF5X
|
||||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
|
||||
|
||||
#define CFG_TUSB_DEBUG 0
|
||||
|
||||
/*------------- RTOS -------------*/
|
||||
#define CFG_TUSB_OS OPT_OS_NONE
|
||||
//#define CFG_TUD_TASK_PRIO 0
|
||||
//#define CFG_TUD_TASK_QUEUE_SZ 16
|
||||
//#define CFG_TUD_TASK_STACK_SZ 150
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DEVICE CONFIGURATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/*------------- Core -------------*/
|
||||
#define CFG_TUD_DESC_AUTO 1
|
||||
#define CFG_TUD_DESC_VID 0x239A
|
||||
#define CFG_TUD_DESC_PID 0x802A
|
||||
|
||||
#define CFG_TUD_ENDOINT0_SIZE 64
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#define CFG_TUD_CDC 0
|
||||
#define CFG_TUD_MSC 1
|
||||
#define CFG_TUD_HID_KEYBOARD 0
|
||||
#define CFG_TUD_HID_MOUSE 0
|
||||
#define CFG_TUD_HID_GENERIC 0
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* CLASS DRIVER
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
// FIFO size of CDC TX and RX
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE 1024
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE 1024
|
||||
|
||||
/* TX is sent automatically on every Start of Frame event ~ 1ms.
|
||||
* If not enabled, application must call tud_cdc_flush() periodically
|
||||
* Note: Enabled this could overflow device task, if it does, define
|
||||
* CFG_TUD_TASK_QUEUE_SZ with large value
|
||||
*/
|
||||
#define CFG_TUD_CDC_FLUSH_ON_SOF 0
|
||||
|
||||
// Number of supported Logical Unit Number (At least 1)
|
||||
#define CFG_TUD_MSC_MAXLUN 1
|
||||
|
||||
// Number of Blocks
|
||||
#define CFG_TUD_MSC_BLOCK_NUM (256*1024)/512
|
||||
|
||||
// Block size
|
||||
#define CFG_TUD_MSC_BLOCK_SZ 512
|
||||
|
||||
// Buffer size for each read/write transfer, the more the better
|
||||
#define CFG_TUD_MSC_BUFSIZE (4*1024)
|
||||
|
||||
// Vendor name included in Inquiry response, max 8 bytes
|
||||
#define CFG_TUD_MSC_VENDOR "Adafruit"
|
||||
|
||||
// Product name included in Inquiry response, max 16 bytes
|
||||
#define CFG_TUD_MSC_PRODUCT "CircuitPY nRF52"
|
||||
|
||||
// Product revision string included in Inquiry response, max 4 bytes
|
||||
#define CFG_TUD_MSC_PRODUCT_REV "1.0"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USB RAM PLACEMENT
|
||||
//--------------------------------------------------------------------+
|
||||
#define CFG_TUSB_ATTR_USBRAM
|
||||
#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_CONFIG_H_ */
|
78
ports/nrf/usb/tusb_descriptors.c
Normal file
78
ports/nrf/usb/tusb_descriptors.c
Normal file
@ -0,0 +1,78 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file tusb_descriptors.c
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This file is part of the tinyusb stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// STRING DESCRIPTORS
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// array of pointer to string descriptors
|
||||
uint16_t const * const string_desc_arr [] =
|
||||
{
|
||||
// 0 index is supported language = English
|
||||
TUD_DESC_STRCONV(0x0409),
|
||||
|
||||
// Manufacturer
|
||||
TUD_DESC_STRCONV('A','d','a','f','r','u','i','t',' ','I','n','d','u','s','t','r','i','e','s'),
|
||||
|
||||
// Product
|
||||
TUD_DESC_STRCONV('C','i','r','c','u','i','t','P','Y',' ','n','R','F','5','2'),
|
||||
|
||||
// Serials TODO use chip ID
|
||||
TUD_DESC_STRCONV('1', '2', '3', '4', '5'),
|
||||
|
||||
// CDC Interface
|
||||
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','S','e','r','i','a','l'),
|
||||
|
||||
// MSC Interface
|
||||
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','S','t','o','r','a','g','e'),
|
||||
|
||||
// Custom Interface
|
||||
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','C','u','s','t','o','m')
|
||||
};
|
||||
|
||||
// tud_desc_set is required by tinyusb stack
|
||||
// since CFG_TUD_DESC_AUTO is enabled, we only need to set string_arr
|
||||
tud_desc_set_t tud_desc_set =
|
||||
{
|
||||
.device = NULL,
|
||||
.config = NULL,
|
||||
.string_arr = (uint8_t const **) string_desc_arr,
|
||||
.hid_report = NULL
|
||||
};
|
Loading…
Reference in New Issue
Block a user