File tree Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 22#
33# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
44# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
5+ # SPDX-FileCopyrightText: Copyright (c) 2025 Peggy Zhu, Analog Devices, Inc.
56#
67# SPDX-License-Identifier: MIT
78
@@ -83,7 +84,8 @@ INC += \
8384 -I$(PERIPH_SRC ) /ICC \
8485 -I$(PERIPH_SRC ) /TMR \
8586 -I$(PERIPH_SRC ) /RTC \
86- -I$(PERIPH_SRC ) /UART
87+ -I$(PERIPH_SRC ) /UART \
88+ -I$(PERIPH_SRC ) /TRNG
8789
8890INC += -I$(CMSIS_ROOT ) /Device/Maxim/$(MCU_VARIANT_UPPER ) /Source/GCC
8991
@@ -116,7 +118,9 @@ SRC_MAX32 += \
116118 $(PERIPH_SRC ) /TMR/tmr_$(DIE_TYPE ) .c \
117119 $(PERIPH_SRC ) /UART/uart_common.c \
118120 $(PERIPH_SRC ) /UART/uart_$(DIE_TYPE ) .c \
119- $(PERIPH_SRC ) /UART/uart_revb.c
121+ $(PERIPH_SRC ) /UART/uart_revb.c \
122+ $(PERIPH_SRC ) /TRNG/trng_revb.c \
123+ $(PERIPH_SRC ) /TRNG/trng_$(DIE_TYPE ) .c
120124
121125SRC_C += $(SRC_MAX32 ) \
122126 boards/$(BOARD ) /board.c \
Original file line number Diff line number Diff line change 22//
33// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
44// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries
5+ // SPDX-FileCopyrightText: Copyright (c) 2025 Peggy Zhu, Analog Devices, Inc.
56//
67// SPDX-License-Identifier: MIT
78
1516
1617// #include "peripherals/periph.h"
1718
19+ // true random number generator, TRNG
20+ #include "trng.h"
21+
1822bool common_hal_os_urandom (uint8_t * buffer , uint32_t length ) {
1923 #if (HAS_TRNG )
20- // todo (low prior): implement
24+ // get a random number of "length" number of bytes
25+ MXC_TRNG_Random (buffer , length );
26+ return true;
2127 #else
2228 #endif
2329 return false;
Original file line number Diff line number Diff line change 22#
33# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
44# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
5+ # SPDX-FileCopyrightText: Copyright (c) 2025 Peggy Zhu, Analog Devices, Inc.
56#
67# SPDX-License-Identifier: MIT
78
@@ -51,7 +52,7 @@ CIRCUITPY_BITBANGIO ?= 1
5152# Requires Microcontroller
5253CIRCUITPY_TOUCHIO ?= 1
5354# Requires OS
54- CIRCUITPY_RANDOM ?= 0
55+ CIRCUITPY_RANDOM ?= 1
5556# Requires busio.UART
5657CIRCUITPY_CONSOLE_UART ?= 0
5758# Does nothing without I2C
Original file line number Diff line number Diff line change 4444#include "mxc_delay.h"
4545#include "rtc.h"
4646
47+ // true random number generator, TRNG
48+ #include "trng.h"
49+
4750// msec to RTC subsec ticks (4 kHz)
4851/* Converts a time in milleseconds to equivalent RSSA register value */
4952#define MSEC_TO_SS_ALARM (x ) (0 - ((x * 4096) / 1000))
@@ -112,9 +115,18 @@ safe_mode_t port_init(void) {
112115 }
113116 ;
114117
118+ // enable TRNG (true random number generator)
119+ #ifdef CIRCUITPY_RANDOM
120+ MXC_TRNG_Init ();
121+ #endif
122+
115123 return SAFE_MODE_NONE ;
116124}
117125
126+ void TRNG_IRQHandler (void ) {
127+ MXC_TRNG_Handler ();
128+ }
129+
118130void RTC_IRQHandler (void ) {
119131 // Read flags to clear
120132 int flags = MXC_RTC_GetFlags ();
You can’t perform that action at this time.
0 commit comments