Blacklite said:
In the motor firmware look at the communications_controller and communications_process_package functions in ebike_app.c
You will also need to check the state machine in the UART RX interrupt routine, also in ebike_app.c
Thank you so much, that is very helpful.
Today, however, I have been battling with the makefile for 850C and windows. There be dragons there.
However, I think I've slain it, though it might get up and roast me yet.
I didn't know much about
make (and I still don't) but this is a particularly convoluted example that I still don't understand. I think it's probably because it is trying to build different things and trying to make use of common source files and where necessary not have to rebuild things. (Well, I suppose that is what
make is all about), anyway I digress
The main issues with converting it to work with Windows is that operating system commands like rm = rmdir and mkdir are not the same in Linux and Windows. Also the commands in windows don't like trailing slashes for directory/folder names. Commands in windows easily fail. Sometimes the / is ok, sometimes not and a \ must be used (as in a batch file)
Make is a very strange weapon, where logical inference must go out the window (er!) because what works in one context won't in another. Within a "rule" variables only exist within a line and there are strange variable names such $@ $< and so on. It's done my head in. It isn't easy to debug - old school with lots of $(info ...) statements (where it's possible)!
EDIT: You will see from later posts that this does not work with pure windows command. I hadn't made the connection, but I was using a windows command shell called CMDER (which is easy to install) and that allows some Linux (or UNIX) like commands such as ls and allows forward slashes for subfolder separators. Pure windows command only likes \, doesn't have ls only dir whereas Makefile needs \\ and I couldn't get it to work. Close, but no cigar.
However here is the Windows Makefile I created that seems to work: (in ... Color_LCD_860C-master\firmware\860C_850C\src)
Code:
# Copyright (C) 2015 Joerg Hoener
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#GM add this for windows
SHELL=cmd
# we expect DISPLAY_VERSION to be passed as argument to Make, like: make DISPLAY_VERSION="860C_BOOTLOADER"
# check to see if version is defined, if not, assume default
ifndef DISPLAY_VERSION
CFLAGS += -DDISPLAY_850C
DISPLAY_VERSION_DEFINED = yes
$(info WARNING | using default display version: DISPLAY_850C, no bootloader)
endif
ifeq ($(DISPLAY_VERSION), 850C_BOOTLOADER)
CFLAGS += -DDISPLAY_850C
BOOTLOADER = yes
DISPLAY_VERSION_DEFINED = yes
endif
ifeq ($(DISPLAY_VERSION), 860C_BOOTLOADER)
CFLAGS += -DDISPLAY_860C
BOOTLOADER = yes
DISPLAY_VERSION_DEFINED = yes
endif
ifneq ($(DISPLAY_VERSION_DEFINED), yes)
$(error wrong DISPLAY_VERSION or not set)
else
ifeq ($(DISPLAY_VERSION), 850C_BOOTLOADER)
$(info WARNING | using display version: 850C_BOOTLOADER)
endif
ifeq ($(DISPLAY_VERSION), 860C_BOOTLOADER)
$(info WARNING | using display version: 860C_BOOTLOADER)
endif
endif
ifdef BOOTLOADER
CFLAGS += -DUSE_WITH_BOOTLOADER
LFLAGS = -Xlinker --defsym=USE_WITH_BOOTLOADER=1
endif
TCPREFIX = arm-none-eabi-
CC = $(TCPREFIX)gcc
AS = $(TCPREFIX)as
LD = $(TCPREFIX)gcc -v # use GCC and not LD so the math functions work like atan2()
CP = $(TCPREFIX)objcopy
OD = $(TCPREFIX)objdump
GDB = $(TCPREFIX)gdb
SIZE = $(TCPREFIX)size
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = Turn off optimization. Reduce compilation time and make debugging
# produce the expected results.
# 1 = The compiler tries to reduce code size and execution time, without
# performing any optimizations that take a great deal of compilation time.
# 2 = GCC performs nearly all supported optimizations that do not involve a
# space-speed tradeoff. As compared to -O1, this option increases
# both compilation time and the performance of the generated code.
# 3 = Optimize yet more. Turns on -finline-functions and more.
# s = -Os enables all -O2 optimizations that do not typically increase code
# size.
# (See gcc manual for further information)
OPT = 0
# -mfix-cortex-m3-ldrd should be enabled by default for Cortex M3.
# CFLAGS -H show header files
AFLAGS = -I./GD32F10x_standard_peripheral/Include -I -Ispl/CMSIS -Ispl/inc -c -g -mcpu=cortex-m3 -mthumb -l libgcc
#CFLAGS += -I./GD32F10x_standard_peripheral/Include -I./ -I./spl/CMSIS -I./spl/CMSIS/inc -I./spl/inc -DUSE_FULL_ASSERT -DSTM32F10X_MD #-DUSE_STDPERIPH_DRIVER -c -fno-common -O$(OPT) -g -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -l libgcc
#Windows doesn't like -I./ it wants -I. ignore the forward slash
CFLAGS += -I./GD32F10x_standard_peripheral/Include -I. -I./spl/CMSIS -I./spl/CMSIS/inc -I./spl/inc -DUSE_FULL_ASSERT -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER -c -fno-common -O$(OPT) -g -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -l libgcc
# Need following option for LTO as LTO will treat retarget functions as
# unused without following option
CFLAGS += -fno-builtin
CFLAGS += -std=c99 --specs=nano.specs --specs=nosys.specs -Wall -I../../common/include
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
LFLAGS += --specs=nano.specs --specs=nosys.specs # to use newlib nano
LFLAGS += -Xlinker -Map=main.map
#LFLAGS += -u _printf_float # newlib nano printf use floats
#LFLAGS += -u _scanf_float # newlib nano scanf use floats
CPFLAGS = -Obinary
ODFLAGS = -S
#Get all the source files
include ../../common/Makefile.common
COMMONDIR = ../../common/src
OBJDIR = _build
#added here by GM from the dep magic code at bottom
DEPDIR := _deps
#CUSTOM_SOURCES=$(shell find spl ugui_driver *.c -type f -iname '*.c')
#Linux find command doesn't work as provided - gives error
CUSTOM_SOURCES = $(shell ls spl/CMSIS/*.c spl/src/*.c ugui_driver/*.c *.c)
COMMON_SOURCES = fault.c buttons.c utils.c ugui.c fonts.c state.c screen.c mainscreen.c configscreen.c eeprom.c
SOURCES = $(CUSTOM_SOURCES) $(foreach x, $(COMMON_SOURCES), $(COMMONDIR)/$(x))
OBJECTS = $(foreach x, $(basename $(SOURCES)), $(OBJDIR)/$(x).o)
#$(info gm ----------------> $(SOURCES) )
#$(info gm ----------------> $(OBJECTS) )
# dev platform specific.
# OPENOCD_PATH := E:/nrf5/Toolchain/OpenOCD/0.10.0-12-20190422-2015/bin
# OPENOCD_BIN := openocd.exe
# NRFUTIL := $(SDK_ROOT)/external_tools/Windows/nrfutil.exe
OPENOCD_PATH := /usr/local/share/openocd/bin
OPENOCD_BIN := openocd
NRFUTIL := nrfutil
OPENOCD := '$(OPENOCD_PATH)/$(OPENOCD_BIN)' -f $(OPENOCD_PATH)/../scripts/interface/stlink.cfg -f $(OPENOCD_PATH)/../scripts/target/stm32f1x.cfg
all: main.bin size
# Ignore - useful for debugging makefiles
test:
echo objs $(OBJECTS)
clean:
@echo "...cleaning"
# rm -f main.lst main.elf main.bin
# rm -rf $(OBJDIR) .deps
del main.lst
del main.elf
del main.bin
rmdir /S /Q $(OBJDIR)
rmdir /S /Q $(DEPDIR)
#flash_serial: main.bin
# $(STM32FLASH) main.bin
# before using this unlock cpu with
# > stm32f1x unlock 0
# stm32f1x unlocked.
# INFO: a reset or power cycle is required for the new settings to take effect.
#flash_jtag: main.bin
# $(OPENOCD) -c "init; reset halt; sleep 500; stm32f1x mass_erase 0; flash write_bank 0 main.bin 0; shutdown"
#run_jtag: flash_jtag
# $(OPENOCD) -c "init; reset halt; reset run; shutdown"
# Just start an openocd session
#openocd:
# $(OPENOCD)
size:
@echo "Size:"
$(SIZE) main.elf
main.bin: main.elf
# @echo "...copying"
$(CP) $(CPFLAGS) main.elf main.bin
$(OD) $(ODFLAGS) main.elf > main.lst
main.elf: $(OBJECTS) startup_stm32f10x_md.o
@echo "..linking"
$(LD) $^ $(LFLAGS) -o $@
startup_stm32f10x_md.o:
$(AS) $(ASFLAGS) startup_stm32f10x_md.s -o startup_stm32f10x_md.o
#
# The following makefile magic generates proper dependencies for headerfiles, so that if you change a headerfile
# the correct C files that use it will be recompiled
#Changed .deps to _deps in windows (In linux .deps is a hidden file. Also moved higher up this makefile
#DEPDIR := _deps
DEPFLAGS = -MT $@ -MD -MP -MF $(DEPDIR)/$*.d
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
$(OBJDIR)/%.o : %.c $(DEPDIR)/%.d | $(DEPDIR)
# @mkdir -p $(dir $@) $(DEPDIR)/$(dir $<)
# GM Fix - Couldn't fix it within Makefile
# Windows doesn't have -p --parents -which is a flag no error if existing, make parent directories as needed
# $(dir names…) Extracts the directory-part of each file name in names.
# mkdir $(dir $@) $(DEPDIR)/$(dir $<) --didn't work because of trailing / :~0,-1% removes it
# Windows hard code the creation of these two folders
# Can't figure how to drop the trailing / which crashed mkdir in windows so pass to a batch file makedir.bat
makedir $(dir $@)
makedir $(DEPDIR)/$(dir $<)
$(COMPILE.c) $(OUTPUT_OPTION) $<
#$(DEPDIR): ; @mkdir -p $@
$(DEPDIR): ; makedir $@
DEPFILES := $(SOURCES:%.c=$(DEPDIR)/%.d)
$(DEPFILES):
include $(wildcard $(DEPFILES))
I'd like to highlight where I changed things, though I have written comments.
However, the big thing is that you will also need a small batch file that I use to create folders:
This replaces the nice simple one liner near the bottom:
$(OBJDIR)/%.o : %.c $(DEPDIR)/%.d | $(DEPDIR)
# @mkdir -p $(dir $@) $(DEPDIR)/$(dir $<)
I still haven't figured out how this works because it was written by an alien with a gigantic brain. It creates different folders depending on ???? but basically the _build and _dep folders.
By the way I changed the .dep to _dep because really a . file is hidden (at least in linux) and I also didn't like it as a name for a windows file - but change it back if you want.
So you need to create a batch file called makefile.bat
Code:
@echo off
REM This batch file is used with the Makefile as @mkdir -p $(dir $@) $(DEPDIR)/$(dir $<) won't work under windows
REM Gordon Moore 24 July 2021
set dn=%1
set dnl=%dn:~-1%
set dnx=%dn:~0,-1%
::remove any trailing /
if %dnl% == / set dn=%dnx%
::replace / with \ for subfolder creation in windows
set dn=%dn:/=\%
::@echo %dn%
if not exist %dn% mkdir %dn%
If you now do
make clean
make
within the same folder, it should (hopefully) build.
(Oh I commented out some flashing stuff in the Makefile, I suppose these should be re-instated for those who need debugging (openocd) etc rather than just flashing)
I have noted though that there is a very slight difference in the output from SIZE
Windows:
"Size:"
arm-none-eabi-size main.elf
text data bss dec hex filename
271248 5496 57916 334660 51b44 main.elf
Linux
Size:
arm-none-eabi-size main.elf
text data bss dec hex filename
271248 5492 57916 334656 51b40 main.elf
I don't know what the implications of this are.
I also need to compare the output of the bin files against the "master" file from mbrusa. When I attempted this the last time I got some differences which I haven't investigated.
In other words DO NOT FLASH this output until we are confident that all is well.
Now to try the actual shell scripts for the 850C with bootloader and convert them to windows batch files.
I wish I could make the output less verbose!!! Edit: Before anyone says it, I bet that's what some think about me :wink:
Gordon