1.4 Adding Application Logic to Secure Project
To develop and run the application, follow these steps:
- Open the main.c file of the
Secure project and add the following application logic. Add the following code to
register RTC event handlers for a 500 ms compare event. RTC_Timer32CallbackRegister
(rtcEventHandler, 0); and the following code for the EIC callback event handler for
the switch press event EIC_CallbackRegister (EIC_PIN_12, sw0_eventHandler, 0); in
the
main()
function andSYS_Initialize (NULL)
function below:RTC_Timer32CallbackRegister(rtcEventHandler, 0); EIC_CallbackRegister(EIC_PIN_12, sw0_eventHandler, 0);
- Add the line of code to call the
RTC_Timer32Start()
function after registering the callback event handlers.Figure 1-16. Adding Application Logic to Register Callback Event Handlers - Implement the registered callback
event handlers for secure peripherals by adding the following
code.
static void sw0_eventHandler(uintptr_t context) { changeSamplingRate = true; } static void rtcEventHandler (RTC_TIMER32_INT_MASK intCause, uintptr_t context) { if (intCause & RTC_TIMER32_INT_MASK_CMP0) { isRTCTimerExpired = true; } }
Figure 1-17. Adding Application Logic to Implement the Registered Callback Event Handlers - In the
secureApp()
function, add the application logic of toggling LED at different rates of 500 ms, 1s, 2s, and 4s whenever there is a switch press on the board by the user before themain()
function in Secure Project.The complete secure functionality must run in the while(1) super loop of the
main()
function in main.c file of Secure Project.Figure 1-18. Adding Application Logic to Enter Secure App Functionality - Under Source Files >
trustZone, in the
nonsecure_entry.c
file, implement the Non-Secure callables below to access and request the secure application from the Non-Secure application.bool __attribute__((cmse_nonsecure_entry)) readUartTxData(uint8_t *lcluartTxBuffer) { bool localSecureUartStatus = readUartTxStatus; if(localSecureUartStatus == true) { memset((char*)lcluartTxBuffer, 0x00, 100); memcpy(lcluartTxBuffer, uartTxTempBuffer, strlen((const char *)&uartTxTempBuffer[0])); readUartTxStatus = false; } return (localSecureUartStatus); } void __attribute__((cmse_nonsecure_entry)) secureAppEntry(void) { secureApp(); }
Figure 1-19. Adding Application Logic to Implement the NSCs