From 56c195fa9a5a7d2c9a32ce2a7a49d9ecd2ea6fc5 Mon Sep 17 00:00:00 2001 From: zedamota Date: Thu, 17 Feb 2011 14:54:57 +0000 Subject: [PATCH] Flight/Bootloader - Bootloader updater, WORKING - tested with PipX only (should work for all boards though). Led(LED1 different color on each board) Sequence: 1-Power On 2-Led ON for 3 seconds (you can disconnect during this time - safety measure) 3-Led flashes very quickly while the board is being programed (because the program is stored in memory this is very fast and looks like a led glitch) 4-If all good - LED flashes 3 times with a 1sec period and turns off - you may now reboot. 4-If an error ocurred - LED will keep flashing with a 500ms period until power off git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2804 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/Bootloaders/BootloaderUpdater/Makefile | 6 ++-- flight/Bootloaders/BootloaderUpdater/main.c | 34 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/flight/Bootloaders/BootloaderUpdater/Makefile b/flight/Bootloaders/BootloaderUpdater/Makefile index f2288c9b2..7da9d58d7 100644 --- a/flight/Bootloaders/BootloaderUpdater/Makefile +++ b/flight/Bootloaders/BootloaderUpdater/Makefile @@ -34,7 +34,7 @@ ENABLE_DEBUG_PINS ?= NO ENABLE_AUX_UART ?= NO # -USE_BOOTLOADER ?= NO +USE_BOOTLOADER ?= YES # Set to the source bootloader binary SOURCE_BL ?= NULL @@ -67,9 +67,9 @@ MCU = cortex-m3 CHIP = STM32F103CBT BOARD ?= NULL MODEL ?= NULL + ifeq ($(USE_BOOTLOADER), YES) BOOT_MODEL = $(MODEL)_BL - else BOOT_MODEL = $(MODEL)_NB endif @@ -320,7 +320,7 @@ LDFLAGS += $(MATH_LIB) LDFLAGS += -lc -lgcc # Set linker-script name depending on selected submodel name -LDFLAGS +=-T$(LINKERSCRIPTPATH)/link_stm32f10x_$(MODEL).ld +LDFLAGS +=-T$(LINKERSCRIPTPATH)/link_$(BOARD)_$(BOOT_MODEL).ld # Test if quotes are needed for the echo-command result = ${shell echo "test"} diff --git a/flight/Bootloaders/BootloaderUpdater/main.c b/flight/Bootloaders/BootloaderUpdater/main.c index 825d1c7b5..f2cd0495c 100644 --- a/flight/Bootloaders/BootloaderUpdater/main.c +++ b/flight/Bootloaders/BootloaderUpdater/main.c @@ -32,21 +32,22 @@ /* Prototype of PIOS_Board_Init() function */ extern void PIOS_Board_Init(void); extern void FLASH_Download(); -void error(); +void error(int); int main() { PIOS_SYS_Init(); PIOS_Board_Init(); PIOS_LED_On(LED1); - PIOS_DELAY_WaitmS(5000); + PIOS_DELAY_WaitmS(3000); PIOS_LED_Off(LED1); /// Self overwrite check uint32_t base_adress = SCB->VTOR; - if (0x08000000 + (sizeof(dataArray) * 4) > base_adress) - error(); + if (0x08000000 + (sizeof(dataArray)) > base_adress) + error(LED1); /// + FLASH_Unlock(); /// Bootloader memory space erase uint32_t pageAdress; @@ -69,13 +70,15 @@ int main() { } if (fail == TRUE) - error(); + error(LED1); + /// /// Bootloader programing - for (int x = 0; x < sizeof(dataArray); ++x) { + for (int x = 0; x < sizeof(dataArray)/sizeof(uint32_t); ++x) { int result = 0; + PIOS_LED_Toggle(LED1); for (int retry = 0; retry < MAX_WRI_RETRYS; ++retry) { if (result == 0) { result = (FLASH_ProgramWord(0x08000000 + (x * 4), dataArray[x]) @@ -83,18 +86,25 @@ int main() { } } if (result == 0) - error(); + error(LED1); } /// - PIOS_LED_On(LED1); - for (;;) {} + for (int x=0;x<3;++x) { + PIOS_LED_On(led); + PIOS_DELAY_WaitmS(1000); + PIOS_LED_Off(led); + PIOS_DELAY_WaitmS(1000); + } + for (;;) { + PIOS_DELAY_WaitmS(1000); + } } -void error() { +void error(int led) { for (;;) { - PIOS_LED_On(LED1); + PIOS_LED_On(led); PIOS_DELAY_WaitmS(500); - PIOS_LED_Off(LED1); + PIOS_LED_Off(led); PIOS_DELAY_WaitmS(500); } }