Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@priyaltaneja
Copy link

Add SpiMaster implementations across all three platforms:

  • stm32f: HAL-based implementation with GPIO chip select control
  • lnx: spidev interface with configurable mode and speed
  • cli: interactive hex I/O for testing and simulation

Includes Init()/Setup() functions for future bindings integration.

Add SpiMaster implementations across all three platforms:
- stm32f: HAL-based implementation with GPIO chip select control
- lnx: spidev interface with configurable mode and speed
- cli: interactive hex I/O for testing and simulation

Includes Init()/Setup() functions for future bindings integration.
@BlakeFreer BlakeFreer force-pushed the feature/spi-implementation branch from 77ec816 to 610a802 Compare November 14, 2025 18:48
}

// initialize chip select pin as output, set high (inactive)
GPIO_InitTypeDef GPIO_InitStruct = {0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glad you learned stm HAL pin initialization, but you don't need to configure the chip select pin manually. we will configure in in CubeMX so you can assume the Port/Pin is is initialized already

/// initialize the SPI peripheral
/// must be called before using any transmission methods
/// typically called from bindings::Initialize()
void Init() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the Init() function! it's a good idea since we want to guarantee that the CS pin is high on startup

I've seen the if(initialized_) and if(!initialized_) pattern used before, but I find it usually only clutters the code and doesn't provide any value. In Init() there is no harm in initializing twice (the outcome is the same), and in Transmit() / Receive() / TransmitReceive(), the transmission won't happen until you separately edit the code to call Init()

We don't need to protect the developer from forgetting to call Init(), so can you remove the initialized_ field and if(initialized_ checks? Similarly, we don't need to check that hspi != null

}

/// check if the spi peripheral has been initialized
bool IsInitialized() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need this, see comment above

}

/// get the underlying hal spi handle
SPI_HandleTypeDef* GetHandle() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this. When would it be called?

/// initialize the spi device
/// opens the device file and configures spi parameters
void Setup() {
if (initialized_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see this comment https://github.com/macformula/racecar/pull/539/files#r2528588442, don't need the initialized field & checks

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.

4 participants