added changes to max7456.c to add setting speed and removing spi_mod_0 flag with defines from target.h file#11396
Conversation
Branch Targeting SuggestionYou've targeted the
If This is an automated suggestion to help route contributions to the appropriate branch. |
Review Summary by QodoAdd configurable SPI speed and manual mode override for MAX7456
WalkthroughsDescription• Add configurable SPI speed support via MAX7456_SPI_SPEED define • Implement manual SPI mode configuration for STM32H7 targets • Replace hardcoded BUS_SPEED_STANDARD with dynamic speed setting • Support custom hardware configurations without modifying common_hardware Diagramflowchart LR
A["max7456Init"] --> B["max7456ApplyBusSpeed"]
A --> C["max7456SpiModeOverride"]
B --> D["MAX7456_SPI_SPEED define"]
B --> E["BUS_SPEED_STANDARD fallback"]
C --> F["STM32H7 + MAX7456_MANUAL_SPI_CONFIG"]
C --> G["SPI CR1/CFG2 register config"]
File Changes1. src/main/drivers/max7456.c
|
Code Review by Qodo
1.
|
src/main/drivers/max7456.c
Outdated
| maxSpiInstance->CFG2 &= ~(SPI_CFG2_CPHA | SPI_CFG2_CPOL); | ||
| maxSpiInstance->CFG2 |= (SPI_CFG2_CPHA | SPI_CFG2_CPOL); | ||
| maxSpiInstance->CR1 |= SPI_CR1_SPE; |
There was a problem hiding this comment.
2. Mode override forces mode3 🐞 Bug ✓ Correctness
The manual override hard-sets CPOL+CPHA (MODE3) regardless of the bus-device configuration. This can silently override targets that register MAX7456 with DEVFLAGS_SPI_MODE_0 (MODE0), or be redundant when DEVFLAGS_SPI_MODE_0 is omitted (since the bus layer already defaults to MODE3).
Agent Prompt
## Issue description
`max7456SpiModeOverride()` currently forces CPOL+CPHA (SPI MODE3) unconditionally. This can conflict with the bus-device configuration where MAX7456 is commonly registered as MODE0 (`DEVFLAGS_SPI_MODE_0`). It can also be redundant if `DEVFLAGS_SPI_MODE_0` is omitted because the bus layer already defaults to MODE3.
## Issue Context
- `DEVFLAGS_SPI_MODE_0` explicitly maps to MODE0; when unset, MODE3 is used by default.
- The override ignores `state.dev->flags` and always writes MODE3 bits.
## Fix Focus Areas
- src/main/drivers/max7456.c[306-320]
- src/main/drivers/bus.h[152-160]
- src/main/drivers/bus_busdev_spi.c[44-48]
- src/main/target/common_hardware.c[411-413]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Thanks for submitting this! You mentioned "specific STM32H7-based targets" -- any that are currently publicly available? Or is this new hardware you're working on? |
|
Thanks for the review! I have updated the code to address the 2 Qodo bot's points: SPI state and validation. Regarding the Mode 3 override: Without this override, the OSD simply does not initialize on these H7 targets because the bus remains stuck in the default Mode 0 configuration. |
This PR introduces the ability to override default SPI parameters for the MAX7456 OSD chip. These changes are necessary to support specific STM32H7-based targets and custom hardware configurations where the standard DEVFLAGS_SPI_MODE_0 or BUS_SPEED_STANDARD are insufficient or incompatible with the hardware routing.