summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWilliam D. Jones <[email protected]>2019-02-07 21:25:27 -0500
committerWilliam D. Jones <[email protected]>2019-02-07 21:25:27 -0500
commit5645d44127ec5557da907f7784698c64414e4834 (patch)
tree7521ed84213d351287d67e2bc26d36cb8a5992f8 /src
parent28ccc8bd0b9e498ab6c10a52fed6635bbac49aaa (diff)
stm32f4: Add for-loop guard for transmit_packet xfers < 4 chars.
Diffstat (limited to 'src')
-rw-r--r--src/portable/stm/stm32f4/dcd_stm32f4.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/portable/stm/stm32f4/dcd_stm32f4.c b/src/portable/stm/stm32f4/dcd_stm32f4.c
index e71d8e268..034e6c4fa 100644
--- a/src/portable/stm/stm32f4/dcd_stm32f4.c
+++ b/src/portable/stm/stm32f4/dcd_stm32f4.c
@@ -428,9 +428,15 @@ static void transmit_packet(xfer_ctl_t * xfer, USB_OTG_INEndpointTypeDef * in_ep
// Buffer might not be aligned to 32b, so we need to force alignment
// by copying to a temp var.
uint8_t * base = (xfer->buffer + xfer->queued_len);
- for(uint16_t i = 0; i < to_xfer_size_aligned; i += 4) {
- uint32_t tmp = base[i] | (base[i + 1] << 8) | (base[i + 2] << 16) | (base[i + 3] << 24);
- (* tx_fifo) = tmp;
+
+ // This for loop always runs at least once- skip if less than 4 bytes
+ // to send off.
+ if(to_xfer_size >= 4) {
+ for(uint16_t i = 0; i < to_xfer_size_aligned; i += 4) {
+ uint32_t tmp = base[i] | (base[i + 1] << 8) | \
+ (base[i + 2] << 16) | (base[i + 3] << 24);
+ (* tx_fifo) = tmp;
+ }
}
// Do not read beyond end of buffer if not divisible by 4.