STM32F4 SPI Program hangs at TXE non empty
I think I figured out the issue

SPI was enabled inside the HAL_SPI_Transmit() function. It checks wheter SPI is enabled or not inside the function, if not enabled it will enable it.

So if I want to write my own transmit function, I have to enable the corresponding SPI before transmission 

eg:

SPI5-&gt;CR1 |=  SPI_CR1_SPE;
SPI5_write(spiTxBuf[0]);
SPI5_write(spiTxBuf[1]);


where 

void SPI5_write(unsigned char data) {
    while (!(SPI5-&gt;SR &amp; 2)) {}      /* wait until Transfer buffer Empty */
    SPI5-&gt;DR = data;                /* write data */
    while (SPI5-&gt;SR &amp; 0x80) {}      /* wait for transmission done */
}