Skip to content

Commit 3661845

Browse files
authored
Merge pull request #4050 from NXPmicro/Add_KW41_TRNG
Add TRNG support for KW41Z
2 parents 5632ef1 + dfafaa8 commit 3661845

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Hardware entropy collector for the K64F, using Freescale's RNGA
3+
*
4+
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
/*
22+
* Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34
23+
*/
24+
25+
#if defined(DEVICE_TRNG)
26+
27+
#include "fsl_trng.h"
28+
#include "trng_api.h"
29+
30+
void trng_init(trng_t *obj)
31+
{
32+
trng_config_t trngConfig;
33+
34+
TRNG_GetDefaultConfig(&trngConfig);
35+
/* Set sample mode of the TRNG ring oscillator to Von Neumann, for better random data.*/
36+
trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;
37+
/* Initialize TRNG */
38+
TRNG_Init(TRNG0, &trngConfig);
39+
}
40+
41+
void trng_free(trng_t *obj)
42+
{
43+
TRNG_Deinit(TRNG0);
44+
}
45+
46+
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
47+
{
48+
status_t result;
49+
50+
result = TRNG_GetRandomData(TRNG0, output, length);
51+
52+
if (result == kStatus_Success) {
53+
*output_length = length;
54+
return 0;
55+
} else {
56+
return -1;
57+
}
58+
}
59+
60+
#endif

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@
567567
"macros": ["CPU_MKW41Z512VHT4", "FSL_RTOS_MBED"],
568568
"inherits": ["Target"],
569569
"detect_code": ["0201"],
570-
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
570+
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "TRNG", "STDIO_MESSAGES"],
571571
"release_versions": ["2", "5"],
572572
"device_name": "MKW41Z512xxx4"
573573
},

0 commit comments

Comments
 (0)