add unique id for imxrt

This commit is contained in:
hathach 2024-07-18 09:24:29 +07:00
parent c6339204f4
commit ea5deb0018
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
3 changed files with 28 additions and 2 deletions

View File

@ -24,8 +24,8 @@
* This file is part of the TinyUSB stack.
*/
#ifndef _BOARD_API_H_
#define _BOARD_API_H_
#ifndef BOARD_API_H_
#define BOARD_API_H_
#ifdef __cplusplus
extern "C" {

View File

@ -40,6 +40,7 @@
#include "fsl_iomuxc.h"
#include "fsl_clock.h"
#include "fsl_lpuart.h"
#include "fsl_ocotp.h"
#ifdef __GNUC__
#pragma GCC diagnostic pop
@ -186,6 +187,29 @@ uint32_t board_button_read(void) {
return BUTTON_STATE_ACTIVE == GPIO_PinRead(BUTTON_PORT, BUTTON_PIN);
}
size_t board_get_unique_id(uint8_t id[], size_t max_len) {
(void) max_len;
#if FSL_FEATURE_OCOTP_HAS_TIMING_CTRL
OCOTP_Init(OCOTP, CLOCK_GetFreq(kCLOCK_IpgClk));
#else
OCOTP_Init(OCOTP, 0u);
#endif
// Reads shadow registers 0x01 - 0x04 (Configuration and Manufacturing Info)
// into 8 bit wide destination, avoiding punning.
for (int i = 0; i < 4; ++i) {
uint32_t wr = OCOTP_ReadFuseShadowRegister(OCOTP, i + 1);
for (int j = 0; j < 4; j++) {
id[i*4+j] = wr & 0xff;
wr >>= 8;
}
}
OCOTP_Deinit(OCOTP);
return 16;
}
int board_uart_read(uint8_t* buf, int len) {
int count = 0;

View File

@ -44,6 +44,7 @@ function(add_board_target BOARD_TARGET)
${SDK_DIR}/drivers/igpio/fsl_gpio.c
${SDK_DIR}/drivers/lpspi/fsl_lpspi.c
${SDK_DIR}/drivers/lpuart/fsl_lpuart.c
${SDK_DIR}/drivers/ocotp/fsl_ocotp.c
${SDK_DIR}/devices/${MCU_VARIANT}/system_${MCU_VARIANT_WITH_CORE}.c
${SDK_DIR}/devices/${MCU_VARIANT}/xip/fsl_flexspi_nor_boot.c
${SDK_DIR}/devices/${MCU_VARIANT}/drivers/fsl_clock.c
@ -75,6 +76,7 @@ function(add_board_target BOARD_TARGET)
${SDK_DIR}/drivers/igpio
${SDK_DIR}/drivers/lpspi
${SDK_DIR}/drivers/lpuart
${SDK_DIR}/drivers/ocotp
)
update_board(${BOARD_TARGET})