/* Configure the SPI as Master. 
To support multiple masters (dynamic switching between master and slave) you must set SSOE to 0 and select either software or hardware control of the NSS pin. */
int spi_init_master(uint32_t spi, uint32_t br, uint32_t cpol, uint32_t cpha, uint32_t dff, uint32_t lsbfirst)
/* Configure the SPI as Master. 
To support multiple masters (dynamic switching between master and slave) you must set SSOE to 0 and select either software or hardware control of the NSS pin. */
int spi_init_master(uint32_t spi, uint32_t br, uint32_t cpol, uint32_t cpha, uint32_t dff, uint32_t lsbfirst)
{
	uint32_t reg32 = SPI_CR1(spi);
	reg32 &= SPI_CR1_SPE | SPI_CR1_CRCEN | SPI_CR1_CRCNEXT;
	reg32 |= SPI_CR1_MSTR;
	reg32 |= br;
	reg32 |= cpol;
	reg32 |= cpha;
	reg32 |= dff;
	reg32 |= lsbfirst;
	SPI_CR2(spi) |= SPI_CR2_SSOE;
	SPI_CR1(spi) = reg32;
	return 0;
}