Skip to content

Commit fbaa148

Browse files
committed
updating hcd rusb2
- make osal_task_delay() as weak function in usbh - implement osal_task_delay() in hcd rusb2 (may moved to other places)
1 parent b56c4fe commit fbaa148

File tree

9 files changed

+78
-78
lines changed

9 files changed

+78
-78
lines changed

examples/device/cdc_msc_freertos/skip.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ mcu:RP2040
88
mcu:SAMD11
99
mcu:SAMX7X
1010
mcu:VALENTYUSB_EPTRI
11+
mcu:RAXXX
1112
family:broadcom_32bit
1213
family:broadcom_64bit

examples/device/hid_composite_freertos/skip.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ mcu:RP2040
88
mcu:SAMD11
99
mcu:SAMX7X
1010
mcu:VALENTYUSB_EPTRI
11+
mcu:RAXXX
1112
family:broadcom_32bit
1213
family:broadcom_64bit
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
board:mimxrt1060_evk
22
board:mimxrt1064_evk
33
mcu:RP2040
4+
mcu:ra6m5

hw/bsp/ra/boards/ra6m5_ek/board.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ set(MCU_VARIANT ra6m5)
33

44
set(JLINK_DEVICE R7FA6M5BH)
55

6-
# default to PORT1 Highspeed
6+
# Device port default to PORT1 Highspeed
77
if (NOT DEFINED PORT)
88
set(PORT 1)
99
endif()
1010

11+
# Host port will be the other port
12+
set(HOST_PORT $<NOT:${PORT}>)
13+
1114
function(update_board TARGET)
1215
target_compile_definitions(${TARGET} PUBLIC
1316
BOARD_TUD_RHPORT=${PORT}
17+
BOARD_TUH_RHPORT=${HOST_PORT}
1418
# port 0 is fullspeed, port 1 is highspeed
1519
BOARD_TUD_MAX_SPEED=$<IF:${PORT},OPT_MODE_HIGH_SPEED,OPT_MODE_FULL_SPEED>
20+
BOARD_TUH_MAX_SPEED=$<IF:${HOST_PORT},OPT_MODE_HIGH_SPEED,OPT_MODE_FULL_SPEED>
1621
)
1722
endfunction()

hw/bsp/ra/family.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
1313

1414
set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
1515

16-
set(FAMILY_MCUS RAXXX CACHE INTERNAL "")
16+
set(FAMILY_MCUS RAXXX ${MCU_VARIANT} CACHE INTERNAL "")
1717

1818
#------------------------------------
1919
# BOARD_TARGET

src/host/usbh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static bool usbh_control_xfer_cb (uint8_t daddr, uint8_t ep_addr, xfer_result_t
256256

257257
#if CFG_TUSB_OS == OPT_OS_NONE
258258
// TODO rework time-related function later
259-
void osal_task_delay(uint32_t msec)
259+
TU_ATTR_WEAK void osal_task_delay(uint32_t msec)
260260
{
261261
const uint32_t start = hcd_frame_number(_usbh_controller);
262262
while ( ( hcd_frame_number(_usbh_controller) - start ) < msec ) {}

src/portable/renesas/rusb2/dcd_rusb2.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
#include "tusb_option.h"
2929

30+
#if CFG_TUD_ENABLED && defined(TUP_USBIP_RUSB2)
31+
3032
// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
3133
// We disable SOF for now until needed later on
3234
#define USE_SOF 0
3335

34-
#if CFG_TUD_ENABLED && defined(TUP_USBIP_RUSB2)
35-
3636
#include "device/dcd.h"
3737
#include "rusb2_type.h"
3838

@@ -53,6 +53,13 @@
5353
#error "Unsupported MCU"
5454
#endif
5555

56+
//--------------------------------------------------------------------+
57+
// Application API for setting IRQ number
58+
//--------------------------------------------------------------------+
59+
void tud_int_set_irqnum(uint8_t rhport, int32_t irqnum) {
60+
rusb2_controller[rhport].irqnum = irqnum;
61+
}
62+
5663
//--------------------------------------------------------------------+
5764
// MACRO TYPEDEF CONSTANT ENUM
5865
//--------------------------------------------------------------------+
@@ -681,7 +688,6 @@ static void enable_interrupt(uint32_t pswi)
681688
void dcd_init(uint8_t rhport)
682689
{
683690
rusb2_reg_t* rusb = RUSB2_REG(rhport);
684-
685691
rusb2_module_start(rhport, true);
686692

687693
#ifdef RUSB2_SUPPORT_HIGHSPEED

src/portable/renesas/rusb2/hcd_rusb2.c

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727

2828
#include "tusb_option.h"
2929

30-
#if CFG_TUH_ENABLED && (TU_CHECK_MCU(OPT_MCU_RX63X, OPT_MCU_RX65X, OPT_MCU_RX72N) || \
31-
TU_CHECK_MCU(OPT_MCU_RAXXX))
30+
#if CFG_TUH_ENABLED && defined(TUP_USBIP_RUSB2)
3231

3332
#include "host/hcd.h"
3433
#include "rusb2_type.h"
@@ -41,8 +40,14 @@
4140

4241
#if TU_CHECK_MCU(OPT_MCU_RX63X, OPT_MCU_RX65X, OPT_MCU_RX72N)
4342
#include "rusb2_rx.h"
43+
4444
#elif TU_CHECK_MCU(OPT_MCU_RAXXX)
4545
#include "rusb2_ra.h"
46+
47+
void osal_task_delay(uint32_t msec) {
48+
R_BSP_SoftwareDelay(msec, BSP_DELAY_UNITS_MILLISECONDS);
49+
}
50+
4651
#else
4752
#error "Unsupported MCU"
4853
#endif
@@ -67,19 +72,6 @@
6772
TU_ATTR_PACKED_BEGIN
6873
TU_ATTR_BIT_FIELD_ORDER_BEGIN
6974

70-
typedef struct TU_ATTR_PACKED {
71-
union {
72-
struct {
73-
uint16_t : 8;
74-
uint16_t TRCLR: 1;
75-
uint16_t TRENB: 1;
76-
uint16_t : 0;
77-
};
78-
uint16_t TRE;
79-
};
80-
uint16_t TRN;
81-
} reg_pipetre_t;
82-
8375
typedef union TU_ATTR_PACKED {
8476
struct {
8577
volatile uint16_t u8: 8;
@@ -308,8 +300,9 @@ static bool pipe_xfer_out(unsigned num)
308300
pipe_write_packet(buf, (volatile void*)&RUSB2->D0FIFO, len);
309301
pipe->buf = (uint8_t*)buf + len;
310302
}
311-
if (len < mps)
303+
if (len < mps) {
312304
RUSB2->D0FIFOCTR = RUSB2_CFIFOCTR_BVAL_Msk;
305+
}
313306
RUSB2->D0FIFOSEL = 0;
314307
while (RUSB2->D0FIFOSEL_b.CURPIPE) ; /* if CURPIPE bits changes, check written value */
315308
pipe->remaining = rem - len;
@@ -488,60 +481,60 @@ static void enable_interrupt(uint32_t pswi)
488481

489482
bool hcd_init(uint8_t rhport)
490483
{
491-
(void)rhport;
492-
493-
#if (CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST)
494-
RUSB2->SYSCFG_b.HSE = 1;
495-
RUSB2->PHYSET_b.HSEB = 0;
496-
RUSB2->PHYSET_b.DIRPD = 0;
497-
R_BSP_SoftwareDelay((uint32_t) 1, BSP_DELAY_UNITS_MILLISECONDS);
498-
RUSB2->PHYSET_b.PLLRESET = 0;
499-
RUSB2->LPSTS_b.SUSPENDM = 1;
500-
while (!RUSB2->PLLSTA_b.PLLLOCK);
501-
RUSB2->SYSCFG_b.DRPD = 1;
502-
RUSB2->SYSCFG_b.DCFM = 1;
503-
RUSB2->SYSCFG_b.DPRPU = 0;
504-
RUSB2->SYSCFG_b.CNEN = 1;
505-
RUSB2->BUSWAIT |= 0x0F00U;
506-
RUSB2->SOFCFG_b.INTL = 1;
507-
RUSB2->DVSTCTR0_b.VBUSEN = 1;
508-
RUSB2->CFIFOSEL_b.MBW = 1;
509-
RUSB2->D0FIFOSEL_b.MBW = 1;
510-
RUSB2->D1FIFOSEL_b.MBW = 1;
511-
RUSB2->INTSTS0 = 0;
512-
for (volatile int i = 0; i < 30000; ++i) ;
513-
RUSB2->SYSCFG_b.USBE = 1;
514-
#else
515-
/* HOST DEVICE Full SPEED */
516-
RUSB2->SYSCFG_b.SCKE = 1; /* USB Clock enable */
517-
while (!RUSB2->SYSCFG_b.SCKE) ;
518-
RUSB2->SYSCFG_b.DPRPU = 0; /* D+ pull up enable - 0/disable in host mode */
519-
RUSB2->SYSCFG_b.DRPD = 1; /* D+/D- pull down - 1/in Host mode (pag.834)*/
520-
RUSB2->SYSCFG_b.DCFM = 1; /* HOST or Device - 1/HOST */
521-
522-
RUSB2->DVSTCTR0_b.VBUSEN = 1;
523-
524-
RUSB2->SYSCFG_b.DRPD = 1;
525-
for (volatile int i = 0; i < 30000; ++i) ;
526-
RUSB2->SYSCFG_b.USBE = 1;
484+
rusb2_reg_t* rusb = RUSB2_REG(rhport);
485+
rusb2_module_start(rhport, true);
486+
487+
#ifdef RUSB2_SUPPORT_HIGHSPEED
488+
if (rusb2_is_highspeed_rhport(rhport) ) {
489+
rusb->SYSCFG_b.HSE = 1;
490+
rusb->PHYSET_b.HSEB = 0;
491+
rusb->PHYSET_b.DIRPD = 0;
492+
R_BSP_SoftwareDelay((uint32_t) 1, BSP_DELAY_UNITS_MILLISECONDS);
493+
rusb->PHYSET_b.PLLRESET = 0;
494+
rusb->LPSTS_b.SUSPENDM = 1;
495+
while ( !rusb->PLLSTA_b.PLLLOCK );
496+
rusb->SYSCFG_b.DRPD = 1;
497+
rusb->SYSCFG_b.DCFM = 1;
498+
rusb->SYSCFG_b.DPRPU = 0;
499+
rusb->SYSCFG_b.CNEN = 1;
500+
rusb->BUSWAIT |= 0x0F00U;
501+
rusb->SOFCFG_b.INTL = 1;
502+
rusb->DVSTCTR0_b.VBUSEN = 1;
503+
rusb->CFIFOSEL_b.MBW = 1;
504+
rusb->D0FIFOSEL_b.MBW = 1;
505+
rusb->D1FIFOSEL_b.MBW = 1;
506+
rusb->INTSTS0 = 0;
507+
for ( volatile int i = 0; i < 30000; ++i );
508+
rusb->SYSCFG_b.USBE = 1;
509+
} else
527510
#endif
511+
{
512+
rusb->SYSCFG_b.SCKE = 1;
513+
while ( !rusb->SYSCFG_b.SCKE ) {}
514+
rusb->SYSCFG_b.DCFM = 1; // Host function
515+
rusb->SYSCFG_b.DPRPU = 0; // Disable D+ pull up
516+
rusb->SYSCFG_b.DRPD = 1; // Enable D+/D- pull down
528517

529-
// MCU specific PHY init
530-
rusb2_phy_init();
518+
rusb->DVSTCTR0_b.VBUSEN = 1;
519+
for ( volatile int i = 0; i < 30000; ++i ) {} // FIXME do we need to wait here? how long ?
520+
//R_BSP_SoftwareDelay(10, BSP_DELAY_UNITS_MILLISECONDS);
521+
rusb->SYSCFG_b.USBE = 1;
531522

532-
#if (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST)
533-
RUSB2->PHYSLEW = 0x5;
534-
RUSB2->DPUSR0R_FS_b.FIXPHY0 = 0u; /* Transceiver Output fixed */
535-
#endif
523+
// MCU specific PHY init
524+
rusb2_phy_init();
525+
526+
rusb->PHYSLEW = 0x5;
527+
rusb->DPUSR0R_FS_b.FIXPHY0 = 0u; /* Transceiver Output fixed */
528+
}
536529

537530
/* Setup default control pipe */
538-
RUSB2->DCPCFG = RUSB2_PIPECFG_SHTNAK_Msk;
539-
RUSB2->DCPMAXP = 64;
540-
RUSB2->INTENB0 = RUSB2_INTSTS0_BRDY_Msk | RUSB2_INTSTS0_NRDY_Msk | RUSB2_INTSTS0_BEMP_Msk;
541-
RUSB2->INTENB1 = RUSB2_INTSTS1_SACK_Msk | RUSB2_INTSTS1_SIGN_Msk | RUSB2_INTSTS1_ATTCH_Msk | RUSB2_INTSTS1_DTCH_Msk;
542-
RUSB2->BEMPENB = 1;
543-
RUSB2->NRDYENB = 1;
544-
RUSB2->BRDYENB = 1;
531+
rusb->DCPCFG = RUSB2_PIPECFG_SHTNAK_Msk;
532+
rusb->DCPMAXP = 64;
533+
rusb->INTENB0 = RUSB2_INTSTS0_BRDY_Msk | RUSB2_INTSTS0_NRDY_Msk | RUSB2_INTSTS0_BEMP_Msk;
534+
rusb->INTENB1 = RUSB2_INTSTS1_SACK_Msk | RUSB2_INTSTS1_SIGN_Msk | RUSB2_INTSTS1_ATTCH_Msk | RUSB2_INTSTS1_DTCH_Msk;
535+
rusb->BEMPENB = 1;
536+
rusb->NRDYENB = 1;
537+
rusb->BRDYENB = 1;
545538

546539
return true;
547540
}

src/portable/renesas/rusb2/rusb2_ra.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@ TU_ATTR_ALWAYS_INLINE static inline void rusb2_int_disable(uint8_t rhport) {
106106
TU_ATTR_ALWAYS_INLINE static inline void rusb2_phy_init(void) {
107107
}
108108

109-
//--------------------------------------------------------------------+
110-
// Application API for setting IRQ number
111-
//--------------------------------------------------------------------+
112-
void tud_int_set_irqnum(uint8_t rhport, int32_t irqnum) {
113-
rusb2_controller[rhport].irqnum = irqnum;
114-
}
115-
116109
#ifdef __cplusplus
117110
}
118111
#endif

0 commit comments

Comments
 (0)