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

Commit d5f7686

Browse files
committed
Makefile can build for bootloader. Enable automatic power off. Initial screen showing firmware version, link for site and porject name
1 parent fd0f373 commit d5f7686

4 files changed

Lines changed: 62 additions & 40 deletions

File tree

Bafang_color_LCD_850C/Bafang_LCD_850C_firmware/src/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# You should have received a copy of the GNU General Public License
1414
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16+
# uncomment next lines to build for bootloader
17+
CFLAGS = -DUSE_WITH_BOOTLOADER
18+
LFLAGS = -Xlinker --defsym=USE_WITH_BOOTLOADER=1
1619

1720
TCPREFIX = arm-none-eabi-
1821
CC = $(TCPREFIX)gcc
@@ -40,11 +43,11 @@ OPT = 0
4043
# -mfix-cortex-m3-ldrd should be enabled by default for Cortex M3.
4144
# CFLAGS -H show header files
4245
AFLAGS = -I./GD32F10x_standard_peripheral/Include -I -Ispl/CMSIS -Ispl/inc -c -g -mcpu=cortex-m3 -mthumb -l libgcc
43-
CFLAGS = -I./GD32F10x_standard_peripheral/Include -I./ -I./spl/CMSIS -I./spl/CMSIS/inc -I./spl/inc -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -c -fno-common -O$(OPT) -g -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -l libgcc -DUSE_COLOR_RGB565
46+
CFLAGS += -I./GD32F10x_standard_peripheral/Include -I./ -I./spl/CMSIS -I./spl/CMSIS/inc -I./spl/inc -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -c -fno-common -O$(OPT) -g -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -l libgcc -DUSE_COLOR_RGB565
4447
# Need following option for LTO as LTO will treat retarget functions as
4548
# unused without following option
4649
CFLAGS+ = -fno-builtin
47-
LFLAGS = -Tstm32_flash.ld -L/usr/lib/gcc/arm-none-eabi/4.9.3/armv7-m -lgcc -lm -nostartfiles -lnosys -mcpu=cortex-m3 -mthumb -Wl,--gc-sections
50+
LFLAGS += -Tstm32_flash.ld -L/usr/lib/gcc/arm-none-eabi/4.9.3/armv7-m -lgcc -lm -nostartfiles -lnosys -mcpu=cortex-m3 -mthumb -Wl,--gc-sections
4851
#LFLAGS += --specs=nano.specs # to use newlib nano
4952
#LFLAGS += -u _printf_float # newlib nano printf use floats
5053
#LFLAGS += -u _scanf_float # newlib nano scanf use floats

Bafang_color_LCD_850C/Bafang_LCD_850C_firmware/src/lcd.c

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void l2_low_pass_filter_battery_voltage_current_power(void);
8080
void update_menu_flashing_state(void);
8181
void calc_battery_soc_watts_hour(void);
8282
void l2_calc_odometer(void);
83-
static void l2_automatic_power_off_management(void);
83+
static void automatic_power_off_management(void);
8484
void brake(void);
8585
void walk_assist_state(void);
8686
void wheel_speed(void);
@@ -109,6 +109,7 @@ void change_graph(void);
109109
void lcd_init(void)
110110
{
111111
bafang_500C_lcd_init();
112+
lcd_set_backlight_intensity(20); // need otherwise no image will be shownbefore this
112113
UG_FillScreen(C_BLACK);
113114

114115
lcd_configurations_screen_init();
@@ -195,6 +196,7 @@ void lcd_clock(void)
195196
graphs_clock_2();
196197
}
197198

199+
automatic_power_off_management();
198200
power_off_management();
199201

200202
// must be reset after a full cycle of lcd_clock()
@@ -965,43 +967,44 @@ void l2_calc_odometer(void)
965967
// }
966968
}
967969

968-
static void l2_automatic_power_off_management(void)
970+
static void automatic_power_off_management(void)
969971
{
970-
// static uint8_t ui8_lcd_power_off_time_counter_minutes = 0;
971-
// static uint16_t ui16_lcd_power_off_time_counter = 0;
972-
//
973-
// if(configuration_variables.ui8_lcd_power_off_time_minutes != 0)
974-
// {
975-
// // see if we should reset the automatic power off minutes counter
976-
// if ((l3_vars.ui16_wheel_speed_x10 > 0) || // wheel speed > 0
977-
// (l3_vars.ui8_battery_current_x5 > 0) || // battery current > 0
978-
// (l3_vars.ui8_braking) || // braking
979-
// buttons_get_events()) // any button active
980-
// {
981-
// ui16_lcd_power_off_time_counter = 0;
982-
// ui8_lcd_power_off_time_counter_minutes = 0;
983-
// }
984-
//
985-
// // increment the automatic power off minutes counter
986-
// ui16_lcd_power_off_time_counter++;
987-
//
988-
// // check if we should power off the LCD
989-
// if(ui16_lcd_power_off_time_counter >= (10 * 60)) // 1 minute passed
990-
// {
991-
// ui16_lcd_power_off_time_counter = 0;
992-
//
993-
// ui8_lcd_power_off_time_counter_minutes++;
994-
// if(ui8_lcd_power_off_time_counter_minutes >= configuration_variables.ui8_lcd_power_off_time_minutes)
995-
// {
996-
// lcd_power_off(1);
997-
// }
998-
// }
999-
// }
1000-
// else
1001-
// {
1002-
// ui16_lcd_power_off_time_counter = 0;
1003-
// ui8_lcd_power_off_time_counter_minutes = 0;
1004-
// }
972+
static uint8_t ui8_lcd_power_off_time_counter_minutes = 0;
973+
static uint16_t ui16_lcd_power_off_time_counter = 0;
974+
975+
if(l3_vars.ui8_lcd_power_off_time_minutes != 0)
976+
{
977+
// see if we should reset the automatic power off minutes counter
978+
if ((l3_vars.ui16_wheel_speed_x10 > 0) || // wheel speed > 0
979+
(l3_vars.ui8_battery_current_x5 > 0) || // battery current > 0
980+
(l3_vars.ui8_braking) || // braking
981+
buttons_get_events()) // any button active
982+
{
983+
ui16_lcd_power_off_time_counter = 0;
984+
ui8_lcd_power_off_time_counter_minutes = 0;
985+
}
986+
987+
// increment the automatic power off minutes counter
988+
ui16_lcd_power_off_time_counter++;
989+
990+
// check if we should power off the LCD
991+
if(ui16_lcd_power_off_time_counter >= (50 * 60)) // 1 minute passed
992+
{
993+
ui16_lcd_power_off_time_counter = 0;
994+
995+
ui8_lcd_power_off_time_counter_minutes++;
996+
if(ui8_lcd_power_off_time_counter_minutes >= l3_vars.ui8_lcd_power_off_time_minutes)
997+
{
998+
lcd_power_off(1);
999+
}
1000+
}
1001+
}
1002+
// keep automatic_power_off_management disabled
1003+
else
1004+
{
1005+
ui16_lcd_power_off_time_counter = 0;
1006+
ui8_lcd_power_off_time_counter_minutes = 0;
1007+
}
10051008
}
10061009

10071010
void update_menu_flashing_state(void)

Bafang_color_LCD_850C/Bafang_LCD_850C_firmware/src/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ int main(void)
3939
SetSysClockTo128Mhz();
4040
RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
4141

42+
// if building for original bootloader (from manufacturer), relocate flash after 20K (0x5000) that is the space that bootloader uses
43+
#ifdef USE_WITH_BOOTLOADER
44+
NVIC_SetVectorTable(NVIC_VectTab_FLASH, (uint32_t) 0x5000);
45+
#endif
46+
4247
pins_init();
4348
system_power(1);
4449
systick_init();
@@ -51,6 +56,17 @@ int main(void)
5156
graphs_init();
5257
buttons_init();
5358

59+
// print firmware version on LCD
60+
UG_SetBackcolor(C_BLACK);
61+
UG_SetForecolor(C_WHITE);
62+
UG_FontSelect(&TITLE_TEXT_FONT);
63+
UG_PutString(92, 75, "Flexible");
64+
UG_PutString(24, 111, "OpenSource ebike");
65+
UG_FontSelect(&SMALL_TEXT_FONT);
66+
UG_PutString(61, 192, "https://github.com");
67+
UG_PutString(14, 214, "/OpenSource-EBike-firmware");
68+
UG_PutString(78, 344, "firmware v0.4.0");
69+
5470
// block until user release the buttons
5571
while(buttons_get_onoff_state() ||
5672
buttons_get_down_state() ||

Bafang_color_LCD_850C/Bafang_LCD_850C_firmware/src/stm32_flash.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ _Min_Stack_Size = 0x800; /* required amount of stack */
4242
/* Specify the memory areas */
4343
MEMORY
4444
{
45-
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
45+
FLASH (rx) : ORIGIN = DEFINED(USE_WITH_BOOTLOADER) ? (0x08000000 + 20K) : 0x08000000, LENGTH = DEFINED(USE_WITH_BOOTLOADER) ? (512K - 20K) : 512K
4646
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
4747
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
4848
}

0 commit comments

Comments
 (0)