From 98b0f406dc06c6741582a65656b312bf0111b460 Mon Sep 17 00:00:00 2001 From: zedamota Date: Sun, 21 Nov 2010 19:37:40 +0000 Subject: [PATCH] OP-21/Bootloader - fixes GPS connected issues, enhances timings problems, further work on serial support git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2136 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/Bootloaders/OpenPilot/Makefile | 2 +- flight/Bootloaders/OpenPilot/inc/common.h | 8 + .../Bootloaders/OpenPilot/inc/pios_config.h | 13 +- flight/Bootloaders/OpenPilot/main.c | 14 +- flight/Bootloaders/OpenPilot/op_dfu.c | 2 +- flight/Bootloaders/OpenPilot/pios_board.c | 150 +----------------- flight/PiOS/Boards/STM3210E_OP.h | 15 +- 7 files changed, 36 insertions(+), 168 deletions(-) diff --git a/flight/Bootloaders/OpenPilot/Makefile b/flight/Bootloaders/OpenPilot/Makefile index 5cdaec2ca..11d0c7f7e 100644 --- a/flight/Bootloaders/OpenPilot/Makefile +++ b/flight/Bootloaders/OpenPilot/Makefile @@ -155,7 +155,7 @@ SRC += $(PIOSCOMMON)/pios_com.c #SRC += $(PIOSCOMMON)/pios_bmp085.c SRC += $(PIOSCOMMON)/pios_opahrs_v0.c SRC += $(PIOSCOMMON)/pios_bl_helper.c - +SRC += $(PIOSCOMMON)/pios_iap.c SRC += $(PIOSCOMMON)/pios_opahrs_proto.c SRC += $(PIOSCOMMON)/printf-stdarg.c diff --git a/flight/Bootloaders/OpenPilot/inc/common.h b/flight/Bootloaders/OpenPilot/inc/common.h index cb1ae045d..3e8496d3f 100644 --- a/flight/Bootloaders/OpenPilot/inc/common.h +++ b/flight/Bootloaders/OpenPilot/inc/common.h @@ -66,6 +66,14 @@ typedef enum { //2 } DFUTransfer; /**************************************************/ +/* OP_DFU transfer port */ +/**************************************************/ +typedef enum { + Usb, //0 + Serial +//2 +} DFUPort; +/**************************************************/ /* OP_DFU programable programable HW types */ /**************************************************/ typedef enum { diff --git a/flight/Bootloaders/OpenPilot/inc/pios_config.h b/flight/Bootloaders/OpenPilot/inc/pios_config.h index b94d83759..327a273f2 100644 --- a/flight/Bootloaders/OpenPilot/inc/pios_config.h +++ b/flight/Bootloaders/OpenPilot/inc/pios_config.h @@ -36,27 +36,17 @@ #define PIOS_INCLUDE_BL_HELPER #define USB_HID /* Enable/Disable PiOS Modules */ -//#define PIOS_INCLUDE_ADC #define PIOS_INCLUDE_DELAY -//#define PIOS_INCLUDE_I2C #define PIOS_INCLUDE_IRQ #define PIOS_INCLUDE_LED -//#define PIOS_INCLUDE_SPEKTRUM -//#define PIOS_INCLUDE_PPM -//#define PIOS_INCLUDE_PWM -//#define PIOS_INCLUDE_SERVO #define PIOS_INCLUDE_SPI #define PIOS_INCLUDE_SYS #define PIOS_INCLUDE_USART #define PIOS_INCLUDE_USB_HID -//#define PIOS_INCLUDE_BMP085 #define PIOS_INCLUDE_OPAHRS #define PIOS_INCLUDE_COM -//#define PIOS_INCLUDE_SDCARD -//#define PIOS_INCLUDE_SETTINGS -//#define PIOS_INCLUDE_FREERTOS #define PIOS_INCLUDE_GPIO -//#define PIOS_INCLUDE_EXTI +#define PIOS_NO_GPS /* Defaults for Logging */ @@ -73,7 +63,6 @@ #define SERVOS_POSITION_MIN 800 #define SERVOS_POSITION_MAX 2200 - #endif /* PIOS_CONFIG_H */ /** * @} diff --git a/flight/Bootloaders/OpenPilot/main.c b/flight/Bootloaders/OpenPilot/main.c index 1660f3291..067441183 100644 --- a/flight/Bootloaders/OpenPilot/main.c +++ b/flight/Bootloaders/OpenPilot/main.c @@ -38,10 +38,11 @@ #include "stopwatch.h" #include "op_dfu.h" #include "usb_lib.h" +#include "pios_iap.h" /* 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) +#define BSL_HOLD_STATE ((PIOS_USB_DETECT_GPIO_PORT->IDR & PIOS_USB_DETECT_GPIO_PIN) ? 0 : 1) /* Private typedef -----------------------------------------------------------*/ typedef void (*pFunction)(void); @@ -59,6 +60,7 @@ uint32_t sweep_steps2 = 100; // * 5 mS -> 500 mS /* Extern variables ----------------------------------------------------------*/ DFUStates DeviceState; +DFUPort ProgPort; uint8_t JumpToApp = FALSE; uint8_t GO_dfu = FALSE; uint8_t USB_connected = FALSE; @@ -81,13 +83,21 @@ int main() { if (BSL_HOLD_STATE == 0) USB_connected = TRUE; + PIOS_IAP_Init(); + if (PIOS_IAP_CheckRequest() == TRUE) { + User_DFU_request = TRUE; + PIOS_IAP_ClearRequest(); + } GO_dfu = (USB_connected==TRUE) || (User_DFU_request==TRUE); if (GO_dfu == TRUE) { + if(USB_connected) + ProgPort=Usb; + else + ProgPort=Serial; PIOS_Board_Init(); PIOS_OPAHRS_Init(); DeviceState = BLidle; STOPWATCH_Init(100); - USB_connected = TRUE; PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 0); //OPDfuIni(false); diff --git a/flight/Bootloaders/OpenPilot/op_dfu.c b/flight/Bootloaders/OpenPilot/op_dfu.c index 708021cc1..3265f8779 100644 --- a/flight/Bootloaders/OpenPilot/op_dfu.c +++ b/flight/Bootloaders/OpenPilot/op_dfu.c @@ -158,7 +158,7 @@ void processComand(uint8_t *xReceive_Buffer) { case EnterDFU: if (((DeviceState == BLidle) && (Data0 < numberOfDevices)) || (DeviceState == DFUidle)) { - if (Data0 > 0) + if (Data0 > 0)//PORQUE??? OPDfuIni(TRUE); DeviceState = DFUidle; currentProgrammingDestination = devicesTable[Data0].programmingType; diff --git a/flight/Bootloaders/OpenPilot/pios_board.c b/flight/Bootloaders/OpenPilot/pios_board.c index 8d45a782f..d5dc23e7a 100644 --- a/flight/Bootloaders/OpenPilot/pios_board.c +++ b/flight/Bootloaders/OpenPilot/pios_board.c @@ -55,33 +55,11 @@ void PIOS_Board_Init(void) { /* SPI Init */ PIOS_SPI_Init(); - /* Enable and mount the SDCard */ -// PIOS_SDCARD_Init(); -// PIOS_SDCARD_MountFS(0); -#if defined(PIOS_INCLUDE_SPEKTRUM) - /* SPEKTRUM init must come before comms */ - PIOS_SPEKTRUM_Init(); -#endif - /* Initialize UAVObject libraries */ -// EventDispatcherInitialize(); -// UAVObjInitialize(); -// UAVObjectsInitializeAll(); - - /* Initialize the alarms library */ -// AlarmsInitialize(); /* Initialize the PiOS library */ PIOS_COM_Init(); - //PIOS_Servo_Init(); - //PIOS_ADC_Init(); PIOS_GPIO_Init(); -#if defined(PIOS_INCLUDE_PWM) - PIOS_PWM_Init(); -#endif -#if defined(PIOS_INCLUDE_PPM) - PIOS_PPM_Init(); -#endif #if defined(PIOS_INCLUDE_USB_HID) PIOS_USB_HID_Init(0); #endif @@ -358,52 +336,7 @@ const struct pios_usart_cfg pios_usart_telem_cfg = { }, }; -/* - * GPS USART - */ -void PIOS_USART_gps_irq_handler(void); -void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_gps_irq_handler"))); -const struct pios_usart_cfg pios_usart_gps_cfg = { - .regs = USART3, - .remap = GPIO_PartialRemap_USART3, - .init = { - #if defined (PIOS_COM_GPS_BAUDRATE) - .USART_BaudRate = PIOS_COM_GPS_BAUDRATE, - #else - .USART_BaudRate = 57600, - #endif - .USART_WordLength = USART_WordLength_8b, - .USART_Parity = USART_Parity_No, - .USART_StopBits = USART_StopBits_1, - .USART_HardwareFlowControl = USART_HardwareFlowControl_None, - .USART_Mode = USART_Mode_Rx | USART_Mode_Tx, - }, - .irq = { - .handler = PIOS_USART_gps_irq_handler, - .init = { - .NVIC_IRQChannel = USART3_IRQn, - .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH, - .NVIC_IRQChannelSubPriority = 0, - .NVIC_IRQChannelCmd = ENABLE, - }, - }, - .rx = { - .gpio = GPIOC, - .init = { - .GPIO_Pin = GPIO_Pin_11, - .GPIO_Speed = GPIO_Speed_2MHz, - .GPIO_Mode = GPIO_Mode_IPU, - }, - }, - .tx = { - .gpio = GPIOC, - .init = { - .GPIO_Pin = GPIO_Pin_10, - .GPIO_Speed = GPIO_Speed_2MHz, - .GPIO_Mode = GPIO_Mode_AF_PP, - }, - }, -}; + #ifdef PIOS_COM_AUX /* @@ -454,54 +387,6 @@ const struct pios_usart_cfg pios_usart_aux_cfg = { }; #endif -#ifdef PIOS_COM_SPEKTRUM -/* - * SPEKTRUM USART - */ -void PIOS_USART_spektrum_irq_handler(void); -void USART1_IRQHandler() __attribute__ ((alias ("PIOS_USART_spektrum_irq_handler"))); -const struct pios_usart_cfg pios_usart_spektrum_cfg = { - .regs = USART1, - .init = { - #if defined (PIOS_COM_SPEKTRUM_BAUDRATE) - .USART_BaudRate = PIOS_COM_SPEKTRUM_BAUDRATE, - #else - .USART_BaudRate = 115200, - #endif - .USART_WordLength = USART_WordLength_8b, - .USART_Parity = USART_Parity_No, - .USART_StopBits = USART_StopBits_1, - .USART_HardwareFlowControl = USART_HardwareFlowControl_None, - .USART_Mode = USART_Mode_Rx, - }, - .irq = { - .handler = PIOS_USART_spektrum_irq_handler, - .init = { - .NVIC_IRQChannel = USART1_IRQn, - .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH, - .NVIC_IRQChannelSubPriority = 0, - .NVIC_IRQChannelCmd = ENABLE, - }, - }, - .rx = { - .gpio = GPIOA, - .init = { - .GPIO_Pin = GPIO_Pin_10, - .GPIO_Speed = GPIO_Speed_2MHz, - .GPIO_Mode = GPIO_Mode_IPU, - }, - }, - .tx = { - .gpio = GPIOA, - .init = { - .GPIO_Pin = GPIO_Pin_9, - .GPIO_Speed = GPIO_Speed_2MHz, - .GPIO_Mode = GPIO_Mode_IN_FLOATING, - }, - }, -}; -#endif - /* * Board specific number of devices. */ @@ -510,22 +395,12 @@ struct pios_usart_dev pios_usart_devs[] = { { .cfg = &pios_usart_telem_cfg, }, -#define PIOS_USART_GPS 1 - { - .cfg = &pios_usart_gps_cfg, - }, #ifdef PIOS_COM_AUX -#define PIOS_USART_AUX 2 +#define PIOS_USART_AUX 1 { .cfg = &pios_usart_aux_cfg, }, #endif -#ifdef PIOS_COM_SPEKTRUM -#define PIOS_USART_AUX 2 - { - .cfg = &pios_usart_spektrum_cfg, - }, -#endif }; uint8_t pios_usart_num_devices = NELEMENTS(pios_usart_devs); @@ -535,10 +410,6 @@ void PIOS_USART_telem_irq_handler(void) PIOS_USART_IRQ_Handler(PIOS_USART_TELEM); } -void PIOS_USART_gps_irq_handler(void) -{ - PIOS_USART_IRQ_Handler(PIOS_USART_GPS); -} #ifdef PIOS_COM_AUX void PIOS_USART_aux_irq_handler(void) @@ -547,12 +418,6 @@ void PIOS_USART_aux_irq_handler(void) } #endif -#ifdef PIOS_COM_SPEKTRUM -void PIOS_USART_spektrum_irq_handler(void) -{ - SPEKTRUM_IRQHandler(); -} -#endif /* * COM devices @@ -569,10 +434,6 @@ struct pios_com_dev pios_com_devs[] = { .id = PIOS_USART_TELEM, .driver = &pios_usart_com_driver, }, - { - .id = PIOS_USART_GPS, - .driver = &pios_usart_com_driver, - }, #if defined(PIOS_INCLUDE_USB_HID) { .id = 0, @@ -585,12 +446,7 @@ struct pios_com_dev pios_com_devs[] = { .driver = &pios_usart_com_driver, }, #endif -#ifdef PIOS_COM_SPEKTRUM - { - .id = PIOS_USART_AUX, - .driver = &pios_usart_com_driver, - }, -#endif + }; const uint8_t pios_com_num_devices = NELEMENTS(pios_com_devs); diff --git a/flight/PiOS/Boards/STM3210E_OP.h b/flight/PiOS/Boards/STM3210E_OP.h index 2428acafd..d0fc8932a 100644 --- a/flight/PiOS/Boards/STM3210E_OP.h +++ b/flight/PiOS/Boards/STM3210E_OP.h @@ -128,14 +128,19 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8 #define PIOS_COM_TELEM_BAUDRATE 57600 #define PIOS_COM_GPS_BAUDRATE 57600 -#define PIOS_COM_TELEM_RF 0 -#define PIOS_COM_GPS 1 -#define PIOS_COM_TELEM_USB 2 +#ifdef PIOS_NO_GPS + #define PIOS_COM_TELEM_RF 0 + #define PIOS_COM_TELEM_USB 1 +#else + #define PIOS_COM_TELEM_RF 0 + #define PIOS_COM_GPS 1 + #define PIOS_COM_TELEM_USB 2 +#endif #ifdef PIOS_ENABLE_AUX_UART #define PIOS_COM_AUX_BAUDRATE 57600 - #define PIOS_COM_AUX 3 - #define PIOS_COM_DEBUG PIOS_COM_AUX + #define PIOS_COM_AUX 3 + #define PIOS_COM_DEBUG PIOS_COM_AUX #endif #ifdef PIOS_INCLUDE_SPEKTRUM