@@ -173,6 +173,11 @@ static void pipe_write_packet(rusb2_reg_t * rusb, void *buf, volatile void *fifo
173173
174174 volatile uint16_t * ff16 ;
175175 volatile uint8_t * ff8 ;
176+
177+ // flush cache
178+ #ifdef __DCACHE_PRESENT
179+ SCB_CleanInvalidateDCache_by_Addr (& _dcd , sizeof (dcd_data_t ));
180+ #endif
176181
177182 // Highspeed FIFO is 32-bit
178183 if ( rusb2_is_highspeed_reg (rusb ) ) {
@@ -221,6 +226,9 @@ static void pipe_write_packet_ff(rusb2_reg_t * rusb, tu_fifo_t *f, volatile void
221226 uint16_t rem = total_len - count ;
222227 if (rem ) {
223228 rem = tu_min16 (rem , info .len_wrap );
229+ #ifdef __DCACHE_PRESENT
230+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * ) tu_align ((uint32_t ) info .ptr_wrap , 4 ), total_len - info .len_wrap + 31 );
231+ #endif
224232 pipe_write_packet (rusb , info .ptr_wrap , fifo , rem );
225233 count += rem ;
226234 }
@@ -508,6 +516,11 @@ static bool process_pipe_xfer(rusb2_reg_t* rusb, int buffer_type, uint8_t ep_add
508516static bool process_edpt_xfer (rusb2_reg_t * rusb , int buffer_type , uint8_t ep_addr , void * buffer , uint16_t total_bytes )
509517{
510518 const unsigned epn = tu_edpt_number (ep_addr );
519+
520+ #ifdef __DCACHE_PRESENT
521+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * ) tu_align ((uint32_t ) buffer , 4 ), total_bytes + 31 );
522+ #endif
523+
511524 if (0 == epn ) {
512525 return process_pipe0_xfer (rusb , buffer_type , ep_addr , buffer , total_bytes );
513526 } else {
@@ -661,6 +674,8 @@ static void enable_interrupt(uint32_t pswi)
661674
662675void dcd_init (uint8_t rhport )
663676{
677+ tu_memclr (& _dcd , sizeof (dcd_data_t ));
678+
664679 rusb2_reg_t * rusb = RUSB2_REG (rhport );
665680 rusb2_module_start (rhport , true);
666681
@@ -669,10 +684,18 @@ void dcd_init(uint8_t rhport)
669684 rusb -> SYSCFG_b .HSE = 1 ;
670685
671686 // leave CLKSEL as default (0x11) 24Mhz
672-
687+ #ifdef __DCACHE_PRESENT
688+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * ) & _dcd , sizeof (dcd_data_t ));
689+ #endif
673690 // Power and reset UTMI Phy
674691 uint16_t physet = (rusb -> PHYSET | RUSB2_PHYSET_PLLRESET_Msk ) & ~RUSB2_PHYSET_DIRPD_Msk ;
675692 rusb -> PHYSET = physet ;
693+
694+ #if defined(RENESAS_CORTEX_M85 )
695+ // RA8 PHYSET-CLKSEL need set 20Mhz
696+ rusb -> PHYSET = (rusb -> PHYSET & ~(1 << 4 )) | (1 << 5 );
697+ #endif
698+
676699 R_BSP_SoftwareDelay ((uint32_t ) 1 , BSP_DELAY_UNITS_MILLISECONDS );
677700 rusb -> PHYSET_b .PLLRESET = 0 ;
678701
@@ -822,6 +845,9 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc)
822845 * ctr = RUSB2_PIPE_CTR_PID_BUF ;
823846 }
824847
848+ #ifdef __DCACHE_PRESENT
849+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * ) & _dcd , sizeof (dcd_data_t ));
850+ #endif
825851 // TU_LOG1("O %d %x %x\r\n", rusb->PIPESEL, rusb->PIPECFG, rusb->PIPEMAXP);
826852 dcd_int_enable (rhport );
827853
@@ -993,6 +1019,9 @@ void dcd_int_handler(uint8_t rhport)
9931019
9941020 // Control transfer stage changes
9951021 if ( is0 & RUSB2_INTSTS0_CTRT_Msk ) {
1022+ #ifdef __DCACHE_PRESENT
1023+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * ) & _dcd , sizeof (dcd_data_t ));
1024+ #endif
9961025 if ( is0 & RUSB2_INTSTS0_CTSQ_CTRL_RDATA ) {
9971026 /* A setup packet has been received. */
9981027 process_setup_packet (rhport );
@@ -1025,4 +1054,4 @@ void dcd_int_handler(uint8_t rhport)
10251054 }
10261055}
10271056
1028- #endif
1057+ #endif
0 commit comments