From a935c2645555155074c15e37f66ae1647b0aaa04 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 8 Nov 2017 21:46:07 -0500 Subject: [PATCH 1/3] Add UUID access, echo cmd --- Firmware/MotorControl/commands.c | 11 ++++-- Firmware/MotorControl/utils.h | 66 +++++++++++++++++++++++++++++++- tools/test_communication.py | 4 +- 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/Firmware/MotorControl/commands.c b/Firmware/MotorControl/commands.c index 76006a54..b3d5e4e0 100644 --- a/Firmware/MotorControl/commands.c +++ b/Firmware/MotorControl/commands.c @@ -5,6 +5,7 @@ #include #include #include +#include extern PCD_HandleTypeDef hpcd_USB_OTG_FS; @@ -168,10 +169,12 @@ void motor_parse_cmd(uint8_t* buffer, int len, SerialPrintf_t response_interface if (numscan == 2 && motor_number < num_motors) { set_current_setpoint(&motors[motor_number], current_feed_forward); } - } else if(buffer[0] == 'e'){ - int val = printf("Test 1\n"); - int val2 = printf("test 2\n"); - val = 0; + } else if(buffer[0] == 'e'){ // Generic ECHO command for testing + // Retrieves the device signature, revision, flash size, and UUID + printf("Signature: %#x\n", STM_ID_GetSignature()); + printf("Revision: %#x\n", STM_ID_GetRevision()); + printf("Flash Size: %#x KiB\n", STM_ID_GetFlashSize()); + printf("UUID: 0x%lx%lx%lx\n", STM_ID_GetUUID(2), STM_ID_GetUUID(1), STM_ID_GetUUID(0)); } else if (buffer[0] == 'g') { // GET // g <0:float,1:int,2:bool,3:uint16> index int type = 0; diff --git a/Firmware/MotorControl/utils.h b/Firmware/MotorControl/utils.h index 7170b8ca..9f995c7b 100644 --- a/Firmware/MotorControl/utils.h +++ b/Firmware/MotorControl/utils.h @@ -2,6 +2,68 @@ #ifndef __UTILS_H #define __UTILS_H +/** + * @brief Unique ID register address location + */ +#define ID_UNIQUE_ADDRESS (0x1FFF7A10) + +/** + * @brief Flash size register address + */ +#define ID_FLASH_ADDRESS (0x1FFF7A22) + +/** + * @brief Device ID register address + */ +#define ID_DBGMCU_IDCODE (0xE0042000) + +/** + * "Returns" the device signature + * + * Possible returns: + * - 0x0413: STM32F405xx/07xx and STM32F415xx/17xx) + * - 0x0419: STM32F42xxx and STM32F43xxx + * - 0x0423: STM32F401xB/C + * - 0x0433: STM32F401xD/E + * - 0x0431: STM32F411xC/E + * + * Returned data is in 16-bit mode, but only bits 11:0 are valid, bits 15:12 are always 0. + * Defined as macro + */ +#define STM_ID_GetSignature() ((*(uint16_t *)(ID_DBGMCU_IDCODE)) & 0x0FFF) + +/** + * "Returns" the device revision + * + * Revisions possible: + * - 0x1000: Revision A + * - 0x1001: Revision Z + * - 0x1003: Revision Y + * - 0x1007: Revision 1 + * - 0x2001: Revision 3 + * + * Returned data is in 16-bit mode. + */ +#define STM_ID_GetRevision() (*(uint16_t *)(ID_DBGMCU_IDCODE + 2)) + +/** +* "Returns" the Flash size +* +* Returned data is in 16-bit mode, returned value is flash size in kB (kilo bytes). +*/ +#define STM_ID_GetFlashSize() (*(uint16_t *)(ID_FLASH_ADDRESS)) + +/** + * "Returns" the given 32-bit value of the UUID. + * + * Parameters: + * - uint8_t x: + * Value between 0 and 2, corresponding to 4-bytes you want to read from 96bits (12bytes) + * + * Returned data is 32-bit + */ +#define STM_ID_GetUUID(x) ((x >= 0 && x < 3) ? (*(uint32_t *)(ID_UNIQUE_ADDRESS + 4 * (x))) : 0) + #ifndef M_PI #define M_PI 3.14159265358979323846f #endif @@ -13,11 +75,11 @@ // as per the magnitude invariant clarke transform // The magnitude of the alpha-beta vector may not be larger than sqrt(3)/2 // Returns 0 on success, and -1 if the input was out of range -int SVM(float alpha, float beta, float* tA, float* tB, float* tC); +int SVM(float alpha, float beta, float *tA, float *tB, float *tC); //beware of inserting large angles! float wrap_pm_pi(float theta); float fast_atan2(float y, float x); int mod(int dividend, int divisor); -#endif //__UTILS_H +#endif //__UTILS_H diff --git a/tools/test_communication.py b/tools/test_communication.py index 0a24fef1..32d989bb 100644 --- a/tools/test_communication.py +++ b/tools/test_communication.py @@ -39,7 +39,7 @@ def main(args): while running: time.sleep(0.1) try: - command = input("Enter ODrive command:\n") + command = input("\r\nEnter ODrive command:\n") if 'q' in command: running = False sys.exit() @@ -52,7 +52,7 @@ def receive_thread(dev): global ready while running: - time.sleep(0.1) + time.sleep(0.001) try: message = dev.receive(dev.receive_max()) message_ascii = bytes(message).decode('ascii') From 70f1a566313955e426f108029182f72f57b6154d Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Wed, 8 Nov 2017 21:13:33 -0800 Subject: [PATCH 2/3] move stars in util.h --- Firmware/MotorControl/utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/MotorControl/utils.h b/Firmware/MotorControl/utils.h index 9f995c7b..542b7dd7 100644 --- a/Firmware/MotorControl/utils.h +++ b/Firmware/MotorControl/utils.h @@ -75,7 +75,7 @@ // as per the magnitude invariant clarke transform // The magnitude of the alpha-beta vector may not be larger than sqrt(3)/2 // Returns 0 on success, and -1 if the input was out of range -int SVM(float alpha, float beta, float *tA, float *tB, float *tC); +int SVM(float alpha, float beta, float* tA, float* tB, float* tC); //beware of inserting large angles! float wrap_pm_pi(float theta); From f4b934a78af8066f2e71cfae7c20058078d0fd57 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Wed, 8 Nov 2017 21:15:14 -0800 Subject: [PATCH 3/3] change info dump command to 'i' --- Firmware/MotorControl/commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/MotorControl/commands.c b/Firmware/MotorControl/commands.c index b3d5e4e0..6978a091 100644 --- a/Firmware/MotorControl/commands.c +++ b/Firmware/MotorControl/commands.c @@ -169,7 +169,7 @@ void motor_parse_cmd(uint8_t* buffer, int len, SerialPrintf_t response_interface if (numscan == 2 && motor_number < num_motors) { set_current_setpoint(&motors[motor_number], current_feed_forward); } - } else if(buffer[0] == 'e'){ // Generic ECHO command for testing + } else if(buffer[0] == 'i'){ // Dump device info // Retrieves the device signature, revision, flash size, and UUID printf("Signature: %#x\n", STM_ID_GetSignature()); printf("Revision: %#x\n", STM_ID_GetRevision()); @@ -381,4 +381,4 @@ void usb_update_thread() { } } vTaskDelete(osThreadGetId()); -} \ No newline at end of file +}