feat: SPI (MibSPI host mode) driver implementation and host unit tests #83

Closed
opened 2026-07-23 12:47:40 +00:00 by hoogv · 0 comments
Owner

Description

Adds hal/mss/spi_host/hal_spi_host.c/.h — the SPI driver: MibSPI classic (non-buffered, non-DMA) polling master-mode init (mode 0-3 CPOL/CPHA, prescale clamp), blocking byte-shift write/read via SPIDAT1/SPIBUF, software chip-select via hal_gpio_write(), and the IRQ handler decoding SPIFLG to a weak, application-overridable hal_spi_host_irq_handler() hook. Depends on the already-landed GPIO driver (#75) for chip-select, but only via a FFF fake in the test suite — no real hal_gpio.c linked.

Use Case / Rationale

As a firmware developer, I need a hal_spi_host_* API for blocking SPI transfers with software-driven chip select, following the same driver pattern established by GPIO (#75), ESM (#77), UART (#79), and I2C (#81).

User Stories

  • As a developer, I want hal_spi_host_init() to configure mode/prescale from a target bus clock instead of hand-computing SPIFMT0 myself.
  • As a developer, I want hal_spi_host_start_transaction()/hal_spi_host_end_transaction() to drive chip-select as a plain GPIO pin, decoupled from MibSPI's own hardware CS lines.
  • As a QMS reviewer, I want a host-native Catch2 test suite (testing/mss/unit/hal_functionality/test_spi_host.c) covering all four SPI modes, prescale clamping, and the GPIO chip-select calls (via FFF), runnable in CI without target hardware.

Acceptance Criteria

  • hal/mss/spi_host/hal_spi_host.c/.h implemented against this project's current hal/registers/component/spi.h/instance/spi.h
  • testing/mss/unit/hal_functionality/test_spi_host.c passes under ctest, using an FFF fake for hal_gpio_write()
  • Sanity-checked by deliberately breaking the prescale formula and confirming the test suite catches it, then reverting

Functional Impact

None — self-contained addition alongside the already-landed GPIO/ESM/UART/I2C drivers.

Regulatory Impact

None

QMS Impact

None

Risk Impact

No — existing risk coverage sufficient.

Relates to #4, relates to #75, relates to #77, relates to #79, relates to #81

### Description Adds `hal/mss/spi_host/hal_spi_host.c`/`.h` — the SPI driver: MibSPI classic (non-buffered, non-DMA) polling master-mode init (mode 0-3 CPOL/CPHA, prescale clamp), blocking byte-shift write/read via `SPIDAT1`/`SPIBUF`, software chip-select via `hal_gpio_write()`, and the IRQ handler decoding `SPIFLG` to a weak, application-overridable `hal_spi_host_irq_handler()` hook. Depends on the already-landed GPIO driver (#75) for chip-select, but only via a FFF fake in the test suite — no real `hal_gpio.c` linked. ### Use Case / Rationale As a firmware developer, I need a `hal_spi_host_*` API for blocking SPI transfers with software-driven chip select, following the same driver pattern established by GPIO (#75), ESM (#77), UART (#79), and I2C (#81). ### User Stories - As a developer, I want `hal_spi_host_init()` to configure mode/prescale from a target bus clock instead of hand-computing `SPIFMT0` myself. - As a developer, I want `hal_spi_host_start_transaction()`/`hal_spi_host_end_transaction()` to drive chip-select as a plain GPIO pin, decoupled from MibSPI's own hardware CS lines. - As a QMS reviewer, I want a host-native Catch2 test suite (`testing/mss/unit/hal_functionality/test_spi_host.c`) covering all four SPI modes, prescale clamping, and the GPIO chip-select calls (via FFF), runnable in CI without target hardware. ### Acceptance Criteria - [x] `hal/mss/spi_host/hal_spi_host.c`/`.h` implemented against this project's current `hal/registers/component/spi.h`/`instance/spi.h` - [x] `testing/mss/unit/hal_functionality/test_spi_host.c` passes under `ctest`, using an FFF fake for `hal_gpio_write()` - [x] Sanity-checked by deliberately breaking the prescale formula and confirming the test suite catches it, then reverting ### Functional Impact None — self-contained addition alongside the already-landed GPIO/ESM/UART/I2C drivers. ### Regulatory Impact None ### QMS Impact None ### Risk Impact No — existing risk coverage sufficient. ### Related Issues / PRs Relates to #4, relates to #75, relates to #77, relates to #79, relates to #81
hoogv added this to the Development project 2026-07-23 13:31:42 +00:00
hoogv self-assigned this 2026-07-23 13:31:43 +00:00
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
opendutchsolutions.public/hal_awr6843#83
No description provided.