Skip to content

Commit 9057c2a

Browse files
committed
added STM32 UDID reporting
1 parent c749f77 commit 9057c2a

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

fw/v24/inc/util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extern "C" {
1818
#include <string.h>
1919
#include "log.h"
2020

21+
#define STM32_UUID ((uint32_t *)0x1FFFF7E8)
22+
2123
typedef struct {
2224
uint8_t const buffer;
2325
int head;
@@ -30,6 +32,9 @@ bool GetBitAtPos(uint8_t byte, uint8_t pos);
3032
uint8_t SetBitAtPos(uint8_t byte, uint8_t pos, bool value);
3133
void printHexArray(char *outBuf, uint8_t *array, uint8_t len);
3234
unsigned char reverseBits(unsigned char b);
35+
void getUid(uint8_t* buffer);
36+
void getUidString(char *str);
37+
void getCPU();
3338

3439
#ifdef __cplusplus
3540
}

fw/v24/inc/vcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void VCPCallback();
4747
bool VCPWrite(uint8_t *data, uint16_t len);
4848
bool VCPWriteP25Frame(const uint8_t *data, uint16_t len);
4949

50+
void sendVersion();
51+
5052
bool VCPWriteDebug1(const char *text);
5153
bool VCPWriteDebug2(const char *text, int16_t n1);
5254
bool VCPWriteDebug3(const char *text, int16_t n1, int16_t n2);

fw/v24/src/serial.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "fifo.h"
1212
#include "stdbool.h"
1313
#include "config.h"
14+
#include "util.h"
1415

1516
uint8_t serialDMABuffer[SERIAL_BUFFER_SIZE];
1617

@@ -122,5 +123,10 @@ void SerialStartup(UART_HandleTypeDef *huart) {
122123
SerialWrite(huart, " v");
123124
SerialWriteLn(huart, VERSION_STRING);
124125
SerialWriteLn(huart, " " DATE_STRING);
126+
SerialWrite(huart, " SERIAL: ");
127+
// Get chip UID (24-character hex string)
128+
char buffer[25];
129+
getUidString(buffer);
130+
SerialWriteLn(huart, buffer);
125131
SerialWriteLn(huart, "");
126132
}

fw/v24/src/util.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/* Self referential incude */
99
#include "util.h"
10+
#include <inttypes.h>
1011

1112
/**
1213
* @brief Converts an array of chars to a space-separated string with braces
@@ -49,7 +50,7 @@ uint8_t SetBitAtPos(uint8_t byte, uint8_t pos, bool value)
4950
}
5051

5152
/**
52-
* @brief Prints an array of hex characters, space separated
53+
* @brief Prints an array of hex characters
5354
* @param outBuf output buffer (must be 3x the length of input array)
5455
* @param array input array to print
5556
* @param len length of array
@@ -74,4 +75,38 @@ unsigned char reverseBits(unsigned char b)
7475
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
7576
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
7677
return b;
78+
}
79+
80+
/**
81+
* @brief Get the UID of the stm32 chip into a 12-byte buffer
82+
*/
83+
void getUid(uint8_t* buffer)
84+
{
85+
memcpy(buffer, (void*)STM32_UUID, 12);
86+
}
87+
88+
/**
89+
* @brief Read the UID of the STM32 chip to a 25-byte hex string (null-terminated)
90+
*
91+
* @param str 25-byte buffer to write to
92+
*/
93+
void getUidString(char *str)
94+
{
95+
// Get the 12 byte UID
96+
uint8_t buffer[12];
97+
getUid(buffer);
98+
99+
// Print to string
100+
for (int i = 0; i < 12; i++)
101+
{
102+
sprintf(str + (i * 2), "%02X", buffer[i]);
103+
}
104+
}
105+
106+
/**
107+
* @breif Returns the flash size of the STM32F103 chip
108+
*/
109+
uint16_t readFlashSize()
110+
{
111+
return (uint16_t)(0x1FF8007C);
77112
}

fw/v24/src/vcp.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "string.h"
1919
#include "hdlc.h"
2020

21+
const char HARDWARE[] = "DVM-V24 FW " __TIME__ " " __DATE__;
22+
2123
uint8_t vcpRxMsg[VCP_RX_BUF_LEN];
2224

2325
extern bool USB_VCP_DTR;
@@ -122,6 +124,10 @@ void VCPCallback()
122124
// Send the UI
123125
HDLCSendUI(p25data, length - 4);
124126
}
127+
else if (command == CMD_GET_VERSION)
128+
{
129+
sendVersion();
130+
}
125131
LED_USB(0);
126132
}
127133

@@ -209,13 +215,43 @@ bool VCPWriteP25Frame(const uint8_t *data, uint16_t len)
209215
#endif
210216
#ifdef TRACE_VCP
211217
uint8_t hexStrBuf[(len+3)*4];
212-
printHexArray((char*)hexStrBuf, buffer, len+3);
218+
printHexArray((char*)hexStrBuf, buffer, len+3, " ");
213219
log_trace("Sending %s", hexStrBuf);
214220
#endif
215221

216222
return VCPWrite(buffer, len+4);
217223
}
218224

225+
/**
226+
* @brief Send the V24 board version and UID over the VCP
227+
*
228+
* Stolen from the DVM modem firmware
229+
*/
230+
void sendVersion()
231+
{
232+
uint8_t reply[200U];
233+
234+
reply[0U] = DVM_FRAME_START;
235+
reply[1U] = 0U;
236+
reply[2U] = CMD_GET_VERSION;
237+
reply[3U] = 0x01U; // protocol version
238+
reply[4U] = 0x02U; // CPU type (STM32)
239+
240+
// 16-byte UDID
241+
memset(reply + 5U, 0x00U, 16U);
242+
getUid(reply + 5U);
243+
244+
// HW description
245+
uint8_t count = 21;
246+
for (uint8_t i = 0U; i < sizeof(HARDWARE); i++, count++)
247+
reply[count] = HARDWARE[i];
248+
249+
// Total length
250+
reply[1U] = count;
251+
252+
VCPWrite(reply, count);
253+
}
254+
219255
/**
220256
* @brief Write a debug message to the USB port, using the DVMHost modem format
221257
*

0 commit comments

Comments
 (0)