diff --git a/flight/Bootloaders/OpenPilot/Makefile b/flight/Bootloaders/OpenPilot/Makefile index 24d0309b8..f139a3f59 100644 --- a/flight/Bootloaders/OpenPilot/Makefile +++ b/flight/Bootloaders/OpenPilot/Makefile @@ -203,11 +203,6 @@ CDEFS = -DSTM32F10X_$(MODEL) CDEFS += -DUSE_STDPERIPH_DRIVER CDEFS += -DUSE_$(BOARD) -ifeq ($(ENABLE_DEBUG_PINS),YES) -CDEFS += -DPIOS_ENABLE_DEBUG_PINS -endif - - # Place project-specific -D and/or -U options for # Assembler with preprocessor here. #ADEFS = -DUSE_IRQ_ASM_WRAPPER diff --git a/flight/Bootloaders/OpenPilot/bootloader.c b/flight/Bootloaders/OpenPilot/bootloader.c index a74712ffa..4297b8e8f 100644 --- a/flight/Bootloaders/OpenPilot/bootloader.c +++ b/flight/Bootloaders/OpenPilot/bootloader.c @@ -79,6 +79,9 @@ void StartBootloader(void) if(PIOS_COM_ReceiveBufferUsed(OPBL_COM_PORT) > 0) { key = PIOS_COM_ReceiveBuffer(OPBL_COM_PORT); if(key == 0x31) { + /* Flash unlock */ + FLASH_Unlock(); + /* Download user application in the Flash */ SerialDownload(); return; diff --git a/flight/Bootloaders/OpenPilot/inc/bootloader.h b/flight/Bootloaders/OpenPilot/inc/bootloader.h index 4fa620ef9..b36d08fbc 100644 --- a/flight/Bootloaders/OpenPilot/inc/bootloader.h +++ b/flight/Bootloaders/OpenPilot/inc/bootloader.h @@ -31,7 +31,7 @@ typedef void (*pFunction)(void); /* Global Defines */ #define CMD_STRING_SIZE 128 -#define ApplicationAddress 0x8008000 +#define ApplicationAddress (0x8008000) #define PAGE_SIZE (0x800) #define FLASH_SIZE (0x80000) /* 512K */ diff --git a/flight/Bootloaders/OpenPilot/inc/openpilot_bl.h b/flight/Bootloaders/OpenPilot/inc/openpilot_bl.h index a8fef5a00..9df2551bb 100644 --- a/flight/Bootloaders/OpenPilot/inc/openpilot_bl.h +++ b/flight/Bootloaders/OpenPilot/inc/openpilot_bl.h @@ -27,7 +27,7 @@ #ifndef OPENPILOT_BL_H #define OPENPILOT_BL_H -#define OPBL_MAGIC_TIMEOUT 2000 +#define OPBL_MAGIC_TIMEOUT 200 #define OPBL_COM_PORT COM_DEBUG_USART /* PIOS Includes */ diff --git a/flight/Bootloaders/OpenPilot/openpilot_bl.c b/flight/Bootloaders/OpenPilot/openpilot_bl.c index e6458e8a6..4158a57b6 100644 --- a/flight/Bootloaders/OpenPilot/openpilot_bl.c +++ b/flight/Bootloaders/OpenPilot/openpilot_bl.c @@ -31,9 +31,6 @@ static pFunction Jump_To_Application; static uint32_t JumpAddress; -/* Local Variables */ - -/* Function Prototypes */ /** * OpenPilot Bootloader Main function @@ -43,25 +40,23 @@ int main() /* Brings up System using CMSIS functions, enables the LEDs. */ PIOS_SYS_Init(); + /* Initialise LED's */ + PIOS_LED_Off(LED1); + PIOS_LED_Off(LED2); + /* Only go into bootloader when the USB cable is connected */ if(PIOS_USB_CableConnected()) { /* Delay system */ PIOS_DELAY_Init(); - /* Initialise the USB system */ - PIOS_USB_Init(0); + if(PIOS_USB_IsInitialized()) { + /* Initialise the USB system */ + PIOS_USB_Init(0); + } /* Initialise COM Ports */ PIOS_COM_Init(); - /* Initialise LED's */ - PIOS_LED_Init(); - PIOS_LED_Off(LED1); - PIOS_LED_Off(LED2); - - /* Flash unlock */ - FLASH_Unlock(); - /* Execute the IAP driver in order to re-program the Flash */ StartBootloader(); }