From d35a2f9af2d629ebb5053c6f1c91bbaf8f9b1a37 Mon Sep 17 00:00:00 2001 From: Augusto Fraga Giachero Date: Wed, 4 Mar 2020 08:26:05 -0300 Subject: [PATCH 1/5] Move reprogramming logic to RFFEFWUpdate class [utils] Now other scripts can use the RFFEFWUpdate class directly, without the need of an active SCPI connection to make firmware upgrades. --- utils/rffe_nuttx_lib.py | 75 +++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/utils/rffe_nuttx_lib.py b/utils/rffe_nuttx_lib.py index b46bcd7..cd5c368 100644 --- a/utils/rffe_nuttx_lib.py +++ b/utils/rffe_nuttx_lib.py @@ -30,6 +30,43 @@ def write_sector(self, data, start_addr): self.s.send(data) ans = self.s.recv(1) + def reprogram(self, file_path, version, bootloader=False): + major, minor, patch = map(int,re.split('[., _]',version)) + + start_addr = 0x48000 + + with open(file_path, "rb") as f: + + self.erase_all() + + buf = f.read(256) + while buf != b"": + + pad = bytearray() + pad.extend(buf) + + if len(buf) < 256: + pad.extend(b'\377' * (256 - len(pad))) + + self.write_sector(pad, start_addr) + start_addr += 256 + buf = f.read(256) + + boot_sec = bytearray() + boot_sec.extend(b'\377' * 256) + + boot_sec[248] = major + boot_sec[249] = minor + boot_sec[250] = patch + boot_sec[251] = 2 if bootloader else 1 + boot_sec[252] = 0xAA + boot_sec[253] = 0xAA + boot_sec[254] = 0xAA + boot_sec[255] = 0xAA + self.write_sector(boot_sec, 0x0007FF00) + self.reset() + self.close() + def reset(self): self.s.send(b"r") self.s.close() @@ -155,44 +192,8 @@ def reprogram(self, file_path, version, bootloader=False): first argument, a string, is the path to the binary file which corresponds to the program will be loaded in the device. The second argument is the new firmware version formated as: x.y.z or x_y_z""" - pass - major, minor, patch = map(int,re.split('[., _]',version)) - - start_addr = 0x48000 - rffe_fw = RFFEFWUpdate(self.ip) - - with open(file_path, "rb") as f: - - rffe_fw.erase_all() - - buf = f.read(256) - while buf != b"": - - pad = bytearray() - pad.extend(buf) - - if len(buf) < 256: - pad.extend(b'\377' * (256 - len(pad))) - - rffe_fw.write_sector(pad, start_addr) - start_addr += 256 - buf = f.read(256) - - boot_sec = bytearray() - boot_sec.extend(b'\377' * 256) - - boot_sec[248] = major - boot_sec[249] = minor - boot_sec[250] = patch - boot_sec[251] = 2 if bootloader else 1 - boot_sec[252] = 0xAA - boot_sec[253] = 0xAA - boot_sec[254] = 0xAA - boot_sec[255] = 0xAA - rffe_fw.write_sector(boot_sec, 0x0007FF00) - rffe_fw.reset() - self.close() + rffe_fw.reprogram(file_path, version, bootloader); def set_pid_ac_kc(self, value): """Sets the PID Kc parameter in the A/C front-end. The value is passed as a floating-point numpber.""" From 1bca96820ef18adb4071b379da81774f0460e437 Mon Sep 17 00:00:00 2001 From: Augusto Fraga Giachero Date: Wed, 4 Mar 2020 08:58:38 -0300 Subject: [PATCH 2/5] Reset after system crashes [rffe-board] Reset the microcontroller after system crashes to avoid manual intervention in such cases. --- rffe-board/rffe/defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/rffe-board/rffe/defconfig b/rffe-board/rffe/defconfig index 5feb4fb..3897931 100644 --- a/rffe-board/rffe/defconfig +++ b/rffe-board/rffe/defconfig @@ -20,6 +20,7 @@ CONFIG_ARCH_CHIP_LPC1769=y CONFIG_ARCH_CHIP_LPC17XX_40XX=y CONFIG_ARCH_STACKDUMP=y CONFIG_BOARDCTL_RESET=y +CONFIG_BOARD_RESET_ON_ASSERT=1 CONFIG_BOARD_ASSERT_RESET_VALUE=1 CONFIG_BOARD_LOOPSPERMSEC=7982 CONFIG_BUILTIN=y From 66bf020a7643d782da7b241de2a046b638f8862a Mon Sep 17 00:00:00 2001 From: Augusto Fraga Giachero Date: Wed, 4 Mar 2020 09:51:53 -0300 Subject: [PATCH 3/5] Set firmware version to 'devel' when no tag matches When building on other branches than master, no tags are found. Set the firmware version to 'devel' instead of an empty string. --- make.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/make.sh b/make.sh index d9ac462..5e2f26c 100755 --- a/make.sh +++ b/make.sh @@ -9,7 +9,11 @@ git_hash_tag() { NUTTX_GIT_HASH=$(git describe --no-match --always --dirty --abbrev=40) cd .. RFFE_GIT_HASH=$(git describe --no-match --always --dirty --abbrev=40) - RFFE_GIT_TAG=$(git describe --exact-match --tags) + RFFE_GIT_TAG=$(git describe --exact-match --tags 2>/dev/null) + if [ -z "$RFFE_GIT_TAG" ]; then + RFFE_GIT_TAG="devel" + echo "Development build" + fi printf "/* Auto-generated file */\n\n#define APPS_GIT_HASH \"${APPS_GIT_HASH}\"\n#define NUTTX_GIT_HASH \"${NUTTX_GIT_HASH}\"\n#define RFFE_GIT_HASH \"${RFFE_GIT_HASH}\"\n#define RFFE_GIT_TAG \"${RFFE_GIT_TAG}\"\n" > rffe-app/git_version.h } From d43a1c1ccbe9a8a5c505c9d43eff9fed48c7731e Mon Sep 17 00:00:00 2001 From: Augusto Fraga Giachero Date: Wed, 4 Mar 2020 10:34:20 -0300 Subject: [PATCH 4/5] Fix build warnings [nuttx] --- nuttx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuttx b/nuttx index 4f632e2..c4ea466 160000 --- a/nuttx +++ b/nuttx @@ -1 +1 @@ -Subproject commit 4f632e2eba06991b1e286503170d483f037b3d1b +Subproject commit c4ea466caaa22def6d71c76b4c77ce01be8a97e4 From 7587af2799aba90fb77f81eeb39eb43f3d92d792 Mon Sep 17 00:00:00 2001 From: Augusto Fraga Giachero Date: Mon, 9 Mar 2020 08:20:01 -0300 Subject: [PATCH 5/5] Fix gdb scripts [scripts] Newer gdb versions have introduced the 'define-prefix' command making 'def' ambiguous, use 'define' instead. Set the watchdog flag before reseting the lpc1769 microcontroller to avoid entering the rom bootloader. Fix svd path assuming that gdb is executed from the nuttx directory. --- scripts/gdb/gdbinit | 11 ++++++----- scripts/gdb/pygdbinit | 13 +++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/gdb/gdbinit b/scripts/gdb/gdbinit index 167a64d..49c83dd 100644 --- a/scripts/gdb/gdbinit +++ b/scripts/gdb/gdbinit @@ -1,23 +1,24 @@ -def rst +define rst + set *((uint32_t*) 0x40000000) = 1 << 2 monitor reset halt end -def start_timer +define start_timer set *(unsigned int*)0xE000EDFC |= 0x01000000 set *(unsigned int*)0xE0001004 = 0 set *(unsigned int*)0xE0001000 = 1 end -def read_timer +define read_timer p *(unsigned int*)0xE0001004 end -def ldr +define ldr load rst end -def ldrc +define ldrc load rst c diff --git a/scripts/gdb/pygdbinit b/scripts/gdb/pygdbinit index 8e4a72f..a4a7c3c 100644 --- a/scripts/gdb/pygdbinit +++ b/scripts/gdb/pygdbinit @@ -1,23 +1,24 @@ -def rst +define rst + set *((uint32_t*) 0x40000000) = 1 << 2 monitor reset halt end -def start_timer +define start_timer set *(unsigned int*)0xE000EDFC |= 0x01000000 set *(unsigned int*)0xE0001004 = 0 set *(unsigned int*)0xE0001000 = 1 end -def read_timer +define read_timer p *(unsigned int*)0xE0001004 end -def ldr +define ldr load rst end -def ldrc +define ldrc load rst c @@ -34,5 +35,5 @@ LoadSVD() end -svd_load ./scripts/gdb/LPC176x5x_v0.2.svd +svd_load ../scripts/gdb/LPC176x5x_v0.2.svd