Other Parts Discussed in Thread: SYSCONFIG
Tool/software:
Hi,
While developing a project using the CC2745 LaunchPad and the simple_ble example, I created a function using TRNG.h to obtain random bytes of the desired length (lub_size input parameter) into the laub_Rnd array. The implemented code is as follows (I added TRNG manually in sysconfig, Name: CONFIG_TRNG_0, and didn't change any value of TRNG syscfg).
#define RANDOM_BYTE_SIZE 4
// Added TRNG_init() immediately after Board_init() inside the main() function in main_freertos.c.
uint8 BLE_F_IF_Get_RandomByte(uint8* laub_Rnd, uint8 lub_size)
{
TRNG_Handle handle;
TRNG_Params params;
int_fast16_t result;
uint8 randomBytesArray[RANDOM_BYTE_SIZE] = {0};
uint8 lub_byte_cnt = 0;
uint8 lub_size_cnt = lub_size;
uint8 lub_copy_len;
TRNG_Params_init(¶ms);
handle = TRNG_open(CONFIG_TRNG_0, ¶ms);
if (!handle) {
// Handle error
return BLE_D_FALSE;
}
while(lub_size_cnt > 0)
{
result = TRNG_getRandomBytes(handle, randomBytesArray, RANDOM_BYTE_SIZE);
if (result != TRNG_STATUS_SUCCESS) {
// Handle error
TRNG_close(handle);
return BLE_D_FALSE;
}
lub_copy_len = (lub_size_cnt >= RANDOM_BYTE_SIZE) ? RANDOM_BYTE_SIZE : lub_size_cnt;
memcpy(&laub_Rnd[lub_byte_cnt], randomBytesArray, lub_copy_len);
lub_byte_cnt += lub_copy_len;
lub_size_cnt -= lub_copy_len;
}
TRNG_close(handle);
return BLE_D_TRUE;
}
#define RANDOM_BYTE_SIZE 4
// Added TRNG_init() immediately after Board_init() inside the main() function in main_freertos.c.
uint8 BLE_F_IF_Get_RandomByte(uint8* laub_Rnd, uint8 lub_size)
{
TRNG_Handle handle;
// TRNG_Params params;
int_fast16_t result;
uint8 randomBytesArray[RANDOM_BYTE_SIZE] = {0};
uint8 lub_byte_cnt = 0;
uint8 lub_size_cnt = lub_size;
uint8 lub_copy_len;
// TRNG_Params_init(¶ms);
// handle = TRNG_open(CONFIG_TRNG_0, ¶ms);
handle = TRNG_open(0, NULL);
if (!handle) {
// Handle error
return BLE_D_FALSE;
}
while(lub_size_cnt > 0)
{
result = TRNG_getRandomBytes(handle, randomBytesArray, RANDOM_BYTE_SIZE);
if (result != TRNG_STATUS_SUCCESS) {
// Handle error
TRNG_close(handle);
return BLE_D_FALSE;
}
lub_copy_len = (lub_size_cnt >= RANDOM_BYTE_SIZE) ? RANDOM_BYTE_SIZE : lub_size_cnt;
memcpy(&laub_Rnd[lub_byte_cnt], randomBytesArray, lub_copy_len);
lub_byte_cnt += lub_copy_len;
lub_size_cnt -= lub_copy_len;
}
TRNG_close(handle);
return BLE_D_TRUE;
}
When executing this code, after calling the TRNG_getRandomBytes function, the LaunchPad falls into Exception_handlerSpin(). Upon debugging, I found that it falls into an exception at SemaphoreP_pend() during the execution of the HSMLPF3_waitForResult function.
I am curious if I missed any additional settings or if there was an error in using the API.
Could anyone help resolve this issue or provide guidance on correctly using TRNG_getRandomBytes() in the simple_ble example?
(SDK version: 8.40.2.01, SysConfig: 1.22.0)
Thank you.