Skip to content

fix: initialize SPI callback union member for SPI-mode builds (AUD-003) - #182

Open
occamsshavingkit wants to merge 1 commit into
Wiznet:masterfrom
occamsshavingkit:fix/aud-003-spi-callback-init
Open

fix: initialize SPI callback union member for SPI-mode builds (AUD-003)#182
occamsshavingkit wants to merge 1 commit into
Wiznet:masterfrom
occamsshavingkit:fix/aud-003-spi-callback-init

Conversation

@occamsshavingkit

Copy link
Copy Markdown

Summary

Fixes incompatible callback initialization in the WIZCHIP global for SPI-mode builds.

Problem

The WIZCHIP global initializer at Ethernet/wizchip_conf.c:256-277 only initialized the IF.BUS union member (iodata_t (*)(uint32_t) signatures), even when _WIZCHIP_IO_MODE_ selected SPI mode. W5500 register access calls through IF.SPI._read_byte (uint8_t (*)(void)) and IF.SPI._write_byte (void (*)(uint8_t)) — incompatible function signatures through the wrong union member. Any W5500 access before SPI callback registration could HardFault or corrupt memory on common ARM ABIs.

Fix

Add #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_) conditional around the union initializer:

  • SPI mode: initialize IF.SPI with wizchip_spi_readbyte (returns 0), wizchip_spi_writebyte (no-op), and NULL burst callbacks
  • BUS mode: keep existing IF.BUS._read_data/_write_data initialization under #else

Verification

  • Multi-chip compile check: passes for all 7 _WIZCHIP_ values
  • The existing wizchip_spi_readbyte/wizchip_spi_writebyte stubs at wizchip_conf.c:172-182 are reused

The WIZCHIP global initializer at wizchip_conf.c:256-277 only initialized
the IF.BUS union member (iodata_t (*)(uint32_t) signatures), even when
_WIZCHIP_IO_MODE_ selected SPI mode. W5500 SPI access calls through
IF.SPI._read_byte (uint8_t (*)(void)) and IF.SPI._write_byte
(void (*)(uint8_t)) — incompatible signatures through the wrong union
member, which can HardFault or corrupt memory on common ARM ABIs.

Fix: when _WIZCHIP_IO_MODE_ has the SPI bit set, initialize IF.SPI
with the existing wizchip_spi_readbyte/wizchip_spi_writebyte stubs
(return 0 / no-op) and NULL burst callbacks. BUS mode keeps its
existing initialization under #else.
niansa added a commit to niansa/ioLibrary_Driver that referenced this pull request Jul 29, 2026
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.

1 participant