Skip to content

Commit

Permalink
FW upload compression support, TS5700N8501 support
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Dec 5, 2019
1 parent 3789c1a commit 23e6192
Show file tree
Hide file tree
Showing 72 changed files with 392 additions and 51 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
@@ -1,3 +1,11 @@
=== FW 3.63 ===
* NRF remote power meter is now unaffected by temperature decrease and speed limits.
* Added LZO compression support to firmware upload, making firmware updates 30% - 50% faster.
* Added LZO compression support to SWD upload.
* Made serial interrupts priority higher than PWM so that higher speed UART is possible.
* Added support for TS5700N8501 encoder (via COMM port).
* Better observer gain calculation.

=== FW 3.62 ===
* Added COMM_BM_MEM_READ.
* Merged EUC app (experimental).
Expand Down
5 changes: 4 additions & 1 deletion applications/app_custom_template.c
Expand Up @@ -29,6 +29,7 @@
#include "comm_can.h"
#include "hw.h"
#include "commands.h"
#include "timeout.h"

#include <math.h>
#include <string.h>
Expand Down Expand Up @@ -109,9 +110,11 @@ static THD_FUNCTION(my_thread, arg) {
return;
}

timeout_reset(); // Reset timeout if everything is OK.

// Run your logic here. A lot of functionality is available in mc_interface.h.

chThdSleepMicroseconds(10);
chThdSleepMilliseconds(10);
}
}

Expand Down
27 changes: 15 additions & 12 deletions applications/app_uartcomm.c
Expand Up @@ -129,10 +129,12 @@ void app_uartcomm_start_permanent(void) {
}

void app_uartcomm_stop(void) {
sdStop(&HW_UART_DEV);
palSetPadMode(HW_UART_TX_PORT, HW_UART_TX_PIN, PAL_MODE_INPUT_PULLUP);
palSetPadMode(HW_UART_RX_PORT, HW_UART_RX_PIN, PAL_MODE_INPUT_PULLUP);
uart_is_running = false;
if (uart_is_running) {
sdStop(&HW_UART_DEV);
palSetPadMode(HW_UART_TX_PORT, HW_UART_TX_PIN, PAL_MODE_INPUT_PULLUP);
palSetPadMode(HW_UART_RX_PORT, HW_UART_RX_PIN, PAL_MODE_INPUT_PULLUP);
uart_is_running = false;
}

// Notice that the processing thread is kept running in case this call is made from it.
}
Expand All @@ -151,9 +153,8 @@ void app_uartcomm_send_packet(unsigned char *data, unsigned int len) {
void app_uartcomm_configure(uint32_t baudrate, bool permanent_enabled) {
uart_cfg.speed = baudrate;

if (thread_is_running) {
if (thread_is_running && uart_is_running) {
sdStart(&HW_UART_DEV, &uart_cfg);
uart_is_running = true;
}

#ifdef HW_UART_P_DEV
Expand Down Expand Up @@ -193,17 +194,19 @@ static THD_FUNCTION(packet_process_thread, arg) {
while (rx) {
rx = false;

msg_t res = sdGetTimeout(&HW_UART_DEV, TIME_IMMEDIATE);
if (res != MSG_TIMEOUT) {
if (uart_is_running) {
msg_t res = sdGetTimeout(&HW_UART_DEV, TIME_IMMEDIATE);
if (res != MSG_TIMEOUT) {
#ifdef HW_UART_P_DEV
from_p_uart = false;
from_p_uart = false;
#endif
packet_process_byte(res, PACKET_HANDLER);
rx = true;
packet_process_byte(res, PACKET_HANDLER);
rx = true;
}
}

#ifdef HW_UART_P_DEV
res = sdGetTimeout(&HW_UART_P_DEV, TIME_IMMEDIATE);
msg_t res = sdGetTimeout(&HW_UART_P_DEV, TIME_IMMEDIATE);
if (res != MSG_TIMEOUT) {
from_p_uart = true;
packet_process_byte(res, PACKET_HANDLER_P);
Expand Down
Binary file modified build_all/410_o_411_o_412/VESC_0005ohm.bin
Binary file not shown.
Binary file modified build_all/410_o_411_o_412/VESC_default.bin
Binary file not shown.
Binary file modified build_all/410_o_411_o_412/VESC_default_no_hw_limits.bin
Binary file not shown.
Binary file modified build_all/410_o_411_o_412/VESC_servoout.bin
Binary file not shown.
Binary file modified build_all/410_o_411_o_412/VESC_ws2811.bin
Binary file not shown.
Binary file modified build_all/46_o_47/VESC_0005ohm.bin
Binary file not shown.
Binary file modified build_all/46_o_47/VESC_33k.bin
Binary file not shown.
Binary file modified build_all/46_o_47/VESC_default.bin
Binary file not shown.
Binary file modified build_all/46_o_47/VESC_servoout.bin
Binary file not shown.
Binary file modified build_all/46_o_47/VESC_ws2811.bin
Binary file not shown.
Binary file modified build_all/46_o_47/VESC_ws2811_33k.bin
Binary file not shown.
Binary file modified build_all/48/VESC_0005ohm.bin
Binary file not shown.
Binary file modified build_all/48/VESC_default.bin
Binary file not shown.
Binary file modified build_all/48/VESC_servoout.bin
Binary file not shown.
Binary file modified build_all/48/VESC_ws2811.bin
Binary file not shown.
Binary file modified build_all/60/VESC_default.bin
Binary file not shown.
Binary file modified build_all/60/VESC_default_no_hw_limits.bin
Binary file not shown.
Binary file modified build_all/60/VESC_servoout.bin
Binary file not shown.
Binary file modified build_all/60/VESC_ws2811.bin
Binary file not shown.
Binary file modified build_all/75_300/VESC_default.bin
Binary file not shown.
Binary file modified build_all/75_300/VESC_default_no_hw_limits.bin
Binary file not shown.
Binary file modified build_all/75_300/VESC_servoout.bin
Binary file not shown.
Binary file modified build_all/75_300/VESC_ws2811.bin
Binary file not shown.
Binary file modified build_all/75_300_R2/VESC_default.bin
Binary file not shown.
Binary file modified build_all/75_300_R2/VESC_default_no_hw_limits.bin
Binary file not shown.
Binary file modified build_all/75_300_R2/VESC_servoout.bin
Binary file not shown.
Binary file modified build_all/75_300_R2/VESC_ws2811.bin
Binary file not shown.
Binary file modified build_all/A200S_V21/VESC_default.bin
Binary file not shown.
Binary file modified build_all/A200S_V22/VESC_default.bin
Binary file not shown.
Binary file modified build_all/AXIOM/VESC_default.bin
Binary file not shown.
Binary file modified build_all/DAS_RS/VESC_default.bin
Binary file not shown.
Binary file modified build_all/HD/VESC_default.bin
Binary file not shown.
Binary file modified build_all/HD/VESC_default_no_hw_limits.bin
Binary file not shown.
Binary file modified build_all/HD/VESC_servoout.bin
Binary file not shown.
Binary file modified build_all/HD/VESC_ws2811.bin
Binary file not shown.
Binary file modified build_all/UAVC_OMEGA/VESC_default.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion chconf.h
Expand Up @@ -29,7 +29,7 @@
#define _CHCONF_H_

#define CHPRINTF_USE_FLOAT TRUE
#define CORTEX_SIMPLIFIED_PRIORITY FALSE
#define CORTEX_SIMPLIFIED_PRIORITY TRUE
#define PORT_IDLE_THREAD_STACK_SIZE 64
#define PORT_INT_REQUIRED_STACK 128

Expand Down
36 changes: 35 additions & 1 deletion commands.c
Expand Up @@ -45,6 +45,7 @@
#if HAS_BLACKMAGIC
#include "bm_if.h"
#endif
#include "minilzo.h"

#include <math.h>
#include <string.h>
Expand Down Expand Up @@ -222,16 +223,39 @@ void commands_process_packet(unsigned char *data, unsigned int len,
reply_func(send_buffer, ind);
} break;

case COMM_WRITE_NEW_APP_DATA_ALL_CAN_LZO:
case COMM_WRITE_NEW_APP_DATA_ALL_CAN:
if (packet_id == COMM_WRITE_NEW_APP_DATA_ALL_CAN_LZO) {
chMtxLock(&send_buffer_mutex);
memcpy(send_buffer_global, data + 6, len - 6);
int32_t ind = 4;
lzo_uint decompressed_len = buffer_get_uint16(data, &ind);
lzo1x_decompress_safe(send_buffer_global, len - 6, data + 4, &decompressed_len, NULL);
chMtxUnlock(&send_buffer_mutex);
len = decompressed_len + 4;
}

if (nrf_driver_ext_nrf_running()) {
nrf_driver_pause(2000);
}

data[-1] = COMM_WRITE_NEW_APP_DATA;

comm_can_send_buffer(255, data - 1, len + 1, 2);
/* Falls through. */
/* no break */
case COMM_WRITE_NEW_APP_DATA_LZO:
case COMM_WRITE_NEW_APP_DATA: {
if (packet_id == COMM_WRITE_NEW_APP_DATA_LZO) {
chMtxLock(&send_buffer_mutex);
memcpy(send_buffer_global, data + 6, len - 6);
int32_t ind = 4;
lzo_uint decompressed_len = buffer_get_uint16(data, &ind);
lzo1x_decompress_safe(send_buffer_global, len - 6, data + 4, &decompressed_len, NULL);
chMtxUnlock(&send_buffer_mutex);
len = decompressed_len + 4;
}

int32_t ind = 0;
uint32_t new_app_offset = buffer_get_uint32(data, &ind);

Expand Down Expand Up @@ -948,6 +972,7 @@ void commands_process_packet(unsigned char *data, unsigned int len,
case COMM_PING_CAN:
case COMM_BM_CONNECT:
case COMM_BM_ERASE_FLASH_ALL:
case COMM_BM_WRITE_FLASH_LZO:
case COMM_BM_WRITE_FLASH:
case COMM_BM_REBOOT:
case COMM_BM_DISCONNECT:
Expand Down Expand Up @@ -1162,7 +1187,7 @@ static THD_FUNCTION(blocking_thread, arg) {

COMM_PACKET_ID packet_id;
static mc_configuration mcconf, mcconf_old;
static uint8_t send_buffer[384];
static uint8_t send_buffer[512];

packet_id = data[0];
data++;
Expand Down Expand Up @@ -1410,7 +1435,16 @@ static THD_FUNCTION(blocking_thread, arg) {
}
} break;

case COMM_BM_WRITE_FLASH_LZO:
case COMM_BM_WRITE_FLASH: {
if (packet_id == COMM_BM_WRITE_FLASH_LZO) {
memcpy(send_buffer, data + 6, len - 6);
int32_t ind = 4;
lzo_uint decompressed_len = buffer_get_uint16(data, &ind);
lzo1x_decompress_safe(send_buffer, len - 6, data + 4, &decompressed_len, NULL);
len = decompressed_len + 4;
}

int32_t ind = 0;
uint32_t addr = buffer_get_uint32(data, &ind);

Expand Down
8 changes: 4 additions & 4 deletions conf_general.c
Expand Up @@ -798,8 +798,8 @@ bool conf_general_measure_flux_linkage_openloop(float current, float duty,
const int max_time = 15000;

while (fabsf(mc_interface_get_duty_cycle_now()) < duty) {
mcpwm_foc_set_openloop(current, mcconf.m_invert_direction ? -rpm_now : rpm_now);
rpm_now += erpm_per_sec / 1000.0;
mcpwm_foc_set_openloop(current, mcconf.m_invert_direction ? -rpm_now : rpm_now);

chThdSleepMilliseconds(1);
cnt++;
Expand Down Expand Up @@ -841,13 +841,13 @@ bool conf_general_measure_flux_linkage_openloop(float current, float duty,
float id_avg = 0.0;
float samples2 = 0.0;

for (int i = 0;i < 1000;i++) {
for (int i = 0;i < 30000;i++) {
vq_avg += mcpwm_foc_get_vq();
vd_avg += mcpwm_foc_get_vd();
iq_avg += mcpwm_foc_get_iq();
id_avg += mcpwm_foc_get_id();
samples2 += 1.0;
chThdSleepMilliseconds(1);
chThdSleep(1);
}

vq_avg /= samples2;
Expand Down Expand Up @@ -1131,7 +1131,7 @@ int conf_general_detect_apply_all_foc(float max_power_loss,
float bw = 1.0 / (tc * 1e-6);
float kp = l * bw;
float ki = r * bw;
float gain = 0.001 / (lambda * lambda);
float gain = (0.00001 / r) / (lambda * lambda);

mcconf_old.motor_type = MOTOR_TYPE_FOC;
mcconf_old.foc_motor_r = r;
Expand Down
11 changes: 6 additions & 5 deletions conf_general.h
Expand Up @@ -22,7 +22,7 @@

// Firmware version
#define FW_VERSION_MAJOR 3
#define FW_VERSION_MINOR 62
#define FW_VERSION_MINOR 63

#include "datatypes.h"

Expand Down Expand Up @@ -151,14 +151,15 @@
//#include "appconf_custom.h"
//#include "appconf_ellwee.h"

#include "hw.h"
#include "mcconf_default.h"
#include "appconf_default.h"

/*
* Set APP_CUSTOM_TO_USE to the name of the main C file of the custom application.
*/
//#define APP_CUSTOM_TO_USE "app_custom_template.c"
//#include "app_erockit_conf.h"

#include "hw.h"
#include "mcconf_default.h"
#include "appconf_default.h"

/*
* Enable blackmagic probe output on SWD port
Expand Down
2 changes: 1 addition & 1 deletion confgenerator.h
Expand Up @@ -8,7 +8,7 @@
#include <stdbool.h>

// Constants
#define MCCONF_SIGNATURE 503309878
#define MCCONF_SIGNATURE 3875075384
#define APPCONF_SIGNATURE 783041200

// Functions
Expand Down
6 changes: 5 additions & 1 deletion datatypes.h
Expand Up @@ -129,7 +129,8 @@ typedef enum {
SENSOR_PORT_MODE_ABI,
SENSOR_PORT_MODE_AS5047_SPI,
SENSOR_PORT_MODE_AD2S1205,
SENSOR_PORT_MODE_SINCOS
SENSOR_PORT_MODE_SINCOS,
SENSOR_PORT_MODE_TS5700N8501
} sensor_port_mode;

typedef struct {
Expand Down Expand Up @@ -687,6 +688,9 @@ typedef enum {
COMM_PLOT_SET_GRAPH,
COMM_GET_DECODED_BALANCE,
COMM_BM_MEM_READ,
COMM_WRITE_NEW_APP_DATA_LZO,
COMM_WRITE_NEW_APP_DATA_ALL_CAN_LZO,
COMM_BM_WRITE_FLASH_LZO
} COMM_PACKET_ID;

// CAN commands
Expand Down

0 comments on commit 23e6192

Please sign in to comment.