mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-21 15:34:33 +08:00
replace UUID_... property by serial_number
This commit is contained in:
@@ -57,6 +57,8 @@
|
||||
#include "usart.h"
|
||||
#include "usb_device.h"
|
||||
#include "gpio.h"
|
||||
#include "utils.h"
|
||||
#include "commands.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
@@ -107,6 +109,15 @@ int main(void)
|
||||
jump_to_builtin_bootloader();
|
||||
}
|
||||
|
||||
// This procedure of building a USB serial number should be identical
|
||||
// to the way the STM's built-in USB bootloader does it. This means
|
||||
// that the device will have the same serial number in normal and DFU mode.
|
||||
uint32_t uuid0 = *(uint32_t *) (ID_UNIQUE_ADDRESS + 0);
|
||||
uint32_t uuid1 = *(uint32_t *) (ID_UNIQUE_ADDRESS + 4);
|
||||
uint32_t uuid2 = *(uint32_t *) (ID_UNIQUE_ADDRESS + 8);
|
||||
uint32_t uuid_mixed_part = uuid0 + uuid2;
|
||||
serial_number = ((uint64_t)uuid_mixed_part << 16) | (uint64_t)(uuid1 >> 16);
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration----------------------------------------------------------*/
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_conf.h"
|
||||
#include "utils.h"
|
||||
#include "commands.h"
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
|
||||
@@ -328,21 +328,11 @@ uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *l
|
||||
*/
|
||||
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
// This procedure of building a USB serial number should be identical
|
||||
// to the way the STM's built-in USB bootloader does it. This means
|
||||
// that the device will have the same serial number in normal and DFU mode.
|
||||
uint32_t uuid0 = *(uint32_t *) (ID_UNIQUE_ADDRESS + 0);
|
||||
uint32_t uuid1 = *(uint32_t *) (ID_UNIQUE_ADDRESS + 4);
|
||||
uint32_t uuid2 = *(uint32_t *) (ID_UNIQUE_ADDRESS + 8);
|
||||
uint32_t uuid_first_part = uuid0 + uuid2;
|
||||
uint8_t str[13];
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
str[i] = "0123456789ABCDEF"[(uuid_first_part >> 28) & 0xf];
|
||||
uuid_first_part <<= 4;
|
||||
}
|
||||
for (size_t i = 8; i < 12; ++i) {
|
||||
str[i] = "0123456789ABCDEF"[(uuid1 >> 28) & 0xf];
|
||||
uuid1 <<= 4;
|
||||
uint8_t str[13]; // 12 digits + null termination
|
||||
uint64_t val = serial_number;
|
||||
for (size_t i = 0; i < 12; ++i) {
|
||||
str[i] = "0123456789ABCDEF"[(val >> (48-4)) & 0xf];
|
||||
val <<= 4;
|
||||
}
|
||||
str[12] = 0;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ Please add a note of your changes below this heading if you make a Pull Request.
|
||||
### Changed
|
||||
* The build is now configured using the `tup.config` file instead of editing source files. Make sure you set your board version correctly. See [here](README.md#configuring-the-build) for details.
|
||||
* Update CubeMX generated STM platform code to version 1.19.0
|
||||
* Remove `UUID_0`, `UUID_1` and `UUID_2` from USB protocol. Use `serial_number` instead.
|
||||
|
||||
# Releases
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||
extern USBD_HandleTypeDef hUsbDeviceFS;
|
||||
uint64_t serial_number;
|
||||
|
||||
/* Private constant data -----------------------------------------------------*/
|
||||
// TODO: make command to switch gpio_mode during run-time
|
||||
@@ -115,9 +116,7 @@ void enter_dfu_mode() {
|
||||
// clang-format off
|
||||
const Endpoint endpoints[] = {
|
||||
Endpoint::make_property("vbus_voltage", const_cast<const float*>(&vbus_voltage)),
|
||||
Endpoint::make_property("UUID_0", (const uint32_t*)(ID_UNIQUE_ADDRESS + 0*4)),
|
||||
Endpoint::make_property("UUID_1", (const uint32_t*)(ID_UNIQUE_ADDRESS + 1*4)),
|
||||
Endpoint::make_property("UUID_2", (const uint32_t*)(ID_UNIQUE_ADDRESS + 2*4)),
|
||||
Endpoint::make_property("serial_number", const_cast<const uint64_t *>(&serial_number)),
|
||||
Endpoint::make_function("run_anticogging_calibration", &motors_run_anticogging_calibration_func),
|
||||
// No parameters, but still requires a close_tree()
|
||||
Endpoint::close_tree(),
|
||||
|
||||
@@ -19,6 +19,8 @@ void set_cmd_buffer(uint8_t *buf, uint32_t len);
|
||||
void usb_update_thread();
|
||||
void USB_receive_packet(const uint8_t *buffer, size_t length);
|
||||
|
||||
extern uint64_t serial_number;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user