Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 7f402f4

Browse files
committed
WIP different bootloader for TSDZ2 and BAfang
1 parent 12f252b commit 7f402f4

9 files changed

Lines changed: 72 additions & 14 deletions

File tree

firmware/EBike_wireless_bootloader/firmware/Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,28 @@ OUTPUT_DIRECTORY := _build
55
SDK_ROOT := ../../common_firmware/nRF5_SDK_16.0.0
66

77
PROJ_DIR := .
8+
9+
ifdef MOTOR_TSDZ2
10+
$(warning )
11+
$(warning MOTOR: TSDZ2)
12+
MOTOR = TSDZ2
13+
CFLAGS = -DMOTOR_TSDZ2
14+
endif
15+
16+
ifdef MOTOR_BAFANG
17+
$(warning )
18+
$(warning MOTOR: BAFANG)
19+
MOTOR = BAFANG_M500_M600
20+
CFLAGS = -DMOTOR_BAFANG
21+
endif
22+
823
# project build flags
924
BOOTLOADER_VERSION:= 10 # integer 10's digit MAJOR VERSION , 1's digit MINOR VERSION ie: 10 = Version 1.0
1025
DEBUG ?= 0
1126
SD_REQ := 0xB9 #s340 sd is required
1227
NRF_DFU_BL_ALLOW_DOWNGRADE := 1 #allow the bootloader to be downgraded
1328
BOARD_USE_SF_CLOCK := 1 #use the softdevice LFCLK
1429

15-
16-
1730
ifeq ($(DEBUG), 1)
1831
#SOFT_DEVICE = $(PROJ_DIR)/include/S340_and_TSDZ2_remote.hex
1932
SOFT_DEVICE = $(SDK_ROOT)/components/softdevice/s340/hex/ANT_s340_nrf52840_6.1.1.hex
@@ -24,8 +37,6 @@ endif
2437
$(OUTPUT_DIRECTORY)/nrf52840_xxaa.out: \
2538
LINKER_SCRIPT := secure_bootloader_gcc_nrf52.ld
2639

27-
28-
2940
# Source files common to all targets
3041
SRC_FILES += \
3142
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \

firmware/EBike_wireless_bootloader/firmware/include/pins.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ typedef enum {
2424
// NRF52840 NORDIC Dongle
2525
#if defined(BOARD_PCA10059)
2626

27+
#ifdef MOTOR_TSDZ2
2728
typedef enum {
2829
PLUS__PIN = 13,
2930
MINUS__PIN = 15,
3031
BUTTON_PIN_ELEMENTS = 2 // must be updated when added or removed an element
3132
} button_pins_t;
33+
#elif defined(MOTOR_BAFANG)
34+
typedef enum {
35+
PLUS__PIN = 13,
36+
BUTTON_PIN_ELEMENTS = 1 // must be updated when added or removed an element
37+
} button_pins_t;
38+
#endif
39+
3240
#endif
3341

3442
// NRF52840 Dongle (The Blue One)

firmware/EBike_wireless_bootloader/firmware/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,14 @@ static bool gpio_init(void)
270270
err_code = nrf_drv_gpiote_init();
271271
APP_ERROR_CHECK(err_code);
272272

273+
#ifdef MOTOR_TSDZ2
273274
bootloader_pin_pressed = check_pin_and_enable_interrupt(PLUS__PIN);
274275
bootloader_pin_pressed |= check_pin_and_enable_interrupt(MINUS__PIN);
276+
#elif defined(MOTOR_BAFANG)
277+
bootloader_pin_pressed = check_pin_and_enable_interrupt(PLUS__PIN);
278+
#else
279+
#error MOTOR_TSDZ2 or MOTOR_BAFANG must be defined
280+
#endif
275281

276282
return bootloader_pin_pressed;
277283
}
@@ -280,8 +286,12 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
280286
{
281287
if (int_type == NRF_DRV_RTC_INT_COMPARE0)
282288
{
289+
#ifdef MOTOR_TSDZ2
283290
if ((read_pin(PLUS__PIN) == 0) &&
284291
(read_pin(MINUS__PIN) == 0))
292+
#elif defined(MOTOR_BAFANG)
293+
if (read_pin(PLUS__PIN) == 0)
294+
#endif
285295
{
286296
g_start_bootloader = true;
287297
}
@@ -308,7 +318,12 @@ static void rtc_config(void)
308318
APP_ERROR_CHECK(err_code);
309319

310320
//Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
321+
#ifdef MOTOR_TSDZ2
311322
err_code = nrf_drv_rtc_cc_set(&rtc, 0, 10 * 8, true);
323+
#elif defined(MOTOR_BAFANG)
324+
err_code = nrf_drv_rtc_cc_set(&rtc, 0, 10 * 3, true);
325+
#endif
326+
312327
APP_ERROR_CHECK(err_code);
313328

314329
//Power on RTC instance
@@ -363,10 +378,15 @@ int main(void)
363378
lfclk_config();
364379

365380
// disable buttons
381+
#ifdef MOTOR_TSDZ2
366382
nrf_drv_gpiote_in_uninit(PLUS__PIN);
367383
nrf_drv_gpiote_in_event_disable(PLUS__PIN);
368384
nrf_drv_gpiote_in_uninit(MINUS__PIN);
369385
nrf_drv_gpiote_in_event_disable(MINUS__PIN);
386+
#elif defined(MOTOR_BAFANG)
387+
nrf_drv_gpiote_in_uninit(PLUS__PIN);
388+
nrf_drv_gpiote_in_event_disable(PLUS__PIN);
389+
#endif
370390

371391
// RTC uninit because it will be used by the softdevice
372392
rtc_uninit();

firmware/EBike_wireless_bootloader/firmware/workspace.code-workspace

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"settings": {
1111
"git.ignoreLimitWarning": true,
1212
"files.associations": {
13-
"nrf_assert.h": "c"
14-
}
13+
"nrf_assert.h": "c",
14+
"pins.h": "c"
15+
}
1516
}
1617
}

firmware/display/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,13 @@ for_development_only: display_firmware bl_settings final
383383

384384

385385
TSDZ2_bootloader:
386-
cd $(BOOTLOADER_DIR) && make -f ./Makefile
386+
ifdef MOTOR_TSDZ2
387+
cd $(BOOTLOADER_DIR) && make -f ./Makefile MOTOR_TSDZ2=1
388+
endif
389+
390+
ifdef MOTOR_BAFANG
391+
cd $(BOOTLOADER_DIR) && make -f ./Makefile DMOTOR_BAFANG=1
392+
endif
387393

388394
# We use srec_cat here but if you want to be able to use the combined hex file with nRF Connect you should use Nordic's mergehex tool
389395
final:

firmware/display/can.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include "buttons.h"
1414
#include "state.h"
1515

16+
#ifdef MOTOR_TSDZ2
17+
18+
#elif defined(MOTOR_BAFANG)
19+
1620
static rt_vars_t *mp_rt_vars = NULL;
1721
static ui_vars_t *mp_ui_vars = NULL;
1822

@@ -264,3 +268,4 @@ void can_set_max_wheel_speed(uint16_t value) {
264268
CANSPI_Transmit(&canMessage);
265269
nrf_delay_ms(100);
266270
}
271+
#endif

firmware/display/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,9 @@ int main(void)
12321232
}
12331233
}
12341234

1235-
#ifdef MOTOR_BAFANG
1235+
#ifdef MOTOR_TSDZ2
1236+
1237+
#elif defined(MOTOR_BAFANG)
12361238
// process the CAN messages
12371239
// call as fast as possible
12381240
ui32_time_now = get_time_base_counter_1ms();

firmware/display/mainscreen.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,16 @@ Field custom1 = FIELD_CUSTOMIZABLE_PTR(&ui_vars.field_selectors[0], customizable
176176
custom6 = FIELD_CUSTOMIZABLE_PTR(&ui_vars.field_selectors[5], customizables);
177177

178178

179-
Field bootHeading = FIELD_DRAWTEXT_RO("EasyDIY"),
180-
bootURL_1 = FIELD_DRAWTEXT_RO("Bafang"),
181-
bootURL_2 = FIELD_DRAWTEXT_RO("M500/M600"),
182-
183179
#ifdef MOTOR_TSDZ2
180+
Field bootHeading = FIELD_DRAWTEXT_RO("EasyDIY"),
181+
bootURL_1 = FIELD_DRAWTEXT_RO("TSDZ2"),
182+
bootURL_2 = FIELD_DRAWTEXT_RO(""),
184183
bootVersion = FIELD_DRAWTEXT_RO(VERSION_STRING),
185184
bootStatus2 = FIELD_DRAWTEXT_RW(.msg = "");
186185
#elif defined(MOTOR_BAFANG)
186+
Field bootHeading = FIELD_DRAWTEXT_RO("EasyDIY"),
187+
bootURL_1 = FIELD_DRAWTEXT_RO("Bafang"),
188+
bootURL_2 = FIELD_DRAWTEXT_RO("M500/M600"),
187189
bootVersion = FIELD_DRAWTEXT_RO(VERSION_STRING);
188190
#endif
189191

@@ -569,7 +571,8 @@ void mainscreen_clock(void) {
569571
DisplayResetToDefaults();
570572
TripMemoriesReset();
571573
DisplayResetBluetoothPeers();
572-
#ifdef MOTOR_BAFANG
574+
#ifdef MOTOR_TSDZ2
575+
#elif defined(MOTOR_BAFANG)
573576
updateAssistLevels();
574577
torqueSensorCalibration();
575578
positionSensorCalibration();
@@ -1028,7 +1031,8 @@ void onSetConfigurationBatterySOCUsedWh(uint32_t v) {
10281031
ui_vars.ui32_wh_x10_offset = v;
10291032
}
10301033

1031-
#ifdef MOTOR_BAFANG
1034+
#ifdef MOTOR_TSDZ2
1035+
#elif defined(MOTOR_BAFANG)
10321036
void onSetConfigurationChangeMaxWheelSpeed(uint32_t v) {
10331037
can_set_max_wheel_speed(v);
10341038
}

firmware/display/state.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "state.h"
1515
#include "ledalert.h"
1616
#include "display.h"
17+
#include "buttons.h"
1718

1819
typedef enum {
1920
FRAME_TYPE_ALIVE = 0,

0 commit comments

Comments
 (0)