From 8eae895c839a87dc20ff17db14d4066e6d9605c9 Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 29 Jun 2015 19:11:22 +0200 Subject: [PATCH] [Taranis X9E] The bootloader was not started (trims masks hardcoded) --- radio/src/loadboot.cpp | 53 ++++++++----------- radio/src/targets/taranis/bootloader/boot.cpp | 39 -------------- 2 files changed, 22 insertions(+), 70 deletions(-) diff --git a/radio/src/loadboot.cpp b/radio/src/loadboot.cpp index 8215e9ae3..e59c088dc 100644 --- a/radio/src/loadboot.cpp +++ b/radio/src/loadboot.cpp @@ -51,12 +51,8 @@ #if defined(PCBSKY9X) #include "AT91SAM3S4.h" -#elif defined(PCBTARANIS) && defined(REV9E) - #include "stm32f4xx.h" - #include "stm32f4xx_gpio.h" -#elif defined(PCBTARANIS) - #include "stm32f2xx.h" - #include "stm32f2xx_gpio.h" +#else + #include "board_taranis.h" #endif #if defined(PCBTARANIS) @@ -93,14 +89,12 @@ const uint8_t BootCode[] = { __attribute__ ((section(".bootrodata"), used)) void _bootStart() { + RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph | I2C_RCC_AHB1Periph | SD_RCC_AHB1Periph, ENABLE); + // turn soft power ON now - RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // Enable portD clock GPIOD->BSRRL = 1; GPIOD->MODER = (GPIOD->MODER & 0xFFFFFFFC) | 1; - RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN; // Enable portC clock - RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN; // Enable portE clock - GPIOC->PUPDR = 0x00000004; GPIOE->PUPDR = 0x00000040; @@ -109,30 +103,27 @@ void _bootStart() bwdt_reset(); } - if ((GPIOE->IDR & 0x00000008) == 0) { - if ((GPIOC->IDR & 0x00000002) == 0) { - // Bootloader needed - const uint8_t *src; - uint8_t *dest; - uint32_t size; + if (!(TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR) && !(TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)) { + // Bootloader needed + const uint8_t *src; + uint8_t *dest; + uint32_t size; - bwdt_reset(); - size = sizeof(BootCode); - src = BootCode; - dest = (uint8_t *) 0x20000000; - - for (; size; size -= 1) { - *dest++ = *src++; - } - // Could check for a valid copy to RAM here - // Go execute bootloader - bwdt_reset(); - - uint32_t address = *(uint32_t *) 0x20000004; - - ((void (*)(void)) (address))(); // Go execute the loaded application + bwdt_reset(); + size = sizeof(BootCode); + src = BootCode; + dest = (uint8_t *) 0x20000000; + for (; size; size -= 1) { + *dest++ = *src++; } + // Could check for a valid copy to RAM here + // Go execute bootloader + bwdt_reset(); + + uint32_t address = *(uint32_t *) 0x20000004; + + ((void (*)(void)) (address))(); // Go execute the loaded application } // run_application() ; diff --git a/radio/src/targets/taranis/bootloader/boot.cpp b/radio/src/targets/taranis/bootloader/boot.cpp index 71647d6c2..5d888885a 100755 --- a/radio/src/targets/taranis/bootloader/boot.cpp +++ b/radio/src/targets/taranis/bootloader/boot.cpp @@ -155,45 +155,6 @@ typedef int32_t rotenc_t; extern rotenc_t x9de_rotenc; #endif -/*---------------------------------------------------------------------------- - * Global functions - *----------------------------------------------------------------------------*/ - -#if defined(PCBSKY9X) -// Starts TIMER0 at full speed (MCK/2) for delay timing -// @ 36MHz this is 18MHz -// This was 6 MHz, we may need to slow it to TIMER_CLOCK2 (MCK/8=4.5 MHz) -void start_timer0() -{ - register Tc *ptc; - - PMC->PMC_PCER0 |= 0x00800000L; // Enable peripheral clock to TC0 - - ptc = TC0;// Tc block 0 (TC0-2) - ptc->TC_BCR = 0;// No sync - ptc->TC_BMR = 2; - ptc->TC_CHANNEL[0].TC_CMR = 0x00008001;// Waveform mode MCK/8 for 36MHz osc.(Upset be write below) - ptc->TC_CHANNEL[0].TC_RC = 0xFFF0; - ptc->TC_CHANNEL[0].TC_RA = 0; - ptc->TC_CHANNEL[0].TC_CMR = 0x00008040;// 0000 0000 0000 0000 1000 0000 0100 0000, stop at regC, 18MHz - ptc->TC_CHANNEL[0].TC_CCR = 5;// Enable clock and trigger it (may only need trigger) -} - -void stop_timer0( void ) -{ - TC0->TC_CHANNEL[0].TC_CCR = TC_CCR0_CLKDIS; // Disable clock -} - -void delay2ms() -{ - TC0->TC_CHANNEL[0].TC_CCR = 5;// Enable clock and trigger it (may only need trigger) - while ( TC0->TC_CHANNEL[0].TC_CV < 36000 )// 2mS, Value depends on MCK/2 (used 18MHz) - { - // Wait - } -} -#endif - void interrupt10ms(void) { Tenms |= 1; // 10 mS has passed