Skip to content

Commit 00e3064

Browse files
author
Cruz Monrreal
authored
Merge pull request #8437 from NXPmicro/Fix_TRNG_HAL
MCUXpresso: Fix for the TRNG HAL driver
2 parents 996a31f + f29a597 commit 00e3064

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/trng_api.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* Reference: "K66 Sub-Family Reference Manual, Rev. 2", chapter 38
2323
*/
2424

25+
#if defined(DEVICE_TRNG)
26+
2527
#include <stdlib.h>
2628
#include "cmsis.h"
2729
#include "fsl_common.h"
@@ -48,21 +50,21 @@ void trng_free(trng_t *obj)
4850
*/
4951
static void trng_get_byte(unsigned char *byte)
5052
{
53+
*byte = 0;
5154
size_t bit;
5255

5356
/* 34.5 Steps 3-4-5: poll SR and read from OR when ready */
5457
for( bit = 0; bit < 8; bit++ )
5558
{
56-
while( ( RNG->SR & RNG_SR_OREG_LVL_MASK ) == 0 );
57-
*byte |= ( RNG->OR & 1 ) << bit;
59+
while((RNG->SR & RNG_SR_OREG_LVL_MASK) == 0 );
60+
*byte |= (RNG->OR & 1) << bit;
5861
}
5962
}
6063

6164
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
6265
{
6366
(void)obj;
6467
size_t i;
65-
int ret;
6668

6769
/* Set "Interrupt Mask", "High Assurance" and "Go",
6870
* unset "Clear interrupt" and "Sleep" */
@@ -81,3 +83,5 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
8183

8284
return 0;
8385
}
86+
87+
#endif

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/trng_api.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
*
1919
*/
2020

21-
/*
22-
* Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34
23-
*/
24-
2521
#if defined(DEVICE_TRNG)
2622

2723
#include <stdlib.h>
@@ -46,10 +42,11 @@ void trng_free(trng_t *obj)
4642

4743
/*
4844
* Get one byte of entropy from the RNG, assuming it is up and running.
49-
* As recommended (34.1.1), get only one bit of each output.
45+
* As recommended, get only one bit of each output.
5046
*/
5147
static void trng_get_byte(unsigned char *byte)
5248
{
49+
*byte = 0;
5350
size_t bit;
5451

5552
/* 34.5 Steps 3-4-5: poll SR and read from OR when ready */
@@ -64,7 +61,6 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
6461
{
6562
(void)obj;
6663
size_t i;
67-
int ret;
6864

6965
/* Set "Interrupt Mask", "High Assurance" and "Go",
7066
* unset "Clear interrupt" and "Sleep" */

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/trng_api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void trng_free(trng_t *obj)
4646
*/
4747
static void trng_get_byte(unsigned char *byte)
4848
{
49+
*byte = 0;
4950
size_t bit;
5051

5152
/* 34.5 Steps 3-4-5: poll SR and read from OR when ready */

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/trng_api.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
*
1919
*/
2020

21-
/*
22-
* Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34
23-
*/
24-
2521
#if defined(DEVICE_TRNG)
2622

2723
#include <stdlib.h>
@@ -46,10 +42,11 @@ void trng_free(trng_t *obj)
4642

4743
/*
4844
* Get one byte of entropy from the RNG, assuming it is up and running.
49-
* As recommended (34.1.1), get only one bit of each output.
45+
* As recommended, get only one bit of each output.
5046
*/
5147
static void trng_get_byte(unsigned char *byte)
5248
{
49+
*byte = 0;
5350
size_t bit;
5451

5552
/* 34.5 Steps 3-4-5: poll SR and read from OR when ready */

0 commit comments

Comments
 (0)