Skip to content

F4: improve make to support selecting boards #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ If you want to use a ***High Density Device*** such as ***STM32F103RCT6**, then
***STM32F4xx***

```[YOUR_HDD_PATH]\STM32_HID_bootloader\bootloader\F4>make clean``` Clears the previous generated files
```[YOUR_HDD_PATH]\STM32_HID_bootloader\bootloader\F4>make``` Creates the **hid_bootloader.bin** file

```[YOUR_HDD_PATH]\STM32_HID_bootloader\bootloader\F4>make build_f407_vgt6_pe0``` Creates the **f407_vgt6_pe.bin** file and copies it to the bootloader_only_binaries directory. Edit the Makefile to see all supported options

After compiling, the binary file can be found in:

Expand Down
54 changes: 30 additions & 24 deletions bootloader/F4/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,36 @@
#define HID_MAGIC_NUMBER_BKP_VALUE 0x424C



#define BOOT_1_PIN GPIO_PIN_15 //DIYMROE STM32F407VGT board (Button PD15, LED PE0)
#define BOOT_1_PORT GPIOD
#define BOOT_1_ENABLED GPIO_PIN_RESET
#define LED_1_PIN GPIO_PIN_0
#define LED_1_PORT GPIOE

// #define BOOT_1_PIN GPIO_PIN_2 //Black VET6 (http://wiki.stm32duino.com/index.php?title=STM32F407)
// #define BOOT_1_PORT GPIOB
// #define BOOT_1_ENABLED GPIO_PIN_SET // Active if this pin goes to 3.3V (Logic HIGH)
// #define LED_1_PIN GPIO_PIN_6 //PA6 = LED D2
// #define LED_1_PORT GPIOA

//#define BOOT_1_PIN GPIO_PIN_4 //Arch_MAX (Button PB4, LED PB3)
//#define BOOT_1_PORT GPIOB
//#define BOOT_1_ENABLED GPIO_PIN_RESET
//#define LED_1_PIN GPIO_PIN_3
//#define LED_1_PORT GPIOB

// #define BOOT_1_PIN GPIO_PIN_13 //Nucleo STM32F411RE board (Button PC13, LED PA5)
// #define BOOT_1_PORT GPIOC
// #define BOOT_1_ENABLED GPIO_PIN_RESET
// #define LED_1_PIN GPIO_PIN_5
// #define LED_1_PORT GPIOA
#if defined TARGET_F407_VGT6_PE0
#define BOOT_1_PIN GPIO_PIN_15 //DIYMROE VGT6 (https://stm32-base.org/boards/STM32F407VGT6-diymore.html)
#define BOOT_1_PORT GPIOD
#define BOOT_1_ENABLED GPIO_PIN_RESET
#define LED_1_PIN GPIO_PIN_0
#define LED_1_PORT GPIOE

#elif defined TARGET_F407_VET6_PA6
#define BOOT_1_PIN GPIO_PIN_2 //Black VET6 (https://stm32-base.org/boards/STM32F407VET6-STM32-F4VE-V2.0.html)
#define BOOT_1_PORT GPIOB
#define BOOT_1_ENABLED GPIO_PIN_SET // Active if pin 3.3V (Logic HIGH)
#define LED_1_PIN GPIO_PIN_6
#define LED_1_PORT GPIOA

// #define BOOT_1_PIN GPIO_PIN_4 //Arch_MAX
// #define BOOT_1_PORT GPIOB
// #define BOOT_1_ENABLED GPIO_PIN_RESET
// #define LED_1_PIN GPIO_PIN_3
// #define LED_1_PORT GPIOB

#elif defined TARGET_F411_NUCLEO_PA5
#define BOOT_1_PIN GPIO_PIN_13 //Nucleo STM32F411RE
#define BOOT_1_PORT GPIOC
#define BOOT_1_ENABLED GPIO_PIN_RESET
#define LED_1_PIN GPIO_PIN_5
#define LED_1_PORT GPIOA

#else
#error "No config for this target"
#endif

/* USER CODE END Private defines */

Expand Down
35 changes: 25 additions & 10 deletions bootloader/F4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ OPT = -Og
#######################################
# Build path
BUILD_DIR = build
BIN_DIR = bootloader_only_binaries

######################################
# source
Expand Down Expand Up @@ -81,6 +82,7 @@ Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c
ASM_SOURCES = \
startup_stm32f407xx.s

SRCS += $(C_SRCS)

#######################################
# binaries
Expand Down Expand Up @@ -145,7 +147,7 @@ C_INCLUDES = \
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -std=gnu99 -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(TARGETFLAGS) $(OPT) -std=gnu99 -Wall -fdata-sections -ffunction-sections

ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
Expand All @@ -155,22 +157,32 @@ endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"

# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin

#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = STM32F407VETx_FLASH.ld
f407_vgt6_peo: $(SRCS) clean build_f407_vgt6_pe0 copy_f407_vgt6_pe0
f407_vet6_pa6: $(SRCS) clean build_f407_vet6_pa6 copy_f407_vet6_pa6
# f411_nucleo_pa5: clean build_f411_nucleo_pa5 copy_f411_nucleo_pa5

build_f407_vgt6_pe0: TARGETFLAGS= -DTARGET_F407_VGT6_PE0
build_f407_vgt6_pe0: LDSCRIPT = STM32F407VGTx_FLASH.ld
build_f407_vgt6_pe0: all
copy_f407_vgt6_pe0: $(BIN_DIR)
$(ECHO) "COPY $(BIN_DIR)/f407_vgt6_peo.bin"
cp $(BUILD_DIR)/$(TARGET).bin $(BIN_DIR)/f407_vgt6_peo.bin

build_f407_vet6_pa6: TARGETFLAGS= -DTARGET_F407_VET6_PA6
build_f407_vet6_pa6: LDSCRIPT = STM32F407VETx_FLASH.ld
build_f407_vet6_pa6: all
copy_f407_vet6_pa6: $(BIN_DIR)
$(ECHO) "COPY $(BIN_DIR)/f407_vet6_pa6.bin"
cp $(BUILD_DIR)/$(TARGET).bin $(BIN_DIR)/f407_vet6_pa6.bin

# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -specs=nosys.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--no-wchar-size-warning -Wl,--gc-sections

# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin


#######################################
# build the application
#######################################
Expand Down Expand Up @@ -203,6 +215,9 @@ $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(Q)$(BIN) $< $@

$(BUILD_DIR):
$(Q)mkdir $@

$(BIN_DIR):
$(Q)mkdir $@

#######################################
Expand Down
189 changes: 189 additions & 0 deletions bootloader/F4/STM32F407VGTx_FLASH.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
*****************************************************************************
**

** File : LinkerScript.ld
**
** Abstract : Linker script for STM32F407VGTx Device with
** 1024KByte FLASH, 128KByte RAM
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used.
**
** Target : STMicroelectronics STM32
**
**
** Distribution: The file is distributed as is, without any warranty
** of any kind.
**
** (c)Copyright Ac6.
** You may use this file as-is or modify it according to the needs of your
** project. Distribution of this file (unmodified or modified) is not
** permitted. Ac6 permit registered System Workbench for MCU users the
** rights to distribute the assembled, compiled & linked contents of this
** file as part of an application binary file, provided that it is built
** using the System Workbench for MCU toolchain.
**
*****************************************************************************
*/

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20020000; /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */

/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
}

/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH

/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)

KEEP (*(.init))
KEEP (*(.fini))

. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH

/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH

.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH

.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH

/* used by the startup to initialize data */
_sidata = LOADADDR(.data);

/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */

. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH

_siccmram = LOADADDR(.ccmram);

/* CCM-RAM section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.ccmram :
{
. = ALIGN(4);
_sccmram = .; /* create a global symbol at ccmram start */
*(.ccmram)
*(.ccmram*)

. = ALIGN(4);
_eccmram = .; /* create a global symbol at ccmram end */
} >CCMRAM AT> FLASH


/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)

. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM

/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM



/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}

.ARM.attributes 0 : { *(.ARM.attributes) }
}


Binary file not shown.
Binary file not shown.