From 96f2358caadfd55d6fd3b888ef5d21f22fc2439c Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 20 Apr 2024 22:08:08 +0200 Subject: firmware: Add 64 bit MAC to shell prompt This demonstrates that the readout of the 64 bit MAC address from the STM32WL55 microcontroller works and is useful to recognize used devices. --- firmware/src/uid64.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 firmware/src/uid64.c (limited to 'firmware/src/uid64.c') diff --git a/firmware/src/uid64.c b/firmware/src/uid64.c new file mode 100644 index 0000000..984b7fe --- /dev/null +++ b/firmware/src/uid64.c @@ -0,0 +1,41 @@ +#include + +#include + +#include "uid64.h" + +#define UID64_NODE DT_NODELABEL(uid64) + +uint64_t uid64_get(void) { +#if DT_NODE_EXISTS(UID64_NODE) + return *(volatile uint64_t *) DT_REG_ADDR(UID64_NODE); +#else + return 0; +#endif +} + +void uid64_to_string(uint64_t uid, char *str) { + uint8_t *source = (uint8_t *)&uid + 7; + char *sink = str; + + for (unsigned int i = 0; i < 8; i++) { + /* delimiter */ + if (i > 0) { + *sink = ':'; + sink++; + } + + /* byte values */ + snprintf(sink, 3, "%02x", *source); + source--; + sink += 2; + } +} + +bool uid64_available(void) { +#if DT_NODE_EXISTS(UID64_NODE) + return true; +#else + return false; +#endif +} -- cgit v1.2.3-70-g09d2