adjust script to include user code
This commit is contained in:
parent
f5831e083f
commit
19148125fe
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
*~
|
||||
.*~
|
||||
.*.sw?
|
||||
cube/build
|
@ -1,3 +1,4 @@
|
||||
// Processed by ../tools/insertMyCode.sh
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
@ -25,7 +26,8 @@
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "main2.h";
|
||||
#include "main2.h"
|
||||
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
@ -69,6 +71,7 @@ int main(void)
|
||||
/* USER CODE BEGIN 1 */
|
||||
my_setup_1();
|
||||
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
@ -95,6 +98,7 @@ int main(void)
|
||||
/* USER CODE BEGIN 2 */
|
||||
my_setup_2();
|
||||
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@ -105,6 +109,7 @@ int main(void)
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
my_loop();
|
||||
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
@ -166,10 +171,12 @@ void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
my_errorHandler();
|
||||
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
while(1) { };
|
||||
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
|
@ -1,5 +1,6 @@
|
||||
# Processed by ../tools/insertMyCode.sh
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Tue Oct 06 13:31:48 CEST 2020]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Tue Oct 06 15:22:01 CEST 2020]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
@ -36,6 +37,7 @@ BUILD_DIR = build
|
||||
######################################
|
||||
# C sources
|
||||
C_SOURCES = \
|
||||
User/Src/main2.c \
|
||||
Core/Src/main.c \
|
||||
Core/Src/gpio.c \
|
||||
Core/Src/adc.c \
|
||||
@ -58,7 +60,7 @@ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
|
||||
Core/Src/system_stm32f1xx.c
|
||||
Core/Src/system_stm32f1xx.c
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
@ -115,11 +117,12 @@ AS_INCLUDES =
|
||||
|
||||
# C includes
|
||||
C_INCLUDES = \
|
||||
-IUser/Inc \
|
||||
-ICore/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
|
||||
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
|
||||
-IDrivers/CMSIS/Include
|
||||
-IDrivers/CMSIS/Include \
|
||||
-IDrivers/CMSIS/Include
|
||||
|
||||
|
||||
@ -192,4 +195,4 @@ clean:
|
||||
#######################################
|
||||
-include $(wildcard $(BUILD_DIR)/*.d)
|
||||
|
||||
# *** EOF ***
|
||||
# *** EOF ***
|
195
cube/Makefile-bak
Normal file
195
cube/Makefile-bak
Normal file
@ -0,0 +1,195 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Tue Oct 06 15:22:01 CEST 2020]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
# Generic Makefile (based on gcc)
|
||||
#
|
||||
# ChangeLog :
|
||||
# 2017-02-10 - Several enhancements + project update mode
|
||||
# 2015-07-22 - first version
|
||||
# ------------------------------------------------
|
||||
|
||||
######################################
|
||||
# target
|
||||
######################################
|
||||
TARGET = cube
|
||||
|
||||
|
||||
######################################
|
||||
# building variables
|
||||
######################################
|
||||
# debug build?
|
||||
DEBUG = 1
|
||||
# optimization
|
||||
OPT = -Og
|
||||
|
||||
|
||||
#######################################
|
||||
# paths
|
||||
#######################################
|
||||
# Build path
|
||||
BUILD_DIR = build
|
||||
|
||||
######################################
|
||||
# source
|
||||
######################################
|
||||
# C sources
|
||||
C_SOURCES = \
|
||||
Core/Src/main.c \
|
||||
Core/Src/gpio.c \
|
||||
Core/Src/adc.c \
|
||||
Core/Src/usart.c \
|
||||
Core/Src/stm32f1xx_it.c \
|
||||
Core/Src/stm32f1xx_hal_msp.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
|
||||
Core/Src/system_stm32f1xx.c
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
startup_stm32f103xe.s
|
||||
|
||||
|
||||
#######################################
|
||||
# binaries
|
||||
#######################################
|
||||
PREFIX = arm-none-eabi-
|
||||
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
|
||||
# either it can be added to the PATH environment variable.
|
||||
ifdef GCC_PATH
|
||||
CC = $(GCC_PATH)/$(PREFIX)gcc
|
||||
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
|
||||
CP = $(GCC_PATH)/$(PREFIX)objcopy
|
||||
SZ = $(GCC_PATH)/$(PREFIX)size
|
||||
else
|
||||
CC = $(PREFIX)gcc
|
||||
AS = $(PREFIX)gcc -x assembler-with-cpp
|
||||
CP = $(PREFIX)objcopy
|
||||
SZ = $(PREFIX)size
|
||||
endif
|
||||
HEX = $(CP) -O ihex
|
||||
BIN = $(CP) -O binary -S
|
||||
|
||||
#######################################
|
||||
# CFLAGS
|
||||
#######################################
|
||||
# cpu
|
||||
CPU = -mcpu=cortex-m3
|
||||
|
||||
# fpu
|
||||
# NONE for Cortex-M0/M0+/M3
|
||||
|
||||
# float-abi
|
||||
|
||||
|
||||
# mcu
|
||||
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
|
||||
|
||||
# macros for gcc
|
||||
# AS defines
|
||||
AS_DEFS =
|
||||
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
-DUSE_HAL_DRIVER \
|
||||
-DSTM32F103xE
|
||||
|
||||
|
||||
# AS includes
|
||||
AS_INCLUDES =
|
||||
|
||||
# C includes
|
||||
C_INCLUDES = \
|
||||
-ICore/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
|
||||
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
|
||||
-IDrivers/CMSIS/Include \
|
||||
-IDrivers/CMSIS/Include
|
||||
|
||||
|
||||
# compile gcc flags
|
||||
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -g -gdwarf-2
|
||||
endif
|
||||
|
||||
|
||||
# Generate dependency information
|
||||
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
|
||||
|
||||
|
||||
#######################################
|
||||
# LDFLAGS
|
||||
#######################################
|
||||
# link script
|
||||
LDSCRIPT = STM32F103VCTx_FLASH.ld
|
||||
|
||||
# libraries
|
||||
LIBS = -lc -lm -lnosys
|
||||
LIBDIR =
|
||||
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||
|
||||
# default action: build all
|
||||
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
||||
|
||||
|
||||
#######################################
|
||||
# build the application
|
||||
#######################################
|
||||
# list of objects
|
||||
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
||||
vpath %.c $(sort $(dir $(C_SOURCES)))
|
||||
# list of ASM program objects
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
|
||||
vpath %.s $(sort $(dir $(ASM_SOURCES)))
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
|
||||
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
|
||||
$(AS) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
|
||||
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
|
||||
$(SZ) $@
|
||||
|
||||
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||
$(HEX) $< $@
|
||||
|
||||
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||
$(BIN) $< $@
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir $@
|
||||
|
||||
#######################################
|
||||
# clean up
|
||||
#######################################
|
||||
clean:
|
||||
-rm -fR $(BUILD_DIR)
|
||||
|
||||
#######################################
|
||||
# dependencies
|
||||
#######################################
|
||||
-include $(wildcard $(BUILD_DIR)/*.d)
|
||||
|
||||
# *** EOF ***
|
11
cube/User/Inc/main2.h
Normal file
11
cube/User/Inc/main2.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef _MAIN2_H_
|
||||
#define _MAIN2_H_
|
||||
|
||||
|
||||
void my_setup_1();
|
||||
void my_setup_2();
|
||||
void my_loop();
|
||||
void my_errorHandler();
|
||||
|
||||
|
||||
#endif // _MAIN2_H_
|
15
cube/User/Src/main2.c
Normal file
15
cube/User/Src/main2.c
Normal file
@ -0,0 +1,15 @@
|
||||
void my_setup_1() {
|
||||
|
||||
}
|
||||
|
||||
void my_setup_2() {
|
||||
|
||||
}
|
||||
|
||||
void my_loop() {
|
||||
|
||||
}
|
||||
|
||||
void my_errorHandler() {
|
||||
|
||||
}
|
@ -120,7 +120,7 @@ ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.2
|
||||
ProjectManager.FreePins=false
|
||||
ProjectManager.HalAssertFull=false
|
||||
ProjectManager.HeapSize=0x200
|
||||
ProjectManager.KeepUserCode=true
|
||||
ProjectManager.KeepUserCode=false
|
||||
ProjectManager.LastFirmware=true
|
||||
ProjectManager.LibraryCopy=1
|
||||
ProjectManager.MainLocation=Core/Src
|
||||
|
19
readme.md
19
readme.md
@ -1,5 +1,22 @@
|
||||
On Ubuntu install
|
||||
On Ubuntu/Debian install
|
||||
|
||||
* gcc-arm-none-eabi
|
||||
* openocd
|
||||
|
||||
|
||||
Alternatively use the Docker image wollud1969/build-env-arm-none-eabi:1.0.0
|
||||
|
||||
docker run -it --rm -v ${PWD}:/mnt wollud1969/build-env-arm-none-eabi:1.0.0 bash
|
||||
|
||||
|
||||
After code generation in CubeMX the Makefile and the file main.c in Core/Src needs
|
||||
to be edited to include user code. From the cube directory in the project root run:
|
||||
|
||||
../tools/insertMyCode.sh
|
||||
|
||||
User code has to life in User/Src and User/Inc. All *.c file from User/Src will be
|
||||
attached to the C_SOURCES variable in the Makefile.
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
while (<>) {
|
||||
print $_;
|
||||
print "#include \"main2.h\";\n" if m/USER CODE BEGIN Includes/;
|
||||
print " my_setup_1();\n" if m/USER CODE BEGIN 1/;
|
||||
print " my_setup_2();\n" if m/USER CODE BEGIN 2/;
|
||||
print " my_loop();\n" if m/USER CODE BEGIN 3/;
|
||||
print " my_errorHandler();\n" if m/USER CODE BEGIN Error_Handler/;
|
||||
print " while(1) { };\n" if m/USER CODE END Error_Handler/;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,18 +1,56 @@
|
||||
#!/bin/bash
|
||||
|
||||
MAIN_C=./Core/Src/main.c
|
||||
MAIN_C_BAK=./Core/Src/main.c-bak
|
||||
MAIN_C_BAK=${MAIN_C}-bak
|
||||
|
||||
if [ ! -f $MAIN_C ]; then
|
||||
echo "no $MAIN_C available"
|
||||
exit 1
|
||||
fi
|
||||
if [ -f $MAIN_C_BAK ]; then
|
||||
echo "$MAIN_C_BAK already available, delete manually"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mv $MAIN_C $MAIN_C_BAK
|
||||
cat $MAIN_C_BAK | ../tools/insertMyCode.pl > $MAIN_C
|
||||
MAKEFILE=./Makefile
|
||||
MAKEFILE_BAK=${MAKEFILE}-bak
|
||||
|
||||
|
||||
|
||||
PROCESSED="Processed by $0"
|
||||
|
||||
checkFile () {
|
||||
FILE=$1
|
||||
BAK_FILE=$2
|
||||
if [ ! -f $FILE ]; then
|
||||
echo "no $FILE available"
|
||||
exit 1
|
||||
fi
|
||||
if [ -f $BAK_FILE ]; then
|
||||
echo "$BAK_FILE already available, delete manually"
|
||||
exit 1
|
||||
fi
|
||||
grep -q "$PROCESSED" $FILE
|
||||
if [ "$?" = "0" ]; then
|
||||
echo "$FILE has already been processed"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
checkFile $MAIN_C $MAIN_C_BAK
|
||||
checkFile $MAKEFILE $MAKEFILE_BAK
|
||||
|
||||
|
||||
cp $MAIN_C $MAIN_C_BAK
|
||||
echo "// $PROCESSED" > $MAIN_C
|
||||
cat $MAIN_C_BAK | \
|
||||
sed -e 's,\(/\* USER CODE BEGIN Includes \*/\),\1\n#include "main2.h"\n,' | \
|
||||
sed -e 's,\(/\* USER CODE BEGIN 1 \*/\),\1\n my_setup_1();\n,' | \
|
||||
sed -e 's,\(/\* USER CODE BEGIN 2 \*/\),\1\n my_setup_2();\n,' | \
|
||||
sed -e 's,\(/\* USER CODE BEGIN 3 \*/\),\1\n my_loop();\n,' | \
|
||||
sed -e 's,\(/\* USER CODE BEGIN Error_Handler_Debug \*/\),\1\n my_errorHandler();\n,' | \
|
||||
sed -e 's,\(/\* USER CODE END Error_Handler_Debug \*/\),\1\n while(1) { };\n,' >> $MAIN_C
|
||||
|
||||
|
||||
SRC_EXT=''
|
||||
for I in User/Src/*.c; do
|
||||
SRC_EXT+="$I "
|
||||
done
|
||||
|
||||
cp $MAKEFILE $MAKEFILE_BAK
|
||||
echo "# $PROCESSED" > $MAKEFILE
|
||||
cat $MAKEFILE_BAK | \
|
||||
sed -e 's,\(C_SOURCES = \\\),\1\n'"$SRC_EXT"' \\,' | \
|
||||
sed -e 's,\(C_INCLUDES = \\\),\1\n-IUser/Inc \\,' >> $MAKEFILE
|
||||
|
Loading…
x
Reference in New Issue
Block a user