Save the value x held by the secure code in the non-secure memory.
Access the non-secure memory where the value x will be stored from the non-secure code.
I want to do something like this, but after writing a value to non-secure memory with secure code, the value is not retained even if the memory is referenced from non-secure code.
Is there any way?
When Secure code has to access Non-secure memory using an address that is calculated by the Non-secure state, it cannot trust that the address lies in a Non-secure memory region. Secure code that accesses Non-secure memory on behalf of the Non-secure state must only do so if the Non-secure state has permission to perform the same access itself.
Refer https://developer.arm.com/docs/100720/0200/secure-software-guidelines?_ga=2.73227285.727592800.1581309915-1512883713.1532507181 on secure software guidelines that need to be followed for ARMv8-M based processors.