Skip to content
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

fixes: busio, SPI OS error 5 for mimxrt10xx #4048

Merged
merged 3 commits into from
Feb 9, 2021

Conversation

janderit
Copy link

@janderit janderit commented Jan 22, 2021

I ran into an issue trying to connect an MCP2515 CAN bus controller via SPI to a Teensy 4.0 (using adafruit_mcp2515) and might have a simple solution to this and possibly related issues #3763 and #3055.

After a few CAN messages transferred, there is an exception with the following information.

common_hal_busio_spi_read: status 400
Traceback (most recent call last):
  File "code.py", line 49, in <module>
  File "code.py", line 44, in <module>
  File "/lib/adafruit_mcp2515/canio/__init__.py", line 102, in receive
  File "/lib/adafruit_mcp2515/__init__.py", line 355, in unread_message_count
  File "/lib/adafruit_mcp2515/__init__.py", line 421, in _read_from_rx_buffers
  File "/lib/adafruit_mcp2515/__init__.py", line 386, in _read_rx_buffer
  File "/lib/adafruit_mcp2515/__init__.py", line 386, in _read_rx_buffer
OSError: [Errno 5] Input/output error

It seems that SPI might occasionally be busy. The SPI drivers (e.g. MIMXRT10xx_SDK/.../MIMXRT1062/drivers/fsl_lpspi.c ) then return kStatus_LPSPI_Busy, which in busio mimxrt10xx/common-hal/busio/SPI.c translates into false result, thus resulting in OS Error 5.

Attempting a simple busy waiting loop in case of kStatus_LPSPI_Busy instead seems to do the trick. The problem seems to be resolved and I so far did not see more than a single additional iteration of the idle loop.

However, since I do not know the details of how SPI works here, I have no idea whether this simple solution is too simple. So if someone can asses this, please comment.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Would you mind changing it to do a fixed number of retries? I'm worried about a hang as-is. Thanks for looking into this!

@janderit
Copy link
Author

Would you mind changing it to do a fixed number of retries? I'm worried about a hang as-is. Thanks for looking into this!

Sure, will do.

@janderit janderit force-pushed the fix_3763_mimxrt10xx_spi branch from e461df7 to 5bf08c5 Compare February 7, 2021 16:10
@janderit janderit marked this pull request as ready for review February 7, 2021 16:12
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Thank you!

@tannewt tannewt merged commit 0ceac79 into adafruit:main Feb 9, 2021
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.

2 participants