Skip to content

Commit b92419a

Browse files
committed
Fix the DMA transmission : half transfert complete is used
1 parent 9afeae0 commit b92419a

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

Inc/it_sdk/wrappers.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ _SPI_Status spi_write_byte(
168168
);
169169

170170
_SPI_Status spi_transmit_dma_start(
171-
ITSDK_SPI_HANDLER_TYPE * spi,
171+
SPI_HandleTypeDef * spi,
172172
uint8_t * pData,
173173
uint16_t size,
174-
void (* pCallback)( void ) // Callback function to call on Tx complete
174+
void (* pCallbackHC)( void ), // Half Transfer Complete callback
175+
void (* pCallbackTC)( void ) // TransferComplete callback
175176
);
176177

177178
_SPI_Status spi_transmit_dma_stop(

Src/drivers/sx1276/sigfox_lowlevel.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,16 @@ void STLL_Transmit_DMA_Start( uint16_t *pDataSource, uint16_t Size)
278278

279279
/**
280280
* Start the DMA transmission
281+
* The buffer contains a full DMA transfer information but to not miss any transmission
282+
* The HalfTransmit interrupt is used to add new data into the circular buffer. That way
283+
* we have no risk to loose data.
284+
* So here the callback used is the Half Tx one.
281285
*/
282286
if ( spi_transmit_dma_start(
283287
&ITSDK_SX1276_SPI,
284288
(uint8_t *)pDataSource,
285289
Size,
290+
STLL_onSpiDmaTxComplete, // Normally only half Tx callback should be rise
286291
STLL_onSpiDmaTxComplete
287292
) != SPI_OK ) {
288293
LOG_ERROR_SFXSX1276(("** spi_transmit_dma_start Error \r\n"));

Src/stm32l_sdk/spi/spi.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void spi_reset(
9191
* Override the HAL_SPI_TxCpltCallback for DMA transfert completion
9292
*/
9393
static void (* __spi_dma_tranfertCompleteCB)( void ) = NULL;
94+
static void (* __spi_dma_tranfertHalfCompleteCB)( void ) = NULL;
9495

9596
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
9697
DMA_HandleTypeDef *hdma= hspi->hdmatx;
@@ -101,16 +102,32 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
101102
}
102103
}
103104

105+
void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi) {
106+
DMA_HandleTypeDef *hdma= hspi->hdmatx;
107+
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma) );
108+
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma) );
109+
if ( __spi_dma_tranfertHalfCompleteCB != NULL ) {
110+
__spi_dma_tranfertHalfCompleteCB();
111+
}
112+
}
113+
114+
104115
_SPI_Status spi_transmit_dma_start(
105116
SPI_HandleTypeDef * spi,
106117
uint8_t * pData,
107118
uint16_t size,
108-
void (* pCallback)( void )
119+
void (* pCallbackHC)( void ),
120+
void (* pCallbackTC)( void )
109121
) {
110122
DMA_HandleTypeDef *hdma= spi->hdmatx;
111-
__spi_dma_tranfertCompleteCB = pCallback;
112-
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
113-
__HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC);
123+
__spi_dma_tranfertCompleteCB = pCallbackTC;
124+
__spi_dma_tranfertHalfCompleteCB = pCallbackHC;
125+
if ( __spi_dma_tranfertCompleteCB != NULL ) {
126+
__HAL_DMA_ENABLE_IT(hdma, DMA_IT_TC);
127+
}
128+
if (__spi_dma_tranfertHalfCompleteCB != NULL ) {
129+
__HAL_DMA_ENABLE_IT(hdma, DMA_IT_HT);
130+
}
114131
if ( HAL_SPI_Transmit_DMA(spi, pData, size) == HAL_OK ) {
115132
return SPI_OK;
116133
} else {

0 commit comments

Comments
 (0)