# 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_6(EB) : with DMA, AsyncTransmit
  2. Sequence_1 -- Job_1 --------- SPI_1 -- Channel_1(EB)                 : with DMA, AsyncTransmit
  3. Sequence_2 -- Job_2 --------- SPI_2 -- Channel_2(EB) & Channel_7(EB) : None DMA, AsyncTransmit
  4. Sequence_3 -- Job_3 --------- SPI_3 -- Channel_3(EB)                 : None DMA, AsyncTransmit
  5. Sequence_4 -- Job_4 & Job_6-- SPI_4 -- Channel_4(EB)                 : with DMA, AsyncTransmit
  6. Sequence_5 -- Job_5 --------- SPI_5 -- Channel_5(EB) & Channel_8(IB) : 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.
+ ***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  |  PTA30  |  H4_29  |
|  MOSI  |  PTE01  |  H1_27  |

**SPI1**

|  Function  |  MCU Pin  | EVB pin header|  
| ---- | ------- | ------ |
|  MISO  |  PTA27  |  H1_22  |
|  MOSI  |  PTA29  |  H1_26  |

**SPI2**

|  Function  |  MCU Pin  | EVB pin header|
| ---- | ------- | ------ |
|  MISO  |  PTB27  |  H2_28  |
|  MOSI  |  PTB28  |  H2_29  |

**SPI3**

|  Function  |  MCU Pin  | EVB pin header|
| ---- | ------- | ------ |
|  MISO  |  PTE03  |  H1_21  |
|  MOSI  |  PTA11  |  H4_27  |

**SPI4**

|  Function  |  MCU Pin  | EVB pin header|
| ---- | ------- | ------ |
|  MISO  |  PTD06  |  H2_09  |
|  MOSI  |  PTD07  |  H2_08  |

**SPI5**

|  Function  |  MCU Pin  | EVB pin header|
| ---- | ------- | ------ |
|  MISO  |  PTD11  |  H2_12  |
|  MOSI  |  PTD12  |  H2_11  |

---

## Hardware Requirements

- **Evaluation Board (EVB)**: YTM32B1ME0-Q144-EVB-Rev.B/C
- **Debugger**: J-Link HW v9.2 or later, with the YUNTU `YTM32B1ME0` patch (support package) installed.

**Note**: Please check the version number at the bottom of the EVB. If it is `YTM32B1ME0-EVB-Q144 Rev.C`, please use the example projects ending with `_RevC` for `YTMEVB_Demo`, `Icu_Demo`, and `Dio_Demo`.

---

## Software Requirements

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

  ***Note***: The **YTM32B1ME0** patch needs to be installed, which can be obtained through the **YCT** tool or by contacting the ***Yuntu Sales/FAE team***.


---