Merge from 2.3

This commit is contained in:
Bertrand Songis
2019-12-05 09:29:11 +01:00
161 changed files with 3682 additions and 10305 deletions
+19 -8
View File
@@ -14,6 +14,11 @@ set(HAPTIC YES)
set(GUI_DIR colorlcd)
set(NAVIGATION_TYPE horus)
set(TARGET_DIR horus)
set(LINKER_SCRIPT targets/horus/stm32f4_flash.ld)
set(RTC_BACKUP_RAM YES)
set(LUA YES)
set(PPM_LIMITS_SYMETRICAL YES)
set(USB_SERIAL ON CACHE BOOL "Enable USB serial (CDC)")
if(BOOTLOADER)
set(LINKER_SCRIPT targets/horus/stm32f4_flash_bootloader.ld)
@@ -21,10 +26,6 @@ else()
set(LINKER_SCRIPT targets/horus/stm32f4_flash.ld)
endif()
set(RAMBACKUP YES)
set(PPM_LIMITS_SYMETRICAL YES)
set(USB_SERIAL ON CACHE BOOL "Enable USB serial (CDC)")
option(YAML_STORAGE "Enable YAML storage" NO)
if(YAML_STORAGE)
set(STORAGE_FORMAT YAML)
@@ -104,7 +105,13 @@ endif()
add_definitions(-DPCBREV=${PCBREV})
add_definitions(-DPCBREV_${PCBREV})
set(RADIO_DEPENDENCIES ${RADIO_DEPENDENCIES} ${BITMAPS_TARGET} truetype_fonts)
set(RADIO_DEPENDENCIES
${RADIO_DEPENDENCIES}
${BITMAPS_TARGET}
truetype_fonts
)
set(FIRMWARE_DEPENDENCIES datacopy)
add_definitions(-DPCBHORUS -DSTM32F429_439xx -DSDRAM -DCOLORLCD -DHARDWARE_KEYS)
add_definitions(-DEEPROM_VARIANT=0 -DAUDIO -DVOICE -DRTCLOCK)
@@ -198,9 +205,13 @@ set(STM32LIB_SRC
)
if(PYTHONINTERP_FOUND)
add_custom_target(datacopy
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
WORKING_DIRECTORY ${RADIO_DIRECTORY}/src
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs.h -DPCBHORUS -DPCBX10 -DCPUARM -DCOLORLCD -DBACKUP -Itargets/horus > storage/datacopy.cpp
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs.h -DPCBHORUS -DPCBX10 -DCPUARM -DCOLORLCD -DBACKUP -Itargets/horus > ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
DEPENDS ${RADIO_DIRECTORY}/src/datastructs.h ${RADIO_DIRECTORY}/util/generate_datacopy.py
)
)
add_custom_target(datacopy
DEPENDS ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
)
endif()
+9 -8
View File
@@ -29,10 +29,6 @@ extern "C" {
}
#endif
uint32_t shutdownRequest; // Stores intentional shutdown to avoid reboot loop
uint32_t shutdownReason; // Used for detecting unexpected reboots regardless of reason
uint32_t powerupReason __NOINIT; // Stores power up reason beyond initialization for emergency mode activation
HardwareOptions hardwareOptions;
void watchdogInit(unsigned int duration)
@@ -40,7 +36,7 @@ void watchdogInit(unsigned int duration)
IWDG->KR = 0x5555; // Unlock registers
IWDG->PR = 3; // Divide by 32 => 1kHz clock
IWDG->KR = 0x5555; // Unlock registers
IWDG->RLR = duration; // 1.5 seconds nominal
IWDG->RLR = duration;
IWDG->KR = 0xAAAA; // reload
IWDG->KR = 0xCCCC; // start
}
@@ -173,6 +169,7 @@ void boardInit()
#endif
ledInit();
#if defined(PCBX10) && !defined(RADIO_T16)
sportUpdateInit();
#endif
@@ -189,7 +186,7 @@ void boardOff()
backlightEnable(0);
while (pwrPressed()) {
wdt_reset();
WDG_RESET();
}
SysTick->CTRL = 0; // turn off systick
@@ -209,8 +206,12 @@ void boardOff()
// Shutdown the Haptic
hapticDone();
shutdownRequest = SHUTDOWN_REQUEST;
shutdownReason = NORMAL_POWER_OFF;
#if defined(RTC_BACKUP_RAM)
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, DISABLE);
PWR_BackupRegulatorCmd(DISABLE);
#endif
RTC->BKP0R = SHUTDOWN_REQUEST;
pwrOff();
}
+37 -21
View File
@@ -136,7 +136,7 @@ DRESULT __disk_write(BYTE drv, const BYTE * buff, DWORD sector, UINT count);
#define FLASH_PAGESIZE 256
void unlockFlash();
void lockFlash();
void flashWrite(uint32_t * address, uint32_t * buffer);
void flashWrite(uint32_t * address, const uint32_t * buffer);
uint32_t isFirmwareStart(const uint8_t * buffer);
uint32_t isBootloaderStart(const uint8_t * buffer);
@@ -305,28 +305,22 @@ void rotaryEncoderInit();
void rotaryEncoderCheck();
// WDT driver
#define WDTO_500MS 500
extern uint32_t powerupReason;
#define SHUTDOWN_REQUEST 0xDEADBEEF
#define NO_SHUTDOWN_REQUEST ~SHUTDOWN_REQUEST
#define DIRTY_SHUTDOWN 0xCAFEDEAD
#define NORMAL_POWER_OFF ~DIRTY_SHUTDOWN
#define WDG_DURATION 500 /*ms*/
void watchdogInit(unsigned int duration);
#if defined(SIMU)
#define WAS_RESET_BY_WATCHDOG() (false)
#define WAS_RESET_BY_SOFTWARE() (false)
#define WAS_RESET_BY_WATCHDOG_OR_SOFTWARE() (false)
#define wdt_enable(x)
#define wdt_reset()
#define WDG_ENABLE(x)
#define WDG_RESET()
#else
#if defined(WATCHDOG)
#define wdt_enable(x) watchdogInit(x)
#define wdt_reset() IWDG->KR = 0xAAAA
#define WDG_ENABLE(x) watchdogInit(x)
#define WDG_RESET() IWDG->KR = 0xAAAA
#else
#define wdt_enable(x)
#define wdt_reset()
#define WDG_ENABLE(x)
#define WDG_RESET()
#endif
#define WAS_RESET_BY_WATCHDOG() (RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF))
#define WAS_RESET_BY_SOFTWARE() (RCC->CSR & RCC_CSR_SFTRSTF)
@@ -453,14 +447,41 @@ extern volatile uint32_t pwm_interrupt_count;
#define BATTERY_MAX 115 // 11.5V
#endif
#if defined(__cplusplus)
enum PowerReason {
SHUTDOWN_REQUEST = 0xDEADBEEF,
SOFTRESET_REQUEST = 0xCAFEDEAD,
};
constexpr uint32_t POWER_REASON_SIGNATURE = 0x0178746F;
inline bool UNEXPECTED_SHUTDOWN()
{
#if defined(SIMU) || defined(NO_UNEXPECTED_SHUTDOWN)
return false;
#else
if (WAS_RESET_BY_WATCHDOG())
return true;
else if (WAS_RESET_BY_SOFTWARE())
return RTC->BKP0R != SOFTRESET_REQUEST;
else
return RTC->BKP1R == POWER_REASON_SIGNATURE && RTC->BKP0R != SHUTDOWN_REQUEST;
#endif
}
inline void SET_POWER_REASON(uint32_t value)
{
RTC->BKP0R = value;
RTC->BKP1R = POWER_REASON_SIGNATURE;
}
#endif
#if defined(__cplusplus) && !defined(SIMU)
extern "C" {
#endif
// Power driver
#define SOFT_PWR_CTRL
extern uint32_t shutdownRequest; // Stores intentional shutdown to avoid reboot loop
extern uint32_t shutdownReason; // Used for detecting unexpected reboots regardless of reason
void pwrInit();
uint32_t pwrCheck();
void pwrOn();
@@ -468,11 +489,6 @@ void pwrOff();
void pwrResetHandler();
bool pwrPressed();
uint32_t pwrPressedDuration();
#if defined(SIMU) || defined(NO_UNEXPECTED_SHUTDOWN)
#define UNEXPECTED_SHUTDOWN() (false)
#else
#define UNEXPECTED_SHUTDOWN() ((powerupReason == DIRTY_SHUTDOWN) || WAS_RESET_BY_WATCHDOG_OR_SOFTWARE())
#endif
// Led driver
void ledInit();
@@ -48,7 +48,7 @@ void bootloaderInitScreen()
backlightEnable(BACKLIGHT_LEVEL_MAX);
//TODO: load/decompress bitmaps
// TODO: load/decompress bitmaps
extern void loadFonts();
loadFonts();
}
@@ -73,7 +73,7 @@ void bootloaderDrawScreen(BootloaderState st, int opt, const char* str)
lcd->clear(DEFAULT_BGCOLOR);
if (st == ST_START) {
bootloaderDrawTitle(88, "HORUS BOOTLOADER");
bootloaderDrawTitle(88, "OpenTX Bootloader");
lcd->drawBitmapPattern(90, 72, LBM_FLASH, DEFAULT_COLOR);
lcd->drawText(124, 75, "Write Firmware");
+10 -23
View File
@@ -199,34 +199,21 @@ uint32_t switchState(uint8_t index)
void keysInit()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOB_PINS;
GPIO_Init(GPIOB, &GPIO_InitStructure);
INIT_KEYS_PINS(GPIOB);
#if defined(KEYS_GPIOC_PINS)
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOC_PINS;
GPIO_Init(GPIOC, &GPIO_InitStructure);
INIT_KEYS_PINS(GPIOC);
#endif
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOD_PINS;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOE_PINS;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOH_PINS;
GPIO_Init(GPIOH, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOI_PINS;
GPIO_Init(GPIOI, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOJ_PINS;
GPIO_Init(GPIOJ, &GPIO_InitStructure);
INIT_KEYS_PINS(GPIOD);
INIT_KEYS_PINS(GPIOE);
INIT_KEYS_PINS(GPIOG);
INIT_KEYS_PINS(GPIOH);
INIT_KEYS_PINS(GPIOI);
INIT_KEYS_PINS(GPIOJ);
}
+2 -35
View File
@@ -19,6 +19,7 @@
*/
#include "board.h"
#include "storage/rtc_backup.h"
void pwrInit()
{
@@ -81,9 +82,6 @@ void pwrOn()
GPIO_Init(PWR_ON_GPIO, &GPIO_InitStructure);
GPIO_SetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
shutdownRequest = NO_SHUTDOWN_REQUEST;
shutdownReason = DIRTY_SHUTDOWN;
}
void pwrOff()
@@ -105,38 +103,7 @@ void pwrResetHandler()
__ASM volatile ("nop");
__ASM volatile ("nop");
// We get here whether we are powering up normally, we had an unexpected reboot or we have just powered down normally.
// We want:
// - In the 2nd case, to power ON as soon as possible if an unexpected reboot happened
// (we get there running on remaining capacitor charge, soft power having been cut by the RESET).
// - In the 3rd case, NOT power on as that would prevent from turning the system off.
// - The 1st case does not need to be handled here, but will be as a result of the handling for the 3rd case, see below.
//
// shutdownRequest is used to handle the 3rd case. If we really powered down on purpose this will still be set to SHUTDOWN_REQUEST
// as we left it in pwrOff(). If however we had an unexpected reboot, it would be set to NO_SHUTDOWN_REQUEST as we set it in pwrOn().
// Any other value (e.g. resulting from data corruption) would also keep power on for safety, so this variable can NOT be used
// to detect an unexpected reboot (on a normal power on the contents of the variable are random).
//
// shutdownReason is used to differentiate between an unexpected reboot and a normal power on. We set it to DIRTY_SHUTDOWN in pwrOn()
// in anticipation of a potential reboot. Should there be one the value should be preserved and signal below that we rebooted unexpectedly.
// If it is NOT set to DIRTY_SHUTDOWN we likely had a normal boot and its contents are random. Due to the need to initialize it to detect a
// potential failure ASAP we cannot use it to determine in the firmware why we got there, it has to be buffered.
//
// powerupReason is there to cater for that, and is what is used in the firmware to decide whether we have to enter emergency mode.
// This variable needs to be in a RAM section that is not initialized or zeroed, since once we exit this pwrResetHandler() function the
// C runtime would otherwise overwrite it during program init.
// Only for X12, X10 power circuit causes inability to shut down on some samples.
#if defined(PCBX12S)
if (shutdownRequest != SHUTDOWN_REQUEST || WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
if (shutdownReason == DIRTY_SHUTDOWN) {
powerupReason = DIRTY_SHUTDOWN;
}
if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
pwrOn();
}
#else
if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
pwrOn();
}
#endif
}
@@ -228,8 +228,14 @@ void telemetryPortSetDirectionOutput()
TELEMETRY_USART->CR1 &= ~USART_CR1_RE; // turn off receiver
}
void sportWaitTransmissionComplete()
{
while (!(TELEMETRY_USART->SR & USART_SR_TC));
}
void telemetryPortSetDirectionInput()
{
sportWaitTransmissionComplete();
TELEMETRY_DIR_GPIO->BSRRH = TELEMETRY_DIR_GPIO_PIN; // output disable
TELEMETRY_USART->CR1 |= USART_CR1_RE; // turn on receiver
}