bootloader
This commit is contained in:
parent
1e6ebbc91c
commit
44f0df51f7
|
@ -58,6 +58,10 @@ ifeq ($(USE_SMART_BUILD),)
|
||||||
USE_SMART_BUILD = no
|
USE_SMART_BUILD = no
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(USE_BOOTLOADER),)
|
||||||
|
USE_BOOTLOADER = no
|
||||||
|
endif
|
||||||
|
|
||||||
#
|
#
|
||||||
# Build global options
|
# Build global options
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
@ -137,6 +141,10 @@ include $(PROJECT_DIR)/controllers/system/system.mk
|
||||||
include $(PROJECT_DIR)/controllers/trigger/trigger.mk
|
include $(PROJECT_DIR)/controllers/trigger/trigger.mk
|
||||||
include $(PROJECT_DIR)/console/console.mk
|
include $(PROJECT_DIR)/console/console.mk
|
||||||
|
|
||||||
|
ifeq ($(USE_BOOTLOADER),yes)
|
||||||
|
include $(PROJECT_DIR)/bootloader/bootloader.mk
|
||||||
|
endif
|
||||||
|
|
||||||
# Define linker script file here
|
# Define linker script file here
|
||||||
ifeq ($(LDSCRIPT),)
|
ifeq ($(LDSCRIPT),)
|
||||||
LDSCRIPT= config/stm32f4ems/STM32F407xG_CCM.ld
|
LDSCRIPT= config/stm32f4ems/STM32F407xG_CCM.ld
|
||||||
|
@ -151,6 +159,7 @@ CSRC = $(STARTUPSRC) \
|
||||||
$(HALSRC) \
|
$(HALSRC) \
|
||||||
$(PLATFORMSRC) \
|
$(PLATFORMSRC) \
|
||||||
$(BOARDSRC) \
|
$(BOARDSRC) \
|
||||||
|
$(BOOTLOADERSRC) \
|
||||||
$(CHIBIOS)/os/various/syscalls.c \
|
$(CHIBIOS)/os/various/syscalls.c \
|
||||||
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \
|
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \
|
||||||
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
|
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
|
||||||
|
@ -222,6 +231,7 @@ INCDIR = $(PORTINC) \
|
||||||
$(HALINC) \
|
$(HALINC) \
|
||||||
$(PLATFORMINC) \
|
$(PLATFORMINC) \
|
||||||
$(BOARDINC) \
|
$(BOARDINC) \
|
||||||
|
$(BOOTLOADERINC) \
|
||||||
$(CHCPPINC) \
|
$(CHCPPINC) \
|
||||||
$(CHIBIOS)/os/hal/lib/streams \
|
$(CHIBIOS)/os/hal/lib/streams \
|
||||||
$(CHIBIOS)/os/various \
|
$(CHIBIOS)/os/various \
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
@echo off
|
||||||
|
|
||||||
|
rem Needed for board overrides
|
||||||
|
IF "%BOOTLOADER_CODE_PATH%"=="" (SET BOOTLOADER_CODE_PATH="..")
|
||||||
|
|
||||||
|
echo Starting compilation
|
||||||
|
make -f src/Makefile %1 %2 %3
|
||||||
|
|
||||||
|
if errorlevel 1 echo make compilation failed
|
||||||
|
if errorlevel 1 exit -1
|
||||||
|
|
||||||
|
echo Build complete success.
|
||||||
|
|
||||||
|
cd blbuild
|
||||||
|
rem Generate a header file with binary bootloader code
|
||||||
|
java -jar ../../../java_tools/bin2header.jar bootloader.bin %BOOTLOADER_CODE_PATH%/bootloader_generated.hxx "static const volatile uint8_t bootloader_code[] BOOTLOADER_SECTION"
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
rem Touch 'bootloader_storage.c' to update its modification date (needed for make)
|
||||||
|
copy /b bootloader_storage.c +,,
|
|
@ -0,0 +1,55 @@
|
||||||
|
#ifndef DFU_H_
|
||||||
|
#define DFU_H_
|
||||||
|
|
||||||
|
#include "tunerstudio_io.h"
|
||||||
|
|
||||||
|
// This is where the bootloader starts
|
||||||
|
#define BOOTLOADER_ADDR 0x08000000
|
||||||
|
// Bootloader code max. size, in bytes
|
||||||
|
#define BOOTLOADER_SIZE 0x4000
|
||||||
|
// Number of sectors for the bootloader
|
||||||
|
#define BOOTLOADER_NUM_SECTORS (BOOTLOADER_SIZE/0x4000)
|
||||||
|
|
||||||
|
// This is where the application starts
|
||||||
|
#define APPLICATION_ADDR 0x08008000
|
||||||
|
|
||||||
|
#define DFU_BUFFER_SIZE 258 // Max. 256 bytes at a time plus 2 bytes (numBytes+checksum)
|
||||||
|
|
||||||
|
|
||||||
|
// DFU/USART Protocol is described in AN3155 document "Application note. USART protocol used in the STM32 bootloader"
|
||||||
|
// http://www.st.com/resource/en/application_note/cd00264342.pdf
|
||||||
|
|
||||||
|
#define DFU_UART_CHECK 0x7F // "UART handshake" escape byte
|
||||||
|
|
||||||
|
#define DFU_GET_LIST_CMD 0x00 // "Get supported commands list" command
|
||||||
|
#define DFU_DEVICE_ID_CMD 0x02 // "Get device ID" command
|
||||||
|
#define DFU_READ_CMD 0x11 // "Read memory" command
|
||||||
|
#define DFU_GO_CMD 0x21 // "Go" command
|
||||||
|
#define DFU_WRITE_CMD 0x31 // "Write memory" command
|
||||||
|
#define DFU_ERASE_CMD 0x44 // "Erase memory" command
|
||||||
|
|
||||||
|
#define DFU_VERSION_NUMBER 0x31 // The DFU protocol version number
|
||||||
|
#define DFU_ACK_BYTE 0x79 // Acknowledge byte ID
|
||||||
|
#define DFU_NACK_BYTE 0x1F // Not-Acknowledge byte ID
|
||||||
|
|
||||||
|
#define DFU_SR5_TIMEOUT_FIRST MS2ST(100)
|
||||||
|
#define DFU_SR5_TIMEOUT_NORMAL MS2ST(1000)
|
||||||
|
|
||||||
|
#define MCU_REVISION_MASK 0xfff // MCU Revision ID is needed by DFU protocol
|
||||||
|
|
||||||
|
// The address in MCU system memory where the bootloader version number is stored (2 bytes)
|
||||||
|
#define DFU_BOOTLOADER_VERSION_ADDRESS 0x1FFF76DE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function waits for the command to apply (write, read etc...)
|
||||||
|
*/
|
||||||
|
bool dfuStartLoop(void);
|
||||||
|
/**
|
||||||
|
* @brief Jump to the application
|
||||||
|
*/
|
||||||
|
void dfuJumpToApp(uint32_t addr);
|
||||||
|
|
||||||
|
ts_channel_s *getTsChannel();
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* DFU_H_ */
|
Loading…
Reference in New Issue