# Project Name：Spi_Master_Transfer_Demo

---
## Function description

This demo used to tests different configurations of SPI communication. The program initializes several SPI channels with various data transmission modes:
+ *AsyncTransmit with DMA*
+ *AsyncTransmit without DMA*
+ *AsyncTransmit with polling mode*
+ *AsyncTransmit with interrupt mode*
+ *SyncTransmit, LEVEL_0 API of AutoSAR requirement*

After initialization, the program performs a series of tests by transmitting data and comparing the transmitted and received data. The program also toggles an LED every 50 iterations of the main loop.

 **User case**
 <pre>
  1. Sequence_0 -- Job_0 --------- SPI_0 -- Channel_0(IB) & Channel_1(EB) : with DMA, AsyncTransmit
  2. Sequence_1 -- Job_1 --------- SPI_1 -- Channel_2(EB)                 : with DMA, AsyncTransmit
  3. Sequence_2 -- Job_2 --------- SPI_2 -- Channel_3(EB) & Channel_4(IB) : None DMA, AsyncTransmit
  4. Sequence_3 -- Job_3 --------- SPI_3 -- Channel_5(EB)                 : None DMA, SyncTransmit
</pre>

<p style="text-align: center;"><strong>Note</strong></p>

This demo needs shorting the MOSI and MISO pins of the SPI interface creates a loopback configuration where transmitted data is directly received back by the transmitter.

---
## Setup

+ ***Step1***: Refer to the ***SPI HW connection diagram***, connect the SPI MISO and MOSI port of each SPI bus（The silkscreen on the PCB is incorrect; please connect according to the correct markings on the schematic）.
+ ***Step2***: Open the Spi_Master_Transfer_Demo.yct with the YCT tool, config the toolchain per your required(by default, the VS code + GCC are used)
+ ***Step3***：Generate the codes， you can change the configurations if needed(to adapt to your own HW design), if so, please ensure all the modifications are OK with no any errors exist before generating the code.
+ ***Step4***: Open the generated project with VS code/IAR/Keil IDE per your selected.
+ ***Step5***: Compile the project, power on the EVB and download it to the EVB via the available debugger, such as a J-Link debugger probe.
+ ***Step6***: At last, enjoy the demo example.

### SPI HW connection diagram
**SPI0**

|  Function  |  MCU Pin  | EVB pin header|  
| ---- | ------- | ------ |
|  MISO  |  PTE01  |  H4_18  |
|  MOSI  |  PTE02  |  H4_10  |

**SPI1**

|  Function  |  MCU Pin  | EVB pin header|  
| ---- | ------- | ------ |
|  MISO  |  PTB15  |  H3_15  |
|  MOSI  |  PTD02  |  H3_21  |

**SPI2**

|  Function  |  MCU Pin  | EVB pin header|
| ---- | ------- | ------ |
|  MISO  |  PTE16  |  H4_25  |
|  MOSI  |  PTA08  |  H1_01  |

**SPI3**

|  Function  |  MCU Pin  | EVB pin header|
| ---- | ------- | ------ |
|  MISO  |  PTA11  |  H4_16  |
|  MOSI  |  PTE03  |  H1_18  |
**Note**:
Since SPI3_SCK(PTA13) and SPI3_PCS0(PTA12) are connected to CAN1 phy default, this demo requires disconnecting the jumpers on J6 labeled 3-4 and 5-6.

---

## Hardware requirement
+ **EVB**: YTM32B1MD1-EVB-Q100-Rev.A/B
+ **Debugger**: J-Link HW v9 or later with YUNTU `YTM32B1MD1` patch(support package) installed.

**Note**: Please check the version number at the bottom of the EVB. If it is `YTM32B1MD1-EVB-Q100-Rev.A/B`, please use the example projects ending with `_RevA` for `Icu_Demo`.
---

## Software requirement

+ **Config & Code Generation Tool**
  + **MCAL**: Yuntu Config Tool(YCT) v2.7.0 or later version
+ **Compiler Toolchain**
  + **GCC**: GNU GCC v10.3 or later version
  + **Keil/MDK**: ARM Keil/MDK v5.36 or later version(`armclang v6.18.2` is recommended to be used as the compiler)
  + **IAR**: IAR v9.50 or later version
  + **VS Code**: Microsoft Visual Studio Code IDE v1.76 or later version(C/C++ support, GNU toolchain, CMake v3.25, ninja, Cortex-Debug extensions installation required)
+ **Debugger driver**
    + **J-Link**: SEGGER J-Link v7.82 or later version, YUNTU `YTM32B1MD1` patch(support package) installation required.
    + **Ozone Debugger tool**: SEGGER Ozone v3.28 or later version.

    ***Note***: **YTM32B1MD1** patch install required which can be obtained via **YCT** or contact ***YUNTU sales/FAE team***.

---