Skip to content

Commit a12cb3d

Browse files
authored
Merge pull request arduino#51 from bcmi-labs/usb_host_dev
Usb Host Mass Device Storage Former-commit-id: 411b1f5
2 parents 7b701cc + 3f03adc commit a12cb3d

File tree

161 files changed

+62805
-1868
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+62805
-1868
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.idea/
1+
.idea
2+
cores/arduino/mydebug.cpp
3+
libraries/Storage/.development

Diff for: .gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "extras/tinyusb"]
22
path = extras/tinyusb
3-
url = https://github.com/bcmi-labs/tinyusb.git
3+
url = git@github.com:bcmi-labs/tinyusb.git

Diff for: cores/arduino/FspTransfer.h

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class FspDma {
3333
extend_cfg.p_callback = NULL;
3434
extend_cfg.p_context = NULL;
3535
extend_cfg.activation_source = ELC_EVENT_NONE;
36+
37+
instance.p_ctrl = &ctrl;
38+
instance.p_cfg = &cfg;
39+
instance.p_api = &g_transfer_on_dmac;
3640
}
3741

3842
bool set_activation_source(elc_event_t ev) {
@@ -58,6 +62,7 @@ class FspDma {
5862
dmac_instance_ctrl_t ctrl;
5963
transfer_info_t info;
6064
dmac_extended_cfg_t extend_cfg;
65+
transfer_instance_t instance;
6166
};
6267

6368

Diff for: cores/arduino/IRQManager.cpp

+48-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
#define SPI_MASTER_REQ_NUM 4
1919
#define CAN_REQ_NUM 3
2020
#define ETHERNET_REQ_NUM 1
21+
#define SDCARD_REQ_NUM 3
2122
#define ETHERNET_PRIORITY 12
23+
#define SDCARD_ACCESS_PRIORITY 12
24+
#define SDCARD_DMA_REQ_PRIORITY 12
25+
#define SDCARD_CARD_PRIORITY 12
2226
#define EXTERNAL_PIN_PRIORITY 12
2327
#define UART_SCI_PRIORITY 12
2428
#define USB_PRIORITY 12
@@ -904,7 +908,7 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
904908
********************************************************************** */
905909
else if(p == IRQ_ETHERNET && cfg != NULL) {
906910
ether_cfg_t *eth = (ether_cfg_t *)cfg;
907-
if ((last_interrupt_index + SPI_MASTER_REQ_NUM) < PROG_IRQ_NUM && eth->irq == FSP_INVALID_VECTOR) {
911+
if ((last_interrupt_index + ETHERNET_REQ_NUM) < PROG_IRQ_NUM && eth->irq == FSP_INVALID_VECTOR) {
908912
eth->irq = (IRQn_Type)last_interrupt_index;
909913
eth->interrupt_priority = ETHERNET_PRIORITY;
910914
*(irq_ptr + last_interrupt_index) = (uint32_t)ether_eint_isr;
@@ -951,6 +955,49 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
951955
}
952956
#endif /* CANFD_HOWMANY > 0 */
953957

958+
#if SDCARD_HOWMANY > 0
959+
/* **********************************************************************
960+
SDCARD
961+
********************************************************************** */
962+
else if(p == IRQ_SDCARD && cfg != NULL) {
963+
sdmmc_cfg_t *sd_cfg = (sdmmc_cfg_t *)cfg;
964+
/* SDCARD_ACCESS */
965+
if ((last_interrupt_index + SDCARD_REQ_NUM) < PROG_IRQ_NUM ) {
966+
if(sd_cfg->access_irq == FSP_INVALID_VECTOR) {
967+
968+
sd_cfg->access_irq = (IRQn_Type)last_interrupt_index;
969+
sd_cfg->access_ipl = SDCARD_ACCESS_PRIORITY;
970+
*(irq_ptr + last_interrupt_index) = (uint32_t)sdhimmc_accs_isr;
971+
R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SDHIMMC0_ACCS);
972+
last_interrupt_index++;
973+
}
974+
/*
975+
this interrupt is neeed if DTC is used but it must not be used if
976+
DMA is used
977+
-----------
978+
if(sd_cfg->dma_req_irq == FSP_INVALID_VECTOR) {
979+
sd_cfg->dma_req_irq = (IRQn_Type)last_interrupt_index;
980+
sd_cfg->dma_req_ipl = SDCARD_DMA_REQ_PRIORITY;
981+
*(irq_ptr + last_interrupt_index) = (uint32_t)sdhimmc_dma_req_isr;
982+
R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SDHIMMC0_DMA_REQ);
983+
last_interrupt_index++;
984+
}
985+
*/
986+
if(sd_cfg->card_irq == FSP_INVALID_VECTOR) {
987+
sd_cfg->card_irq = (IRQn_Type)last_interrupt_index;
988+
sd_cfg->card_ipl = SDCARD_CARD_PRIORITY;
989+
*(irq_ptr + last_interrupt_index) = (uint32_t)sdhimmc_card_isr;
990+
R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SDHIMMC0_CARD);
991+
last_interrupt_index++;
992+
}
993+
}
994+
995+
if(sd_cfg->access_irq == FSP_INVALID_VECTOR || sd_cfg->dma_req_irq == FSP_INVALID_VECTOR || sd_cfg->card_irq == FSP_INVALID_VECTOR) {
996+
rv = false;
997+
}
998+
rv = true;
999+
}
1000+
#endif
9541001
else {
9551002
rv = false;
9561003
}

Diff for: cores/arduino/IRQManager.h

+9
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ typedef enum {
4343
IRQ_CAN,
4444
IRQ_ETHERNET,
4545
IRQ_CANFD,
46+
IRQ_SDCARD
4647
} Peripheral_t;
4748

49+
#if SDCARD_HOWMANY > 0
50+
#include "r_sdhi.h"
51+
#endif
52+
53+
4854
#if RTC_HOWMANY > 0
4955
#include "r_rtc_api.h"
5056
#include "r_rtc.h"
@@ -180,6 +186,9 @@ void ether_eint_isr (void);
180186
void canfd_error_isr(void);
181187
void canfd_rx_fifo_isr(void);
182188
void canfd_channel_tx_isr(void);
189+
void sdhimmc_dma_req_isr(void);
190+
void sdhimmc_accs_isr(void);
191+
void sdhimmc_card_isr(void);
183192
#ifdef __cplusplus
184193
}
185194
#endif

Diff for: cores/arduino/tinyusb/host

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../extras/tinyusb/src/host

Diff for: cores/arduino/usb/USB.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,14 @@ void _usbfs_interrupt_handler(void)
232232

233233
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
234234
tuh_int_handler(0);
235+
tuh_task();
235236
#endif
236237

237238
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
238239
tud_int_handler(0);
239-
#endif
240240
tud_task();
241+
#endif
242+
241243
}
242244

243245
void _usbhs_interrupt_handler(void)
@@ -268,12 +270,18 @@ void __USBStart() {
268270
return;
269271
}
270272

271-
/* Enable USB_BASE */
273+
/*
274+
* ENABLE USB
275+
*/
272276
R_SYSTEM->PRCR = (uint16_t) BSP_PRV_PRCR_PRC1_UNLOCK;
273277
R_MSTP->MSTPCRB &= ~(1U << 11U);
274278
R_MSTP->MSTPCRB &= ~(1U << 12U);
275279
R_SYSTEM->PRCR = (uint16_t) BSP_PRV_PRCR_LOCK;
276280

281+
/*
282+
* CONFIGURE USB INTERRUPTS
283+
*/
284+
277285
#ifdef CFG_TUSB_RHPORT0_MODE
278286
#if (CFG_TUSB_RHPORT0_MODE != 0)
279287
usb_irq_cfg.num_of_irqs_required = 4;
@@ -294,7 +302,15 @@ void __USBStart() {
294302

295303
__SetupUSBDescriptor();
296304

305+
/*
306+
* INIT Tiny USB
307+
*/
308+
309+
assert(BOARD_TUD_RHPORT != BOARD_TUH_RHPORT);
310+
/* init device port*/
297311
tud_init(BOARD_TUD_RHPORT);
312+
/* init host port */
313+
tuh_init(BOARD_TUH_RHPORT);
298314

299315
#if 0 //defined(AZURE_RTOS_THREADX)
300316
static TX_BYTE_POOL byte_pool_0;

0 commit comments

Comments
 (0)