diff --git a/flight/Modules/RadioComBridge/RadioComBridge.c b/flight/Modules/RadioComBridge/RadioComBridge.c index b7f4619c3..a283be8e1 100644 --- a/flight/Modules/RadioComBridge/RadioComBridge.c +++ b/flight/Modules/RadioComBridge/RadioComBridge.c @@ -173,7 +173,7 @@ static int32_t RadioComBridgeInitialize(void) // Initialize the UAVObjects that we use GCSReceiverInitialize(); - PipXSettingsInitialize(); + PipXStatusInitialize(); data->send_gcsreceiver = false; data->send_pipxstatus = false; @@ -247,9 +247,10 @@ static void radio2ComBridgeTask(void *parameters) // Receive data from the radio port rx_bytes = PIOS_COM_ReceiveBuffer(data->radio_port, data->radio2com_buf, PIOS_PH_MAX_PACKET, 200); + + // Receive the packet. if (rx_bytes > 0) PHReceivePacket(pios_packet_handler, (PHPacketHandle)data->radio2com_buf, rx_bytes); - } } @@ -260,7 +261,7 @@ static void com2RadioBridgeTask(void * parameters) { uint32_t rx_bytes = 0; portTickType packet_start_time = 0; - uint32_t timeout = 500; + uint32_t timeout = 250; uint32_t inputPort; /* Handle usart/usb -> radio direction */ @@ -439,7 +440,7 @@ static void receiveData(uint8_t *buf, uint8_t len) { UAVTalkRxState state = UAVTalkProcessInputStreamQuiet(data->outUAVTalkCon, buf[i]); /* if(state == UAVTALK_STATE_ERROR) */ - /* DEBUG_PRINTF(2, "OUT Error\n\r"); */ + /* DEBUG_PRINTF(2, "OUT Error\n\r\r"); */ if((state == UAVTALK_STATE_COMPLETE) || (state == UAVTALK_STATE_SYNC)) { // Send the buffer up to this point diff --git a/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h b/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h index e0e389e70..750ac46a9 100755 --- a/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h +++ b/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h @@ -69,7 +69,7 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1 //------------------------ // WATCHDOG_SETTINGS //------------------------ -#define PIOS_WATCHDOG_TIMEOUT 250 +#define PIOS_WATCHDOG_TIMEOUT 500 #define PIOS_WDG_REGISTER BKP_DR4 #define PIOS_WDG_RADIOCOM 0x0001 #define PIOS_WDG_COMRADIO 0x0002 @@ -158,7 +158,7 @@ extern uint32_t pios_com_rfm22b_id; #define PIOS_COM_TELEM_USB (pios_com_telem_usb_id) #define PIOS_COM_VCP_USB (pios_com_vcp_usb_id) #define PIOS_COM_RFM22B_RF (pios_com_rfm22b_id) -#define PIOS_COM_BRIDGE_RADIO PIOS_COM_RFM22B_RF +#define PIOS_COM_BRIDGE_RADIO PIOS_COM_RFM22B_RF #define PIOS_COM_DEBUG PIOS_COM_FLEXI #define PIOS_COM_BRIDGE_COM PIOS_COM_TELEM_SERIAL @@ -292,4 +292,14 @@ uint32_t pios_packet_handler; #define RS_ECC_NPARITY 4 +//------------------------- +// Flash EEPROM Emulation +//------------------------- + +#define PIOS_FLASH_SIZE 0x20000 +#define PIOS_FLASH_EEPROM_START_ADDR 0x08000000 +#define PIOS_FLASH_PAGE_SIZE 1024 +#define PIOS_FLASH_EEPROM_ADDR (PIOS_FLASH_EEPROM_START_ADDR + PIOS_FLASH_SIZE - PIOS_FLASH_PAGE_SIZE) +#define PIOS_FLASH_EEPROM_LEN PIOS_FLASH_PAGE_SIZE + #endif /* STM32103CB_PIPXTREME_H_ */ diff --git a/flight/PipXtreme/Makefile b/flight/PipXtreme/Makefile index 55a68e830..e7985d2d4 100755 --- a/flight/PipXtreme/Makefile +++ b/flight/PipXtreme/Makefile @@ -159,6 +159,7 @@ SRC += $(PIOSSTM32F10X)/pios_wdg.c SRC += $(PIOSSTM32F10X)/pios_tim.c SRC += $(PIOSSTM32F10X)/pios_pwm.c SRC += $(PIOSSTM32F10X)/pios_adc.c +SRC += $(PIOSSTM32F10X)/pios_eeprom.c # PIOS USB related files (separated to make code maintenance more easy) SRC += $(PIOSSTM32F10X)/pios_usb.c diff --git a/flight/PipXtreme/System/inc/pios_config.h b/flight/PipXtreme/System/inc/pios_config.h index 1ff6fca6a..39d51ef1d 100755 --- a/flight/PipXtreme/System/inc/pios_config.h +++ b/flight/PipXtreme/System/inc/pios_config.h @@ -35,7 +35,6 @@ /* Enable/Disable PiOS Modules */ #define PIOS_INCLUDE_DELAY -//#define PIOS_INCLUDE_I2C #define PIOS_INCLUDE_IRQ #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_IAP @@ -44,16 +43,10 @@ #define PIOS_INCLUDE_TIM /* Supported receiver interfaces */ -//#define PIOS_INCLUDE_SPEKTRUM -//#define PIOS_INCLUDE_SBUS #define PIOS_INCLUDE_PPM #define PIOS_INCLUDE_PWM /* Supported USART-based PIOS modules */ -#define PIOS_INCLUDE_TELEMETRY_RF -//#define PIOS_INCLUDE_GPS - -//#define PIOS_INCLUDE_SERVO #define PIOS_INCLUDE_SPI #define PIOS_INCLUDE_SYS #define PIOS_INCLUDE_USART @@ -66,11 +59,9 @@ #define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_EXTI #define PIOS_INCLUDE_RTC -//#define PIOS_INCLUDE_WDG +#define PIOS_INCLUDE_WDG #define PIOS_INCLUDE_BL_HELPER - -/* A really shitty setting saving implementation */ -//#define PIOS_INCLUDE_FLASH_SECTOR_SETTINGS +#define PIOS_INCLUDE_FLASH_EEPROM /* Defaults for Logging */ #define LOG_FILENAME "PIOS.LOG" diff --git a/flight/PipXtreme/System/pios_board.c b/flight/PipXtreme/System/pios_board.c index 71ce058a5..3fd97157d 100755 --- a/flight/PipXtreme/System/pios_board.c +++ b/flight/PipXtreme/System/pios_board.c @@ -30,6 +30,7 @@ #include #include +#include #include #define PIOS_COM_SERIAL_RX_BUF_LEN 192 @@ -73,8 +74,10 @@ void PIOS_Board_Init(void) { EventDispatcherInitialize(); UAVObjInitialize(); +#ifdef PIOS_INCLUDE_WDG /* Initialize watchdog as early as possible to catch faults during init */ PIOS_WDG_Init(); +#endif /* PIOS_INCLUDE_WDG */ /* Initialize IAP */ PIOS_IAP_Init(); @@ -82,12 +85,25 @@ void PIOS_Board_Init(void) { #if defined(PIOS_INCLUDE_RTC) /* Initialize the real-time clock and its associated tick */ PIOS_RTC_Init(&pios_rtc_main_cfg); -#endif +#endif /* PIOS_INCLUDE_RTC */ + + PipXSettingsInitialize(); #if defined(PIOS_INCLUDE_LED) PIOS_LED_Init(&pios_led_cfg); #endif /* PIOS_INCLUDE_LED */ +#if defined(PIOS_INCLUDE_FLASH_EEPROM) + PIOS_EEPROM_Init(&pios_eeprom_cfg); + + /* Read the settings from flash. */ + PipXSettingsData pipxSettings; + if (PIOS_EEPROM_Load((uint8_t*)&pipxSettings, sizeof(PipXSettingsData)) == 0) + PipXSettingsSet(&pipxSettings); + else + PipXSettingsGet(&pipxSettings); +#endif /* PIOS_INCLUDE_FLASH_EEPROM */ + /* Initialize the task monitor library */ TaskMonitorInitialize(); diff --git a/flight/board_hw_defs/pipxtreme/board_hw_defs.c b/flight/board_hw_defs/pipxtreme/board_hw_defs.c index 583318f22..32c5f4994 100644 --- a/flight/board_hw_defs/pipxtreme/board_hw_defs.c +++ b/flight/board_hw_defs/pipxtreme/board_hw_defs.c @@ -474,6 +474,15 @@ const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = { }; #endif /* PIOS_INCLUDE_USB_CDC */ +#if defined(PIOS_INCLUDE_FLASH_EEPROM) +#include + +const struct pios_eeprom_cfg pios_eeprom_cfg = { + .base_address = PIOS_FLASH_EEPROM_ADDR, + .max_size = PIOS_FLASH_EEPROM_LEN, +}; +#endif /* PIOS_INCLUDE_FLASH_EEPROM */ + #if defined(PIOS_INCLUDE_RFM22B) #include