From f46b8366b01a5af3830fdc9fc2e7c724a9df4886 Mon Sep 17 00:00:00 2001 From: Pascal Langer Date: Mon, 11 Dec 2017 18:49:50 +0100 Subject: [PATCH] Small mods --- Multiprotocol/FrSkyX_cc2500.ino | 2 +- Multiprotocol/Multiprotocol.h | 24 ++++++++-------- Multiprotocol/Multiprotocol.ino | 51 ++++++--------------------------- Multiprotocol/Pins.h | 24 +++++++++++----- Multiprotocol/_Config.h | 14 ++++----- 5 files changed, 45 insertions(+), 70 deletions(-) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 6f3c8d7..7ec1895 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -216,7 +216,7 @@ static void __attribute__((unused)) frskyX_data_frame() idxs++; } packet[22]= idxs; - #ifdef SERIAL_DEBUG + #ifdef DEBUG_SERIAL for(uint8_t i=0;i -//#define DEBUG_TX -//#define SERIAL_DEBUG // Only for STM32_BOARD compiled with Upload method "Serial"->usart1, "STM32duino bootloader"->USB serial +//#define DEBUG_PIN // Use pin TX for AVR and SPI_CS for STM32 => DEBUG_PIN_on, DEBUG_PIN_off, DEBUG_PIN_toggle +//#define DEBUG_SERIAL // Only for STM32_BOARD compiled with Upload method "Serial"->usart1, "STM32duino bootloader"->USB serial #ifdef __arm__ // Let's automatically select the board if arm is selected #define STM32_BOARD @@ -215,7 +215,7 @@ void_function_t remote_callback = 0; void setup() { // Setup diagnostic uart before anything else - #ifdef SERIAL_DEBUG + #ifdef DEBUG_SERIAL Serial.begin(115200,SERIAL_8N1); while (!Serial); // Wait for ever for the serial port to connect... debugln("Multiprotocol version: %d.%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_PATCH_LEVEL); @@ -469,6 +469,7 @@ void loop() #else if((TIMER2_BASE->SR & TIMER_SR_CC1IF)!=0) { + debugln("Callback miss"); cli(); OCR1A = TCNT1; sei(); @@ -1247,11 +1248,11 @@ void modules_reset() UDR0; //enable reception and RC complete interrupt UCSR0B = _BV(RXEN0)|_BV(RXCIE0);//rx enable and interrupt - #ifndef DEBUG_TX + #ifndef DEBUG_PIN #if defined(TELEMETRY) initTXSerial( SPEED_100K ) ; #endif //TELEMETRY - #endif //DEBUG_TX + #endif //DEBUG_PIN #ifdef CHECK_FOR_BOOTLOADER if ( boot ) { @@ -1331,44 +1332,7 @@ void pollBoot() else if ( lState == BOOT_READY ) { #ifdef STM32_BOARD - #define SCS_BASE (0xE000E000) /*!< System Control Space Base Address */ - #define SCB_BASE (SCS_BASE + 0x0D00) /*!< System Control Block Base Address */ - #define SCB ((SCB_Type *) SCB_BASE) /*!< SCB configuration struct */ - #define __I volatile /*!< defines 'read only' permissions */ - #define __IO volatile /*!< defines 'read / write' permissions */ - typedef struct - { - __I uint32_t CPUID; /*!< Offset: 0x00 CPU ID Base Register */ - __IO uint32_t ICSR; /*!< Offset: 0x04 Interrupt Control State Register */ - __IO uint32_t VTOR; /*!< Offset: 0x08 Vector Table Offset Register */ - __IO uint32_t AIRCR; /*!< Offset: 0x0C Application Interrupt / Reset Control Register */ - __IO uint32_t SCR; /*!< Offset: 0x10 System Control Register */ - __IO uint32_t CCR; /*!< Offset: 0x14 Configuration Control Register */ - __IO uint8_t SHP[12]; /*!< Offset: 0x18 System Handlers Priority Registers (4-7, 8-11, 12-15) */ - __IO uint32_t SHCSR; /*!< Offset: 0x24 System Handler Control and State Register */ - __IO uint32_t CFSR; /*!< Offset: 0x28 Configurable Fault Status Register */ - __IO uint32_t HFSR; /*!< Offset: 0x2C Hard Fault Status Register */ - __IO uint32_t DFSR; /*!< Offset: 0x30 Debug Fault Status Register */ - __IO uint32_t MMFAR; /*!< Offset: 0x34 Mem Manage Address Register */ - __IO uint32_t BFAR; /*!< Offset: 0x38 Bus Fault Address Register */ - __IO uint32_t AFSR; /*!< Offset: 0x3C Auxiliary Fault Status Register */ - __I uint32_t PFR[2]; /*!< Offset: 0x40 Processor Feature Register */ - __I uint32_t DFR; /*!< Offset: 0x48 Debug Feature Register */ - __I uint32_t ADR; /*!< Offset: 0x4C Auxiliary Feature Register */ - __I uint32_t MMFR[4]; /*!< Offset: 0x50 Memory Model Feature Register */ - __I uint32_t ISAR[5]; /*!< Offset: 0x60 ISA Feature Register */ - } SCB_Type; - #define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */ - #define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */ - #define SCB_AIRCR_PRIGROUP_Pos 8 /*!< SCB AIRCR: PRIGROUP Position */ - #define SCB_AIRCR_PRIGROUP_Msk (7ul << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */ - #define SCB_AIRCR_SYSRESETREQ_Msk (1ul << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ - - // NVIC_SystemReset - SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | - (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | - SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */ - asm("dsb"); + nvic_sys_reset(); while(1); /* wait until reset */ #else cli(); // Disable global int due to RW of 16 bits registers @@ -1569,6 +1533,7 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) { idx=UDR0; // Dummy read discard_frame=1; // Error encountered discard full frame... + debugln("Bad frame"); } if(discard_frame==1) { diff --git a/Multiprotocol/Pins.h b/Multiprotocol/Pins.h index e760180..a73a4c4 100644 --- a/Multiprotocol/Pins.h +++ b/Multiprotocol/Pins.h @@ -21,14 +21,14 @@ #define SERIAL_TX_output SERIAL_TX_ddr |= _BV(SERIAL_TX_pin) #define SERIAL_TX_on SERIAL_TX_port |= _BV(SERIAL_TX_pin) #define SERIAL_TX_off SERIAL_TX_port &= ~_BV(SERIAL_TX_pin) - #ifdef DEBUG_TX - #define DEBUG_TX_on SERIAL_TX_on - #define DEBUG_TX_off SERIAL_TX_off - #define DEBUG_TX_toggle SERIAL_TX_port ^= _BV(SERIAL_TX_pin) + #ifdef DEBUG_PIN + #define DEBUG_PIN_on SERIAL_TX_on + #define DEBUG_PIN_off SERIAL_TX_off + #define DEBUG_PIN_toggle SERIAL_TX_port ^= _BV(SERIAL_TX_pin) #else - #define DEBUG_TX_on - #define DEBUG_TX_off - #define DEBUG_TX_toggle + #define DEBUG_PIN_on + #define DEBUG_PIN_off + #define DEBUG_PIN_toggle #endif // Dial @@ -289,6 +289,16 @@ #define BIND_SET_OUTPUT pinMode(BIND_pin,OUTPUT) #define IS_BIND_BUTTON_on (digitalRead(BIND_pin)==LOW) + #ifdef DEBUG_PIN + #define DEBUG_PIN_on digitalWrite(SPI_CSN_pin,HIGH) + #define DEBUG_PIN_off digitalWrite(SPI_CSN_pin,LOW) + #define DEBUG_PIN_toggle digitalWrite(SPI_CSN_pin,!digitalRead(SPI_CSN_pin)) + #else + #define DEBUG_PIN_on + #define DEBUG_PIN_off + #define DEBUG_PIN_toggle + #endif + #define cli() noInterrupts() #define sei() interrupts() #define delayMilliseconds(x) delay(x) diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 951d8ce..caf5c4e 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -237,15 +237,15 @@ //It is important for the module to know the endpoints of your radio. //Below are some standard transmitters already preconfigured. //Uncomment only the one which matches your transmitter. -#define TX_ER9X //ER9X/ERSKY9X/OpenTX ( 988<->2012µs) -//#define TX_DEVO7 //DEVO (1120<->1920µs) -//#define TX_SPEKTRUM //Spektrum (1100<->1900µs) -//#define TX_HISKY //HISKY (1120<->1920µs) -//#define TX_MPX //Multiplex MC2020 (1250<->1950µs) -//#define TX_WALKERA //Walkera PL0811-01H (1000<->1800µs) +#define TX_ER9X //ER9X/ERSKY9X/OpenTX ( 988<->2012 microseconds) +//#define TX_DEVO7 //DEVO (1120<->1920 microseconds) +//#define TX_SPEKTRUM //Spektrum (1100<->1900 microseconds) +//#define TX_HISKY //HISKY (1120<->1920 microseconds) +//#define TX_MPX //Multiplex MC2020 (1250<->1950 microseconds) +//#define TX_WALKERA //Walkera PL0811-01H (1000<->1800 microseconds) //#define TX_CUSTOM //Custom -// The lines below are used to set the end points in microseconds (µs) if you have selected TX_CUSTOM. +// The lines below are used to set the end points in microseconds if you have selected TX_CUSTOM. // A few things to consider: // - If you put too big values compared to your TX you won't be able to reach the extremes which is bad for throttle as an example // - If you put too low values you won't be able to use your full stick range, it will be maxed out before reaching the ends