9 years, 4 months ago.

STM32 F411RE BurstSPI

Trying to port Burst to the STM32 F4 platform and hit a bit of a roadblock.

I have fastWrite working with the following

static SPI_HandleTypeDef SpiHandle;
void BurstSPI::fastWrite(int data) {
    // Check if data is transmitted
	SpiHandle.Instance = (SPI_TypeDef *)(_spi.spi);
    while (!((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_TXE) != RESET) ? 1 : 0));
    SpiHandle.Instance->DR =(uint16_t)data;
}

having trouble clearing the RX buffer though, tried a bunch of different things with no success, i assumed the below would work as its mostly a direct port of the L152RE code, but no dice, any ideas?

SpiHandle.Instance = (SPI_TypeDef *)(_spi.spi);
status = ((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_BSY) != RESET) ? 1 : 0);
    if(status){
    	while (!((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_RXNE) != RESET) ? 1 : 0));
    	uint16_t dummy = (uint16_t)SpiHandle.Instance->DR;
    }

Question relating to:

Class to be able to send SPI data with almost no overhead, useful at very high speeds. high, Speed, SPI

This is unrelated to your problem, but I'm curious why you have expressions that evaluate to a boolean value, that you then apply extra logic to to convert to a 1 or 0, just in order to evaluate them as a boolean value in an if or while statement? Wouldn't this:

while (!((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_TXE) != RESET) ? 1 : 0));

Just be this:

while (__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_TXE) == RESET);
posted by Dan East 29 Nov 2014

Appear to have got it working at least for my test cases Difference being wait till SPI isnt busy, then read RX, probably should have left the check if their was a byte available, but passes my tests.

#ifdef TARGET_NUCLEO_F411RE
#include "BurstSPI.h"

static SPI_HandleTypeDef SpiHandle;

void BurstSPI::fastWrite(int data) {
    SpiHandle.Instance = (SPI_TypeDef *)(_spi.spi);
    while (!((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_TXE) != RESET) ? 1 : 0));
    SpiHandle.Instance->DR =(uint16_t)data;
    }
    
void BurstSPI::clearRX( void ) {
    SpiHandle.Instance = (SPI_TypeDef *)(_spi.spi);
    //wait till SPI is not busy
    while(__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_BSY) != RESET);    
    //clear RX
    int dummy = SpiHandle.Instance->DR;
}
#endif
posted by James Kidd 29 Nov 2014
Be the first to answer this question.