Merge pull request #59 from Wetmelon/devel

Add UUID access, echo cmd
This commit is contained in:
Oskar Weigl
2017-11-08 21:15:32 -08:00
committed by GitHub
3 changed files with 73 additions and 8 deletions
+8 -5
View File
@@ -5,6 +5,7 @@
#include <gpio.h>
#include <freertos_vars.h>
#include <usbd_cdc.h>
#include <utils.h>
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] == '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());
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;
@@ -378,4 +381,4 @@ void usb_update_thread() {
}
}
vTaskDelete(osThreadGetId());
}
}
+63 -1
View File
@@ -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
@@ -20,4 +82,4 @@ 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
+2 -2
View File
@@ -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')