@@ -36,33 +36,28 @@ endpoint_t pio_usb_ep_pool[PIO_USB_EP_POOL_CNT];
3636static uint8_t ack_encoded [5 ];
3737static uint8_t nak_encoded [5 ];
3838static uint8_t stall_encoded [5 ];
39+ static uint8_t pre_encoded [5 ];
3940
4041//--------------------------------------------------------------------+
4142// Bus functions
4243//--------------------------------------------------------------------+
4344
4445static void __no_inline_not_in_flash_func (send_pre )(const pio_port_t * pp ) {
45- uint8_t data [] = {USB_SYNC , USB_PID_PRE };
46-
4746 // send PRE token in full-speed
4847 uint16_t instr = pp -> fs_tx_pre_program -> instructions [0 ];
4948 pp -> pio_usb_tx -> instr_mem [pp -> offset_tx ] = instr ;
5049
5150 SM_SET_CLKDIV (pp -> pio_usb_tx , pp -> sm_tx , pp -> clk_div_fs_tx );
5251
53- dma_channel_transfer_from_buffer_now (pp -> tx_ch , data , 2 );
54-
5552 pio_sm_exec (pp -> pio_usb_tx , pp -> sm_tx , pp -> tx_start_instr );
53+ dma_channel_transfer_from_buffer_now (pp -> tx_ch , pre_encoded ,
54+ sizeof (pre_encoded ));
5655 pp -> pio_usb_tx -> irq = IRQ_TX_ALL_MASK ; // clear complete flag
5756
58- io_ro_32 * pc = & pp -> pio_usb_tx -> sm [pp -> sm_tx ].addr ;
5957 while ((pp -> pio_usb_tx -> irq & IRQ_TX_EOP_MASK ) == 0 ) {
6058 continue ;
6159 }
6260 pio_sm_clear_fifos (pp -> pio_usb_tx , pp -> sm_tx );
63- while (* pc < PIO_USB_TX_ENCODED_DATA_COMP ) {
64- continue ;
65- }
6661
6762 // change bus speed to low-speed
6863 pio_sm_set_enabled (pp -> pio_usb_tx , pp -> sm_tx , false);
@@ -71,9 +66,9 @@ static void __no_inline_not_in_flash_func(send_pre)(const pio_port_t *pp) {
7166 SM_SET_CLKDIV (pp -> pio_usb_tx , pp -> sm_tx , pp -> clk_div_ls_tx );
7267 pio_sm_set_enabled (pp -> pio_usb_tx , pp -> sm_tx , true);
7368
74- pio_sm_clear_fifos (pp -> pio_usb_tx , pp -> sm_tx );
75- pio_sm_exec (pp -> pio_usb_tx , pp -> sm_tx , pp -> tx_start_instr );
76- SM_SET_CLKDIV_MAXSPEED (pp -> pio_usb_rx , pp -> sm_rx );
69+ // pio_sm_clear_fifos(pp->pio_usb_tx, pp->sm_tx);
70+ // pio_sm_exec(pp->pio_usb_tx, pp->sm_tx, pp->tx_start_instr);
71+ // SM_SET_CLKDIV_MAXSPEED(pp->pio_usb_rx, pp->sm_rx);
7772
7873 pio_sm_set_enabled (pp -> pio_usb_rx , pp -> sm_eop , false);
7974 SM_SET_CLKDIV (pp -> pio_usb_rx , pp -> sm_eop , pp -> clk_div_ls_rx );
@@ -141,10 +136,10 @@ void __no_inline_not_in_flash_func(pio_usb_bus_prepare_receive)(const pio_port_t
141136 pio_sm_restart (pp -> pio_usb_rx , pp -> sm_rx );
142137 pio_sm_exec (pp -> pio_usb_rx , pp -> sm_rx , pp -> rx_reset_instr );
143138 pio_sm_exec (pp -> pio_usb_rx , pp -> sm_rx , pp -> rx_reset_instr2 );
139+ pio_sm_set_enabled (pp -> pio_usb_rx , pp -> sm_rx , true);
144140}
145141
146142void __no_inline_not_in_flash_func (pio_usb_bus_start_receive )(const pio_port_t * pp ) {
147- pp -> pio_usb_rx -> ctrl |= (1 << pp -> sm_rx );
148143 pp -> pio_usb_rx -> irq = IRQ_RX_ALL_MASK ;
149144}
150145
@@ -343,6 +338,8 @@ void pio_usb_bus_init(pio_port_t *pp, const pio_usb_configuration_t *c,
343338 pio_usb_ll_encode_tx_data (raw_packet , 2 , nak_encoded );
344339 raw_packet [1 ] = USB_PID_STALL ;
345340 pio_usb_ll_encode_tx_data (raw_packet , 2 , stall_encoded );
341+ raw_packet [1 ] = USB_PID_PRE ;
342+ pio_usb_ll_encode_tx_data (raw_packet , 2 , pre_encoded );
346343}
347344
348345//--------------------------------------------------------------------+
0 commit comments