diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 41cd7ce1a..5b3a624c1 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -841,7 +841,7 @@ endif() if(CPU_FAMILY STREQUAL STM32) add_custom_target(flash COMMAND dfu-util --alt 0 --dfuse-address 0x08000000 -D firmware.bin - DEPENDS firmware.bin + DEPENDS firmware WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) endif() diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index 6d1a7bb16..73de8c35d 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -280,6 +280,13 @@ int cliDisplay(const char ** argv) else if (!strcmp(argv[1], "volume")) { serialPrint("volume = %d", getVolume()); } +#if defined(CPUSTM32) + else if (!strcmp(argv[1], "uid")) { + char str[LEN_CPU_UID+1]; + getCPUUniqueID(str); + serialPrint("uid = %s", str); + } +#endif #if defined(PCBFLAMENCO) else if (!strcmp(argv[1], "bq24195")) { { @@ -379,7 +386,7 @@ const CliCommand cliCommands[] = { }; int cliHelp(const char ** argv) -{ +{ for (const CliCommand * command = cliCommands; command->name != NULL; command++) { if (argv[1][0] == '\0' || !strcmp(command->name, argv[0])) { serialPrint("%s %s", command->name, command->args); diff --git a/radio/src/strhelpers.cpp b/radio/src/strhelpers.cpp index b387d4434..bce2f0258 100644 --- a/radio/src/strhelpers.cpp +++ b/radio/src/strhelpers.cpp @@ -155,13 +155,14 @@ char * strAppendNumber(char * dest, unsigned int value, uint8_t digits, uint8_t tmp /= radix; } } - dest[digits] = '\0'; - while(digits > 0) { + uint8_t idx = digits; + while(idx > 0) { div_t qr = div(value, radix); - dest[--digits] = (qr.rem >= 10 ? 'A' : '0') + qr.rem; + dest[--idx] = (qr.rem >= 10 ? 'A'-10 : '0') + qr.rem; value = qr.quot; } - return dest + digits; + dest[digits] = '\0'; + return &dest[digits]; } #if defined(CPUARM) || defined(SDCARD) diff --git a/radio/src/targets/horus/board_horus.cpp b/radio/src/targets/horus/board_horus.cpp index 02d90e4b4..c9c715760 100644 --- a/radio/src/targets/horus/board_horus.cpp +++ b/radio/src/targets/horus/board_horus.cpp @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -39,6 +39,16 @@ void watchdogInit(unsigned int duration) IWDG->KR = 0xCCCC ; // start } +void getCPUUniqueID(char * s) +{ + uint32_t * cpu_uid = (uint32_t *)0x1FFF7A10; + char * tmp = strAppendNumber(s, cpu_uid[0], 8, 16); + *tmp = ' '; + tmp = strAppendNumber(tmp+1, cpu_uid[1], 8, 16); + *tmp = ' '; + strAppendNumber(tmp+1, cpu_uid[2], 8, 16); +} + // Start TIMER7 at 2000000Hz void init2MhzTimer() { @@ -144,19 +154,19 @@ extern USB_OTG_CORE_HANDLE USB_OTG_dev; Prepare and send new USB data packet The format of HID_Buffer is defined by - USB endpoint description can be found in + USB endpoint description can be found in file usb_hid_joystick.c, variable HID_JOYSTICK_ReportDesc */ void usbJoystickUpdate(void) { static uint8_t HID_Buffer[HID_IN_PACKET]; - + //buttons HID_Buffer[0] = 0; //buttons for (int i = 0; i < 8; ++i) { if ( channelOutputs[i+8] > 0 ) { HID_Buffer[0] |= (1 << i); - } + } } //analog values @@ -165,7 +175,7 @@ void usbJoystickUpdate(void) int16_t value = channelOutputs[i] / 8; if ( value > 127 ) value = 127; else if ( value < -127 ) value = -127; - HID_Buffer[i+1] = static_cast(value); + HID_Buffer[i+1] = static_cast(value); } USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET ); @@ -220,4 +230,4 @@ void checkTrainerSettings() break; } } -} \ No newline at end of file +} diff --git a/radio/src/targets/horus/board_horus.h b/radio/src/targets/horus/board_horus.h index 7d829ffc0..3a34a796f 100644 --- a/radio/src/targets/horus/board_horus.h +++ b/radio/src/targets/horus/board_horus.h @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -116,6 +116,10 @@ void delay_ms(uint16_t nb); } #endif +// CPU Unique ID +#define LEN_CPU_UID (3*8+2) +void getCPUUniqueID(char * s); + // SD driver #if !defined(SIMU) || defined(SIMU_DISKIO) uint32_t sdIsHC(void); diff --git a/radio/src/targets/taranis/board_taranis.cpp b/radio/src/targets/taranis/board_taranis.cpp index 1147fbad3..ce835c1bb 100644 --- a/radio/src/targets/taranis/board_taranis.cpp +++ b/radio/src/targets/taranis/board_taranis.cpp @@ -39,6 +39,16 @@ void watchdogInit(unsigned int duration) IWDG->KR = 0xCCCC ; // start } +void getCPUUniqueID(char * s) +{ + uint32_t * cpu_uid = (uint32_t *)0x1FFF7A10; + char * tmp = strAppendNumber(s, cpu_uid[0], 8, 16); + *tmp = ' '; + tmp = strAppendNumber(tmp+1, cpu_uid[1], 8, 16); + *tmp = ' '; + strAppendNumber(tmp+1, cpu_uid[2], 8, 16); +} + // Starts TIMER at 2MHz void init2MhzTimer() { diff --git a/radio/src/targets/taranis/board_taranis.h b/radio/src/targets/taranis/board_taranis.h index afa2659a9..935297eff 100644 --- a/radio/src/targets/taranis/board_taranis.h +++ b/radio/src/targets/taranis/board_taranis.h @@ -144,6 +144,10 @@ void delay(uint32_t ms); } #endif +// CPU Unique ID +#define LEN_CPU_UID (3*8+2) +void getCPUUniqueID(char * s); + // SD driver #if !defined(SIMU) || defined(SIMU_DISKIO) uint32_t sdIsHC(void);