|
Internal Interface Wrap
API reference
|
One MCU SPI peripheral + its soft-CS device collection. More...
#include <StmSpi.h>
Static Public Member Functions | |
| static hf_u8_t | ResolveBaudMbr (hf_u32_t kernel_hz, hf_u32_t requested_hz) noexcept |
Smallest CFG1.MBR whose SCK does not exceed requested_hz. | |
Static Public Attributes | |
| static constexpr hf_u16_t | kScratchBytes = 32 |
Private Attributes | |
| hf_spi_bus_config_t | config_ |
| bool | initialized_ {false} |
| bool | mode_applied_ {false} |
| hf_stm32_spi_mode_t | last_mode_ {hf_stm32_spi_mode_t::MODE_0} |
| bool | last_io_swap_ {false} |
| hf_u8_t | last_midi_cycles_ {15} |
| hf_u8_t | last_baud_mbr_ {0xFFU} |
| PlatformMutex | bus_mutex_ {} |
| std::vector< std::unique_ptr< StmSpiDevice > > | devices_ |
| uint8_t | scratch_tx_ [kScratchBytes] {} |
| uint8_t | scratch_rx_ [kScratchBytes] {} |
Friends | |
| class | StmSpiDevice |
| class | StmSpiBusLock |
One MCU SPI peripheral + its soft-CS device collection.
Applies per-device SPI mode on transfer so soft-CS multi-slave buses (e.g. MAX Mode 0 + TLE Mode 1) work despite a single CubeMX SPI Init block. Transfers are serialized with PlatformMutex via StmSpiBusLock. Opt-in bench register-poke paths must take the same lock.
StmI2c).SSOM) so multi-byte transfers are one continuous stream under the asserted CS line.
|
explicitnoexcept |
|
explicitnoexcept |
Convenience: construct directly from a CubeMX HAL handle.
|
noexcept |
|
noexcept |
Apply mode (CPOL/CPHA), midi_cycles (CFG2.MIDI) and clock_speed_hz (CFG1.MBR) if they differ from the last applied values. Safe to call with SPE briefly cleared.
| midi_cycles | SCK idle cycles between data frames (0–15). See hf_spi_device_config_t::inter_data_idle_cycles for why this is per-device: FIFO-serviced slaves want the pause, shift-register slaves (TLE92466ED) need a continuous 32-bit stream. |
| clock_speed_hz | Target SCK in Hz; 0 keeps whatever prescaler is already programmed (CubeMX default). See hf_spi_device_config_t::clock_speed_hz. |
| reconfigured | Optional out-flag: true when CFG1/CFG2 were actually rewritten. Callers use this to decide whether the post-mode CPOL settle is needed — an unchanged peripheral cannot have glitched SCK, so the settle is pure WCET on a same-device repeat frame. |
|
noexcept |
Register a soft-CS device on this bus.
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
Effective SCK in Hz for the prescaler currently programmed.
|
noexcept |
Underlying CubeMX SPI handle (platform wiring only).
|
noexcept |
Kernel clock feeding this SPI peripheral, in Hz (0 if unknown).
Resolved from RCC at call time, so a clock-tree change cannot silently invalidate a hard-coded assumption. SPI1/2/3 share RCC_PERIPHCLK_SPI123, SPI4/5 share SPI45, SPI6 stands alone.
|
noexcept |
Drive every registered soft-CS to idle (active-low → HIGH).
|
noexcept |
|
noexcept |
Exclusive bus lock for mode + FIFO + CS + HAL transfer.
|
noexcept |
Bring-up probe of the shared MISO/SDO net — no scope required.
Retargets miso_port bit miso_pin_pos to a plain input, samples it with the internal pull-up and then the pull-down — first with every soft-CS idle, then with only device selected — and restores the original MODER/PUPDR. A slave that drives SDO overpowers the ~40 kΩ internal pull; a high-Z net simply follows it.
device selected + pull-up reads HIGH, bit3 = device selected + pull-down reads HIGH.Decode: 0x81 idle high-Z and driven LOW when selected — slave is alive and answering zeros. 0x85 high-Z even when selected — slave never drives SDO (unpowered, held in reset, or MISO not landed). 0x80 held LOW with all CS high — short to GND or a peer driving the shared net.
Smallest CFG1.MBR whose SCK does not exceed requested_hz.
| kernel_hz | Peripheral kernel clock. |
| requested_hz | Target SCK. |
requested_hz is below kernel/256, so the bus never runs faster than asked.
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
|
friend |
|
friend |
|
mutableprivate |
|
private |
|
private |
Per-bus internal-SRAM staging for short transfers. Must only be touched under StmSpiBusLock. A single process-wide scratch raced when two buses transferred concurrently (SensorAcquisition ADS pump vs actuator SPI2) and spliced peer bytes into TMC9660 TMCL frames.
|
private |
Last CFG1.MBR written by ApplyDeviceMode; 0xFF = never written, so the CubeMX prescaler stands until a device asks for a specific clock.
|
private |
|
private |
|
private |
|
private |