Skip to content

Commit b82c389

Browse files
committed
Update to latest mbed and add Makefile
1 parent a2d0c27 commit b82c389

File tree

11 files changed

+288
-40
lines changed

11 files changed

+288
-40
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ test_suite.json
9696

9797
# default delivery dir
9898
DELIVERY/
99+
100+
# clang compile commands
101+
compile_commands.json

bms/.gdbinit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
target remote | openocd -f board/st_nucleo_f3.cfg -c "gdb_port pipe"
2+
set remote hardware-breakpoint-limit 6
3+
set remote hardware-watchpoint-limit 4
4+
mon reset halt
5+
load

bms/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.mbedbuild
2-
cmake_build/
2+
cmake_build/
3+
lib-mbed-ltc681x

bms/CMakeLists.txt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,30 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register -Wno-deprecated-declaratio
1212

1313
include(${MBED_PATH}/tools/cmake/app.cmake)
1414

15-
add_subdirectory(${MBED_PATH})
15+
project(${APP_TARGET})
16+
1617

1718
# Libraries
19+
add_subdirectory(${MBED_PATH})
1820
add_subdirectory(lib-mbed-ltc681x)
1921

20-
add_executable(${APP_TARGET}
21-
src/Main.cpp
22-
src/BmsThread.cpp
23-
src/EnergusTempSensor.cpp
24-
src/LTC6811.cpp
25-
)
26-
#target_include_directories(${APP_TARGET} ${ltc681x_SOURCE_DIR})
22+
23+
add_executable(${APP_TARGET})
2724

2825
mbed_configure_app_target(${APP_TARGET})
2926

30-
project(${APP_TARGET})
27+
target_sources(${APP_TARGET}
28+
PRIVATE
29+
src/Main.cpp
30+
src/BmsThread.cpp
31+
src/EnergusTempSensor.cpp
32+
src/LTC6811.cpp
33+
)
3134

3235
target_link_libraries(${APP_TARGET}
33-
mbed-os
34-
lib-mbed-ltc681x
36+
PRIVATE
37+
mbed-os
38+
lib-mbed-ltc681x
3539
)
3640

3741
mbed_set_post_build(${APP_TARGET})

bms/Makefile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# Build file for Formula Slug FS-2 bms
3+
#
4+
5+
MBED_TOOLCHAIN := GCC_ARM
6+
MBED_TARGET := LPC1768
7+
MBED_BUILD_PROFILE := release
8+
9+
BUILD_DIR := cmake_build
10+
11+
DEPENDENCIES := mbed-os lib-mbed-ltc681x
12+
13+
.PHONY: all
14+
all: build-release
15+
16+
#
17+
# Dependency pulling
18+
#
19+
20+
.PHONY: deps
21+
deps: $(DEPENDENCIES)
22+
23+
$(DEPENDENCIES):
24+
mbed-tools deploy
25+
26+
#
27+
# Build profiles
28+
#
29+
30+
$(BUILD_DIR):
31+
mbed-tools configure -t $(MBED_TOOLCHAIN) -m $(MBED_TARGET) -b $(MBED_BUILD_PROFILE)
32+
33+
.PHONY: build
34+
build: deps $(BUILD_DIR)
35+
mbed-tools compile -t $(MBED_TOOLCHAIN) -m $(MBED_TARGET) -b $(MBED_BUILD_PROFILE)
36+
37+
.PHONY: build-debug
38+
build-debug: MBED_BUILD_PROFILE=debug
39+
build-debug: build
40+
41+
.PHONY: build-release
42+
build-release: MBED_BUILD_PROFILE=release
43+
build-release: build
44+
45+
#
46+
# Flashing to devices
47+
#
48+
49+
.PHONY: flash
50+
flash: deps $(BUILD_DIR)
51+
mbed-tools compile -t $(MBED_TOOLCHAIN) -m $(MBED_TARGET) -b $(MBED_BUILD_PROFILE) -f
52+
53+
#
54+
# STM32 F303 debug
55+
#
56+
57+
.PHONY: debug
58+
debug: build-debug
59+
arm-none-eabi-gdb -x .gdbinit ./$(BUILD_DIR)/$(MBED_TARGET)/$(MBED_BUILD_PROFILE)/$(MBED_TOOLCHAIN)/bms.elf
60+
61+
#
62+
# Utilities
63+
#
64+
65+
.PHONY: clean
66+
clean:
67+
rm -rf $(BUILD_DIR)

bms/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# FS-2 bms software
2+
3+
This directory contains the software for the battery management system (BMS) for the FS-2 race car.
4+
5+
## Requirements
6+
7+
The following software is required for building:
8+
- [mbed-tools](https://github.com/ARMmbed/mbed-tools)
9+
- [GNU Arm Embedded Toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm)
10+
11+
## Building
12+
13+
To build the software simply run
14+
15+
```bash
16+
make build
17+
```
18+
19+
This will download all required dependencies and configure and build the project.
20+
21+
*NOTE: The build may fail on the first invocation due to an issue with mbed. In this case simply re-run the build command.*

bms/mbed-os.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os#master
1+
https://github.com/ARMmbed/mbed-os#mbed-os-6.15.0

bms/mbed_app.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"target_overrides": {
33
"LPC1768": {
4+
"platform.stdio-baud-rate": 115200,
5+
"platform.default-serial-baud-rate": 115200,
6+
"MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED": "True"
7+
},
8+
"NUCLEO_F303K8": {
49
"platform.stdio-baud-rate": 115200,
510
"platform.default-serial-baud-rate": 115200
611
}

bms/src/BmsConfig.h

Lines changed: 109 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern DigitalOut* chargerControl;
1919

2020
// Number of LTC6811 battery banks to communicate with
2121
#ifndef BMS_BANK_COUNT
22-
#define BMS_BANK_COUNT 1
22+
#define BMS_BANK_COUNT 4
2323
#endif
2424

2525
// Number of cell voltage readings per LTC6811
@@ -82,42 +82,90 @@ const int BMS_CELL_MAP[12] = {0, 1, 2, 3, -1, -1, 4, 5, 6, -1, -1, -1};
8282
//
8383
// To be set high and held high when software enters fault state
8484
#ifndef BMS_PIN_BMS_FLT
85-
#define BMS_PIN_BMS_FLT p10
85+
86+
#ifdef TARGET_LPC1768
87+
#define BMS_PIN_BMS_FLT p10
88+
#elif TARGET_NUCLEO_F303K8
89+
#define BMS_PIN_BMS_FLT PB_0
90+
#else
91+
#error "Unknown board for BMS_PIN_BMS_FLT"
92+
#endif
93+
8694
#endif
8795

8896
// BMS fault latch
8997
//
9098
// Readback from BMS fault relay to be broadcasted on CAN bus
9199
#ifndef BMS_PIN_BMS_FLT_LAT
92-
#define BMS_PIN_BMS_FLT_LAT NC
100+
101+
#ifdef TARGET_LPC1768
102+
#define BMS_PIN_BMS_FLT_LAT p12
103+
#elif TARGET_NUCLEO_F303K8
104+
#define BMS_PIN_BMS_FLT_LAT PF_1
105+
#else
106+
#error "Unknown board for BMS_PIN_BMS_FLT_LAT"
107+
#endif
108+
93109
#endif
94110

95111
// IMD status input
96112
//
97113
// Reads PWM output from IMD board
98114
#ifndef BMS_PIN_IMD_STATUS
99-
#define BMS_PIN_IMD_STATUS NC
115+
116+
#ifdef TARGET_LPC1768
117+
#define BMS_PIN_IMD_STATUS p14
118+
#elif TARGET_NUCLEO_F303K8
119+
#define BMS_PIN_IMD_STATUS PF_0
120+
#else
121+
#error "Unknown board for BMS_PIN_IMD_STATUS"
122+
#endif
123+
100124
#endif
101125

102126
// IMD fault latch
103127
//
104128
// Readback from IMD fault relay to be broadcasted on CAN bus
105129
#ifndef BMS_PIN_IMD_FLT_LAT
106-
#define BMS_PIN_IMD_FLT_LAT NC
130+
131+
#ifdef TARGET_LPC1768
132+
#define BMS_PIN_IMD_FLT_LAT p13
133+
#elif TARGET_NUCLEO_F303K8
134+
#define BMS_PIN_IMD_FLT_LAT PA_8
135+
#else
136+
#error "Unknown board for BMS_PIN_IMD_FLT_LAT"
137+
#endif
138+
107139
#endif
108140

109141
// Charger output
110142
//
111143
// To be pulled high to enable charger
112144
#ifndef BMS_PIN_CHARGER_CONTROL
113-
#define BMS_PIN_CHARGER_CONTROL p11
145+
146+
#ifdef TARGET_LPC1768
147+
#define BMS_PIN_CHARGER_CONTROL p11
148+
#elif TARGET_NUCLEO_F303K8
149+
#define BMS_PIN_CHARGER_CONTROL PB_1
150+
#else
151+
#error "Unknown board for BMS_PIN_CHARGER_CONTROL"
152+
#endif
153+
114154
#endif
115155

116156
// Current input
117157
//
118158
// Input from analog current sensor
119159
#ifndef BMS_PIN_SIG_CURRENT
120-
#define BMS_PIN_SIG_CURRENT NC
160+
161+
#ifdef TARGET_LPC1768
162+
#define BMS_PIN_SIG_CURRENT p15
163+
#elif TARGET_NUCLEO_F303K8
164+
#define BMS_PIN_SIG_CURRENT PA_0
165+
#else
166+
#error "Unknown board for BMS_PIN_SIG_CURRENT"
167+
#endif
168+
121169
#endif
122170

123171

@@ -127,22 +175,54 @@ const int BMS_CELL_MAP[12] = {0, 1, 2, 3, -1, -1, 4, 5, 6, -1, -1, -1};
127175

128176
// SPI master out slave in
129177
#ifndef BMS_PIN_SPI_MOSI
130-
#define BMS_PIN_SPI_MOSI p5
178+
179+
#ifdef TARGET_LPC1768
180+
#define BMS_PIN_SPI_MOSI p5
181+
#elif TARGET_NUCLEO_F303K8
182+
#define BMS_PIN_SPI_MOSI PA_7
183+
#else
184+
#error "Unknown board for BMS_PIN_SPI_MOSI"
185+
#endif
186+
131187
#endif
132188

133189
// SPI master in slave out
134190
#ifndef BMS_PIN_SPI_MISO
135-
#define BMS_PIN_SPI_MISO p6
191+
192+
#ifdef TARGET_LPC1768
193+
#define BMS_PIN_SPI_MISO p6
194+
#elif TARGET_NUCLEO_F303K8
195+
#define BMS_PIN_SPI_MISO PA_6
196+
#else
197+
#error "Unknown board for BMS_PIN_SPI_MISO"
198+
#endif
199+
136200
#endif
137201

138202
// SPI clock
139203
#ifndef BMS_PIN_SPI_SCLK
140-
#define BMS_PIN_SPI_SCLK p7
204+
205+
#ifdef TARGET_LPC1768
206+
#define BMS_PIN_SPI_SCLK p7
207+
#elif TARGET_NUCLEO_F303K8
208+
#define BMS_PIN_SPI_SCLK PA_5
209+
#else
210+
#error "Unknown board for BMS_PIN_SPI_SCLK"
211+
#endif
212+
141213
#endif
142214

143215
// SPI chip select
144216
#ifndef BMS_PIN_SPI_SSEL
145-
#define BMS_PIN_SPI_SSEL p8
217+
218+
#ifdef TARGET_LPC1768
219+
#define BMS_PIN_SPI_SSEL p8
220+
#elif TARGET_NUCLEO_F303K8
221+
#define BMS_PIN_SPI_SSEL PA_4
222+
#else
223+
#error "Unknown board for BMS_PIN_SPI_SSEL"
224+
#endif
225+
146226
#endif
147227

148228

@@ -152,12 +232,28 @@ const int BMS_CELL_MAP[12] = {0, 1, 2, 3, -1, -1, 4, 5, 6, -1, -1, -1};
152232

153233
// CAN TX pin to transceiver
154234
#ifndef BMS_PIN_CAN_TX
155-
#define BMS_PIN_CAN_TX p29
235+
236+
#ifdef TARGET_LPC1768
237+
#define BMS_PIN_CAN_TX p29
238+
#elif TARGET_NUCLEO_F303K8
239+
#define BMS_PIN_CAN_TX PA_12
240+
#else
241+
#error "Unknown board for BMS_PIN_CAN_TX"
242+
#endif
243+
156244
#endif
157245

158246
// CAN RX pin from transceiver
159247
#ifndef BMS_PIN_CAN_RX
160-
#define BMS_PIN_CAN_RX p30
248+
249+
#ifdef TARGET_LPC1768
250+
#define BMS_PIN_CAN_RX p30
251+
#elif TARGET_NUCLEO_F303K8
252+
#define BMS_PIN_CAN_RX PA_11
253+
#else
254+
#error "Unknown board for BMS_PIN_CAN_RX"
255+
#endif
256+
161257
#endif
162258

163259
// CAN frequency to used

0 commit comments

Comments
 (0)