Let's get back to our aim :-
For SPI, we will develop the same :-
Starting off with the configurable items that the user can tinker with. We will develop again, SPI Configuration structure and SPI Handle structure.
In Serial Comm related peripherals, such as SPI, I2C, CAN, USB, SDIO. You will find one or more Control Registers (CR), Status Register (SR) and Data Register (DR).
SR : Flag an event such as ERROR Event, Bus Idle. CRC-ERROR. Almost all peripherals have one or two status registers.
Let's define macros for different configuration :-
In the CR_1 Register, the second bit field gives us the option to select if we want this SPI Peripheral to act as a Master or Slave. The point to note is by-default it is in Slave mode, thus it won't produce any CLK.
Two main modes :-
1. Full Duplex : 2-line-unidirectional
2. Half Duplex: 1-line-unidirectional . For this, the BIDIOE should be reciprocal for the two. One has to be rx and one has to be tx. To select this, BIDIOE.
Note:
1. For Full-Duplex, BIDIOE is don't care.
2. For the simplex mode, when you want Master to be used as transmitter, you would simply not configure the MISO line and you are good to go. However, if you want to use Master as the receiver, by not configuring the MOSI line, you are actually not providing the SCLK to the slave so the reception just won't happen. Thus, you would have set the RXOnly bit field to force the Master to generate CLK when in RX mode.
3. From here, we get that there are only three bus config Full Duplex, Half-Duplex, SimplexRxOnly because SimplexTxOnly is just FD.
Clock config can be set in BR register to set the prescalar.
These are as explained.
Note: sw slave management is disabled by-default.
Now, let's start to code the API's here :-
https://github.com/manvendra88/STM32_Device_Driver_Development/blob/master/stm32f407xx_spi_driver.h