From eb2a14a64587083361b76271bc1088d7d6761978 Mon Sep 17 00:00:00 2001 From: Stephen Hensley Date: Tue, 4 Aug 2026 14:42:05 -0700 Subject: [PATCH] added some configuration to SPI for SPI6 functionality/clock tree config. --- src/per/spi.cpp | 11 +++++++---- src/per/spi.h | 18 +++++++++--------- src/sys/system.cpp | 9 +++++---- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/per/spi.cpp b/src/per/spi.cpp index 03844599a..192233ed4 100644 --- a/src/per/spi.cpp +++ b/src/per/spi.cpp @@ -788,16 +788,17 @@ static pin_alt_spi spi5_pins_nss[] = {pins_none_spi, pins_none_spi, pins_none_spi}; /* ============== spi6 ============== */ -static pin_alt_spi spi6_pins_sclk[] - = {{Pin(PORTA, 5), GPIO_AF8_SPI6}, pins_none_spi, pins_none_spi}; +static pin_alt_spi spi6_pins_sclk[] = {{Pin(PORTA, 5), GPIO_AF8_SPI6}, + {Pin(PORTG, 13), GPIO_AF5_SPI6}, + pins_none_spi}; static pin_alt_spi spi6_pins_miso[] = {{Pin(PORTB, 4), GPIO_AF8_SPI6}, {Pin(PORTA, 6), GPIO_AF8_SPI6}, - pins_none_spi}; + {Pin(PORTG, 12), GPIO_AF5_SPI6}}; static pin_alt_spi spi6_pins_mosi[] = {{Pin(PORTB, 5), GPIO_AF8_SPI6}, {Pin(PORTA, 7), GPIO_AF8_SPI6}, - pins_none_spi}; + {Pin(PORTG, 14), GPIO_AF5_SPI6}}; static pin_alt_spi spi6_pins_nss[] = {{Pin(PORTA, 4), GPIO_AF8_SPI6}, pins_none_spi, pins_none_spi}; @@ -1023,6 +1024,8 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) break; case SpiHandle::Config::Peripheral::SPI_6: __HAL_RCC_SPI6_CLK_ENABLE(); + HAL_NVIC_SetPriority(SPI6_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(SPI6_IRQn); break; } diff --git a/src/per/spi.h b/src/per/spi.h index 5e6d2e6cc..1e7bbafe5 100644 --- a/src/per/spi.h +++ b/src/per/spi.h @@ -137,10 +137,10 @@ class SpiHandle typedef void (*EndCallbackFunctionPtr)(void* context, Result result); - /** Blocking transmit + /** Blocking transmit \param buff input buffer \param size buffer size - \param timeout how long in milliseconds the function will wait + \param timeout how long in milliseconds the function will wait before returning without successful communication */ Result BlockingTransmit(uint8_t* buff, size_t size, uint32_t timeout = 100); @@ -157,7 +157,7 @@ class SpiHandle \param tx_buff the transmit buffer \param rx_buff the receive buffer \param size the length of the transaction - \param timeout how long in milliseconds the function will wait + \param timeout how long in milliseconds the function will wait before returning without successful communication */ Result BlockingTransmitAndReceive(uint8_t* tx_buff, @@ -165,14 +165,14 @@ class SpiHandle size_t size, uint32_t timeout = 100); - /** DMA-based transmit + /** DMA-based transmit \param *buff input buffer \param size buffer size \param start_callback A callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast. \param end_callback A callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast. - \param callback_context A pointer that will be passed back to you in the callbacks. + \param callback_context A pointer that will be passed back to you in the callbacks. \return Whether the transmit was successful or not */ Result DmaTransmit(uint8_t* buff, @@ -181,14 +181,14 @@ class SpiHandle SpiHandle::EndCallbackFunctionPtr end_callback, void* callback_context); - /** DMA-based receive + /** DMA-based receive \param *buff input buffer \param size buffer size \param start_callback A callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast. \param end_callback A callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast. - \param callback_context A pointer that will be passed back to you in the callbacks. + \param callback_context A pointer that will be passed back to you in the callbacks. \return Whether the receive was successful or not */ Result DmaReceive(uint8_t* buff, @@ -197,7 +197,7 @@ class SpiHandle SpiHandle::EndCallbackFunctionPtr end_callback, void* callback_context); - /** DMA-based transmit and receive + /** DMA-based transmit and receive \param tx_buff the transmit buffer \param rx_buff the receive buffer \param size buffer size @@ -205,7 +205,7 @@ class SpiHandle The callback is called from an interrupt, so keep it fast. \param end_callback A callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast. - \param callback_context A pointer that will be passed back to you in the callbacks. + \param callback_context A pointer that will be passed back to you in the callbacks. \return Whether the receive was successful or not */ Result diff --git a/src/sys/system.cpp b/src/sys/system.cpp index 6f3ca335a..faa9eae32 100644 --- a/src/sys/system.cpp +++ b/src/sys/system.cpp @@ -457,10 +457,10 @@ void System::ConfigureClocks() PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART6 | RCC_PERIPHCLK_USART234578 | RCC_PERIPHCLK_LPUART1 - | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_SPI1 | RCC_PERIPHCLK_SAI2 - | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SDMMC | RCC_PERIPHCLK_I2C2 - | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_USB - | RCC_PERIPHCLK_QSPI | RCC_PERIPHCLK_FMC; + | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_SPI1 | RCC_PERIPHCLK_SPI6 + | RCC_PERIPHCLK_SAI2 | RCC_PERIPHCLK_SAI1 | RCC_PERIPHCLK_SDMMC + | RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_I2C1 + | RCC_PERIPHCLK_USB | RCC_PERIPHCLK_QSPI | RCC_PERIPHCLK_FMC; // PLL 2 // PeriphClkInitStruct.PLL2.PLL2N = 115; // Max Freq @ 3v3 //PeriphClkInitStruct.PLL2.PLL2N = 84; // Max Freq @ 1V9 @@ -501,6 +501,7 @@ void System::ConfigureClocks() PeriphClkInitStruct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLL3; PeriphClkInitStruct.Sai23ClockSelection = RCC_SAI23CLKSOURCE_PLL3; PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL2; + PeriphClkInitStruct.Spi6ClockSelection = RCC_SPI6CLKSOURCE_PCLK4; PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1; PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_D2PCLK2;