Updated linker script and flash helpers to get 128k extra code space. Note that this requires the updated bootloader with compression support.

This commit is contained in:
Benjamin Vedder 2022-01-18 20:31:24 +01:00
parent f74019c940
commit f6baa653ea
7 changed files with 73 additions and 60 deletions

View File

@ -1,3 +1,6 @@
=== FW 6.00 <dev> ===
* Added stack checks.
=== FW 5.03 === === FW 5.03 ===
* Fixed inductance measurement bug. * Fixed inductance measurement bug.
* Speed tracker windup protection. * Speed tracker windup protection.

View File

@ -252,8 +252,8 @@ void commands_process_packet(unsigned char *data, unsigned int len,
send_buffer[ind++] = 1; send_buffer[ind++] = 1;
#endif #endif
#else #else
if (flash_helper_qmlui_data()) { if (flash_helper_code_data(CODE_IND_QML)) {
send_buffer[ind++] = flash_helper_qmlui_flags(); send_buffer[ind++] = flash_helper_code_flags(CODE_IND_QML);
} else { } else {
send_buffer[ind++] = 0; send_buffer[ind++] = 0;
} }
@ -1372,8 +1372,8 @@ void commands_process_packet(unsigned char *data, unsigned int len,
int32_t len_qml = buffer_get_int32(data, &ind); int32_t len_qml = buffer_get_int32(data, &ind);
int32_t ofs_qml = buffer_get_int32(data, &ind); int32_t ofs_qml = buffer_get_int32(data, &ind);
uint8_t *qmlui_data = flash_helper_qmlui_data(); uint8_t *qmlui_data = flash_helper_code_data(CODE_IND_QML);
int32_t qmlui_len = flash_helper_qmlui_size(); int32_t qmlui_len = flash_helper_code_size(CODE_IND_QML);
#ifdef QMLUI_SOURCE_APP #ifdef QMLUI_SOURCE_APP
qmlui_data = data_qml_app; qmlui_data = data_qml_app;
@ -1406,7 +1406,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
if (nrf_driver_ext_nrf_running()) { if (nrf_driver_ext_nrf_running()) {
nrf_driver_pause(6000); nrf_driver_pause(6000);
} }
uint16_t flash_res = flash_helper_erase_qmlui(); uint16_t flash_res = flash_helper_erase_code(CODE_IND_QML);
ind = 0; ind = 0;
uint8_t send_buffer[50]; uint8_t send_buffer[50];
@ -1422,7 +1422,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
if (nrf_driver_ext_nrf_running()) { if (nrf_driver_ext_nrf_running()) {
nrf_driver_pause(2000); nrf_driver_pause(2000);
} }
uint16_t flash_res = flash_helper_write_qmlui(qmlui_offset, data + ind, len - ind); uint16_t flash_res = flash_helper_write_code(CODE_IND_QML, qmlui_offset, data + ind, len - ind);
SHUTDOWN_RESET(); SHUTDOWN_RESET();

View File

@ -24,7 +24,7 @@
#define FW_VERSION_MAJOR 6 #define FW_VERSION_MAJOR 6
#define FW_VERSION_MINOR 00 #define FW_VERSION_MINOR 00
// Set to 0 for building a release and iterate during beta test builds // Set to 0 for building a release and iterate during beta test builds
#define FW_TEST_VERSION_NUMBER 1 #define FW_TEST_VERSION_NUMBER 2
#include "datatypes.h" #include "datatypes.h"

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2016 - 2021 Benjamin Vedder benjamin@vedder.se Copyright 2016 - 2022 Benjamin Vedder benjamin@vedder.se
This file is part of the VESC firmware. This file is part of the VESC firmware.
@ -37,9 +37,11 @@
#define APP_BASE 0 #define APP_BASE 0
#define NEW_APP_BASE 8 #define NEW_APP_BASE 8
#define NEW_APP_SECTORS 3 #define NEW_APP_SECTORS 3
#define APP_MAX_SIZE (1024 * 128 * 3 - 8) // Note that the bootloader needs 8 extra bytes #define APP_MAX_SIZE (1024 * 128 * 4 - 8) // Note that the bootloader needs 8 extra bytes
#define QMLUI_BASE 7 #define QMLUI_BASE 9
#define LISP_BASE 10
#define QMLUI_MAX_SIZE (1024 * 128 - 8) #define QMLUI_MAX_SIZE (1024 * 128 - 8)
#define LISP_MAX_SIZE (1024 * 128 - 8)
// Base address of the Flash sectors // Base address of the Flash sectors
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) // Base @ of Sector 0, 16 Kbytes #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) // Base @ of Sector 0, 16 Kbytes
@ -77,11 +79,16 @@ const crc_info_t __attribute__((section (".crcinfo"))) crc_info = {0xFFFFFFFF, 0
// Private functions // Private functions
static uint16_t erase_sector(uint32_t sector); static uint16_t erase_sector(uint32_t sector);
static uint16_t write_data(uint32_t base, uint8_t *data, uint32_t len); static uint16_t write_data(uint32_t base, uint8_t *data, uint32_t len);
static void qmlui_check(void); static void qmlui_check(int ind);
// Private variables // Private variables
static bool qmlui_check_done = false; typedef struct {
static bool qmlui_ok = false; bool check_done;
bool ok;
} _code_checks;
static _code_checks code_checks[2] = {0};
static int code_sectors[2] = {QMLUI_BASE, LISP_BASE};
// Private constants // Private constants
static const uint32_t flash_addr[FLASH_SECTORS] = { static const uint32_t flash_addr[FLASH_SECTORS] = {
@ -161,47 +168,47 @@ uint16_t flash_helper_write_new_app_data(uint32_t offset, uint8_t *data, uint32_
return write_data(flash_addr[NEW_APP_BASE] + offset, data, len); return write_data(flash_addr[NEW_APP_BASE] + offset, data, len);
} }
uint16_t flash_helper_erase_qmlui(void) { uint16_t flash_helper_erase_code(int ind) {
qmlui_check_done = false; code_checks[ind].check_done = false;
qmlui_ok = false; code_checks[ind].ok = false;
return erase_sector(flash_sector[QMLUI_BASE]); return erase_sector(flash_sector[code_sectors[ind]]);
} }
uint16_t flash_helper_write_qmlui(uint32_t offset, uint8_t *data, uint32_t len) { uint16_t flash_helper_write_code(int ind, uint32_t offset, uint8_t *data, uint32_t len) {
qmlui_check_done = false; code_checks[ind].check_done = false;
qmlui_ok = false; code_checks[ind].ok = false;
return write_data(flash_addr[QMLUI_BASE] + offset, data, len); return write_data(flash_addr[code_sectors[ind]] + offset, data, len);
} }
uint8_t *flash_helper_qmlui_data(void) { uint8_t* flash_helper_code_data(int ind) {
qmlui_check(); qmlui_check(ind);
if (qmlui_check_done && qmlui_ok) { if (code_checks[ind].check_done && code_checks[ind].ok) {
return (uint8_t*)(flash_addr[QMLUI_BASE]) + 8; return (uint8_t*)(flash_addr[code_sectors[ind]]) + 8;
} else { } else {
return 0; return 0;
} }
} }
uint32_t flash_helper_qmlui_size(void) { uint32_t flash_helper_code_size(int ind) {
qmlui_check(); qmlui_check(ind);
if (qmlui_check_done && qmlui_ok) { if (code_checks[ind].check_done && code_checks[ind].ok) {
uint8_t *qmlui_base = (uint8_t*)(flash_addr[QMLUI_BASE]); uint8_t *base = (uint8_t*)(flash_addr[code_sectors[ind]]);
int32_t ind = 0; int32_t index = 0;
return buffer_get_uint32(qmlui_base, &ind); return buffer_get_uint32(base, &index);
} else { } else {
return 0; return 0;
} }
} }
uint16_t flash_helper_qmlui_flags(void) { uint16_t flash_helper_code_flags(int ind) {
qmlui_check(); qmlui_check(ind);
if (qmlui_check_done && qmlui_ok) { if (code_checks[ind].check_done && code_checks[ind].ok) {
uint8_t *qmlui_base = (uint8_t*)(flash_addr[QMLUI_BASE]); uint8_t *base = (uint8_t*)(flash_addr[code_sectors[ind]]);
int32_t ind = 6; int32_t index = 6;
return buffer_get_uint16(qmlui_base, &ind); return buffer_get_uint16(base, &index);
} else { } else {
return 0; return 0;
} }
@ -431,22 +438,22 @@ static uint16_t write_data(uint32_t base, uint8_t *data, uint32_t len) {
return FLASH_COMPLETE; return FLASH_COMPLETE;
} }
static void qmlui_check(void) { static void qmlui_check(int ind) {
if (qmlui_check_done) { if (code_checks[ind].check_done) {
return; return;
} }
uint8_t *qmlui_base = (uint8_t*)(flash_addr[QMLUI_BASE]); uint8_t *base = (uint8_t*)(flash_addr[code_sectors[ind]]);
int32_t ind = 0; int32_t index = 0;
uint32_t qmlui_len = buffer_get_uint32(qmlui_base, &ind); uint32_t qmlui_len = buffer_get_uint32(base, &index);
uint16_t qmlui_crc = buffer_get_uint16(qmlui_base, &ind); uint16_t qmlui_crc = buffer_get_uint16(base, &index);
if (qmlui_len <= QMLUI_MAX_SIZE) { if (qmlui_len <= QMLUI_MAX_SIZE) {
uint16_t crc_calc = crc16(qmlui_base + ind, qmlui_len + 2); // CRC includes the 2 byte flags uint16_t crc_calc = crc16(base + index, qmlui_len + 2); // CRC includes the 2 byte flags
qmlui_ok = crc_calc == qmlui_crc; code_checks[ind].ok = crc_calc == qmlui_crc;
} else { } else {
qmlui_ok = false; code_checks[ind].ok = false;
} }
qmlui_check_done = true; code_checks[ind].check_done = true;
} }

View File

@ -22,16 +22,19 @@
#include "conf_general.h" #include "conf_general.h"
#define CODE_IND_QML 0
#define CODE_IND_LISP 1
// Functions // Functions
uint16_t flash_helper_erase_new_app(uint32_t new_app_size); uint16_t flash_helper_erase_new_app(uint32_t new_app_size);
uint16_t flash_helper_erase_bootloader(void); uint16_t flash_helper_erase_bootloader(void);
uint16_t flash_helper_write_new_app_data(uint32_t offset, uint8_t *data, uint32_t len); uint16_t flash_helper_write_new_app_data(uint32_t offset, uint8_t *data, uint32_t len);
uint16_t flash_helper_erase_qmlui(void); uint16_t flash_helper_erase_code(int ind);
uint16_t flash_helper_write_qmlui(uint32_t offset, uint8_t *data, uint32_t len); uint16_t flash_helper_write_code(int ind, uint32_t offset, uint8_t *data, uint32_t len);
uint8_t *flash_helper_qmlui_data(void); uint8_t* flash_helper_code_data(int ind);
uint32_t flash_helper_qmlui_size(void); uint32_t flash_helper_code_size(int ind);
uint16_t flash_helper_qmlui_flags(void); uint16_t flash_helper_code_flags(int ind);
void flash_helper_jump_to_bootloader(void); void flash_helper_jump_to_bootloader(void);
uint8_t* flash_helper_get_sector_address(uint32_t fsector); uint8_t* flash_helper_get_sector_address(uint32_t fsector);

View File

@ -26,8 +26,8 @@
MEMORY MEMORY
{ {
flash : org = 0x08000000, len = 16k flash : org = 0x08000000, len = 16k
flash2 : org = 0x0800C000, len = 393216 - 16 /* NEW_APP_MAX_SIZE - CRC_INFO */ flash2 : org = 0x0800C000, len = 524288 - 16 /* NEW_APP_MAX_SIZE - CRC_INFO */
crcinfo : org = 0x0805FFF0, len = 8 /* CRC info */ crcinfo : org = 0x0807FFF0, len = 8 /* CRC info */
ram0 : org = 0x20000000, len = 128k /* SRAM1 + SRAM2 */ ram0 : org = 0x20000000, len = 128k /* SRAM1 + SRAM2 */
ram1 : org = 0x20000000, len = 112k /* SRAM1 */ ram1 : org = 0x20000000, len = 112k /* SRAM1 */
ram2 : org = 0x2001C000, len = 16k /* SRAM2 */ ram2 : org = 0x2001C000, len = 16k /* SRAM2 */
@ -146,7 +146,7 @@ SECTIONS
_etext = .; _etext = .;
_textdata = _etext; _textdata = _etext;
_crcinfo_start_address = 0x0805FFF0; _crcinfo_start_address = 0x0807FFF0;
.crcinfo _crcinfo_start_address : .crcinfo _crcinfo_start_address :
{ {

View File

@ -33,12 +33,12 @@
#include "lispbm.h" #include "lispbm.h"
#define HEAP_SIZE 1024 #define HEAP_SIZE 1024
#define LISP_MEM_SIZE MEMORY_SIZE_4K #define LISP_MEM_SIZE MEMORY_SIZE_8K
#define LISP_MEM_BITMAP_SIZE MEMORY_BITMAP_SIZE_4K #define LISP_MEM_BITMAP_SIZE MEMORY_BITMAP_SIZE_8K
__attribute__((section(".ram4"))) static cons_t heap[HEAP_SIZE] __attribute__ ((aligned (8))); __attribute__((section(".ram4"))) static cons_t heap[HEAP_SIZE] __attribute__ ((aligned (8)));
__attribute__((section(".ram4"))) static uint32_t memory_array[LISP_MEM_SIZE]; static uint32_t memory_array[LISP_MEM_SIZE];
__attribute__((section(".ram4"))) static uint32_t bitmap_array[LISP_MEM_BITMAP_SIZE]; static uint32_t bitmap_array[LISP_MEM_BITMAP_SIZE];
static thread_t *eval_tp = 0; static thread_t *eval_tp = 0;
static THD_WORKING_AREA(eval_thread_wa, 2048); static THD_WORKING_AREA(eval_thread_wa, 2048);
@ -64,7 +64,7 @@ static void terminal_start(int argc, const char **argv) {
(void)argc; (void)argc;
(void)argv; (void)argv;
char *code = (char*)(0x08060000); char *code = (char*)(0x080A0000);
if (!lisp_thd_running) { if (!lisp_thd_running) {
lispbm_init(heap, HEAP_SIZE, memory_array, LISP_MEM_SIZE, bitmap_array, LISP_MEM_BITMAP_SIZE); lispbm_init(heap, HEAP_SIZE, memory_array, LISP_MEM_SIZE, bitmap_array, LISP_MEM_BITMAP_SIZE);