From 182a844cd22bd5d332820913dd73f5bd47b00da4 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 4 Jul 2015 03:44:42 +0200 Subject: [PATCH] Add FW version command * Add FW version command to usbdbg. * Add FW version function to openmv.py * Check for major version in the IDE. --- src/omv/usbdbg.c | 14 ++++++++++++++ src/omv/usbdbg.h | 24 +++++++++++++++++++++++- usr/openmv-ide.py | 12 ++++++++++++ usr/openmv.py | 5 +++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/omv/usbdbg.c b/src/omv/usbdbg.c index 8d2fdb237..c9d689964 100644 --- a/src/omv/usbdbg.c +++ b/src/omv/usbdbg.c @@ -60,6 +60,15 @@ void usbdbg_clr_script() void usbdbg_data_in(void *buffer, int length) { switch (cmd) { + case USBDBG_FW_VERSION: { + uint32_t *ver_buf = buffer; + ver_buf[0] = FIRMWARE_VERSION_MAJOR; + ver_buf[1] = FIRMWARE_VERSION_MINOR; + ver_buf[2] = FIRMWARE_VERSION_PATCH; + cmd = USBDBG_NONE; + break; + } + case USBDBG_TX_BUF_LEN: { uint32_t tx_buf_len = usbd_cdc_tx_buf_len(); memcpy(buffer, &tx_buf_len, length); @@ -185,6 +194,11 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t length) { cmd = (enum usbdbg_cmd) request; switch (cmd) { + case USBDBG_FW_VERSION: + xfer_bytes = 0; + xfer_length = length; + break; + case USBDBG_FRAME_SIZE: xfer_bytes = 0; xfer_length = length; diff --git a/src/omv/usbdbg.h b/src/omv/usbdbg.h index 8413d95f2..3208c9883 100644 --- a/src/omv/usbdbg.h +++ b/src/omv/usbdbg.h @@ -8,8 +8,30 @@ */ #ifndef __USBDBG_H__ #define __USBDBG_H__ +/** + * Firmware major, minor and patch versions. + * Increment the major version if the ABI has changed. + * Increment the minor version when a new command is added. + * Increment the patch version for fixes that don't affect the ABI. + * + * Note: incrementing the major version will require a fw upgrade, + * the IDE will Not connect if the major version number is different. + */ +#define FIRMWARE_VERSION_MAJOR (1) +#define FIRMWARE_VERSION_MINOR (1) +#define FIRMWARE_VERSION_PATCH (0) + +/** + * To add a new debugging command, increment the last command value used. + * Set the MSB of the value if the request has a device-to-host data phase. + * Add the command to usr/openmv.py using the same value. + * Handle the command control and data in/out (if any) phases in usbdbg.c. + * + * See usbdbg.c for examples. + */ enum usbdbg_cmd { - USBDBG_NONE=0, + USBDBG_NONE =0x00, + USBDBG_FW_VERSION =0x80, USBDBG_FRAME_SIZE =0x81, USBDBG_FRAME_DUMP =0x82, USBDBG_FRAME_LOCK =0x83, diff --git a/usr/openmv-ide.py b/usr/openmv-ide.py index 137f50ecb..4612e48f2 100755 --- a/usr/openmv-ide.py +++ b/usr/openmv-ide.py @@ -26,6 +26,10 @@ if hasattr(sys,"frozen") and sys.frozen in ("windows_exe", "console_exe"): else: IDE_DIR=os.path.dirname(os.path.realpath(__file__)) +FIRMWARE_VERSION_MAJOR = 1 +FIRMWARE_VERSION_MINOR = 1 +FIRMWARE_VERSION_PATCH = 0 + DATA_DIR = os.path.join(os.path.expanduser("~"), "openmv") #use home dir SCRIPTS_DIR = os.path.join(DATA_DIR, "scripts") EXAMPLES_DIR = os.path.join(IDE_DIR, "examples") @@ -223,6 +227,14 @@ class OMVGtk: return openmv.init(self.serial) + + # check firmware version + fw_ver = openmv.fw_version() + print("fw_version:" + str(fw_ver)) + if (fw_ver[0] != FIRMWARE_VERSION_MAJOR): + self.show_message_dialog(gtk.MESSAGE_ERROR, "Firmware version mismatch! Please upgrade the firmware") + return + # interrupt any running code openmv.stop_script() diff --git a/usr/openmv.py b/usr/openmv.py index 6be6f0941..4bb770dbe 100755 --- a/usr/openmv.py +++ b/usr/openmv.py @@ -22,6 +22,7 @@ __FB_HDR_SIZE =12 # USB Debug commands __USBDBG_CMD = 48 +__USBDBG_FW_VERSION = 0x80 __USBDBG_FRAME_SIZE = 0x81 __USBDBG_FRAME_DUMP = 0x82 __USBDBG_FRAME_LOCK = 0x83 @@ -135,6 +136,10 @@ def tx_buf(bytes): __serial.write(struct.pack("')