From 351edbb3c42bccf80f612a3a9710424787f8d951 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sun, 6 Sep 2020 23:34:57 +0200 Subject: [PATCH] stm32-sx1280: add fallback spi code, make cubemx defines usable --- .../SMTC_Drivers/sx1280-driver-c/sx1280-hal.c | 37 +++++++++++++++++-- .../SMTC_Drivers/sx1280-driver-c/sx1280-hal.h | 4 +- .../SMTC_Drivers/sx1280-driver-c/sx1280.c | 1 - 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280-hal.c b/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280-hal.c index 787c13dae..b3c1ae14f 100644 --- a/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280-hal.c +++ b/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280-hal.c @@ -22,6 +22,25 @@ Maintainer: Miguel Luis, Matthieu Verdy and Benjamin Boulet #include "SEGGER_RTT.h" #define printf(format, ...) SEGGER_RTT_printf(0, format, ## __VA_ARGS__) +// make CubeMX defines usable +#ifndef RADIO_BUSY_PORT +#define RADIO_BUSY_PORT RADIO_BUSY_GPIO_Port +#endif +#ifndef RADIO_BUSY_PIN +#define RADIO_BUSY_PIN RADIO_BUSY_Pin +#endif +#ifndef RADIO_nRESET_PORT +#define RADIO_nRESET_PORT RADIO_nRESET_GPIO_Port +#endif +#ifndef RADIO_nRESET_PIN +#define RADIO_nRESET_PIN RADIO_nRESET_Pin +#endif +#ifndef RADIO_NSS_PORT +#define RADIO_NSS_PORT RADIO_NSS_GPIO_Port +#endif +#ifndef RADIO_NSS_PIN +#define RADIO_NSS_PIN RADIO_NSS_Pin +#endif /*! * \brief Define the size of tx and rx hal buffers * @@ -120,10 +139,10 @@ static uint8_t halTxBuffer[MAX_HAL_BUFFER_SIZE] = {0x00}; static DioIrqHandler **dioIrqHandlers; -#ifdef USE_BK_SPI - extern SPI_HandleTypeDef RADIO_SPI_HANDLE; +#ifdef USE_BK_SPI + static void spi_tx_then_rx(SPI_HandleTypeDef *hspi, const uint8_t * tx_data, uint16_t tx_len, uint8_t * rx_buffer, uint16_t rx_len){ /* Set fiforxthreshold according the reception data length: 8bit */ @@ -160,7 +179,19 @@ static void spi_tx_then_rx(SPI_HandleTypeDef *hspi, const uint8_t * tx_data, uin *rx_buffer++ = *(__IO uint8_t *)&hspi->Instance->DR; } } - +#else +// map onto standard hal functions +void SpiIn( uint8_t *txBuffer, uint16_t size ){ + HAL_SPI_Transmit( &RADIO_SPI_HANDLE, txBuffer, size, HAL_MAX_DELAY ); +} +void SpiInOut( uint8_t *txBuffer, uint8_t *rxBuffer, uint16_t size ) +{ +#ifdef STM32L4XX_FAMILY + // Comment For STM32L0XX and STM32L1XX Intégration, uncomment for STM32L4XX Intégration + HAL_SPIEx_FlushRxFifo( &RADIO_SPI_HANDLERADIO_SPI_HANDLE ); +#endif + HAL_SPI_TransmitReceive( &RADIO_SPI_HANDLE, txBuffer, rxBuffer, size, HAL_MAX_DELAY ); +} #endif /*! diff --git a/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280-hal.h b/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280-hal.h index ae220da86..c97c9c925 100644 --- a/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280-hal.h +++ b/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280-hal.h @@ -22,8 +22,8 @@ Maintainer: Miguel Luis, Matthieu Verdy and Benjamin Boulet * * \brief Define which DIOs are connected */ #define RADIO_DIO1_ENABLE 1 -#define RADIO_DIO2_ENABLE 1 -#define RADIO_DIO3_ENABLE 1 +#define RADIO_DIO2_ENABLE 0 +#define RADIO_DIO3_ENABLE 0 void SX1280HalWaitOnBusy( void ); diff --git a/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280.c b/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280.c index 1c9894bb2..9e5a4c985 100644 --- a/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280.c +++ b/chipset/sx128x/SMTC_Drivers/sx1280-driver-c/sx1280.c @@ -20,7 +20,6 @@ Maintainer: Miguel Luis, Matthieu Verdy and Benjamin Boulet // logging on #include "SEGGER_RTT.h" -extern TIM_HandleTypeDef htim2; #define printf(format, ...) SEGGER_RTT_printf(0, format, ## __VA_ARGS__)