4.2 SAM E70 Xplained Ultra Evaluation Kit

To develop and run the application, follow these steps:

  1. Open the main.c file of the project and add the required variables outside the main() function.
    uint8_t __attribute__ ((aligned(32))) Tx[10] = {0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, 0x8F, 0x9F, 0xAF};
    uint8_t __attribute__ ((aligned(32)))Rx[10];
    
    /* transfer done flag */
    volatile bool Rx_transfer_done = false;
    volatile bool Tx_transfer_done = false;
    
  2. Add the DMA Event Handler for both Tx and Rx outside of the main() function.
    /* This is called after transfer is done */
    void Tx_DMA_EventHandler(XDMAC_TRANSFER_EVENT event, uintptr_t context)
    {
        if (event == XDMAC_TRANSFER_COMPLETE)
        {
            Tx_transfer_done = true;
        }
    }
    
    void Rx_DMA_EventHandler(XDMAC_TRANSFER_EVENT event, uintptr_t context)
    {
        if (event == XDMAC_TRANSFER_COMPLETE)
        {
            Rx_transfer_done = true;
        }
    }
    
    Figure 4-3. Adding Macros, Variables, and Event Handlers
  3. Add the DMA Callback register function, cache invalidate function, and DMA Channel transfer function.
        XDMAC_ChannelCallbackRegister(XDMAC_CHANNEL_0, Tx_DMA_EventHandler, (uintptr_t)NULL);
        XDMAC_ChannelCallbackRegister(XDMAC_CHANNEL_1, Rx_DMA_EventHandler, (uintptr_t)NULL);
        
        DCACHE_INVALIDATE_BY_ADDR((uint32_t *)Tx, 10);
        DCACHE_INVALIDATE_BY_ADDR((uint32_t *)Rx, 10);
        
        XDMAC_ChannelTransfer(XDMAC_CHANNEL_1, (void *)&SPI0_REGS->SPI_RDR, Rx, sizeof(Rx));
        XDMAC_ChannelTransfer(XDMAC_CHANNEL_0, Tx, (void *)&SPI0_REGS->SPI_TDR, sizeof(Tx));
    
    Figure 4-4. Application Logic