fix `invalid pin` error when create `busio.SPI` on MIMXRT10XX port by breakersun · Pull Request #8084 · adafruit/circuitpython · GitHub
Skip to content

fix invalid pin error when create busio.SPI on MIMXRT10XX port#8084

Merged
tannewt merged 1 commit into
adafruit:mainfrom
breakersun:fix-spi
Jun 15, 2023
Merged

fix invalid pin error when create busio.SPI on MIMXRT10XX port#8084
tannewt merged 1 commit into
adafruit:mainfrom
breakersun:fix-spi

Conversation

@breakersun

@breakersun breakersun commented Jun 14, 2023

Copy link
Copy Markdown

on specific SCK/MOSI/MISO pins, the common_hal_busio_spi_construct method always skips some miso pins which will lead to a invalid pin exception when SPI initialized

So the problem is on second loop of searching for mosi pins:


for (uint i = 0; i < sck_count; i++) {
        if (mcu_spi_sck_list[i].pin != clock) {
            continue;
        }
        // if both MOSI and MISO exist, loop search normally
        if ((mosi != NULL) && (miso != NULL)) {
            for (uint j = 0; j < mosi_count; j++) {
                if ((mcu_spi_sdo_list[i].pin != mosi) // <----- problem here, should not skip some mosi pins when searching
                    || (mcu_spi_sck_list[i].bank_idx != mcu_spi_sdo_list[j].bank_idx)) {
                    continue;
                }
                for (uint k = 0; k < miso_count; k++) {
                    if ((mcu_spi_sdi_list[k].pin != miso) // everything needs the same index
                        || (mcu_spi_sck_list[i].bank_idx != mcu_spi_sdi_list[k].bank_idx)) {
                        continue;
                    }

on specific SCK/MOSI/MISO pins, the `common_hal_busio_spi_construct`
method always skip miso pins which will lead to a `invalid pin`
exception when SPI initilized

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

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 1f20328 into adafruit:main Jun 15, 2023
dhalbert pushed a commit to dhalbert/circuitpython that referenced this pull request Sep 19, 2023
The original ESP32 only supports timer source clock APB so it doesn't need
and doesn't have a clk_src field.

The ESP32C3 supports timer source clock APB and XTAL so it does have a
clk_src field, and this needs to be configured to get the correct period.

Fixes adafruit#8084.
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