Skip to content

Commit

Permalink
FW 3.66: Many changes, see changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Jan 12, 2020
1 parent 210ec40 commit b002e5d
Show file tree
Hide file tree
Showing 71 changed files with 892 additions and 114 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
=== FW 3.66 ===
* Added support for HW 100/250.
* Added uptime terminal command.
* Added some delays to DRV8323s SPI driver.
* Added SWD support for NRF52840 with idcode 0x015B.
- TODO: Have a look at https://github.com/blacksphere/blackmagic/commit/302ff20a6d5b806c09e0ca7e996beab3ef3596f4.
* Fixed INVERTED_SHUNT_POLARITY for BLDC.
* Added decoupling to FOC current controller.
* Better motor tracking at high ERPM and low Fsw.
* Made uart and permanent uart more independent.
* Do not write to USB if cable has not been connected.
* Added timeout to USB write.
* Better FOC current control integrator windup protection.
* Added FOC observer type selection options.
* Print TS5700N8501 position in encoder terminal command.

=== FW 3.65 ===
* Added support for PTC motor temperature sensor (e.g. KTY84)
* APP_PPM sleep fix. Should solve CAN issues.
Expand Down
1 change: 1 addition & 0 deletions applications/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void app_uartcomm_start_permanent(void);
void app_uartcomm_stop(void);
void app_uartcomm_configure(uint32_t baudrate, bool permanent_enabled);
void app_uartcomm_send_packet(unsigned char *data, unsigned int len);
void app_uartcomm_send_packet_p(unsigned char *data, unsigned int len);

void app_nunchuk_start(void);
void app_nunchuk_stop(void);
Expand Down
59 changes: 43 additions & 16 deletions applications/app_uartcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@ static volatile bool uart_is_running = false;
static mutex_t send_mutex;
static bool send_mutex_init_done = false;

#ifdef HW_UART_P_DEV
static mutex_t send_mutex_p;
static bool send_mutex_p_init_done = false;
#endif

// Private functions
static void process_packet(unsigned char *data, unsigned int len);
static void send_packet(unsigned char *data, unsigned int len);

#ifdef HW_UART_P_DEV
static void process_packet_p(unsigned char *data, unsigned int len);
static void send_packet_p(unsigned char *data, unsigned int len);
#endif

static SerialConfig uart_cfg = {
BAUDRATE,
0,
Expand All @@ -67,27 +77,29 @@ static void process_packet(unsigned char *data, unsigned int len) {
commands_process_packet(data, len, app_uartcomm_send_packet);
}

static void send_packet(unsigned char *data, unsigned int len) {
#ifdef HW_UART_P_DEV
if (from_p_uart) {
if (uart_p_is_running) {
#ifdef HW_UART_P_DEV_TX
sdWrite(&HW_UART_P_DEV_TX, data, len);
#else
sdWrite(&HW_UART_P_DEV, data, len);
static void process_packet_p(unsigned char *data, unsigned int len) {
commands_process_packet(data, len, app_uartcomm_send_packet_p);
}
#endif
}
} else {
if (uart_is_running) {
sdWrite(&HW_UART_DEV, data, len);
}
}
#else

static void send_packet(unsigned char *data, unsigned int len) {
if (uart_is_running) {
sdWrite(&HW_UART_DEV, data, len);
}
}

#ifdef HW_UART_P_DEV
static void send_packet_p(unsigned char *data, unsigned int len) {
if (uart_p_is_running) {
#ifdef HW_UART_P_DEV_TX
sdWrite(&HW_UART_P_DEV_TX, data, len);
#else
sdWrite(&HW_UART_P_DEV, data, len);
#endif
}
}
#endif

void app_uartcomm_start(void) {
packet_init(send_packet, process_packet, PACKET_HANDLER);
Expand All @@ -111,8 +123,7 @@ void app_uartcomm_start(void) {

void app_uartcomm_start_permanent(void) {
#ifdef HW_UART_P_DEV
packet_init(send_packet, process_packet, PACKET_HANDLER);
packet_init(send_packet, process_packet, PACKET_HANDLER_P);
packet_init(send_packet_p, process_packet_p, PACKET_HANDLER_P);

if (!thread_is_running) {
chThdCreateStatic(packet_process_thread_wa, sizeof(packet_process_thread_wa),
Expand Down Expand Up @@ -159,6 +170,22 @@ void app_uartcomm_send_packet(unsigned char *data, unsigned int len) {
chMtxUnlock(&send_mutex);
}

void app_uartcomm_send_packet_p(unsigned char *data, unsigned int len) {
#ifdef HW_UART_P_DEV
if (!send_mutex_p_init_done) {
chMtxObjectInit(&send_mutex_p);
send_mutex_p_init_done = true;
}

chMtxLock(&send_mutex_p);
packet_send_packet(data, len, PACKET_HANDLER_P);
chMtxUnlock(&send_mutex_p);
#else
(void)data;
(void)len;
#endif
}

void app_uartcomm_configure(uint32_t baudrate, bool permanent_enabled) {
uart_cfg.speed = baudrate;

Expand Down
4 changes: 4 additions & 0 deletions blackmagic/bm_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ static int idcode_to_device(uint32_t idcode) {
ret = 7; break;
case 0x00EB: /* nRF52840 Preview QIAA AA0 */
case 0x0150: /* nRF52840 QIAA C0 */
case 0x015B: /* nRF52840 ?? */
ret = 8; break;
default: ret = -2; break;
}
Expand Down Expand Up @@ -362,6 +363,9 @@ int bm_connect(void) {

if (cur_target) {
ret = idcode_to_device(target_idcode(cur_target));
if (ret < 0) {
commands_printf("Unknown idcode: 0x%04X\n", target_idcode(cur_target));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions blackmagic/target/nrf51.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ bool nrf51_probe(target *t)
return true;
case 0x00EB: /* nRF52840 Preview QIAA AA0 */
case 0x0150: /* nRF52840 QIAA C0 */
case 0x015B: /* nRF52840 ?? */
t->driver = "Nordic nRF52";
target_add_ram(t, 0x20000000, 256*1024);
nrf51_add_flash(t, 0x00000000, 1024*1024, NRF52_PAGE_SIZE);
Expand Down
Binary file added build_all/100_250/VESC_default.bin
Binary file not shown.
Binary file added build_all/100_250/VESC_default_no_hw_limits.bin
Binary file not shown.
Binary file added build_all/100_250/VESC_servoout.bin
Binary file not shown.
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/60_MK3/VESC_default.bin
Binary file not shown.
Binary file modified build_all/60_MK3/VESC_default_no_hw_limits.bin
Binary file not shown.
Binary file modified build_all/60_MK3/VESC_servoout.bin
Binary file not shown.
Binary file modified build_all/60_MK3/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.
31 changes: 31 additions & 0 deletions build_all/rebuild_all
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,34 @@ cd $FWPATH
make clean
cd $DIR

#################### HW 100_250 ########################

COPYDIR=100_250
rm -f $COPYDIR/*

# default
cd $FWPATH
touch conf_general.h
make -j8 build_args='-DHW_SOURCE=\"hw_100_250.c\" -DHW_HEADER=\"hw_100_250.h\"' USE_VERBOSE_COMPILE=no
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default.bin

# default with HW limits disables
cd $FWPATH
touch conf_general.h
make -j8 build_args='-DDISABLE_HW_LIMITS -DHW_SOURCE=\"hw_100_250.c\" -DHW_HEADER=\"hw_100_250.h\"' USE_VERBOSE_COMPILE=no
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default_no_hw_limits.bin

# servoout
cd $FWPATH
touch conf_general.h
make -j8 build_args='-DSERVO_OUT_ENABLE=1 -DHW_SOURCE=\"hw_100_250.c\" -DHW_HEADER=\"hw_100_250.h\"' USE_VERBOSE_COMPILE=no
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_servoout.bin

# Clean
cd $FWPATH
make clean
cd $DIR

34 changes: 29 additions & 5 deletions comm_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
static uint8_t serial_rx_buffer[SERIAL_RX_BUFFER_SIZE];
static int serial_rx_read_pos = 0;
static int serial_rx_write_pos = 0;
static THD_WORKING_AREA(serial_read_thread_wa, 256);
static THD_WORKING_AREA(serial_read_thread_wa, 128);
static THD_WORKING_AREA(serial_process_thread_wa, 4096);
static mutex_t send_mutex;
static thread_t *process_tp;
static volatile unsigned int write_timeout_cnt = 0;

// Private functions
static void process_packet(unsigned char *data, unsigned int len);
Expand All @@ -44,9 +45,9 @@ static void send_packet_raw(unsigned char *buffer, unsigned int len);
static THD_FUNCTION(serial_read_thread, arg) {
(void)arg;

chRegSetThreadName("USB-Serial read");
chRegSetThreadName("USB read");

uint8_t buffer[128];
uint8_t buffer[2];
int had_data = 0;

for(;;) {
Expand All @@ -72,7 +73,7 @@ static THD_FUNCTION(serial_read_thread, arg) {
static THD_FUNCTION(serial_process_thread, arg) {
(void)arg;

chRegSetThreadName("USB-Serial process");
chRegSetThreadName("USB process");

process_tp = chThdGetSelfX();

Expand All @@ -94,7 +95,26 @@ static void process_packet(unsigned char *data, unsigned int len) {
}

static void send_packet_raw(unsigned char *buffer, unsigned int len) {
chSequentialStreamWrite(&SDU1, buffer, len);
static bool was_timeout = false;

/*
* Only write to USB if the cable has been connected at least once. If a timeout occurs
* make sure that this call does not stall on the next call, as the timeout probably occured
* because noone is listening on the USB.
*/
if (comm_usb_serial_configured_cnt() > 0) {
unsigned int written = 0;
if (was_timeout) {
written = SDU1.vmt->writet(&SDU1, buffer, len, TIME_IMMEDIATE);
} else {
written = SDU1.vmt->writet(&SDU1, buffer, len, MS2ST(100));
}

was_timeout = written != len;
if (was_timeout) {
write_timeout_cnt++;
}
}
}

void comm_usb_init(void) {
Expand All @@ -113,3 +133,7 @@ void comm_usb_send_packet(unsigned char *data, unsigned int len) {
packet_send_packet(data, len, PACKET_HANDLER);
chMtxUnlock(&send_mutex);
}

unsigned int comm_usb_get_write_timeout_cnt(void) {
return write_timeout_cnt;
}
1 change: 1 addition & 0 deletions comm_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
// Functions
void comm_usb_init(void);
void comm_usb_send_packet(unsigned char *data, unsigned int len);
unsigned int comm_usb_get_write_timeout_cnt(void);

#endif /* COMM_USB_H_ */
10 changes: 9 additions & 1 deletion comm_usb_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,12 @@ static const USBEndpointConfig ep2config = {
NULL
};

static volatile int configured_cnt = 0;

/*
* Handles the USB driver global events.
*/
static void usb_event(USBDriver *usbp, usbevent_t event) {

switch (event) {
case USB_EVENT_RESET:
return;
Expand All @@ -273,6 +274,7 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
sduConfigureHookI(&SDU1);

chSysUnlockFromISR();
configured_cnt++;
return;
case USB_EVENT_SUSPEND:
return;
Expand Down Expand Up @@ -331,3 +333,9 @@ void comm_usb_serial_init(void) {
int comm_usb_serial_is_active(void) {
return SDU1.config->usbp->state == USB_ACTIVE;
}

// Every time the USB cable is plugged in a configuration is done. Unfortunately
// I haven't found a way to detect when the USB cable gets unplugged.
int comm_usb_serial_configured_cnt(void) {
return configured_cnt;
}
1 change: 1 addition & 0 deletions comm_usb_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ extern SerialUSBDriver SDU1;
// Functions
void comm_usb_serial_init(void);
int comm_usb_serial_is_active(void);
int comm_usb_serial_configured_cnt(void);

#endif /* COMM_USB_SERIAL_H_ */
5 changes: 4 additions & 1 deletion conf_general.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

// Firmware version
#define FW_VERSION_MAJOR 3
#define FW_VERSION_MINOR 65
#define FW_VERSION_MINOR 66

#include "datatypes.h"

Expand Down Expand Up @@ -123,6 +123,9 @@

//#define HW_SOURCE "hw_rd2.c"
//#define HW_HEADER "hw_rd2.h"

//#define HW_SOURCE "hw_100_250.c"
//#define HW_HEADER "hw_100_250.h"
#endif

#ifndef HW_SOURCE
Expand Down
6 changes: 6 additions & 0 deletions confgenerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *
buffer[ind++] = conf->foc_temp_comp;
buffer_append_float32_auto(buffer, conf->foc_temp_comp_base_temp, &ind);
buffer_append_float32_auto(buffer, conf->foc_current_filter_const, &ind);
buffer[ind++] = conf->foc_cc_decoupling;
buffer[ind++] = conf->foc_observer_type;
buffer_append_int16(buffer, conf->gpd_buffer_notify_left, &ind);
buffer_append_int16(buffer, conf->gpd_buffer_interpol, &ind);
buffer_append_float32_auto(buffer, conf->gpd_current_filter_const, &ind);
Expand Down Expand Up @@ -363,6 +365,8 @@ bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *c
conf->foc_temp_comp = buffer[ind++];
conf->foc_temp_comp_base_temp = buffer_get_float32_auto(buffer, &ind);
conf->foc_current_filter_const = buffer_get_float32_auto(buffer, &ind);
conf->foc_cc_decoupling = buffer[ind++];
conf->foc_observer_type = buffer[ind++];
conf->gpd_buffer_notify_left = buffer_get_int16(buffer, &ind);
conf->gpd_buffer_interpol = buffer_get_int16(buffer, &ind);
conf->gpd_current_filter_const = buffer_get_float32_auto(buffer, &ind);
Expand Down Expand Up @@ -625,6 +629,8 @@ void confgenerator_set_defaults_mcconf(mc_configuration *conf) {
conf->foc_temp_comp = MCCONF_FOC_TEMP_COMP;
conf->foc_temp_comp_base_temp = MCCONF_FOC_TEMP_COMP_BASE_TEMP;
conf->foc_current_filter_const = MCCONF_FOC_CURRENT_FILTER_CONST;
conf->foc_cc_decoupling = MCCONF_FOC_CC_DECOUPLING;
conf->foc_observer_type = MCCONF_FOC_OBSERVER_TYPE;
conf->gpd_buffer_notify_left = MCCONF_GPD_BUFFER_NOTIFY_LEFT;
conf->gpd_buffer_interpol = MCCONF_GPD_BUFFER_INTERPOL;
conf->gpd_current_filter_const = MCCONF_GPD_CURRENT_FILTER_CONST;
Expand Down
2 changes: 1 addition & 1 deletion confgenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdbool.h>

// Constants
#define MCCONF_SIGNATURE 2967846088
#define MCCONF_SIGNATURE 1671830952
#define APPCONF_SIGNATURE 783041200

// Functions
Expand Down
15 changes: 15 additions & 0 deletions datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ typedef enum {
MOTOR_TYPE_GPD
} mc_motor_type;

// FOC current controller decoupling mode.
typedef enum {
FOC_CC_DECOUPLING_DISABLED = 0,
FOC_CC_DECOUPLING_CROSS,
FOC_CC_DECOUPLING_BEMF,
FOC_CC_DECOUPLING_CROSS_BEMF
} mc_foc_cc_decoupling_mode;

typedef enum {
FOC_OBSERVER_ORTEGA_ORIGINAL = 0,
FOC_OBSERVER_ORTEGA_ITERATIVE
} mc_foc_observer_type;

typedef enum {
FAULT_CODE_NONE = 0,
FAULT_CODE_OVER_VOLTAGE,
Expand Down Expand Up @@ -268,6 +281,8 @@ typedef struct {
bool foc_temp_comp;
float foc_temp_comp_base_temp;
float foc_current_filter_const;
mc_foc_cc_decoupling_mode foc_cc_decoupling;
mc_foc_observer_type foc_observer_type;
// GPDrive
int gpd_buffer_notify_left;
int gpd_buffer_interpol;
Expand Down
Loading

0 comments on commit b002e5d

Please sign in to comment.