Skip to content

Commit 9f85be0

Browse files
committed
MIMXRT1050_EVK: Add TRNG support
Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent 9bf85ef commit 9f85be0

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Hardware entropy collector for the K66F, 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: "K66 Sub-Family Reference Manual, Rev. 2", chapter 38
23+
*/
24+
25+
#include <stdlib.h>
26+
#include "cmsis.h"
27+
#include "fsl_trng.h"
28+
#include "trng_api.h"
29+
30+
void trng_init(trng_t *obj)
31+
{
32+
(void)obj;
33+
trng_config_t trngConfig;
34+
TRNG_GetDefaultConfig(&trngConfig);
35+
TRNG_Init(TRNG, &trngConfig);
36+
}
37+
38+
void trng_free(trng_t *obj)
39+
{
40+
(void)obj;
41+
TRNG_Deinit(TRNG);
42+
}
43+
44+
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
45+
{
46+
(void)obj;
47+
48+
if(TRNG_GetRandomData(TRNG, output, length) != kStatus_Success) {
49+
return -1;
50+
}
51+
*output_length = length;
52+
53+
return 0;
54+
}

targets/targets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,8 @@
19551955
"SERIAL",
19561956
"SPI",
19571957
"SPISLAVE",
1958-
"STDIO_MESSAGES"
1958+
"STDIO_MESSAGES",
1959+
"TRNG"
19591960
],
19601961
"release_versions": ["2", "5"],
19611962
"features": ["LWIP"],

0 commit comments

Comments
 (0)