Skip to content

Fixes connect() bug, crash bug, I/O error bug, and more. #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 22, 2023
Merged

Fixes connect() bug, crash bug, I/O error bug, and more. #23

merged 13 commits into from
Aug 22, 2023

Conversation

alrvid
Copy link
Contributor

@alrvid alrvid commented Aug 14, 2023

  1. Fixes USB thumb drive remove and insert again bug
  2. Fixes crash on mount() before connect() bug
  3. Fixes incorrect comment about stall handling
  4. Fixes I/O errors when writing to some USB thumb drive models
  5. Fixes incorrectly named constant (MAX_NYET_RETRY to MAX_NOTREADY_RETRY)
  6. Improves the source code comments in several locations

Alrik Vidstrom added 6 commits August 14, 2023 11:51
The device address was incorrectly hard-coded as 0 when the channel was
re-initialized after recovery of a USB_TYPE_ERROR.
The HAL_HCD_HC_Halt() function doesn't actually halt a channel correctly,
so this fix replaces those calls with code that does. This is necessary
both when freeing the bulk endpoints when a USB thumb drive is disconnected,
but also when performing error recovery on a channel that is blocked in a
NAK state. The HAL_HCD_HC_Init() function doesn't return the channel to an
active state itself, so there's also code added to do that. Finally, the
endpoint object must be returned to USB_TYPE_IDLE at the end of such an
error recovery.
Reverting previous incorrect spelling mistake fix. The comment should really be
about unstall (not uninstall) as in clearing the halted feature of the USB EPs
when receiving a stall.
An older fix (commit 72d0aa6) introduced the possiblity of dereferencing an
uninitialized host pointer by moving the getHostInst() call from USBHostMSD()'s
constructor to connect(). This is now solved by adding guards against an
uninitialized host pointer in checkResult(), SCSITransfer() and getMaxLun().
The practical implication of the bug was that mounting before connecting led
to a crash, but now just leads to an error message from the mount call.
Adds a 50 us delay after the request to disable a channel, to give it
time to actually disable.
Setting state to USB_TYPE_IDLE allows the library to recover from an error after the channels
have been cleared. But this might lead to some errors going unreported, and should be improved
in the future - but at least the library passes all our tests from higher levels in the stack
at this point, which it didn't before. Our tests don't show any signs of data loss when the
error recovery kicks in with the current solution. Fixing this last problem will probably take
quite some effort (time), which isn't possible at the moment.
@github-actions
Copy link

Memory usage change @ d8287c3

Board flash % RAM for global variables %
arduino:mbed_giga:giga 🔺 +64 - +128 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 +64 - +128 +0.01 - +0.02 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
Click for full report table
Board examples/DirList
flash
% examples/DirList
RAM for global variables
% examples/FileRead
flash
% examples/FileRead
RAM for global variables
% examples/FileWrite
flash
% examples/FileWrite
RAM for global variables
% examples/OptaDirList
flash
% examples/OptaDirList
RAM for global variables
% examples/PortentaOTA
flash
% examples/PortentaOTA
RAM for global variables
%
arduino:mbed_giga:giga 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 64 0.0 0 0.0 64 0.0 0 0.0
arduino:mbed_opta:opta 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
Click for full report CSV
Board,examples/DirList<br>flash,%,examples/DirList<br>RAM for global variables,%,examples/FileRead<br>flash,%,examples/FileRead<br>RAM for global variables,%,examples/FileWrite<br>flash,%,examples/FileWrite<br>RAM for global variables,%,examples/OptaDirList<br>flash,%,examples/OptaDirList<br>RAM for global variables,%,examples/PortentaOTA<br>flash,%,examples/PortentaOTA<br>RAM for global variables,%
arduino:mbed_giga:giga,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,64,0.0,0,0.0,64,0.0,0,0.0
arduino:mbed_opta:opta,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A

@alrvid
Copy link
Contributor Author

alrvid commented Aug 14, 2023

The Spell Check failure is because a comment correctly contains the word "unstall" - as in clearing the halted feature of the USB EPs when receiving a stall. It's not supposed to be "uninstall" even though that would satisfy Spell Check.

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Spell Check failure is because a comment correctly contains the word "unstall"

Please add the word that is producing the false spell check positive to the ignore-words-list field of the .codespellrc configuration file:

ignore-words-list = freeed,

See commit 3d1019e for more information.
@github-actions
Copy link

Memory usage change @ 69326c0

Board flash % RAM for global variables %
arduino:mbed_giga:giga 🔺 +64 - +128 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 +64 - +128 +0.01 - +0.02 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
Click for full report table
Board examples/DirList
flash
% examples/DirList
RAM for global variables
% examples/FileRead
flash
% examples/FileRead
RAM for global variables
% examples/FileWrite
flash
% examples/FileWrite
RAM for global variables
% examples/OptaDirList
flash
% examples/OptaDirList
RAM for global variables
% examples/PortentaOTA
flash
% examples/PortentaOTA
RAM for global variables
%
arduino:mbed_giga:giga 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 64 0.0 0 0.0 64 0.0 0 0.0
arduino:mbed_opta:opta 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
Click for full report CSV
Board,examples/DirList<br>flash,%,examples/DirList<br>RAM for global variables,%,examples/FileRead<br>flash,%,examples/FileRead<br>RAM for global variables,%,examples/FileWrite<br>flash,%,examples/FileWrite<br>RAM for global variables,%,examples/OptaDirList<br>flash,%,examples/OptaDirList<br>RAM for global variables,%,examples/PortentaOTA<br>flash,%,examples/PortentaOTA<br>RAM for global variables,%
arduino:mbed_giga:giga,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,64,0.0,0,0.0,64,0.0,0,0.0
arduino:mbed_opta:opta,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A

@alrvid alrvid requested a review from per1234 August 17, 2023 05:48
Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to codespell configuration are perfect. I'm not able to evaluate the changes to the library codebase.

Thanks @alrvid!

Set state to USB_TYPE_IDLE to allow recover from the error, but return the error. The
previous solution didn't correctly report all errors.
@github-actions
Copy link

Memory usage change @ c333aa4

Board flash % RAM for global variables %
arduino:mbed_giga:giga 🔺 +64 - +128 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 +64 - +128 +0.01 - +0.02 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
Click for full report table
Board examples/DirList
flash
% examples/DirList
RAM for global variables
% examples/FileRead
flash
% examples/FileRead
RAM for global variables
% examples/FileWrite
flash
% examples/FileWrite
RAM for global variables
% examples/OptaDirList
flash
% examples/OptaDirList
RAM for global variables
% examples/PortentaOTA
flash
% examples/PortentaOTA
RAM for global variables
%
arduino:mbed_giga:giga 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 64 0.0 0 0.0
arduino:mbed_opta:opta 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
Click for full report CSV
Board,examples/DirList<br>flash,%,examples/DirList<br>RAM for global variables,%,examples/FileRead<br>flash,%,examples/FileRead<br>RAM for global variables,%,examples/FileWrite<br>flash,%,examples/FileWrite<br>RAM for global variables,%,examples/OptaDirList<br>flash,%,examples/OptaDirList<br>RAM for global variables,%,examples/PortentaOTA<br>flash,%,examples/PortentaOTA<br>RAM for global variables,%
arduino:mbed_giga:giga,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,64,0.0,0,0.0
arduino:mbed_opta:opta,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A

Alrik Vidstrom added 2 commits August 20, 2023 14:02
MAX_NYET_RETRY is an incorrect name, because URB_NOTREADY can have several different
causes that are unrelated to each other. Therefore, MAX_NOTREADY_RETRY is a better
name. This commit also changes a comment regarding the case where the max retries
limit has been reached, to better describe what happens.
Increases the MAX_NOTREADY_RETRY from 5 to 50000. The previous value (5) was not
nearly enough to handle the slow writes to some USB thumb drives. While it worked
with some models, it failed all the time with others. 50000 might be a bit on the
high side, but it adds margin since we can't possibly test all the models out there.
@github-actions
Copy link

Memory usage change @ 8c3c35a

Board flash % RAM for global variables %
arduino:mbed_giga:giga 🔺 +64 - +128 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 +64 - +128 +0.01 - +0.02 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
Click for full report table
Board examples/DirList
flash
% examples/DirList
RAM for global variables
% examples/FileRead
flash
% examples/FileRead
RAM for global variables
% examples/FileWrite
flash
% examples/FileWrite
RAM for global variables
% examples/OptaDirList
flash
% examples/OptaDirList
RAM for global variables
% examples/PortentaOTA
flash
% examples/PortentaOTA
RAM for global variables
%
arduino:mbed_giga:giga 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 64 0.0 0 0.0
arduino:mbed_opta:opta 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
Click for full report CSV
Board,examples/DirList<br>flash,%,examples/DirList<br>RAM for global variables,%,examples/FileRead<br>flash,%,examples/FileRead<br>RAM for global variables,%,examples/FileWrite<br>flash,%,examples/FileWrite<br>RAM for global variables,%,examples/OptaDirList<br>flash,%,examples/OptaDirList<br>RAM for global variables,%,examples/PortentaOTA<br>flash,%,examples/PortentaOTA<br>RAM for global variables,%
arduino:mbed_giga:giga,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,64,0.0,0,0.0
arduino:mbed_opta:opta,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A

@github-actions
Copy link

Memory usage change @ a4ac6d1

Board flash % RAM for global variables %
arduino:mbed_giga:giga 🔺 +64 - +128 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 +64 - +128 +0.01 - +0.02 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
Click for full report table
Board examples/DirList
flash
% examples/DirList
RAM for global variables
% examples/FileRead
flash
% examples/FileRead
RAM for global variables
% examples/FileWrite
flash
% examples/FileWrite
RAM for global variables
% examples/OptaDirList
flash
% examples/OptaDirList
RAM for global variables
% examples/PortentaOTA
flash
% examples/PortentaOTA
RAM for global variables
%
arduino:mbed_giga:giga 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 64 0.0 0 0.0
arduino:mbed_opta:opta 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
Click for full report CSV
Board,examples/DirList<br>flash,%,examples/DirList<br>RAM for global variables,%,examples/FileRead<br>flash,%,examples/FileRead<br>RAM for global variables,%,examples/FileWrite<br>flash,%,examples/FileWrite<br>RAM for global variables,%,examples/OptaDirList<br>flash,%,examples/OptaDirList<br>RAM for global variables,%,examples/PortentaOTA<br>flash,%,examples/PortentaOTA<br>RAM for global variables,%
arduino:mbed_giga:giga,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,64,0.0,0,0.0
arduino:mbed_opta:opta,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A

@alrvid alrvid changed the title Fixes connect() bug, crash bug, and comment error Fixes connect() bug, crash bug, I/O error bug, and more. Aug 20, 2023
Alrik Vidstrom added 3 commits August 20, 2023 17:42
This commit improves the source code comments in several locations, adding explanations
for things that might easily be misunderstood, or take a long time to understand.
errror => error
recover => recovery
@github-actions
Copy link

Memory usage change @ 3a90c05

Board flash % RAM for global variables %
arduino:mbed_giga:giga 🔺 +64 - +128 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 +64 - +128 +0.01 - +0.02 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
Click for full report table
Board examples/DirList
flash
% examples/DirList
RAM for global variables
% examples/FileRead
flash
% examples/FileRead
RAM for global variables
% examples/FileWrite
flash
% examples/FileWrite
RAM for global variables
% examples/OptaDirList
flash
% examples/OptaDirList
RAM for global variables
% examples/PortentaOTA
flash
% examples/PortentaOTA
RAM for global variables
%
arduino:mbed_giga:giga 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 64 0.0 0 0.0
arduino:mbed_opta:opta 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0 64 0.01 0 0.0 128 0.02 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
Click for full report CSV
Board,examples/DirList<br>flash,%,examples/DirList<br>RAM for global variables,%,examples/FileRead<br>flash,%,examples/FileRead<br>RAM for global variables,%,examples/FileWrite<br>flash,%,examples/FileWrite<br>RAM for global variables,%,examples/OptaDirList<br>flash,%,examples/OptaDirList<br>RAM for global variables,%,examples/PortentaOTA<br>flash,%,examples/PortentaOTA<br>RAM for global variables,%
arduino:mbed_giga:giga,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,64,0.0,0,0.0
arduino:mbed_opta:opta,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0,64,0.01,0,0.0,128,0.02,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A

@facchinm
Copy link
Collaborator

Lovely work, thanks a lot!

@facchinm facchinm merged commit 133d9c1 into arduino-libraries:master Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants