mirror of
https://github.com/Noltari/pico-uart-bridge.git
synced 2025-05-14 08:12:20 +00:00
retrieve serial from flash ID
This commit is contained in:
parent
05e4815f6b
commit
758cec2b5f
4 changed files with 24 additions and 2 deletions
|
@ -17,6 +17,7 @@ target_include_directories(uart_bridge PUBLIC
|
||||||
target_link_libraries(uart_bridge
|
target_link_libraries(uart_bridge
|
||||||
pico_multicore
|
pico_multicore
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
|
hardware_flash
|
||||||
tinyusb_device)
|
tinyusb_device)
|
||||||
|
|
||||||
pico_add_extra_outputs(uart_bridge)
|
pico_add_extra_outputs(uart_bridge)
|
||||||
|
|
3
serial.h
Normal file
3
serial.h
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
extern char serial[17];
|
|
@ -10,6 +10,9 @@
|
||||||
#include <pico/stdlib.h>
|
#include <pico/stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <tusb.h>
|
#include <tusb.h>
|
||||||
|
#include <hardware/flash.h>
|
||||||
|
|
||||||
|
#include "serial.h"
|
||||||
|
|
||||||
#if !defined(MIN)
|
#if !defined(MIN)
|
||||||
#define MIN(a, b) ((a > b) ? b : a)
|
#define MIN(a, b) ((a > b) ? b : a)
|
||||||
|
@ -263,12 +266,23 @@ void init_uart_data(uint8_t itf) {
|
||||||
parity_usb2uart(ud->usb_lc.parity));
|
parity_usb2uart(ud->usb_lc.parity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void init_serial() {
|
||||||
|
uint8_t id[8];
|
||||||
|
flash_get_unique_id(id);
|
||||||
|
for (int i = 0; i < 8; ++i) {
|
||||||
|
sprintf(serial + 2 * i, "%X", id[i]);
|
||||||
|
}
|
||||||
|
serial[16] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int itf;
|
int itf;
|
||||||
|
|
||||||
set_sys_clock_khz(250000, false);
|
set_sys_clock_khz(250000, false);
|
||||||
|
|
||||||
|
init_serial();
|
||||||
|
|
||||||
for (itf = 0; itf < CFG_TUD_CDC; itf++)
|
for (itf = 0; itf < CFG_TUD_CDC; itf++)
|
||||||
init_uart_data(itf);
|
init_uart_data(itf);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include <tusb.h>
|
#include <tusb.h>
|
||||||
|
|
||||||
|
#include "serial.h"
|
||||||
|
|
||||||
#define DESC_STR_MAX 20
|
#define DESC_STR_MAX 20
|
||||||
|
|
||||||
#define USBD_VID 0x2E8A /* Raspberry Pi */
|
#define USBD_VID 0x2E8A /* Raspberry Pi */
|
||||||
|
@ -68,10 +70,12 @@ static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = {
|
||||||
USBD_CDC_IN_OUT_MAX_SIZE),
|
USBD_CDC_IN_OUT_MAX_SIZE),
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *const usbd_desc_str[] = {
|
char serial[17];
|
||||||
|
|
||||||
|
static char *const usbd_desc_str[] = {
|
||||||
[USBD_STR_MANUF] = "Raspberry Pi",
|
[USBD_STR_MANUF] = "Raspberry Pi",
|
||||||
[USBD_STR_PRODUCT] = "Pico",
|
[USBD_STR_PRODUCT] = "Pico",
|
||||||
[USBD_STR_SERIAL] = "000000000000",
|
[USBD_STR_SERIAL] = serial,
|
||||||
[USBD_STR_CDC] = "Board CDC",
|
[USBD_STR_CDC] = "Board CDC",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue