Scenario A: Host writes 5 bytes to
target
- Host sends HELLO via COM port
- tud_cdc_rx_cb() queues data
- usb2spi_pushTask()
- Queue [H, E, L, L, O] with length = 5
- Main loop: usb2spi_popTask()
- Get task from queue
- SPI write: data=[H,E,L,L,O]
- DMA transfers to SPI TX FIFO
- SPI hardware executes
- SPI_0_INST_IRQHandler()
- DL_SPI_IIDX_DMA_DONE_TX: DMA finished
- DL_SPI_IIDX_TX_EMPTY: Transmission complete
- fifoCompleteRead() marks task consumed
Scenario B: host reads 64 bytes from
target
- SPI target has data, pulls GPIO high
- GPIO interrupt fires
- SPISlaveDataReady = true
- Main loop detects: spi2usb_pushTask()
- Flush SPI RX/TX FIFOs
- Setup DMA TX: send dummy data (clock
generation)
- Setup DMA RX: SPI RX → buffer
- Start SPI transfer (64 bytes)
- SPI Hardware executes
- SPI_0_INST_IRQHandler()
- DL_SPI_IIDX_DMA_DONE_RX: All data received
- fifoCompleteWrite(&gSPI2USBTask), and mark
ready for USB transmission
- Main loop: spi2usb_popTask()
- Send 64 bytes to USB
- fifoCompleteRead() marks task done
- Host receives 64 bytes on COM port