1.5 Adding Application Code to Non-Secure Project

  1. In the main() function below SYS_Initialize() add the following line of code to register callback event handlers.

    DMAC_ChannelCallbackRegister(DMAC_CHANNEL_0, usartTxDmaChannelHandler, 0);

  2. Implement the registered callback event handler before the main() function.
    static void usartTxDmaChannelHandler(DMAC_TRANSFER_EVENT event, uintptr_t contextHandle)
    {
        if (event == DMAC_TRANSFER_EVENT_COMPLETE)
        {
            isUSARTTxComplete = true;
        }
    }
    
    Figure 1-20. Adding Application Logic to Implement DMAC Channel Handler
  3. Add the below code to enter the secure functionality from this Non-Secure application.
    DMAC_ChannelCallbackRegister(DMAC_CHANNEL_0, usartTxDmaChannelHandler, 0);
        while ( true )
        {
            if (readUartTxData(nonSecureUartTxBuffer) == true)
            {
            /* Maintain state machines of all polled MPLAB Harmony modules. */
                DMAC_ChannelTransfer(DMAC_CHANNEL_0, nonSecureUartTxBuffer, \
                        (const void *)&(SERCOM3_REGS->USART_INT.SERCOM_DATA), \
                        strlen((const char*)nonSecureUartTxBuffer));
            }
            secureAppEntry();
        }
    
    Figure 1-21. Adding Application Logic to Enter Secure Functionality from Non-Secure App
  4. Under Header Files > trustZone, in the nonsecure_entry.h file, add the following code by declaring NSCs with extern keyword to access and request the Secure application from the Non-Secure application.
    extern bool readUartTxData(uint8_t *lcluartTxBuffer);
    extern void secureAppEntry(void);
    
    Figure 1-22. Global NSCs to Access and Request Secure App from Non-Secure App