Skip to content

Commit b002e5d

Browse files
committed
FW 3.66: Many changes, see changelog
1 parent 210ec40 commit b002e5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+892
-114
lines changed

CHANGELOG

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
=== FW 3.66 ===
2+
* Added support for HW 100/250.
3+
* Added uptime terminal command.
4+
* Added some delays to DRV8323s SPI driver.
5+
* Added SWD support for NRF52840 with idcode 0x015B.
6+
- TODO: Have a look at https://github.com/blacksphere/blackmagic/commit/302ff20a6d5b806c09e0ca7e996beab3ef3596f4.
7+
* Fixed INVERTED_SHUNT_POLARITY for BLDC.
8+
* Added decoupling to FOC current controller.
9+
* Better motor tracking at high ERPM and low Fsw.
10+
* Made uart and permanent uart more independent.
11+
* Do not write to USB if cable has not been connected.
12+
* Added timeout to USB write.
13+
* Better FOC current control integrator windup protection.
14+
* Added FOC observer type selection options.
15+
* Print TS5700N8501 position in encoder terminal command.
16+
117
=== FW 3.65 ===
218
* Added support for PTC motor temperature sensor (e.g. KTY84)
319
* APP_PPM sleep fix. Should solve CAN issues.

applications/app.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void app_uartcomm_start_permanent(void);
4747
void app_uartcomm_stop(void);
4848
void app_uartcomm_configure(uint32_t baudrate, bool permanent_enabled);
4949
void app_uartcomm_send_packet(unsigned char *data, unsigned int len);
50+
void app_uartcomm_send_packet_p(unsigned char *data, unsigned int len);
5051

5152
void app_nunchuk_start(void);
5253
void app_nunchuk_stop(void);

applications/app_uartcomm.c

+43-16
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,20 @@ static volatile bool uart_is_running = false;
4141
static mutex_t send_mutex;
4242
static bool send_mutex_init_done = false;
4343

44+
#ifdef HW_UART_P_DEV
45+
static mutex_t send_mutex_p;
46+
static bool send_mutex_p_init_done = false;
47+
#endif
48+
4449
// Private functions
4550
static void process_packet(unsigned char *data, unsigned int len);
4651
static void send_packet(unsigned char *data, unsigned int len);
4752

53+
#ifdef HW_UART_P_DEV
54+
static void process_packet_p(unsigned char *data, unsigned int len);
55+
static void send_packet_p(unsigned char *data, unsigned int len);
56+
#endif
57+
4858
static SerialConfig uart_cfg = {
4959
BAUDRATE,
5060
0,
@@ -67,27 +77,29 @@ static void process_packet(unsigned char *data, unsigned int len) {
6777
commands_process_packet(data, len, app_uartcomm_send_packet);
6878
}
6979

70-
static void send_packet(unsigned char *data, unsigned int len) {
7180
#ifdef HW_UART_P_DEV
72-
if (from_p_uart) {
73-
if (uart_p_is_running) {
74-
#ifdef HW_UART_P_DEV_TX
75-
sdWrite(&HW_UART_P_DEV_TX, data, len);
76-
#else
77-
sdWrite(&HW_UART_P_DEV, data, len);
81+
static void process_packet_p(unsigned char *data, unsigned int len) {
82+
commands_process_packet(data, len, app_uartcomm_send_packet_p);
83+
}
7884
#endif
79-
}
80-
} else {
81-
if (uart_is_running) {
82-
sdWrite(&HW_UART_DEV, data, len);
83-
}
84-
}
85-
#else
85+
86+
static void send_packet(unsigned char *data, unsigned int len) {
8687
if (uart_is_running) {
8788
sdWrite(&HW_UART_DEV, data, len);
8889
}
90+
}
91+
92+
#ifdef HW_UART_P_DEV
93+
static void send_packet_p(unsigned char *data, unsigned int len) {
94+
if (uart_p_is_running) {
95+
#ifdef HW_UART_P_DEV_TX
96+
sdWrite(&HW_UART_P_DEV_TX, data, len);
97+
#else
98+
sdWrite(&HW_UART_P_DEV, data, len);
8999
#endif
100+
}
90101
}
102+
#endif
91103

92104
void app_uartcomm_start(void) {
93105
packet_init(send_packet, process_packet, PACKET_HANDLER);
@@ -111,8 +123,7 @@ void app_uartcomm_start(void) {
111123

112124
void app_uartcomm_start_permanent(void) {
113125
#ifdef HW_UART_P_DEV
114-
packet_init(send_packet, process_packet, PACKET_HANDLER);
115-
packet_init(send_packet, process_packet, PACKET_HANDLER_P);
126+
packet_init(send_packet_p, process_packet_p, PACKET_HANDLER_P);
116127

117128
if (!thread_is_running) {
118129
chThdCreateStatic(packet_process_thread_wa, sizeof(packet_process_thread_wa),
@@ -159,6 +170,22 @@ void app_uartcomm_send_packet(unsigned char *data, unsigned int len) {
159170
chMtxUnlock(&send_mutex);
160171
}
161172

173+
void app_uartcomm_send_packet_p(unsigned char *data, unsigned int len) {
174+
#ifdef HW_UART_P_DEV
175+
if (!send_mutex_p_init_done) {
176+
chMtxObjectInit(&send_mutex_p);
177+
send_mutex_p_init_done = true;
178+
}
179+
180+
chMtxLock(&send_mutex_p);
181+
packet_send_packet(data, len, PACKET_HANDLER_P);
182+
chMtxUnlock(&send_mutex_p);
183+
#else
184+
(void)data;
185+
(void)len;
186+
#endif
187+
}
188+
162189
void app_uartcomm_configure(uint32_t baudrate, bool permanent_enabled) {
163190
uart_cfg.speed = baudrate;
164191

blackmagic/bm_if.c

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static int idcode_to_device(uint32_t idcode) {
133133
ret = 7; break;
134134
case 0x00EB: /* nRF52840 Preview QIAA AA0 */
135135
case 0x0150: /* nRF52840 QIAA C0 */
136+
case 0x015B: /* nRF52840 ?? */
136137
ret = 8; break;
137138
default: ret = -2; break;
138139
}
@@ -362,6 +363,9 @@ int bm_connect(void) {
362363

363364
if (cur_target) {
364365
ret = idcode_to_device(target_idcode(cur_target));
366+
if (ret < 0) {
367+
commands_printf("Unknown idcode: 0x%04X\n", target_idcode(cur_target));
368+
}
365369
}
366370
}
367371

blackmagic/target/nrf51.c

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ bool nrf51_probe(target *t)
176176
return true;
177177
case 0x00EB: /* nRF52840 Preview QIAA AA0 */
178178
case 0x0150: /* nRF52840 QIAA C0 */
179+
case 0x015B: /* nRF52840 ?? */
179180
t->driver = "Nordic nRF52";
180181
target_add_ram(t, 0x20000000, 256*1024);
181182
nrf51_add_flash(t, 0x00000000, 1024*1024, NRF52_PAGE_SIZE);

build_all/100_250/VESC_default.bin

384 KB
Binary file not shown.
Binary file not shown.

build_all/100_250/VESC_servoout.bin

384 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

build_all/46_o_47/VESC_0005ohm.bin

0 Bytes
Binary file not shown.

build_all/46_o_47/VESC_33k.bin

0 Bytes
Binary file not shown.

build_all/46_o_47/VESC_default.bin

0 Bytes
Binary file not shown.

build_all/46_o_47/VESC_servoout.bin

0 Bytes
Binary file not shown.

build_all/46_o_47/VESC_ws2811.bin

0 Bytes
Binary file not shown.

build_all/46_o_47/VESC_ws2811_33k.bin

0 Bytes
Binary file not shown.

build_all/48/VESC_0005ohm.bin

0 Bytes
Binary file not shown.

build_all/48/VESC_default.bin

0 Bytes
Binary file not shown.

build_all/48/VESC_servoout.bin

0 Bytes
Binary file not shown.

build_all/48/VESC_ws2811.bin

0 Bytes
Binary file not shown.

build_all/60/VESC_default.bin

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

build_all/60/VESC_servoout.bin

0 Bytes
Binary file not shown.

build_all/60/VESC_ws2811.bin

0 Bytes
Binary file not shown.

build_all/60_MK3/VESC_default.bin

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

build_all/60_MK3/VESC_servoout.bin

0 Bytes
Binary file not shown.

build_all/60_MK3/VESC_ws2811.bin

0 Bytes
Binary file not shown.

build_all/75_300/VESC_default.bin

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

build_all/75_300/VESC_servoout.bin

0 Bytes
Binary file not shown.

build_all/75_300/VESC_ws2811.bin

0 Bytes
Binary file not shown.

build_all/75_300_R2/VESC_default.bin

0 Bytes
Binary file not shown.
Binary file not shown.

build_all/75_300_R2/VESC_servoout.bin

0 Bytes
Binary file not shown.

build_all/75_300_R2/VESC_ws2811.bin

0 Bytes
Binary file not shown.

build_all/A200S_V21/VESC_default.bin

0 Bytes
Binary file not shown.

build_all/A200S_V22/VESC_default.bin

0 Bytes
Binary file not shown.

build_all/AXIOM/VESC_default.bin

0 Bytes
Binary file not shown.

build_all/DAS_RS/VESC_default.bin

0 Bytes
Binary file not shown.

build_all/HD/VESC_default.bin

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

build_all/HD/VESC_servoout.bin

0 Bytes
Binary file not shown.

build_all/HD/VESC_ws2811.bin

0 Bytes
Binary file not shown.

build_all/UAVC_OMEGA/VESC_default.bin

0 Bytes
Binary file not shown.

build_all/rebuild_all

+31
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,34 @@ cd $FWPATH
399399
make clean
400400
cd $DIR
401401

402+
#################### HW 100_250 ########################
403+
404+
COPYDIR=100_250
405+
rm -f $COPYDIR/*
406+
407+
# default
408+
cd $FWPATH
409+
touch conf_general.h
410+
make -j8 build_args='-DHW_SOURCE=\"hw_100_250.c\" -DHW_HEADER=\"hw_100_250.h\"' USE_VERBOSE_COMPILE=no
411+
cd $DIR
412+
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default.bin
413+
414+
# default with HW limits disables
415+
cd $FWPATH
416+
touch conf_general.h
417+
make -j8 build_args='-DDISABLE_HW_LIMITS -DHW_SOURCE=\"hw_100_250.c\" -DHW_HEADER=\"hw_100_250.h\"' USE_VERBOSE_COMPILE=no
418+
cd $DIR
419+
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default_no_hw_limits.bin
420+
421+
# servoout
422+
cd $FWPATH
423+
touch conf_general.h
424+
make -j8 build_args='-DSERVO_OUT_ENABLE=1 -DHW_SOURCE=\"hw_100_250.c\" -DHW_HEADER=\"hw_100_250.h\"' USE_VERBOSE_COMPILE=no
425+
cd $DIR
426+
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_servoout.bin
427+
428+
# Clean
429+
cd $FWPATH
430+
make clean
431+
cd $DIR
432+

comm_usb.c

+29-5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
static uint8_t serial_rx_buffer[SERIAL_RX_BUFFER_SIZE];
3333
static int serial_rx_read_pos = 0;
3434
static int serial_rx_write_pos = 0;
35-
static THD_WORKING_AREA(serial_read_thread_wa, 256);
35+
static THD_WORKING_AREA(serial_read_thread_wa, 128);
3636
static THD_WORKING_AREA(serial_process_thread_wa, 4096);
3737
static mutex_t send_mutex;
3838
static thread_t *process_tp;
39+
static volatile unsigned int write_timeout_cnt = 0;
3940

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

47-
chRegSetThreadName("USB-Serial read");
48+
chRegSetThreadName("USB read");
4849

49-
uint8_t buffer[128];
50+
uint8_t buffer[2];
5051
int had_data = 0;
5152

5253
for(;;) {
@@ -72,7 +73,7 @@ static THD_FUNCTION(serial_read_thread, arg) {
7273
static THD_FUNCTION(serial_process_thread, arg) {
7374
(void)arg;
7475

75-
chRegSetThreadName("USB-Serial process");
76+
chRegSetThreadName("USB process");
7677

7778
process_tp = chThdGetSelfX();
7879

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

9697
static void send_packet_raw(unsigned char *buffer, unsigned int len) {
97-
chSequentialStreamWrite(&SDU1, buffer, len);
98+
static bool was_timeout = false;
99+
100+
/*
101+
* Only write to USB if the cable has been connected at least once. If a timeout occurs
102+
* make sure that this call does not stall on the next call, as the timeout probably occured
103+
* because noone is listening on the USB.
104+
*/
105+
if (comm_usb_serial_configured_cnt() > 0) {
106+
unsigned int written = 0;
107+
if (was_timeout) {
108+
written = SDU1.vmt->writet(&SDU1, buffer, len, TIME_IMMEDIATE);
109+
} else {
110+
written = SDU1.vmt->writet(&SDU1, buffer, len, MS2ST(100));
111+
}
112+
113+
was_timeout = written != len;
114+
if (was_timeout) {
115+
write_timeout_cnt++;
116+
}
117+
}
98118
}
99119

100120
void comm_usb_init(void) {
@@ -113,3 +133,7 @@ void comm_usb_send_packet(unsigned char *data, unsigned int len) {
113133
packet_send_packet(data, len, PACKET_HANDLER);
114134
chMtxUnlock(&send_mutex);
115135
}
136+
137+
unsigned int comm_usb_get_write_timeout_cnt(void) {
138+
return write_timeout_cnt;
139+
}

comm_usb.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
// Functions
2626
void comm_usb_init(void);
2727
void comm_usb_send_packet(unsigned char *data, unsigned int len);
28+
unsigned int comm_usb_get_write_timeout_cnt(void);
2829

2930
#endif /* COMM_USB_H_ */

comm_usb_serial.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,12 @@ static const USBEndpointConfig ep2config = {
250250
NULL
251251
};
252252

253+
static volatile int configured_cnt = 0;
254+
253255
/*
254256
* Handles the USB driver global events.
255257
*/
256258
static void usb_event(USBDriver *usbp, usbevent_t event) {
257-
258259
switch (event) {
259260
case USB_EVENT_RESET:
260261
return;
@@ -273,6 +274,7 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
273274
sduConfigureHookI(&SDU1);
274275

275276
chSysUnlockFromISR();
277+
configured_cnt++;
276278
return;
277279
case USB_EVENT_SUSPEND:
278280
return;
@@ -331,3 +333,9 @@ void comm_usb_serial_init(void) {
331333
int comm_usb_serial_is_active(void) {
332334
return SDU1.config->usbp->state == USB_ACTIVE;
333335
}
336+
337+
// Every time the USB cable is plugged in a configuration is done. Unfortunately
338+
// I haven't found a way to detect when the USB cable gets unplugged.
339+
int comm_usb_serial_configured_cnt(void) {
340+
return configured_cnt;
341+
}

comm_usb_serial.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ extern SerialUSBDriver SDU1;
77
// Functions
88
void comm_usb_serial_init(void);
99
int comm_usb_serial_is_active(void);
10+
int comm_usb_serial_configured_cnt(void);
1011

1112
#endif /* COMM_USB_SERIAL_H_ */

conf_general.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
// Firmware version
2424
#define FW_VERSION_MAJOR 3
25-
#define FW_VERSION_MINOR 65
25+
#define FW_VERSION_MINOR 66
2626

2727
#include "datatypes.h"
2828

@@ -123,6 +123,9 @@
123123

124124
//#define HW_SOURCE "hw_rd2.c"
125125
//#define HW_HEADER "hw_rd2.h"
126+
127+
//#define HW_SOURCE "hw_100_250.c"
128+
//#define HW_HEADER "hw_100_250.h"
126129
#endif
127130

128131
#ifndef HW_SOURCE

confgenerator.c

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *
9797
buffer[ind++] = conf->foc_temp_comp;
9898
buffer_append_float32_auto(buffer, conf->foc_temp_comp_base_temp, &ind);
9999
buffer_append_float32_auto(buffer, conf->foc_current_filter_const, &ind);
100+
buffer[ind++] = conf->foc_cc_decoupling;
101+
buffer[ind++] = conf->foc_observer_type;
100102
buffer_append_int16(buffer, conf->gpd_buffer_notify_left, &ind);
101103
buffer_append_int16(buffer, conf->gpd_buffer_interpol, &ind);
102104
buffer_append_float32_auto(buffer, conf->gpd_current_filter_const, &ind);
@@ -363,6 +365,8 @@ bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *c
363365
conf->foc_temp_comp = buffer[ind++];
364366
conf->foc_temp_comp_base_temp = buffer_get_float32_auto(buffer, &ind);
365367
conf->foc_current_filter_const = buffer_get_float32_auto(buffer, &ind);
368+
conf->foc_cc_decoupling = buffer[ind++];
369+
conf->foc_observer_type = buffer[ind++];
366370
conf->gpd_buffer_notify_left = buffer_get_int16(buffer, &ind);
367371
conf->gpd_buffer_interpol = buffer_get_int16(buffer, &ind);
368372
conf->gpd_current_filter_const = buffer_get_float32_auto(buffer, &ind);
@@ -625,6 +629,8 @@ void confgenerator_set_defaults_mcconf(mc_configuration *conf) {
625629
conf->foc_temp_comp = MCCONF_FOC_TEMP_COMP;
626630
conf->foc_temp_comp_base_temp = MCCONF_FOC_TEMP_COMP_BASE_TEMP;
627631
conf->foc_current_filter_const = MCCONF_FOC_CURRENT_FILTER_CONST;
632+
conf->foc_cc_decoupling = MCCONF_FOC_CC_DECOUPLING;
633+
conf->foc_observer_type = MCCONF_FOC_OBSERVER_TYPE;
628634
conf->gpd_buffer_notify_left = MCCONF_GPD_BUFFER_NOTIFY_LEFT;
629635
conf->gpd_buffer_interpol = MCCONF_GPD_BUFFER_INTERPOL;
630636
conf->gpd_current_filter_const = MCCONF_GPD_CURRENT_FILTER_CONST;

confgenerator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <stdbool.h>
99

1010
// Constants
11-
#define MCCONF_SIGNATURE 2967846088
11+
#define MCCONF_SIGNATURE 1671830952
1212
#define APPCONF_SIGNATURE 783041200
1313

1414
// Functions

datatypes.h

+15
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ typedef enum {
8585
MOTOR_TYPE_GPD
8686
} mc_motor_type;
8787

88+
// FOC current controller decoupling mode.
89+
typedef enum {
90+
FOC_CC_DECOUPLING_DISABLED = 0,
91+
FOC_CC_DECOUPLING_CROSS,
92+
FOC_CC_DECOUPLING_BEMF,
93+
FOC_CC_DECOUPLING_CROSS_BEMF
94+
} mc_foc_cc_decoupling_mode;
95+
96+
typedef enum {
97+
FOC_OBSERVER_ORTEGA_ORIGINAL = 0,
98+
FOC_OBSERVER_ORTEGA_ITERATIVE
99+
} mc_foc_observer_type;
100+
88101
typedef enum {
89102
FAULT_CODE_NONE = 0,
90103
FAULT_CODE_OVER_VOLTAGE,
@@ -268,6 +281,8 @@ typedef struct {
268281
bool foc_temp_comp;
269282
float foc_temp_comp_base_temp;
270283
float foc_current_filter_const;
284+
mc_foc_cc_decoupling_mode foc_cc_decoupling;
285+
mc_foc_observer_type foc_observer_type;
271286
// GPDrive
272287
int gpd_buffer_notify_left;
273288
int gpd_buffer_interpol;

0 commit comments

Comments
 (0)