stm32/usbd_hid_interface: Address possible race condition vs. interrupt.
The USB IRQ may fire once USBD_HID_ClearNAK() is called and then change the last_read_len value.
This commit is contained in:
parent
1f1623d3b7
commit
ca36645410
@ -94,12 +94,13 @@ int usbd_hid_rx(usbd_hid_itf_t *hid, size_t len, uint8_t *buf, uint32_t timeout)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy bytes from device to user buffer
|
// Copy bytes from device to user buffer
|
||||||
memcpy(buf, hid->buffer[hid->current_read_buffer], hid->last_read_len);
|
int read_len = hid->last_read_len;
|
||||||
|
memcpy(buf, hid->buffer[hid->current_read_buffer], read_len);
|
||||||
hid->current_read_buffer = !hid->current_read_buffer;
|
hid->current_read_buffer = !hid->current_read_buffer;
|
||||||
|
|
||||||
// Clear NAK to indicate we are ready to read more data
|
// Clear NAK to indicate we are ready to read more data
|
||||||
USBD_HID_ClearNAK(hid->usbd);
|
USBD_HID_ClearNAK(hid->usbd);
|
||||||
|
|
||||||
// Success, return number of bytes read
|
// Success, return number of bytes read
|
||||||
return hid->last_read_len;
|
return read_len;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user