Awadhy Mohammed | 71bd937 | 2023-08-07 14:46:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include "cmsis_compiler.h" |
| 10 | #include "psa/client.h" |
| 11 | #include "psa/crypto.h" |
| 12 | #include "tfm_plat_ns.h" |
| 13 | #include "Driver_USART.h" |
| 14 | #include "uart_stdout.h" |
| 15 | |
| 16 | /** |
| 17 | * \brief Modified table template for user defined SVC functions |
| 18 | * |
| 19 | * \details RTX has a weak definition of osRtxUserSVC, which |
| 20 | * is overridden here |
| 21 | */ |
| 22 | #if defined(__ARMCC_VERSION) |
| 23 | #if (__ARMCC_VERSION == 6110004) |
| 24 | /* Workaround needed for a bug in Armclang 6.11, more details at: |
| 25 | * http://www.keil.com/support/docs/4089.htm |
| 26 | */ |
| 27 | __attribute__((section(".gnu.linkonce"))) |
| 28 | #endif |
| 29 | |
| 30 | /* Avoids the semihosting issue */ |
| 31 | #if (__ARMCC_VERSION >= 6010050) |
| 32 | __asm(" .global __ARM_use_no_argv\n"); |
| 33 | #endif |
| 34 | #endif |
| 35 | |
| 36 | /** |
| 37 | * \brief Platform peripherals and devices initialization. |
| 38 | * Can be overridden for platform specific initialization. |
| 39 | * |
| 40 | * \return ARM_DRIVER_OK if the initialization succeeds |
| 41 | */ |
| 42 | __WEAK int32_t tfm_ns_platform_init(void) |
| 43 | { |
| 44 | stdio_init(); |
| 45 | |
| 46 | return ARM_DRIVER_OK; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * \brief main() function |
| 51 | */ |
| 52 | #ifndef __GNUC__ |
| 53 | __attribute__((noreturn)) |
| 54 | #endif |
| 55 | int main(void) |
| 56 | { |
| 57 | if (tfm_ns_platform_init() != ARM_DRIVER_OK) { |
| 58 | /* Avoid undefined behavior if platform init failed */ |
| 59 | while(1); |
| 60 | } |
| 61 | |
| 62 | printf("Non-Secure system starting...\r\n"); |
| 63 | printf("Hello TF-M world\r\n"); |
| 64 | |
| 65 | uint32_t fw_version = psa_framework_version(); |
Anton Komlev | 95add8a | 2024-05-09 14:33:11 +0100 | [diff] [blame^] | 66 | printf("PSA Framework Version = %d.%d\r\n", fw_version >> 8, fw_version & 0xFF); |
Awadhy Mohammed | 71bd937 | 2023-08-07 14:46:15 +0100 | [diff] [blame] | 67 | |
| 68 | uint8_t number; |
| 69 | printf("Testing psa get random number...\r\n"); |
| 70 | for (int i = 1; i <= 5; i++) { |
| 71 | if (psa_generate_random(&number, sizeof(number)) == PSA_SUCCESS) { |
| 72 | printf("%d: psa_generate_random() = %d\r\n", i, number); |
| 73 | } else { |
| 74 | printf("psa_generate_random() failed.\r\n"); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | printf("End of TF-M example App\r\n"); |
| 79 | |
| 80 | for (;;) { |
| 81 | } |
| 82 | } |