Repository navigation
arch/xtensa/esp32s3: Make SPI CS, MOSI and MISO pins signed - #20541
Merged
GUIDINGLI merged 1 commit intoOct 9, 2026
Merged
Conversation
The CS, MOSI and MISO pins can be set to -1 in Kconfig when the board does not use them, and esp32s3_spi_init() skips a pin when it is negative. The pins are stored as uint8_t in esp32s3_spi_config_s, so -1 becomes 255, every "pin >= 0" check is always true, and 255 is passed to esp_gpiowrite() and esp_configgpio(), which trips their DEBUGASSERT. Store these three pins as int8_t so -1 is kept and the existing checks work. Fixes apache#20186 Assisted-by: Grok Bot Signed-off-by: Zhaoqi Xu <[email protected]>
xiaoxiang781216
approved these changes
Oct 9, 2026
GUIDINGLI
approved these changes
Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ESP32S3_SPIx_CSPIN,_MOSIPINand_MISOPINaccept-1in Kconfig for boards that don't use the pin (arch/esp32s3: The MISO and C/S pins are optional #16085), andesp32s3_spi_init()/esp32s3_spi_select()skip a pin when it is negative. Butstruct esp32s3_spi_config_sstores those pins asuint8_t, so-1becomes 255, everypin >= 0check is always true, and 255 ends up inesp_gpiowrite()/esp_configgpio()(which assertpin < SOC_GPIO_PIN_COUNT). TheCONFIG_ESP32S3_SPI_UDCSfallback for a missing CS pin is never reached either.arch/xtensa/src/esp32s3/esp32s3_spi.c, the type ofcs_pin,mosi_pinandmiso_pininesp32s3_spi_config_s.int8_tso-1survives and the existing checks work.clk_pinis not optional and staysuint8_t.Assisted-by:trailer in the commit as CONTRIBUTING.md requires. TheSigned-off-by:is mine.Impact
-1(e.g.lckfb-szpi-esp32s3:lcd,esp32s3-m5-cardputer:fb) no longer touch GPIO 255. Boards with real pins are unchanged.Testing
I confirm that changes are verified on local setup and works as intended:
lckfb-szpi-esp32s3:lcd(SPI2 CS=-1, MISO=-1, SWCS+UDCS),esp32s3-m5-cardputer:fb(MISO=-1),esp32s3-devkit:spi(all pins set). Build-tested only, I don't have one of these boards.Testing logs before change (
lckfb-szpi-esp32s3:lcd,make EXTRAFLAGS=-Wtype-limits):and in the generated code
esp32s3_spibus_initialize()loadscs_pinwithl8uiand callsesp_gpiowrite()/esp_configgpio()with no branch.Testing logs after change:
the pins are sign-extended and checked (
sext+bltz) before each GPIO call, and the UDCSesp32s3_spi2_select()path is now reached when CS is -1. All three configurations above build and link with noesp32s3_spi.cwarnings (rebuilt on current master).tools/checkpatch.sh -c -u -m -g HEAD~1..HEAD: all checks pass.PR verification Self-Check