Understood:
I see the difference between the T3.x version of code and T4.x version of code:
In the 3.x we have:
Code:
int usb_rawhid_recv(void *buffer, uint32_t timeout)
{
usb_packet_t *rx_packet;
uint32_t begin = millis();
while (1) {
if (!usb_configuration) return -1;
rx_packet = usb_rx(RAWHID_RX_ENDPOINT);
if (rx_packet) break;
if (millis() - begin > timeout || !timeout) return 0;
yield();
}
memcpy(buffer, rx_packet->buf, RAWHID_RX_SIZE);
usb_free(rx_packet);
return RAWHID_RX_SIZE;
}
Where in the T4.x we have:
Code:
int usb_rawhid_recv(void *buffer, uint32_t timeout)
{
uint32_t wait_begin_at = systick_millis_count;
uint32_t tail = rx_tail;
while (1) {
if (!usb_configuration) return -1; // usb not enumerated by host
if (tail != rx_head) break;
if (systick_millis_count - wait_begin_at > timeout) {
return 0;
}
yield();
}
// digitalWriteFast(0, LOW);
if (++tail > RX_NUM) tail = 0;
uint32_t i = rx_list[tail];
rx_tail = tail;
memcpy(buffer, rx_buffer + i * RAWHID_RX_SIZE, RAWHID_RX_SIZE);
rx_queue_transfer(i);
//memset(rx_transfer, 0, sizeof(rx_transfer));
//usb_prepare_transfer(rx_transfer + 0, rx_buffer, RAWHID_RX_SIZE, 0);
//usb_receive(RAWHID_RX_ENDPOINT, rx_transfer + 0);
return RAWHID_RX_SIZE;
}
Notice the lines:
3x: if (millis() - begin > timeout || !timeout) return 0;
4x: if (systick_millis_count - wait_begin_at > timeout) {
try changing the 4x code like:
if ((systick_millis_count - wait_begin_at > timeout) || !timeout) {
And see if works better for you