walkround for samd21 setup_packet overflow#586
Conversation
increase setup packet size from 8 to 12, since USB DMA controller is suspected to overflow the buffer with 2 extra bytes
|
In https://www.avrfreaks.net/forum/getting-extrange-data-enumeration-process-usb-uc3c?skey=multi_packet_size, someone asks about two extra bytes they are getting, and the reply is that those are the CRC bytes. This is for AVR, but it's a clue. I think this may be the issue. From the data sheet, 32.6.2.7, page 799:
Size PCKSIZE is 0x3, which means 64 bytes, and since the incoming packet is 8 bytes, then the USB peripheral thinks there's room for the two CRC bytes, and it writes 8 data bytes and the 2 CRC bytes, total 10. The code does this: sram_registers[0][0].PCKSIZE.bit.MULTI_PACKET_SIZE = sizeof(_setup_packet);but the next section explains the purpose of
So it seems like this is the correct fix, though it could be 8+2 instead of 8+4. But what about SAMD51? I don't know why we don't see 10 bytes written there. The SAMD51 data sheet has what looks like identical language about writing the CRC bytes. |
Thanks @dhalbert, the CRC part does make lots of sense. In case of setup packet, Also there is a scenario when scheduling the ZLP ACK, we have to also prepare for the next setup The reason is next setup packet can occur just right after the ACK, before the IRQ is trigger and give tinyusb stack chance to call
Yeah, though since the memory pointer must be aligned of 4, it is more or less the same, I will update code with comment just to clear this up. |
|
Do you think that |
|
If you merge this, in whatever form, I'll make a PR for CircuitPython and then test this more thoroughly, including on WIndows 7, etc. Thanks. |
I just poke at microchip driver, they use MULTI_PACKET_SIZE=8, so I think we are good, increase it has a greater chance for greater overflow I guess.
merging now PS: update comment to remove walkaround, it seems to be a "correct" fix. |
…func_lookup non-flash safe for flash functions (hathach#586) * add typedef signatures and ROM code defines for bootrom functions. Propogate uses thru SDK code. Add _inline version of rom_func_lookup


Describe the PR
increase setup packet size from 8 to
1210, since USB DMA controller is suspected to overflow the buffer with 2 extra bytes for CRC (somehow I decide there is enough space for CRC). Issue is discovered while troubleshooting adafruit/circuitpython#3912 . This is considered awalkaround/hack rather thanactual fix.It may probably overflow more than 4 bytes in the future, currently42 bytes is too cheap for a fix considering the amount of work to trace it down so far. We may take a look at it later on if needed (like figuring out why USB DMA decide to do so).@dhalbert