Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ports/analog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
# SPDX-FileCopyrightText: Copyright (c) 2025 Peggy Zhu, Analog Devices, Inc.
#
# SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -83,7 +84,8 @@ INC += \
-I$(PERIPH_SRC)/ICC \
-I$(PERIPH_SRC)/TMR \
-I$(PERIPH_SRC)/RTC \
-I$(PERIPH_SRC)/UART
-I$(PERIPH_SRC)/UART \
-I$(PERIPH_SRC)/TRNG

INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC

Expand Down Expand Up @@ -116,7 +118,9 @@ SRC_MAX32 += \
$(PERIPH_SRC)/TMR/tmr_$(DIE_TYPE).c \
$(PERIPH_SRC)/UART/uart_common.c \
$(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \
$(PERIPH_SRC)/UART/uart_revb.c
$(PERIPH_SRC)/UART/uart_revb.c \
$(PERIPH_SRC)/TRNG/trng_revb.c \
$(PERIPH_SRC)/TRNG/trng_$(DIE_TYPE).c

SRC_C += $(SRC_MAX32) \
boards/$(BOARD)/board.c \
Expand Down
8 changes: 7 additions & 1 deletion ports/analog/common-hal/os/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries
// SPDX-FileCopyrightText: Copyright (c) 2025 Peggy Zhu, Analog Devices, Inc.
//
// SPDX-License-Identifier: MIT

Expand All @@ -15,9 +16,14 @@

// #include "peripherals/periph.h"

// true random number generator, TRNG
#include "trng.h"

bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) {
#if (HAS_TRNG)
// todo (low prior): implement
// get a random number of "length" number of bytes
MXC_TRNG_Random(buffer, length);
return true;
#else
#endif
return false;
Expand Down
3 changes: 2 additions & 1 deletion ports/analog/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
# SPDX-FileCopyrightText: Copyright (c) 2025 Peggy Zhu, Analog Devices, Inc.
#
# SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -51,7 +52,7 @@ CIRCUITPY_BITBANGIO ?= 1
# Requires Microcontroller
CIRCUITPY_TOUCHIO ?= 1
# Requires OS
CIRCUITPY_RANDOM ?= 0
CIRCUITPY_RANDOM ?= 1
# Requires busio.UART
CIRCUITPY_CONSOLE_UART ?= 0
# Does nothing without I2C
Expand Down
12 changes: 12 additions & 0 deletions ports/analog/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#include "mxc_delay.h"
#include "rtc.h"

// true random number generator, TRNG
#include "trng.h"

// msec to RTC subsec ticks (4 kHz)
/* Converts a time in milleseconds to equivalent RSSA register value */
#define MSEC_TO_SS_ALARM(x) (0 - ((x * 4096) / 1000))
Expand Down Expand Up @@ -112,9 +115,18 @@ safe_mode_t port_init(void) {
}
;

// enable TRNG (true random number generator)
#ifdef CIRCUITPY_RANDOM
MXC_TRNG_Init();
#endif

return SAFE_MODE_NONE;
}

void TRNG_IRQHandler(void) {
MXC_TRNG_Handler();
}

void RTC_IRQHandler(void) {
// Read flags to clear
int flags = MXC_RTC_GetFlags();
Expand Down