This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-EM-CC2745R10-Q1: psa_import_key() runs incorrectly

Part Number: LP-EM-CC2745R10-Q1
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hi,

Here are my software and hardware versions:

LP-EM-CC2745R10-Q1

simplelink_lowpower_f3_sdk_8_40_00_61

CCS Version: 20.0.2.5__1.6.2

I was recently learning about the use of secure key stores, and I tested the examples\rtos\LP_EM_CC2745R10_Q1\drivers\psaRawKeyAgreement routine, And according to this routine in the examples\rtos\LP_EM_CC2745R10_Q1\ble5stack\basic_ble routine to write my own test function.When it was running, something went wrong and eventually an exception was located in the psa_import_key() function, which seemed to stop there without running backwards.

Here's my function:

static void test3(void)
{

    psa_status_t status;
    int_fast16_t ret;
    psa_key_attributes_t attributes;
    psa_key_id_t privateKeyID;
    size_t outputLength;

    uint8_t privateKey[] ={
            0x7D, 0x7D, 0xC5, 0xF7, 0x1E, 0xB2, 0x9D, 0xDA, 0xF8, 0x0D, 0x62, 0x14, 0x63, 0x2E, 0xEA, 0xE0,
            0x3D, 0x90, 0x58, 0xAF, 0x1F, 0xB6, 0xD2, 0x2E, 0xD8, 0x0B, 0xAD, 0xB6, 0x2B, 0xC1, 0xA5, 0x34,
        };
    uint8_t peerPublicKey[] =
        {
            /* clang-format off */
            0x04, /* Uncompressed point format prefix byte */
            /* X */
            0x70, 0x0C, 0x48, 0xF7, 0x7F, 0x56, 0x58, 0x4C, 0x5C, 0xC6, 0x32, 0xCA, 0x65, 0x64, 0x0D, 0xB9,
            0x1B, 0x6B, 0xAC, 0xCE, 0x3A, 0x4D, 0xF6, 0xB4, 0x2C, 0xE7, 0xCC, 0x83, 0x88, 0x33, 0xD2, 0x87,
            /* Y */
            0xDB, 0x71, 0xE5, 0x09, 0xE3, 0xFD, 0x9B, 0x06, 0x0D, 0xDB, 0x20, 0xBA, 0x5C, 0x51, 0xDC, 0xC5,
            0x94, 0x8D, 0x46, 0xFB, 0xF6, 0x40, 0xDF, 0xE0, 0x44, 0x17, 0x82, 0xCA, 0xB8, 0x5F, 0xA4, 0xAC,
            /* clang-format on */
        };
    uint8_t expectedSharedSecret[] =
        {
            /* raw encoded x-coordinate */
            0x46, 0xFC, 0x62, 0x10, 0x64, 0x20, 0xFF, 0x01, 0x2E, 0x54, 0xA4, 0x34, 0xFB, 0xDD, 0x2D, 0x25,
            0xCC, 0xC5, 0x85, 0x20, 0x60, 0x56, 0x1E, 0x68, 0x04, 0x0D, 0xD7, 0x77, 0x89, 0x97, 0xBD, 0x7B,
        };

     uint8_t sharedSecret[66];

    status = psa_crypto_init();
    if (status != PSA_SUCCESS)
    {
        tprintf("Error: psa_crypto_init() failed. Status = %d\n", status);
        while (1) {}
    }

        /* Provision the HW Unique Key needed to store key blobs */
    ret = HSMLPF3_provisionHUK();
    if (ret != HSMLPF3_STATUS_SUCCESS)
    {
        tprintf("Error: HSMLPF3_provisionHUK() failed. Status = %d\n", ret);
        while (1) {}
    }

        attributes = PSA_KEY_ATTRIBUTES_INIT;
        psa_set_key_algorithm(&attributes, PSA_ALG_ECDH);
        psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
        psa_set_key_bits(&attributes, 256);
        psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
        psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
                                            PSA_KEY_PERSISTENCE_DEFAULT,
                                            PSA_KEY_LOCATION_HSM_ASSET_STORE));
        
        privateKeyID = PSA_KEY_ID_USER_MIN;
        psa_set_key_id(&attributes, privateKeyID);

        tprintf("222222222222 \r\n");
        /* Import the private key */
        status = psa_import_key(&attributes, privateKey, sizeof(privateKey), &privateKeyID);

        if (status != PSA_SUCCESS)
        {
            tprintf("Error: psa_import_key() failed. Status = %d\n", status);
            /* Skip to next key lifetime if key import fails */
            while(1){};
        }
        tprintf("333333333333 \r\n");
                /* Retrieve the updated key attributes */
        status = psa_get_key_attributes(privateKeyID, &attributes);

        if (status != PSA_SUCCESS)
        {
            tprintf("Error: psa_get_key_attributes() failed. Status = %d\n", status);
        }

        /* Zero the shared secret output buffer */
        (void)memset(&sharedSecret[0], 0, sizeof(sharedSecret));

        tprintf("Calling psa_raw_key_agreement() \r\n");

        /* Compute the shared secret using ECDH */
        status = psa_raw_key_agreement(PSA_ALG_ECDH,
                                       privateKeyID,
                                       peerPublicKey,
                                       sizeof(peerPublicKey),
                                       sharedSecret,
                                       sizeof(sharedSecret),
                                       &outputLength);

        if (status == PSA_SUCCESS)
        {
            tprintf("Shared Secret: %d \r\n", outputLength);

            printHexMessage(uart, (char *)share_key, sharedSecret, sizeof(sharedSecret));
            printBanner(uart, (char *)"*");
        }   
}

void App_StackInitDoneHandler(gapDeviceInitDoneEvent_t *deviceInitDoneData)
{
    bStatus_t status = SUCCESS;

    GPIO_init();
    GPIO_setConfig(CONFIG_GPIO_LED_GREEN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    GPIO_setConfig(CONFIG_GPIO_LED_RED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    GPIO_write( CONFIG_GPIO_LED_GREEN, CONFIG_LED_ON );
    GPIO_write( CONFIG_GPIO_LED_RED, CONFIG_LED_ON );

    UART2_Params_init(&uartParams);
    uartParams.baudRate = 115200;

    uart = UART2_open(CONFIG_UART2_0, &uartParams);

    if (uart == NULL)
    {
        /* UART2_open() failed */
        while (1) {}
    }

    char array[] = "example start !! \r\n";
    printClearText(uart,array,NULL,0);


    test3();

}

Here's the log of its run, seemingly stuck in the psa_import_key() function.

When I ported the test3() function to the psaRawKeyAgreement routine, it worked fine.

/*
 * Copyright (c) 2024, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  ======== psaRawKeyAgreement.c ========
 */
#include <stdint.h>
#include <stdio.h>
#include <string.h>

/* POSIX Header files */
#include <pthread.h>

/* PSA Crypto header file */
#include <third_party/psa_crypto/include/psa/crypto.h>

/* Driver Header files */
#include <ti/display/Display.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/cryptoutils/hsm/HSMLPF3.h>

#include <ti/devices/DeviceFamily.h>

/* Driver configuration */
#include "ti_drivers_config.h"

#define THREAD_STACK_SIZE 1536

/* Array of valid PSA key lifetimes */
static const psa_key_lifetime_t lifetimes[] = {
    PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_VOLATILE, PSA_KEY_LOCATION_LOCAL_STORAGE),
    PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_DEFAULT, PSA_KEY_LOCATION_LOCAL_STORAGE),
#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX)
    PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_VOLATILE, PSA_KEY_LOCATION_HSM_ASSET_STORE),
    PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_DEFAULT, PSA_KEY_LOCATION_HSM_ASSET_STORE),
    PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_HSM_ASSET_STORE,
                                                   PSA_KEY_LOCATION_HSM_ASSET_STORE),
#endif
};

static const size_t lifetimeCnt = sizeof(lifetimes) / sizeof(psa_key_lifetime_t);

#define BITS_TO_BYTES(bits) (((bits) + 7u) / 8u)

#define MAX_CURVE_LENGTH_BYTES 66 /* P-521 */
#define MAX_PUB_KEY_BYTES      ((MAX_CURVE_LENGTH_BYTES * 2) + 1)

typedef struct
{
    uint8_t privateKey[MAX_CURVE_LENGTH_BYTES];
    uint8_t peerPublicKey[MAX_PUB_KEY_BYTES];
    uint8_t expectedSharedSecret[MAX_PUB_KEY_BYTES];
    psa_ecc_family_t curveFamily;
    size_t curveBits;
} keyAgreementTestVector;

static const keyAgreementTestVector testVector = {
    /* P-256 Count = 0 from CAVS 14.1 ECC CDH Primitive (SP800-56A
     * Section 5.7.1.2) Test Information for "testecccdh".
     */
    .privateKey =
        {
            0x7D, 0x7D, 0xC5, 0xF7, 0x1E, 0xB2, 0x9D, 0xDA, 0xF8, 0x0D, 0x62, 0x14, 0x63, 0x2E, 0xEA, 0xE0,
            0x3D, 0x90, 0x58, 0xAF, 0x1F, 0xB6, 0xD2, 0x2E, 0xD8, 0x0B, 0xAD, 0xB6, 0x2B, 0xC1, 0xA5, 0x34,
        },
    .peerPublicKey =
        {
            /* clang-format off */
            0x04, /* Uncompressed point format prefix byte */
            /* X */
            0x70, 0x0C, 0x48, 0xF7, 0x7F, 0x56, 0x58, 0x4C, 0x5C, 0xC6, 0x32, 0xCA, 0x65, 0x64, 0x0D, 0xB9,
            0x1B, 0x6B, 0xAC, 0xCE, 0x3A, 0x4D, 0xF6, 0xB4, 0x2C, 0xE7, 0xCC, 0x83, 0x88, 0x33, 0xD2, 0x87,
            /* Y */
            0xDB, 0x71, 0xE5, 0x09, 0xE3, 0xFD, 0x9B, 0x06, 0x0D, 0xDB, 0x20, 0xBA, 0x5C, 0x51, 0xDC, 0xC5,
            0x94, 0x8D, 0x46, 0xFB, 0xF6, 0x40, 0xDF, 0xE0, 0x44, 0x17, 0x82, 0xCA, 0xB8, 0x5F, 0xA4, 0xAC,
            /* clang-format on */
        },
    .expectedSharedSecret =
        {
            /* raw encoded x-coordinate */
            0x46, 0xFC, 0x62, 0x10, 0x64, 0x20, 0xFF, 0x01, 0x2E, 0x54, 0xA4, 0x34, 0xFB, 0xDD, 0x2D, 0x25,
            0xCC, 0xC5, 0x85, 0x20, 0x60, 0x56, 0x1E, 0x68, 0x04, 0x0D, 0xD7, 0x77, 0x89, 0x97, 0xBD, 0x7B,
        },
    .curveFamily = PSA_ECC_FAMILY_SECP_R1,
    .curveBits   = 256,
};

#define MSG_BUFFER_SIZE 256
static char msgBuf[MSG_BUFFER_SIZE];

static Display_Handle display;

/*
 *  ======== printByteArray ========
 */
static void printByteArray(Display_Handle display, const char *desc, const uint8_t *array, size_t len)
{
    char *dest = &msgBuf[0];
    size_t i;

    strcpy(dest, desc);
    dest += strlen(desc);

    /* Format the message as printable hex */
    for (i = 0; i < len; i++)
    {
        sprintf(dest + (i * 2), "%02X", *(array + i));
    }

    Display_printf(display, 0U, 0U, msgBuf);
}

/*
 *  ======== printKeyLifetime ========
 */
static void printKeyLifetime(psa_key_lifetime_t lifetime)
{
    char *dest                        = &msgBuf[0];
    psa_key_persistence_t persistence = PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime);
    psa_key_location_t location       = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);

    strcpy(dest, "Key persistence/location: ");
    dest = &msgBuf[0] + strlen(msgBuf);

    if (persistence == PSA_KEY_PERSISTENCE_VOLATILE)
    {
        strcpy(dest, "[Volatile / ");
    }
    else if (persistence == PSA_KEY_PERSISTENCE_DEFAULT)
    {
        strcpy(dest, "[Default / ");
    }
#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX)
    else if (persistence == PSA_KEY_PERSISTENCE_HSM_ASSET_STORE)
    {
        strcpy(dest, "[HSM Asset Store / ");
    }
#endif

    dest = &msgBuf[0] + strlen(msgBuf);

    if (location == PSA_KEY_LOCATION_LOCAL_STORAGE)
    {
        strcpy(dest, "Local Storage]");
    }
#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX)
    else if (location == PSA_KEY_LOCATION_HSM_ASSET_STORE)
    {
        strcpy(dest, "HSM Asset Store]");
    }
#endif

    Display_printf(display, 0U, 0U, msgBuf);
}

/*
 *  ======== keyAgreementThread ========
 */
static void *keyAgreementThread(void *arg0)
{
    // psa_key_attributes_t attributes;
    // psa_key_id_t privateKeyID;
    // psa_key_lifetime_t lifetime;
    // psa_status_t status;
    // size_t expectedSharedSecretLength;
    // size_t outputLength;
    // size_t peerKeyLength;
    // size_t privateKeyLength;
    // size_t ssIndex;
    // uint_fast8_t i;
    // uint_fast8_t passCnt = 0U;
    // uint8_t sharedSecret[MAX_CURVE_LENGTH_BYTES];

    // peerKeyLength              = PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(testVector.curveBits);
    // privateKeyLength           = BITS_TO_BYTES(testVector.curveBits);
    // expectedSharedSecretLength = BITS_TO_BYTES(testVector.curveBits);

    // /* Print the key agreement inputs */
    // printByteArray(display, "Private Key: 0x", testVector.privateKey, privateKeyLength);
    // printByteArray(display, "Peer Public Key: 0x", testVector.peerPublicKey, peerKeyLength);
    // Display_printf(display, 0U, 0U, "");

    // /* Loop for all valid key lifetimes */
    // for (i = 0U; i < lifetimeCnt; i++)
    // {
    //     lifetime = lifetimes[i];

    //     /* Init private key attributes */
    //     attributes = PSA_KEY_ATTRIBUTES_INIT;
    //     psa_set_key_algorithm(&attributes, PSA_ALG_ECDH);
    //     psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(testVector.curveFamily));
    //     psa_set_key_bits(&attributes, testVector.curveBits);
    //     psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
    //     psa_set_key_lifetime(&attributes, lifetime);

    //     if (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) != PSA_KEY_PERSISTENCE_VOLATILE)
    //     {
    //         /* Set the key ID for non-volatile keys, Range:[PSA_KEY_ID_USER_MIN - PSA_KEY_ID_USER_MAX] */
    //         privateKeyID = PSA_KEY_ID_USER_MIN + i;
    //         psa_set_key_id(&attributes, privateKeyID);
    //     }

    //     printKeyLifetime(lifetime);

    //     /* Import the private key */
    //     status = psa_import_key(&attributes, testVector.privateKey, privateKeyLength, &privateKeyID);

    //     if (status != PSA_SUCCESS)
    //     {
    //         Display_printf(display, 0U, 0U, "Error: psa_import_key() failed. Status = %d\n", status);
    //         /* Skip to next key lifetime if key import fails */
    //         continue;
    //     }

    //     /* Retrieve the updated key attributes */
    //     status = psa_get_key_attributes(privateKeyID, &attributes);

    //     if (status != PSA_SUCCESS)
    //     {
    //         Display_printf(display, 0U, 0U, "Error: psa_get_key_attributes() failed. Status = %d\n", status);
    //     }

    //     Display_printf(display, 0U, 0U, "Key ID: 0x%x", psa_get_key_id(&attributes));

    //     /* Zero the shared secret output buffer */
    //     (void)memset(&sharedSecret[0], 0, sizeof(sharedSecret));

    //     Display_printf(display, 0U, 0U, "Calling psa_raw_key_agreement()");

    //     /* Compute the shared secret using ECDH */
    //     status = psa_raw_key_agreement(PSA_ALG_ECDH,
    //                                    privateKeyID,
    //                                    testVector.peerPublicKey,
    //                                    peerKeyLength,
    //                                    sharedSecret,
    //                                    sizeof(sharedSecret),
    //                                    &outputLength);

    //     if (status == PSA_SUCCESS)
    //     {
    //         printByteArray(display, "Shared Secret: 0x", sharedSecret, outputLength);

    //         if (outputLength == expectedSharedSecretLength)
    //         {
    //             /* Verify shared secret output matches expected */
    //             for (ssIndex = 0; ssIndex < expectedSharedSecretLength; ssIndex++)
    //             {
    //                 if (sharedSecret[ssIndex] != testVector.expectedSharedSecret[ssIndex])
    //                 {
    //                     Display_printf(display,
    //                                    0U,
    //                                    0U,
    //                                    "Error: sharedSecret[%d] = 0x%02x does not match expected 0x%02x\n",
    //                                    ssIndex,
    //                                    sharedSecret[ssIndex],
    //                                    testVector.expectedSharedSecret[ssIndex]);

    //                     status = PSA_ERROR_GENERIC_ERROR;
    //                     break;
    //                 }
    //             }
    //         }
    //         else
    //         {
    //             /* Returned shared secret output length did not match expected */
    //             status = PSA_ERROR_GENERIC_ERROR;
    //         }

    //         if (status == PSA_SUCCESS)
    //         {
    //             passCnt++;
    //             Display_printf(display, 0U, 0U, "PASSED!\n");
    //         }
    //     }
    //     else
    //     {
    //         Display_printf(display, 0U, 0U, "Error: psa_raw_key_agreement() failed. Status = %d\n", status);
    //     }

    //     /* Destroy the key that was imported */
    //     status = psa_destroy_key(privateKeyID);

    //     if (status != PSA_SUCCESS)
    //     {
    //         Display_printf(display, 0U, 0U, "Error: psa_destroy_key() failed. Status = %d\n", status);
    //     }
    // }

    // Display_printf(display, 0U, 0U, "DONE!\n");

    // if (passCnt == lifetimeCnt)
    // {
    //     /* Turn on LED1 to indicate key agreement with all key lifetimes passed */
    //     GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_ON);
    // }


    psa_status_t status;
    int_fast16_t ret;
    psa_key_attributes_t attributes;
    psa_key_id_t privateKeyID;
    size_t outputLength;

    uint8_t privateKey[] ={
            0x7D, 0x7D, 0xC5, 0xF7, 0x1E, 0xB2, 0x9D, 0xDA, 0xF8, 0x0D, 0x62, 0x14, 0x63, 0x2E, 0xEA, 0xE0,
            0x3D, 0x90, 0x58, 0xAF, 0x1F, 0xB6, 0xD2, 0x2E, 0xD8, 0x0B, 0xAD, 0xB6, 0x2B, 0xC1, 0xA5, 0x34,
        };
    uint8_t peerPublicKey[] =
        {
            /* clang-format off */
            0x04, /* Uncompressed point format prefix byte */
            /* X */
            0x70, 0x0C, 0x48, 0xF7, 0x7F, 0x56, 0x58, 0x4C, 0x5C, 0xC6, 0x32, 0xCA, 0x65, 0x64, 0x0D, 0xB9,
            0x1B, 0x6B, 0xAC, 0xCE, 0x3A, 0x4D, 0xF6, 0xB4, 0x2C, 0xE7, 0xCC, 0x83, 0x88, 0x33, 0xD2, 0x87,
            /* Y */
            0xDB, 0x71, 0xE5, 0x09, 0xE3, 0xFD, 0x9B, 0x06, 0x0D, 0xDB, 0x20, 0xBA, 0x5C, 0x51, 0xDC, 0xC5,
            0x94, 0x8D, 0x46, 0xFB, 0xF6, 0x40, 0xDF, 0xE0, 0x44, 0x17, 0x82, 0xCA, 0xB8, 0x5F, 0xA4, 0xAC,
            /* clang-format on */
        };
    uint8_t expectedSharedSecret[] =
        {
            /* raw encoded x-coordinate */
            0x46, 0xFC, 0x62, 0x10, 0x64, 0x20, 0xFF, 0x01, 0x2E, 0x54, 0xA4, 0x34, 0xFB, 0xDD, 0x2D, 0x25,
            0xCC, 0xC5, 0x85, 0x20, 0x60, 0x56, 0x1E, 0x68, 0x04, 0x0D, 0xD7, 0x77, 0x89, 0x97, 0xBD, 0x7B,
        };

     uint8_t sharedSecret[66];

    status = psa_crypto_init();
    if (status != PSA_SUCCESS)
    {
         Display_printf(display, 0U, 0U, "Error: psa_crypto_init() failed. Status = %d\n", status);
        while (1) {}
    }

        /* Provision the HW Unique Key needed to store key blobs */
    ret = HSMLPF3_provisionHUK();
    if (ret != HSMLPF3_STATUS_SUCCESS)
    {
         Display_printf(display, 0U, 0U, "Error: HSMLPF3_provisionHUK() failed. Status = %d\n", ret);
        while (1) {}
    }

        attributes = PSA_KEY_ATTRIBUTES_INIT;
        psa_set_key_algorithm(&attributes, PSA_ALG_ECDH);
        psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
        psa_set_key_bits(&attributes, 256);
        psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
        psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
                                            PSA_KEY_PERSISTENCE_DEFAULT,
                                            PSA_KEY_LOCATION_HSM_ASSET_STORE));
        
        privateKeyID = PSA_KEY_ID_USER_MIN;
        psa_set_key_id(&attributes, privateKeyID);

         Display_printf(display, 0U, 0U, "222222222222 \r\n");
        /* Import the private key */
        status = psa_import_key(&attributes, privateKey, sizeof(privateKey), &privateKeyID);

        if (status != PSA_SUCCESS)
        {
             Display_printf(display, 0U, 0U, "Error: psa_import_key() failed. Status = %d\n", status);
            /* Skip to next key lifetime if key import fails */
            while(1){};
        }
         Display_printf(display, 0U, 0U, "333333333333 \r\n");
                /* Retrieve the updated key attributes */
        status = psa_get_key_attributes(privateKeyID, &attributes);

        if (status != PSA_SUCCESS)
        {
             Display_printf(display, 0U, 0U, "Error: psa_get_key_attributes() failed. Status = %d\n", status);
        }

        /* Zero the shared secret output buffer */
        (void)memset(&sharedSecret[0], 0, sizeof(sharedSecret));

         Display_printf(display, 0U, 0U, "Calling psa_raw_key_agreement() \r\n");

        /* Compute the shared secret using ECDH */
        status = psa_raw_key_agreement(PSA_ALG_ECDH,
                                       privateKeyID,
                                       peerPublicKey,
                                       sizeof(peerPublicKey),
                                       sharedSecret,
                                       sizeof(sharedSecret),
                                       &outputLength);

        if (status == PSA_SUCCESS)
        {
             Display_printf(display, 0U, 0U, "Shared Secret: %d \r\n", outputLength);

              printByteArray(display, "Shared Secret: 0x", sharedSecret, outputLength);

              if(memcmp(sharedSecret,expectedSharedSecret,sizeof(expectedSharedSecret)) == 0)
              {
                     Display_printf(display, 0U, 0U, "PASSED!\n");
              }

            // printHexMessage(uart, (char *)share_key, sharedSecret, sizeof(sharedSecret));
            // printBanner(uart, (char *)"*");
        }   


    return (NULL);
}

/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    int retc;
    int_fast16_t ret;
    psa_status_t status;
    pthread_attr_t attrs;
    pthread_t thread0;
    struct sched_param priParam;

    /* Initialize display driver */
    Display_init();

    /* Open the display for output */
    display = Display_open(Display_Type_UART, NULL);
    if (display == NULL)
    {
        /* Failed to open display driver */
        while (1) {}
    }

    // Display_printf(display, 0U, 0U, "\nStarting the PSA Crypto Raw Key Agreement example.\n");

    // /* Initialize PSA Crypto */
    // status = psa_crypto_init();
    // if (status != PSA_SUCCESS)
    // {
    //     Display_printf(display, 0U, 0U, "Error: psa_crypto_init() failed. Status = %d\n", status);
    //     while (1) {}
    // }

    // Display_printf(display, 0U, 0U, "Provisioning Hardware Unique Key (HUK)...\n");

    // /* Provision the HW Unique Key needed to store key blobs */
    // ret = HSMLPF3_provisionHUK();
    // if (ret != HSMLPF3_STATUS_SUCCESS)
    // {
    //     Display_printf(display, 0U, 0U, "Error: HSMLPF3_provisionHUK() failed. Status = %d\n", ret);
    //     while (1) {}
    // }

    /* Turn on LED0 to indicate successful initialization */
    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

    /* Set priority and stack size attributes */
    priParam.sched_priority = 1;

    retc = pthread_attr_init(&attrs);
    retc |= pthread_attr_setschedparam(&attrs, &priParam);
    retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
    retc |= pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE);
    if (retc != 0)
    {
        /* Failed to set thread attributes */
        while (1) {}
    }

    /* Create encrypt thread */
    retc = pthread_create(&thread0, &attrs, keyAgreementThread, NULL);
    if (retc != 0)
    {
        /* pthread_create() failed */
        while (1) {}
    }

    return (NULL);
}

I think it may be caused by problems in other project configurations, such as.syscfg file, but I found no abnormalities after comparison.

Here is my config file:

/*
 *  ======== ti_drivers_config.c ========
 *  Configured TI-Drivers module definitions
 *
 *  DO NOT EDIT - This file is generated for the LP_EM_CC2745R10_Q1
 *  by the SysConfig tool.
 */

#include <stddef.h>
#include <stdint.h>

#ifndef DeviceFamily_CC27XX
#define DeviceFamily_CC27XX
#endif

#include <ti/devices/DeviceFamily.h>

#include "ti_drivers_config.h"

/*
 *  =============================== AESCBC ===============================
 */

#include <ti/drivers/AESCBC.h>
#include <ti/drivers/aescbc/AESCBCLPF3.h>

#define CONFIG_AESCBC_COUNT 1
AESCBCLPF3_Object AESCBCLPF3_objects[CONFIG_AESCBC_COUNT];

/*
 *  ======== AESCBCLPF3_hwAttrs ========
 */
const AESCBCLPF3_HWAttrs AESCBCLPF3_hwAttrs[CONFIG_AESCBC_COUNT] = {
    {
        .intPriority = (~0),
    },
};

const AESCBC_Config AESCBC_config[CONFIG_AESCBC_COUNT] = {
    {   /* CONFIG_AESCBC_0 */
        .object  = &AESCBCLPF3_objects[CONFIG_AESCBC_0],
        .hwAttrs = &AESCBCLPF3_hwAttrs[CONFIG_AESCBC_0]
    },
};

const uint_least8_t CONFIG_AESCBC_0_CONST = CONFIG_AESCBC_0;
const uint_least8_t AESCBC_count = CONFIG_AESCBC_COUNT;

/*
 *  =============================== AESCCM ===============================
 */

#include <ti/drivers/AESCCM.h>
#include <ti/drivers/aesccm/AESCCMLPF3.h>

#define CONFIG_AESCCM_COUNT 1
AESCCMLPF3_Object AESCCMLPF3_objects[CONFIG_AESCCM_COUNT];

/*
 *  ======== AESCCMLPF3_hwAttrs ========
 */
const AESCCMLPF3_HWAttrs AESCCMLPF3_hwAttrs[CONFIG_AESCCM_COUNT] = {
    {
        .intPriority = (~0),
    },
};

const AESCCM_Config AESCCM_config[CONFIG_AESCCM_COUNT] = {
    {   /* CONFIG_AESCCM0 */
        .object  = &AESCCMLPF3_objects[CONFIG_AESCCM0],
        .hwAttrs = &AESCCMLPF3_hwAttrs[CONFIG_AESCCM0]
    },
};

const uint_least8_t CONFIG_AESCCM0_CONST = CONFIG_AESCCM0;
const uint_least8_t AESCCM_count = CONFIG_AESCCM_COUNT;

/*
 *  =============================== AESCTRDRBG ===============================
 */

#include <ti/drivers/AESCTRDRBG.h>
#include <ti/drivers/aesctrdrbg/AESCTRDRBGXX.h>

#define CONFIG_AESCTRDRBG_COUNT 1

/*
 *  ======== aesctrdrbgXXObjects ========
 */
AESCTRDRBGXX_Object aesctrdrbgXXObjects[CONFIG_AESCTRDRBG_COUNT];

/*
 *  ======== aesctrdrbgXXHWAttrs ========
 */
const AESCTRDRBGXX_HWAttrs aesctrdrbgXXHWAttrs[CONFIG_AESCTRDRBG_COUNT] = {
    /* CONFIG_AESCTRDRBG_0 */
    {
        .aesctrHWAttrs.intPriority = (~0)
    },
};

/*
 *  ======== AESCTRDRBG_config ========
 */
const AESCTRDRBG_Config AESCTRDRBG_config[CONFIG_AESCTRDRBG_COUNT] = {
    /* CONFIG_AESCTRDRBG_0 */
    {
        .object = &aesctrdrbgXXObjects[CONFIG_AESCTRDRBG_0],
        .hwAttrs = &aesctrdrbgXXHWAttrs[CONFIG_AESCTRDRBG_0]
    },
};

const uint_least8_t CONFIG_AESCTRDRBG_0_CONST = CONFIG_AESCTRDRBG_0;
const uint_least8_t AESCTRDRBG_count = CONFIG_AESCTRDRBG_COUNT;

/*
 *  =============================== AESECB ===============================
 */

#include <ti/drivers/AESECB.h>
#include <ti/drivers/aesecb/AESECBLPF3.h>

#define CONFIG_AESECB_COUNT 1
AESECBLPF3_Object AESECBLPF3_objects[CONFIG_AESECB_COUNT];

/*
 *  ======== AESECBLPF3_hwAttrs ========
 */
const AESECBLPF3_HWAttrs AESECBLPF3_hwAttrs[CONFIG_AESECB_COUNT] = {
    {
        .intPriority = (~0),
    },
};

const AESECB_Config AESECB_config[CONFIG_AESECB_COUNT] = {
    {   /* CONFIG_AESECB0 */
        .object  = &AESECBLPF3_objects[CONFIG_AESECB0],
        .hwAttrs = &AESECBLPF3_hwAttrs[CONFIG_AESECB0]
    },
};


const uint_least8_t CONFIG_AESECB0_CONST = CONFIG_AESECB0;
const uint_least8_t AESECB_count = CONFIG_AESECB_COUNT;

/*
 *  =============================== AESGCM ===============================
 */

#include <ti/drivers/AESGCM.h>
#include <ti/drivers/aesgcm/AESGCMLPF3HSM.h>

#define CONFIG_AESGCM_COUNT 1

AESGCMLPF3HSM_Object AESGCMLPF3HSM_objects[CONFIG_AESGCM_COUNT];

/*
 *  ======== AESGCMLPF3HSM_hwAttrs ========
 */
const AESGCMLPF3HSM_HWAttrs AESGCMLPF3HSM_hwAttrs[CONFIG_AESGCM_COUNT] = {
    {
        .intPriority = (~0),
    },
};

const AESGCM_Config AESGCM_config[CONFIG_AESGCM_COUNT] = {
    {   /* CONFIG_AESGCM_0 */
        .object  = &AESGCMLPF3HSM_objects[CONFIG_AESGCM_0],
        .hwAttrs = &AESGCMLPF3HSM_hwAttrs[CONFIG_AESGCM_0]
    },
};

const uint_least8_t CONFIG_AESGCM_0_CONST = CONFIG_AESGCM_0;
const uint_least8_t AESGCM_count = CONFIG_AESGCM_COUNT;


/*
 *  =============================== Key Store ===============================
 */
#include <third_party/hsmddk/include/Integration/Adapter_PSA/incl/adapter_psa_key_management.h>

uint8_t volatileAllocBuffer[KEYSTORE_VOLATILE_MEMORY_POOL_SIZE];
const size_t volatileAllocBufferSizeBytes  = KEYSTORE_VOLATILE_MEMORY_POOL_SIZE;

const size_t MBEDTLS_KEY_VOLATILE_COUNT    = KEYSTORE_VOLATILE_SLOT_COUNT;
const size_t MBEDTLS_KEY_ASSET_STORE_COUNT = KEYSTORE_ASSET_STORE_SLOT_COUNT;
/* For cache slots */
const size_t MBEDTLS_KEY_PERSISTENT_COUNT  = KEYSTORE_PERSISTENT_SLOT_COUNT;
/* For Key Store flash space */
const size_t FLASH_KEY_PERSISTENT_COUNT    = KEYSTORE_PERSISTENT_NUM_KEYS;
/* ITS flash area */
const size_t FLASH_ITS_SIZE                = KEYSTORE_FLASH_SIZE;

psa_key_context_t gl_PSA_Key[KEYSTORE_TOTAL_SLOT_COUNT];


/*
 *  =============================== DMA ===============================
 */

#include <ti/drivers/dma/UDMALPF3.h>
#include <ti/devices/cc27xx/inc/hw_memmap.h>

const UDMALPF3_Config UDMALPF3_config = {
        .CtrlBaseAddr = UDMALPF3_CONFIG_BASE,
};

/*
 *  =============================== ECDH ===============================
 */

#include <ti/drivers/ECDH.h>
#include <ti/drivers/ecdh/ECDHLPF3HSM.h>

#define CONFIG_ECDH_COUNT 2

ECDHLPF3HSM_Object ECDHLPF3HSM_objects[CONFIG_ECDH_COUNT];

/*
 *  ======== ECDHLPF3HSMHWAttrs ========
 */
const ECDHLPF3HSM_HWAttrs ECDHLPF3HSM_hwAttrs[CONFIG_ECDH_COUNT] = {
    {0},
    {0},
};

const ECDH_Config ECDH_config[CONFIG_ECDH_COUNT] = {
    {   /* CONFIG_ECDH0 */
        .object  = &ECDHLPF3HSM_objects[CONFIG_ECDH0],
        .hwAttrs = &ECDHLPF3HSM_hwAttrs[CONFIG_ECDH0]
    },
    {   /* CONFIG_ECDH1 */
        .object  = &ECDHLPF3HSM_objects[CONFIG_ECDH1],
        .hwAttrs = &ECDHLPF3HSM_hwAttrs[CONFIG_ECDH1]
    },
};

const uint_least8_t CONFIG_ECDH0_CONST = CONFIG_ECDH0;
const uint_least8_t CONFIG_ECDH1_CONST = CONFIG_ECDH1;
const uint_least8_t ECDH_count = CONFIG_ECDH_COUNT;
/*
 *  =============================== ECDSA ===============================
 */

#include <ti/drivers/ECDSA.h>
#include <ti/drivers/ecdsa/ECDSALPF3HSM.h>

#define CONFIG_ECDSA_COUNT 1
ECDSALPF3HSM_Object ecdsaLpf3HsmObjects[CONFIG_ECDSA_COUNT];

/*
 *  ======== ecdsaLpf3HsmHWAttrs ========
 */
const ECDSALPF3HSM_HWAttrs ecdsaLpf3HsmHWAttrs[CONFIG_ECDSA_COUNT] = {
    {0},
};

const ECDSA_Config ECDSA_config[CONFIG_ECDSA_COUNT] = {
    {   /* CONFIG_ECDSA_0 */
        .object         = &ecdsaLpf3HsmObjects[CONFIG_ECDSA_0],
        .hwAttrs        = &ecdsaLpf3HsmHWAttrs[CONFIG_ECDSA_0]
    },
};

const uint_least8_t CONFIG_ECDSA_0_CONST = CONFIG_ECDSA_0;
const uint_least8_t ECDSA_count = CONFIG_ECDSA_COUNT;

/*
 *  =============================== GPIO ===============================
 */

#include <ti/drivers/GPIO.h>

/* The range of pins available on this device */
const uint_least8_t GPIO_pinLowerBound = 0;
const uint_least8_t GPIO_pinUpperBound = 28;

/*
 *  ======== gpioPinConfigs ========
 *  Array of Pin configurations
 */
GPIO_PinConfig gpioPinConfigs[29] = {
    /* Owned by CONFIG_BUTTON_1 as Button GPIO */
    GPIO_CFG_INPUT_INTERNAL | GPIO_CFG_IN_INT_NONE | GPIO_CFG_PULL_UP_INTERNAL, /* CONFIG_GPIO_BUTTON_1_INPUT */
    /* Owned by CONFIG_UART2_0 as TX */
    GPIO_CFG_OUTPUT_INTERNAL | GPIO_CFG_OUT_STR_MED | GPIO_CFG_OUT_HIGH, /* CONFIG_GPIO_UART2_0_TX */
    /* Owned by CONFIG_UART2_0 as RX */
    GPIO_CFG_INPUT_INTERNAL | GPIO_CFG_IN_INT_NONE | GPIO_CFG_PULL_DOWN_INTERNAL, /* CONFIG_GPIO_UART2_0_RX */
    GPIO_CFG_NO_DIR, /* DIO_3 */
    GPIO_CFG_NO_DIR, /* DIO_4 */
    GPIO_CFG_NO_DIR, /* DIO_5 */
    GPIO_CFG_NO_DIR, /* DIO_6 */
    GPIO_CFG_NO_DIR, /* DIO_7 */
    GPIO_CFG_NO_DIR, /* DIO_8 */
    GPIO_CFG_DO_NOT_CONFIG, /* DIO_9 */
    GPIO_CFG_DO_NOT_CONFIG, /* DIO_10 */
    GPIO_CFG_NO_DIR, /* DIO_11 */
    GPIO_CFG_OUTPUT_INTERNAL | GPIO_CFG_OUT_STR_MED | GPIO_CFG_OUT_LOW, /* CONFIG_GPIO_LED_GREEN */
    GPIO_CFG_NO_DIR, /* DIO_13 */
    GPIO_CFG_NO_DIR, /* DIO_14 */
    GPIO_CFG_NO_DIR, /* DIO_15 */
    GPIO_CFG_OUTPUT_INTERNAL | GPIO_CFG_OUT_STR_MED | GPIO_CFG_OUT_LOW, /* CONFIG_GPIO_LED_RED */
    GPIO_CFG_NO_DIR, /* DIO_17 */
    GPIO_CFG_NO_DIR, /* DIO_18 */
    GPIO_CFG_NO_DIR, /* DIO_19 */
    /* Owned by CONFIG_BUTTON_0 as Button GPIO */
    GPIO_CFG_INPUT_INTERNAL | GPIO_CFG_IN_INT_NONE | GPIO_CFG_PULL_UP_INTERNAL, /* CONFIG_GPIO_BUTTON_0_INPUT */
    GPIO_CFG_NO_DIR, /* DIO_21 */
    GPIO_CFG_NO_DIR, /* DIO_22 */
    GPIO_CFG_NO_DIR, /* DIO_23 */
    GPIO_CFG_NO_DIR, /* DIO_24 */
    GPIO_CFG_NO_DIR, /* DIO_25 */
    GPIO_CFG_NO_DIR, /* DIO_26 */
    GPIO_CFG_NO_DIR, /* DIO_27 */
    GPIO_CFG_NO_DIR, /* DIO_28 */
};

/*
 *  ======== gpioCallbackFunctions ========
 *  Array of callback function pointers
 *  Change at runtime with GPIO_setCallback()
 */
GPIO_CallbackFxn gpioCallbackFunctions[29];

/*
 *  ======== gpioUserArgs ========
 *  Array of user argument pointers
 *  Change at runtime with GPIO_setUserArg()
 *  Get values with GPIO_getUserArg()
 */
void* gpioUserArgs[29];

const uint_least8_t CONFIG_GPIO_LED_GREEN_CONST = CONFIG_GPIO_LED_GREEN;
const uint_least8_t CONFIG_GPIO_LED_RED_CONST = CONFIG_GPIO_LED_RED;
const uint_least8_t CONFIG_GPIO_UART2_0_TX_CONST = CONFIG_GPIO_UART2_0_TX;
const uint_least8_t CONFIG_GPIO_UART2_0_RX_CONST = CONFIG_GPIO_UART2_0_RX;
const uint_least8_t CONFIG_GPIO_BUTTON_0_INPUT_CONST = CONFIG_GPIO_BUTTON_0_INPUT;
const uint_least8_t CONFIG_GPIO_BUTTON_1_INPUT_CONST = CONFIG_GPIO_BUTTON_1_INPUT;

/*
 *  ======== GPIO_config ========
 */
const GPIO_Config GPIO_config = {
    .configs = (GPIO_PinConfig *)gpioPinConfigs,
    .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions,
    .userArgs = gpioUserArgs,
    .intPriority = (~0)
};

/*
 *  =============================== NVS ===============================
 */

#include <ti/drivers/NVS.h>
#include <ti/drivers/nvs/NVSLPF3.h>

/*
 *  NVSLPF3 Internal NVS flash region definitions
 *
 * Place uninitialized char arrays at addresses
 * corresponding to the 'regionBase' addresses defined in
 * the configured NVS regions. These arrays are used as
 * place holders so that the linker will not place other
 * content there.
 *
 * For GCC targets, the char arrays are each placed into
 * the shared ".nvs" section. The user must add content to
 * their GCC linker command file to place the .nvs section
 * at the lowest 'regionBase' address specified in their NVS
 * regions.
 */

#if defined(__TI_COMPILER_VERSION__) || defined(__clang__)

static char flashBuf0[0x4000] __attribute__ ((retain, noinit, location(0xe4000)));

#elif defined(__IAR_SYSTEMS_ICC__)

__no_init static char flashBuf0[0x4000] @ 0xe4000;

#elif defined(__GNUC__)

__attribute__ ((section (".nvs")))
static char flashBuf0[0x4000];

#endif

NVSLPF3_Object NVSLPF3_objects[1];

static const NVSLPF3_HWAttrs NVSLPF3_hwAttrs[1] = {
    /* CONFIG_NVSINTERNAL */
    {
        .regionBase = (void *) flashBuf0,
        .regionSize = 0x4000
    },
};

#define CONFIG_NVS_COUNT 1

const NVS_Config NVS_config[CONFIG_NVS_COUNT] = {
    /* CONFIG_NVSINTERNAL */
    {
        .fxnTablePtr = &NVSLPF3_fxnTable,
        .object = &NVSLPF3_objects[0],
        .hwAttrs = &NVSLPF3_hwAttrs[0],
    },
};

const uint_least8_t CONFIG_NVSINTERNAL_CONST = CONFIG_NVSINTERNAL;
const uint_least8_t NVS_count = CONFIG_NVS_COUNT;

/*
 *  =============================== Power ===============================
 */
#include <ti/drivers/Power.h>
#include "ti_drivers_config.h"
#include DeviceFamily_constructPath(driverlib/ckmd.h)
#include DeviceFamily_constructPath(driverlib/pmctl.h)

extern void PowerCC27XX_standbyPolicy(void);


const PowerCC27XX_Config PowerCC27XX_config = {
    .policyInitFxn              = NULL,
    .policyFxn                  = PowerCC27XX_standbyPolicy,
    .startInitialHfxtAmpCompFxn = NULL,
};



/*
 *  =============================== RNG ===============================
 */

#include <ti/drivers/RNG.h>
#include <ti/drivers/rng/RNGLPF3HSM.h>

#define CONFIG_RNG_COUNT 1

#if defined(__IAR_SYSTEMS_ICC__)
#pragma data_alignment=32
#else
__attribute__ ((aligned (32)))
#endif

const RNG_ReturnBehavior RNGLPF3HSM_returnBehavior = RNG_RETURN_BEHAVIOR_BLOCKING;

RNGLPF3HSM_Object RNGLPF3HSM_objects[CONFIG_RNG_COUNT];

const RNGLPF3HSM_HWAttrs RNGLPF3HSM_hwAttrs = {
    .intPriority = 0x0
};

const RNG_Config RNG_config[CONFIG_RNG_COUNT] = {
    {   /* CONFIG_RNG_0 */
        .object         = &RNGLPF3HSM_objects[CONFIG_RNG_0],
        .hwAttrs        = NULL
    },
};

const uint_least8_t CONFIG_RNG_0_CONST = CONFIG_RNG_0;
const uint_least8_t RNG_count = CONFIG_RNG_COUNT;

/*
 *  =============================== SHA2 ===============================
 */

#include <ti/drivers/SHA2.h>
#include <ti/drivers/sha2/SHA2LPF3HSM.h>

#define CONFIG_SHA2_COUNT 1

SHA2LPF3HSM_Object SHA2LPF3HSM_objects[CONFIG_SHA2_COUNT];

/*
 *  ======== SHA2LPF3HSMHWAttrs ========
 */
const SHA2LPF3HSM_HWAttrs SHA2LPF3HSM_hwAttrs[CONFIG_SHA2_COUNT] = {
    {0},
};

const SHA2_Config SHA2_config[CONFIG_SHA2_COUNT] = {
    {   /* CONFIG_SHA2_0 */
        .object         = &SHA2LPF3HSM_objects[CONFIG_SHA2_0],
        .hwAttrs        = &SHA2LPF3HSM_hwAttrs[CONFIG_SHA2_0]
    },
};

const uint_least8_t CONFIG_SHA2_0_CONST = CONFIG_SHA2_0;
const uint_least8_t SHA2_count = CONFIG_SHA2_COUNT;
/*
 *  =============================== UART2 ===============================
 */

#include <ti/drivers/UART2.h>
#include <ti/drivers/uart2/UART2LPF3.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/dma/UDMALPF3.h>
#include <ti/drivers/Power.h>
#include <ti/devices/cc27xx/inc/hw_memmap.h>
#include <ti/devices/cc27xx/inc/hw_ints.h>
#include <ti/devices/cc27xx/inc/hw_evtsvt.h>

#define CONFIG_UART2_COUNT 1

UART2LPF3_Object UART2LPF3_objects[CONFIG_UART2_COUNT];

static unsigned char uart2RxRingBuffer0[32];
/* TX ring buffer allocated to be used for nonblocking mode */
static unsigned char uart2TxRingBuffer0[32];



ALLOCATE_CONTROL_TABLE_ENTRY(dmaChannel3ControlTableEntry, 3);
ALLOCATE_CONTROL_TABLE_ENTRY(dmaChannel2ControlTableEntry, 2);

static const UART2LPF3_HWAttrs UART2LPF3_hwAttrs[CONFIG_UART2_COUNT] = {
  {
    .baseAddr           = UART0_BASE,
    .intNum             = INT_UART0_COMB,
    .intPriority        = (~0),
    .rxPin              = CONFIG_GPIO_UART2_0_RX,
    .txPin              = CONFIG_GPIO_UART2_0_TX,
    .ctsPin             = GPIO_INVALID_INDEX,
    .rtsPin             = GPIO_INVALID_INDEX,
    .flowControl        = UART2_FLOWCTRL_NONE,
    .rxBufPtr           = uart2RxRingBuffer0,
    .rxBufSize          = sizeof(uart2RxRingBuffer0),
    .txBufPtr           = uart2TxRingBuffer0,
    .txBufSize          = sizeof(uart2TxRingBuffer0),
    .txPinMux           = GPIO_MUX_PORTCFG_PFUNC4,
    .rxPinMux           = GPIO_MUX_PORTCFG_PFUNC4,
    .ctsPinMux          = GPIO_MUX_GPIO_INTERNAL,
    .rtsPinMux          = GPIO_MUX_GPIO_INTERNAL,
    .dmaRxTableEntryPri = &dmaChannel3ControlTableEntry,
    .dmaTxTableEntryPri = &dmaChannel2ControlTableEntry,
    .rxChannelMask      = UDMA_CHANNEL_3_M,
    .txChannelMask      = UDMA_CHANNEL_2_M,
    .rxChannelEvtMux    = EVTSVT_DMACH3SEL_IPID_UART0RXTRG,
    .txChannelEvtMux    = EVTSVT_DMACH2SEL_IPID_UART0TXTRG,
    .codingScheme       = UART2LPF3_CODING_UART,
    .concatenateFIFO    = false,
    .irLPClkDivider     = 8,
    .powerID            = PowerLPF3_PERIPH_UART0
  },
};

const UART2_Config UART2_config[CONFIG_UART2_COUNT] = {
    {   /* CONFIG_UART2_0 */
        .object      = &UART2LPF3_objects[CONFIG_UART2_0],
        .hwAttrs     = &UART2LPF3_hwAttrs[CONFIG_UART2_0]
    },
};

const uint_least8_t CONFIG_UART2_0_CONST = CONFIG_UART2_0;
const uint_least8_t UART2_count = CONFIG_UART2_COUNT;


/*
 *  =============================== Button ===============================
 */
#include <ti/drivers/apps/Button.h>

#define CONFIG_BUTTON_COUNT 2
Button_Object ButtonObjects[CONFIG_BUTTON_COUNT];

static const Button_HWAttrs ButtonHWAttrs[CONFIG_BUTTON_COUNT] = {
    /* CONFIG_BUTTON_0 */
    /* LaunchPad Button BTN-1 (Left) */
    {
        .gpioIndex = CONFIG_GPIO_BUTTON_0_INPUT,
        .pullMode = Button_PULL_UP,
        .internalPullEnabled = 1,
    },
    /* CONFIG_BUTTON_1 */
    /* LaunchPad Button BTN-2 (Right) */
    {
        .gpioIndex = CONFIG_GPIO_BUTTON_1_INPUT,
        .pullMode = Button_PULL_UP,
        .internalPullEnabled = 1,
    },
};

const Button_Config Button_config[CONFIG_BUTTON_COUNT] = {
    /* CONFIG_BUTTON_0 */
    /* LaunchPad Button BTN-1 (Left) */
    {
        .object = &ButtonObjects[CONFIG_BUTTON_0],
        .hwAttrs = &ButtonHWAttrs[CONFIG_BUTTON_0]
    },
    /* CONFIG_BUTTON_1 */
    /* LaunchPad Button BTN-2 (Right) */
    {
        .object = &ButtonObjects[CONFIG_BUTTON_1],
        .hwAttrs = &ButtonHWAttrs[CONFIG_BUTTON_1]
    },
};

const uint_least8_t CONFIG_BUTTON_0_CONST = CONFIG_BUTTON_0;
const uint_least8_t CONFIG_BUTTON_1_CONST = CONFIG_BUTTON_1;
const uint_least8_t Button_count = CONFIG_BUTTON_COUNT;

/*
 *  =============================== BatMon Support ===============================
 */
#include <ti/drivers/batterymonitor/BatMonSupportLPF3.h>

#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(inc/hw_evtsvt.h)
#include DeviceFamily_constructPath(inc/hw_ints.h)

const BatMonSupportLPF3_Config BatMonSupportLPF3_config = {
    .intNum = INT_CPUIRQ2,
    .intPriority = (~0),
    .intMux = EVTSVT_CPUIRQ2SEL_PUBID_AON_PMU_COMB
};

#include <stdbool.h>

#include <ti/devices/cc27xx/driverlib/cpu.h>
#include <ti/devices/cc27xx/driverlib/hapi.h>

#include <ti/drivers/GPIO.h>

/* Board GPIO defines */
#define BOARD_EXT_FLASH_SPI_CS      19
#define BOARD_EXT_FLASH_SPI_CLK     3
#define BOARD_EXT_FLASH_SPI_PICO    5
#define BOARD_EXT_FLASH_SPI_POCI    4
/*
 *  ======== Board_sendExtFlashByte ========
 */
void Board_sendExtFlashByte(uint8_t byte)
{
    uint8_t i;

    /* SPI Flash CS */
    GPIO_write(BOARD_EXT_FLASH_SPI_CS, 0);

    for (i = 0; i < 8; i++) {
        GPIO_write(BOARD_EXT_FLASH_SPI_CLK, 0); /* SPI Flash CLK */

        /* SPI Flash PICO */
        GPIO_write(BOARD_EXT_FLASH_SPI_PICO, (byte >> (7 - i)) & 0x01);
        GPIO_write(BOARD_EXT_FLASH_SPI_CLK, 1);  /* SPI Flash CLK */

        /* Waste a few cycles to keep the CLK high for at
         * least 45% of the period.
         * 3 cycles per loop: 16 loops @ 96 MHz = 0.5 us.
         */
        CPUDelay(16);
    }

    GPIO_write(BOARD_EXT_FLASH_SPI_CLK, 0);  /* CLK */
    GPIO_write(BOARD_EXT_FLASH_SPI_CS, 1);  /* CS */

    /* Keep CS high at least 40 us */
    HapiWaitUs(40);
}

/*
 *  ======== Board_wakeUpExtFlash ========
 */
void Board_wakeUpExtFlash(void)
{
    /* SPI Flash CS*/
    GPIO_setConfig(BOARD_EXT_FLASH_SPI_CS, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_HIGH | GPIO_CFG_OUT_STR_MED);

    /* To wake up we need to toggle the chip select at
     * least 20 ns and then wait at least 35 us.
     */

    /* Toggle chip select for ~20ns to wake ext. flash */
    GPIO_write(BOARD_EXT_FLASH_SPI_CS, 0);
    /* 3 cycles per loop: 2 loop @ 96 MHz ~= 62 ns */
    CPUDelay(2);
    GPIO_write(BOARD_EXT_FLASH_SPI_CS, 1);
    /* Wait for 35 us */
    HapiWaitUs(35);
}

/*
 *  ======== Board_shutDownExtFlash ========
 */
void Board_shutDownExtFlash(void)
{
    /* To be sure we are putting the flash into sleep and not waking it,
     * we first have to make a wake up call
     */
    Board_wakeUpExtFlash();

    /* SPI Flash CS*/
    GPIO_setConfig(BOARD_EXT_FLASH_SPI_CS, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_HIGH | GPIO_CFG_OUT_STR_MED);
    /* SPI Flash CLK */
    GPIO_setConfig(BOARD_EXT_FLASH_SPI_CLK, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_LOW | GPIO_CFG_OUT_STR_MED);
    /* SPI Flash PICO */
    GPIO_setConfig(BOARD_EXT_FLASH_SPI_PICO, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_LOW | GPIO_CFG_OUT_STR_MED);
    /* SPI Flash POCI */
    GPIO_setConfig(BOARD_EXT_FLASH_SPI_POCI, GPIO_CFG_IN_PD);

    uint8_t extFlashShutdown = 0xB9;

    Board_sendExtFlashByte(extFlashShutdown);

    GPIO_resetConfig(BOARD_EXT_FLASH_SPI_CS);
    GPIO_resetConfig(BOARD_EXT_FLASH_SPI_CLK);
    GPIO_resetConfig(BOARD_EXT_FLASH_SPI_PICO);
    GPIO_resetConfig(BOARD_EXT_FLASH_SPI_POCI);
}


#include <ti/drivers/Board.h>

/*
 *  ======== Board_initHook ========
 *  Perform any board-specific initialization needed at startup.  This
 *  function is declared weak to allow applications to override it if needed.
 */
void __attribute__((weak)) Board_initHook(void)
{
}

/*
 *  ======== Board_init ========
 *  Perform any initialization needed before using any board APIs
 */
void Board_init(void)
{
    /* ==== /ti/drivers/Power initialization ==== */

    /* Set non-default cap array trims */
    CKMDSetInitialCapTrim(33, 33);
    CKMDSetTargetCapTrim(33, 33);

    Power_init();


    PowerLPF3_selectLFXT();
    PMCTLSetVoltageRegulator(PMCTL_VOLTAGE_REGULATOR_DCDC);


    PowerLPF3_initHFXTCompensation(61075777, /* floor(14.5616 * 2^22) */
                                   -1831946, /* floor(-0.43677 * 2^22) */
                                   -35777, /* floor(-0.00853 * 2^22) */
                                   419, /* floor(0.0001 * 2^22) */
                                   22,
                                   false);               /* FCFG trim-values available */

    /* HFXT temperature compensation will be performed as long as the measured temperature exceeds -50
     * degrees Celsius, and drifts 2 degrees or more.
     */
    PowerLPF3_enableHFXTCompensation(-50, 2);

    /* ==== /ti/drivers/GPIO initialization ==== */
    /* Setup GPIO module and default-initialise pins */
    GPIO_init();

    /* ==== /ti/drivers/DMA initialization ==== */
    UDMALPF3_init();

    /* ==== /ti/drivers/RCL initialization ==== */

    RNG_init();

    Board_shutDownExtFlash();

    Board_initHook();
}

/*
 *  ======== ti_drivers_config.h ========
 *  Configured TI-Drivers module declarations
 *
 *  The macros defines herein are intended for use by applications which
 *  directly include this header. These macros should NOT be hard coded or
 *  copied into library source code.
 *
 *  Symbols declared as const are intended for use with libraries.
 *  Library source code must extern the correct symbol--which is resolved
 *  when the application is linked.
 *
 *  DO NOT EDIT - This file is generated for the LP_EM_CC2745R10_Q1
 *  by the SysConfig tool.
 */
#ifndef ti_drivers_config_h
#define ti_drivers_config_h

#define CONFIG_SYSCONFIG_PREVIEW

#define CONFIG_LP_EM_CC2745R10_Q1
#ifndef DeviceFamily_CC27XX
#define DeviceFamily_CC27XX
#endif

#include <ti/devices/DeviceFamily.h>

#include <stdint.h>

/* support C++ sources */
#ifdef __cplusplus
extern "C" {
#endif


/*
 *  ======== AESCBC ========
 */

extern const uint_least8_t                  CONFIG_AESCBC_0_CONST;
#define CONFIG_AESCBC_0                     0
#define CONFIG_TI_DRIVERS_AESCBC_COUNT      1


/*
 *  ======== AESCCM ========
 */

extern const uint_least8_t                  CONFIG_AESCCM0_CONST;
#define CONFIG_AESCCM0                      0
#define CONFIG_TI_DRIVERS_AESCCM_COUNT      1


/*
 *  ======== AESCTRDRBG ========
 */

extern const uint_least8_t                      CONFIG_AESCTRDRBG_0_CONST;
#define CONFIG_AESCTRDRBG_0                     0
#define CONFIG_TI_DRIVERS_AESCTRDRBG_COUNT      1


/*
 *  ======== AESECB ========
 */

extern const uint_least8_t                  CONFIG_AESECB0_CONST;
#define CONFIG_AESECB0                      0
#define CONFIG_TI_DRIVERS_AESECB_COUNT      1


/*
 *  ======== AESGCM ========
 */

extern const uint_least8_t                  CONFIG_AESGCM_0_CONST;
#define CONFIG_AESGCM_0                     0
#define CONFIG_TI_DRIVERS_AESGCM_COUNT      1



/*
 *  ======== Key Store ========
 */

#define KEYSTORE_VOLATILE_MEMORY_POOL_SIZE 824

#define KEYSTORE_VOLATILE_SLOT_COUNT       2
#define KEYSTORE_ASSET_STORE_SLOT_COUNT    3
#define KEYSTORE_PERSISTENT_SLOT_COUNT     3
#define KEYSTORE_TOTAL_SLOT_COUNT          8

#define KEYSTORE_PERSISTENT_NUM_KEYS       23
#define KEYSTORE_FLASH_SIZE                8192


/*
 *  ======== ECDH ========
 */

extern const uint_least8_t              CONFIG_ECDH0_CONST;
#define CONFIG_ECDH0                    0
extern const uint_least8_t              CONFIG_ECDH1_CONST;
#define CONFIG_ECDH1                    1
#define CONFIG_TI_DRIVERS_ECDH_COUNT    2


/*
 *  ======== ECDSA ========
 */

extern const uint_least8_t                  CONFIG_ECDSA_0_CONST;
#define CONFIG_ECDSA_0                      0
#define CONFIG_TI_DRIVERS_ECDSA_COUNT       1


/*
 *  ======== GPIO ========
 */
extern const uint_least8_t CONFIG_GPIO_LED_GREEN_CONST;
#define CONFIG_GPIO_LED_GREEN 12

extern const uint_least8_t CONFIG_GPIO_LED_RED_CONST;
#define CONFIG_GPIO_LED_RED 16

/* Owned by CONFIG_UART2_0 as  */
extern const uint_least8_t CONFIG_GPIO_UART2_0_TX_CONST;
#define CONFIG_GPIO_UART2_0_TX 1

/* Owned by CONFIG_UART2_0 as  */
extern const uint_least8_t CONFIG_GPIO_UART2_0_RX_CONST;
#define CONFIG_GPIO_UART2_0_RX 2

/* Owned by CONFIG_BUTTON_0 as  */
extern const uint_least8_t CONFIG_GPIO_BUTTON_0_INPUT_CONST;
#define CONFIG_GPIO_BUTTON_0_INPUT 20

/* Owned by CONFIG_BUTTON_1 as  */
extern const uint_least8_t CONFIG_GPIO_BUTTON_1_INPUT_CONST;
#define CONFIG_GPIO_BUTTON_1_INPUT 0

/* The range of pins available on this device */
extern const uint_least8_t GPIO_pinLowerBound;
extern const uint_least8_t GPIO_pinUpperBound;

/* LEDs are active high */
#define CONFIG_GPIO_LED_ON  (1)
#define CONFIG_GPIO_LED_OFF (0)

#define CONFIG_LED_ON  (CONFIG_GPIO_LED_ON)
#define CONFIG_LED_OFF (CONFIG_GPIO_LED_OFF)


/*
 *  ======== NVS ========
 */

extern const uint_least8_t              CONFIG_NVSINTERNAL_CONST;
#define CONFIG_NVSINTERNAL              0
#define CONFIG_TI_DRIVERS_NVS_COUNT     1





/*
 *  ======== RNG ========
 */

extern const uint_least8_t              CONFIG_RNG_0_CONST;
#define CONFIG_RNG_0                    0
#define CONFIG_TI_DRIVERS_RNG_COUNT     1

#define RNG_POOL_BYTE_SIZE 



/*
 *  ======== SHA2 ========
 */

extern const uint_least8_t              CONFIG_SHA2_0_CONST;
#define CONFIG_SHA2_0                   0
#define CONFIG_TI_DRIVERS_SHA2_COUNT    1


/*
 *  ======== UART2 ========
 */

/*
 *  TX: DIO1
 *  RX: DIO2
 *  XDS110 UART
 */
extern const uint_least8_t                  CONFIG_UART2_0_CONST;
#define CONFIG_UART2_0                      0
#define CONFIG_TI_DRIVERS_UART2_COUNT       1


/*
 *  ======== Button ========
 */

extern const uint_least8_t                  CONFIG_BUTTON_0_CONST;
#define CONFIG_BUTTON_0                     0
extern const uint_least8_t                  CONFIG_BUTTON_1_CONST;
#define CONFIG_BUTTON_1                     1
#define CONFIG_TI_DRIVERS_BUTTON_COUNT      2


/*
 *  ======== Board_init ========
 *  Perform all required TI-Drivers initialization
 *
 *  This function should be called once at a point before any use of
 *  TI-Drivers.
 */
extern void Board_init(void);

/*
 *  ======== Board_initGeneral ========
 *  (deprecated)
 *
 *  Board_initGeneral() is defined purely for backward compatibility.
 *
 *  All new code should use Board_init() to do any required TI-Drivers
 *  initialization _and_ use <Driver>_init() for only where specific drivers
 *  are explicitly referenced by the application.  <Driver>_init() functions
 *  are idempotent.
 */
#define Board_initGeneral Board_init

#ifdef __cplusplus
}
#endif

#endif /* include guard */

Hope to get your help.

Thanks.

  • Hello Ethan, 

    I apologize for the delay, but I will send a response tomorrow (03/24). 

    Thank you for your patience. 

    Thanks, 
    Isaac

  • Hello Ethan, 

    I was able to debug more today. I did not find anything definitive with your setup, but I am fairly certain the issue with your code lies with the location when creating the attributes. 

    When you define the section below: 

            psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
                                                PSA_KEY_PERSISTENCE_DEFAULT,
                                                PSA_KEY_LOCATION_HSM_ASSET_STORE));

    The basic_ble example project does not identify PSA_KEY_LOCATION_HSM_ASSET_STORE. I don't think this should be the case, and I am going to talk with R&D about it. I believe if you change this to the key store location it should work, but I have not had time to test this. 

    Thanks, 

    Isaac