mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-16 08:29:15 +01:00
OP-1477 - Fix bootloader
This commit is contained in:
parent
9b61fc611b
commit
1970e0a870
@ -14,9 +14,9 @@ OPENOCD_CONFIG := stm32f0x.cfg
|
||||
|
||||
# Note: These must match the values in link_$(BOARD)_memory.ld
|
||||
BL_BANK_BASE := 0x08000000 # Start of bootloader flash
|
||||
BL_BANK_SIZE := 0x00001000 # Should include BD_INFO region
|
||||
FW_BANK_BASE := 0x08001000 # Start of firmware flash
|
||||
FW_BANK_SIZE := 0x00008000 # Should include FW_DESC_SIZE
|
||||
BL_BANK_SIZE := 0x00002000 # Should include BD_INFO region
|
||||
FW_BANK_BASE := 0x08002000 # Start of firmware flash
|
||||
FW_BANK_SIZE := 0x00006000 # Should include FW_DESC_SIZE
|
||||
|
||||
FW_DESC_SIZE := 0x00000064
|
||||
|
||||
|
@ -25,10 +25,31 @@
|
||||
*/
|
||||
|
||||
#define BOARD_REVISION_GPSP 1
|
||||
|
||||
/*
|
||||
* GPS Platinum board.
|
||||
* pins allocation:
|
||||
* port | Pins
|
||||
* -------------|-------------
|
||||
* GPS I2C | PB7 SDA
|
||||
* | PB6 SCL
|
||||
* ---------------------------
|
||||
* Led HB | PB4
|
||||
* ---------------------------
|
||||
* Mag/Flash SPI| PA4 MAG SS
|
||||
* | PA5 SCK
|
||||
* | PA6 MISO
|
||||
* | PA7 MOSI
|
||||
* | PB1 FLASH SS
|
||||
* | PB0 Mag Int
|
||||
*----------------------------
|
||||
* Main Port | PA9 TX
|
||||
* | PA10 RX
|
||||
*----------------------------
|
||||
*/
|
||||
#if defined(PIOS_INCLUDE_LED)
|
||||
|
||||
#include <pios_led_priv.h>
|
||||
|
||||
static const struct pios_gpio pios_leds_gpsp[] = {
|
||||
// PB4
|
||||
[PIOS_LED_HEARTBEAT] = {
|
||||
@ -36,11 +57,12 @@ static const struct pios_gpio pios_leds_gpsp[] = {
|
||||
.gpio = GPIOB,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_4,
|
||||
.GPIO_Mode = GPIO_OType_OD,
|
||||
.GPIO_Mode = GPIO_Mode_OUT,
|
||||
.GPIO_OType = GPIO_OType_OD,
|
||||
.GPIO_Speed = GPIO_Speed_Level_1,
|
||||
},
|
||||
},
|
||||
.active_low = true
|
||||
.active_low = false
|
||||
},
|
||||
};
|
||||
|
||||
@ -208,6 +230,7 @@ static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
|
||||
|
||||
static const struct pios_usart_cfg pios_usart_generic_main_cfg = {
|
||||
.regs = USART1,
|
||||
.remap = GPIO_AF_0,
|
||||
.init = {
|
||||
.USART_BaudRate = 57600,
|
||||
.USART_WordLength = USART_WordLength_8b,
|
||||
@ -219,8 +242,7 @@ static const struct pios_usart_cfg pios_usart_generic_main_cfg = {
|
||||
.irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USART1_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelPriority = PIOS_IRQ_PRIO_MID,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
@ -229,7 +251,8 @@ static const struct pios_usart_cfg pios_usart_generic_main_cfg = {
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_10,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_IPU,
|
||||
.GPIO_OType = GPIO_OType_OD,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
},
|
||||
},
|
||||
.tx = {
|
||||
@ -237,7 +260,8 @@ static const struct pios_usart_cfg pios_usart_generic_main_cfg = {
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_9,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -20,11 +20,16 @@ ifndef OPENPILOT_IS_COOL
|
||||
$(error Top level Makefile must be used to build this target)
|
||||
endif
|
||||
|
||||
## The standard CMSIS startup
|
||||
SRC += $(CMSIS_DEVICEDIR)/Source/system_stm32f0xx.c
|
||||
PIOS_OMITS_USB = YES
|
||||
PIOS_APPS_MINIMAL = YES
|
||||
|
||||
include ../board-info.mk
|
||||
include $(ROOT_DIR)/make/firmware-defs.mk
|
||||
|
||||
## The standard CMSIS startup
|
||||
SRC += $(CMSIS_DEVICEDIR)/system_stm32f0xx.c
|
||||
|
||||
|
||||
include $(ROOT_DIR)/make/boot-defs.mk
|
||||
include $(ROOT_DIR)/make/common-defs.mk
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
#define PIOS_INCLUDE_LED
|
||||
#define PIOS_INCLUDE_IAP
|
||||
#define PIOS_INCLUDE_COM
|
||||
#define PIOS_INCLUDE_USART
|
||||
#define PIOS_INCLUDE_COM_MSG
|
||||
#define PIOS_INCLUDE_BL_HELPER
|
||||
#define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT
|
||||
|
@ -27,6 +27,8 @@
|
||||
*/
|
||||
|
||||
#include <pios.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <pios_board_info.h>
|
||||
#include <op_dfu.h>
|
||||
#include <pios_iap.h>
|
||||
@ -36,7 +38,6 @@
|
||||
/* Prototype of PIOS_Board_Init() function */
|
||||
extern void PIOS_Board_Init(void);
|
||||
extern void FLASH_Download();
|
||||
#define BSL_HOLD_STATE ((PIOS_USB_DETECT_GPIO_PORT->IDR & PIOS_USB_DETECT_GPIO_PIN) ? 0 : 1)
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
typedef void (*pFunction)(void);
|
||||
@ -59,10 +60,9 @@ uint8_t tempcount = 0;
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
DFUStates DeviceState;
|
||||
int16_t status = 0;
|
||||
uint8_t JumpToApp = FALSE;
|
||||
uint8_t GO_dfu = FALSE;
|
||||
uint8_t USB_connected = FALSE;
|
||||
uint8_t User_DFU_request = FALSE;
|
||||
bool JumpToApp = false;
|
||||
bool GO_dfu = false;
|
||||
bool User_DFU_request = false;
|
||||
static uint8_t mReceive_Buffer[63];
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count);
|
||||
@ -75,36 +75,33 @@ int main()
|
||||
PIOS_Board_Init();
|
||||
PIOS_IAP_Init();
|
||||
|
||||
USB_connected = FALSE;
|
||||
|
||||
if (PIOS_IAP_CheckRequest() == TRUE) {
|
||||
if (PIOS_IAP_CheckRequest() == false) {
|
||||
PIOS_DELAY_WaitmS(1000);
|
||||
User_DFU_request = TRUE;
|
||||
User_DFU_request = false;
|
||||
PIOS_IAP_ClearRequest();
|
||||
}
|
||||
|
||||
GO_dfu = (USB_connected == TRUE) || (User_DFU_request == TRUE);
|
||||
GO_dfu = (User_DFU_request == true);
|
||||
|
||||
if (GO_dfu == TRUE) {
|
||||
PIOS_Board_Init();
|
||||
if (User_DFU_request == TRUE) {
|
||||
if (GO_dfu == true) {
|
||||
if (User_DFU_request == true) {
|
||||
DeviceState = DFUidle;
|
||||
} else {
|
||||
DeviceState = BLidle;
|
||||
}
|
||||
} else {
|
||||
JumpToApp = TRUE;
|
||||
JumpToApp = true;
|
||||
}
|
||||
|
||||
uint32_t stopwatch = 0;
|
||||
uint32_t prev_ticks = PIOS_DELAY_GetuS();
|
||||
while (TRUE) {
|
||||
while (true) {
|
||||
/* Update the stopwatch */
|
||||
uint32_t elapsed_ticks = PIOS_DELAY_GetuSSince(prev_ticks);
|
||||
prev_ticks += elapsed_ticks;
|
||||
stopwatch += elapsed_ticks;
|
||||
|
||||
if (JumpToApp == TRUE) {
|
||||
if (JumpToApp == true) {
|
||||
jump_to_app();
|
||||
}
|
||||
|
||||
@ -164,8 +161,8 @@ int main()
|
||||
if (stopwatch > 50 * 1000 * 1000) {
|
||||
stopwatch = 0;
|
||||
}
|
||||
if ((stopwatch > 6 * 1000 * 1000) && ((DeviceState == BLidle) || (DeviceState == DFUidle && !USB_connected))) {
|
||||
JumpToApp = TRUE;
|
||||
if ((stopwatch > 6 * 1000 * 1000) && ((DeviceState == BLidle) || (DeviceState == DFUidle))) {
|
||||
JumpToApp = true;
|
||||
}
|
||||
|
||||
processRX();
|
||||
@ -183,8 +180,7 @@ void jump_to_app()
|
||||
RCC_APB1PeriphResetCmd(0xffffffff, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(0xffffffff, DISABLE);
|
||||
RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);
|
||||
_SetCNTR(0); // clear interrupt mask
|
||||
_SetISTR(0); // clear all requests
|
||||
|
||||
JumpAddress = *(__IO uint32_t *)(bdinfo->fw_base + 4);
|
||||
Jump_To_Application = (pFunction)JumpAddress;
|
||||
/* Initialize user application's Stack Pointer */
|
||||
@ -210,8 +206,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count)
|
||||
|
||||
uint8_t processRX()
|
||||
{
|
||||
// if (PIOS_COM_MSG_Receive(PIOS_COM_TELEM_USB, mReceive_Buffer, sizeof(mReceive_Buffer))) {
|
||||
// processComand(mReceive_Buffer);
|
||||
// }
|
||||
return TRUE;
|
||||
if (PIOS_COM_MSG_Receive(PIOS_COM_TELEM_RF, mReceive_Buffer, sizeof(mReceive_Buffer))) {
|
||||
processComand(mReceive_Buffer);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -36,8 +36,9 @@
|
||||
*/
|
||||
#include "../board_hw_defs.c"
|
||||
|
||||
uint32_t pios_com_telem_usb_id;
|
||||
uint32_t pios_com_telem_rf_id;
|
||||
|
||||
void setupCom();
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
* initializes all the core subsystems on this specific hardware
|
||||
@ -50,12 +51,6 @@ void PIOS_Board_Init(void)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Enable Prefetch Buffer */
|
||||
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
|
||||
|
||||
/* Flash 2 wait state */
|
||||
FLASH_SetLatency(FLASH_Latency_2);
|
||||
|
||||
/* Delay system */
|
||||
PIOS_DELAY_Init();
|
||||
|
||||
@ -68,6 +63,16 @@ void PIOS_Board_Init(void)
|
||||
#endif /* PIOS_INCLUDE_LED */
|
||||
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE); // TODO Tirar
|
||||
setupCom();
|
||||
board_init_complete = true;
|
||||
}
|
||||
|
||||
void setupCom(){
|
||||
uint32_t pios_usart_generic_id;
|
||||
if (PIOS_USART_Init(&pios_usart_generic_id, &pios_usart_generic_main_cfg)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
if (PIOS_COM_MSG_Init(&pios_com_telem_rf_id, &pios_usart_com_driver, pios_usart_generic_id)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
}
|
||||
|
@ -57,8 +57,8 @@
|
||||
// ------------------------
|
||||
// BOOTLOADER_SETTINGS
|
||||
// ------------------------
|
||||
#define BOARD_READABLE TRUE
|
||||
#define BOARD_WRITABLE TRUE
|
||||
#define BOARD_READABLE true
|
||||
#define BOARD_WRITABLE true
|
||||
#define MAX_DEL_RETRYS 3
|
||||
|
||||
// ------------------------
|
||||
@ -122,6 +122,7 @@ extern uint32_t pios_i2c_gps_adapter_id;
|
||||
|
||||
extern uint32_t pios_com_telem_rf_id;
|
||||
#define PIOS_COM_TELEM_RF (pios_com_telem_rf_id)
|
||||
#define PIOS_COM_TELEM_USB (pios_com_telem_rf_id)
|
||||
|
||||
#if defined(PIOS_INCLUDE_DEBUG_CONSOLE)
|
||||
extern uint32_t pios_com_debug_id;
|
||||
|
Loading…
x
Reference in New Issue
Block a user