From d384fae9f472256b2b345e4809f25cd35a073e62 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 25 Jun 2016 10:06:29 +1000 Subject: [PATCH 1/5] Fix for needing to slow down serial in the CLI for F4 targets. Problem is with the CLI in configurator dropping packets. It is understood that too much processing occurs following each packet, and the receive buffer starts to drop packets in the configurator. Once the BF config is updated, this fix can be removed. --- src/main/drivers/serial_usb_vcp.c | 1 + src/main/io/serial_cli.c | 32 ++++++++++++++++++++++++++----- src/main/target/common.h | 5 +++++ src/main/vcpf4/usbd_cdc_vcp.c | 14 ++++++-------- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/main/drivers/serial_usb_vcp.c b/src/main/drivers/serial_usb_vcp.c index 5dc3ddb872..d4a25e6932 100644 --- a/src/main/drivers/serial_usb_vcp.c +++ b/src/main/drivers/serial_usb_vcp.c @@ -117,6 +117,7 @@ static bool usbVcpFlush(vcpPort_t *port) if (count == 0) { return true; } + if (!usbIsConnected() || !usbIsConfigured()) { return false; } diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index d7279327f7..04a0526dea 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -1902,10 +1902,11 @@ static void dumpValues(uint16_t valueSection) cliPrintf("set %s = ", valueTable[i].name); cliPrintVar(value, 0); cliPrint("\r\n"); - -#ifdef STM32F4 + +#ifdef USE_SLOW_SERIAL_CLI delay(2); #endif + } } @@ -1979,6 +1980,9 @@ static void cliDump(char *cmdline) if (yaw < 0) cliWrite(' '); cliPrintf("%s\r\n", ftoa(yaw, buf)); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } #ifdef USE_SERVOS @@ -2000,6 +2004,10 @@ static void cliDump(char *cmdline) masterConfig.customServoMixer[i].max, masterConfig.customServoMixer[i].box ); + +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } #endif @@ -2012,12 +2020,18 @@ static void cliDump(char *cmdline) if (featureNames[i] == NULL) break; cliPrintf("feature -%s\r\n", featureNames[i]); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } for (i = 0; ; i++) { // reenable what we want. if (featureNames[i] == NULL) break; if (mask & (1 << i)) cliPrintf("feature %s\r\n", featureNames[i]); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } @@ -2077,6 +2091,9 @@ static void cliDump(char *cmdline) for (channel = 0; channel < INPUT_SOURCE_COUNT; channel++) { if (servoDirection(i, channel) < 0) { cliPrintf("smix reverse %d %d r\r\n", i , channel); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } } } @@ -2109,6 +2126,9 @@ static void cliDump(char *cmdline) changeControlRateProfile(currentRateIndex); cliRateProfile(""); +#ifdef USE_SLOW_SERIAL_CLI + delay(2); +#endif } cliPrint("\r\n# restore original profile selection\r\n"); @@ -2133,7 +2153,8 @@ static void cliDump(char *cmdline) } } -void cliDumpProfile(uint8_t profileIndex) { +void cliDumpProfile(uint8_t profileIndex) +{ if (profileIndex >= MAX_PROFILE_COUNT) // Faulty values return; @@ -2148,7 +2169,8 @@ void cliDumpProfile(uint8_t profileIndex) { cliRateProfile(""); } -void cliDumpRateProfile(uint8_t rateProfileIndex) { +void cliDumpRateProfile(uint8_t rateProfileIndex) +{ if (rateProfileIndex >= MAX_RATEPROFILES) // Faulty values return; @@ -2718,7 +2740,7 @@ static void cliSet(char *cmdline) cliPrintVar(val, len); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui cliPrint("\r\n"); -#ifdef STM32F4 +#ifdef USE_SLOW_SERIAL_CLI delay(2); #endif } diff --git a/src/main/target/common.h b/src/main/target/common.h index a9d961e4da..9a8d6aede7 100644 --- a/src/main/target/common.h +++ b/src/main/target/common.h @@ -18,11 +18,16 @@ #pragma once #ifdef STM32F4 + #define TASK_GYROPID_DESIRED_PERIOD 125 #define SCHEDULER_DELAY_LIMIT 10 +#define USE_SLOW_SERIAL_CLI + #else + #define TASK_GYROPID_DESIRED_PERIOD 1000 #define SCHEDULER_DELAY_LIMIT 100 + #endif #define SERIAL_RX diff --git a/src/main/vcpf4/usbd_cdc_vcp.c b/src/main/vcpf4/usbd_cdc_vcp.c index b42757adf1..93ac1aaa5c 100644 --- a/src/main/vcpf4/usbd_cdc_vcp.c +++ b/src/main/vcpf4/usbd_cdc_vcp.c @@ -153,12 +153,11 @@ static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len) *******************************************************************************/ uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength) { - if(USB_Tx_State!=1) - { - VCP_DataTx(ptrBuffer,sendLength); - return sendLength; - } - return 0; + if (USB_Tx_State) + return 0; + + VCP_DataTx(ptrBuffer, sendLength); + return sendLength; } /** @@ -171,7 +170,6 @@ uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength) */ static uint16_t VCP_DataTx(uint8_t* Buf, uint32_t Len) { - uint16_t ptr = APP_Rx_ptr_in; uint32_t i; @@ -179,7 +177,7 @@ static uint16_t VCP_DataTx(uint8_t* Buf, uint32_t Len) APP_Rx_Buffer[ptr++ & (APP_RX_DATA_SIZE-1)] = Buf[i]; APP_Rx_ptr_in = ptr % APP_RX_DATA_SIZE; - + return USBD_OK; } From b953e1c0b4b161a026b6e209e4eb60fc2f31c0af Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 25 Jun 2016 10:37:53 +1000 Subject: [PATCH 2/5] Additional delay never eventuates with new pwm_protocol and disabling of feature for OS42 and MS - why needed for 125? --- src/main/config/config.c | 14 ++------------ src/main/config/config.h | 1 - src/main/io/serial_cli.c | 4 ++-- src/main/io/serial_msp.c | 1 - 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/main/config/config.c b/src/main/config/config.c index 1fa036c084..72091a643e 100755 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -1046,7 +1046,8 @@ void changeProfile(uint8_t profileIndex) beeperConfirmationBeeps(profileIndex + 1); } -void changeControlRateProfile(uint8_t profileIndex) { +void changeControlRateProfile(uint8_t profileIndex) +{ if (profileIndex > MAX_RATEPROFILES) { profileIndex = MAX_RATEPROFILES - 1; } @@ -1054,17 +1055,6 @@ void changeControlRateProfile(uint8_t profileIndex) { activateControlRateConfig(); } -void handleOneshotFeatureChangeOnRestart(void) -{ - // Shutdown PWM on all motors prior to soft restart - StopPwmAllMotors(); - delay(50); - // Apply additional delay when OneShot125 feature changed from on to off state - if (feature(FEATURE_ONESHOT125) && !featureConfigured(FEATURE_ONESHOT125)) { - delay(ONESHOT_FEATURE_CHANGED_DELAY_ON_BOOT_MS); - } -} - void latchActiveFeatures() { activeFeaturesLatch = masterConfig.enabledFeatures; diff --git a/src/main/config/config.h b/src/main/config/config.h index 9150540cfd..c26bbe6455 100644 --- a/src/main/config/config.h +++ b/src/main/config/config.h @@ -50,7 +50,6 @@ typedef enum { FEATURE_VTX = 1 << 25, } features_e; -void handleOneshotFeatureChangeOnRestart(void); void latchActiveFeatures(void); bool featureConfigured(uint32_t mask); bool feature(uint32_t mask); diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 04a0526dea..237a5310f1 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -2563,12 +2563,12 @@ static void cliRateProfile(char *cmdline) { } } -static void cliReboot(void) { +static void cliReboot(void) +{ cliPrint("\r\nRebooting"); bufWriterFlush(cliWriter); waitForSerialPortToFinishTransmitting(cliPort); stopMotors(); - handleOneshotFeatureChangeOnRestart(); systemReset(); } diff --git a/src/main/io/serial_msp.c b/src/main/io/serial_msp.c index 4e31f76cef..d2b6cc0c8d 100644 --- a/src/main/io/serial_msp.c +++ b/src/main/io/serial_msp.c @@ -1969,7 +1969,6 @@ void mspProcess(void) if (isRebootScheduled) { waitForSerialPortToFinishTransmitting(candidatePort->port); stopMotors(); - handleOneshotFeatureChangeOnRestart(); // On real flight controllers, systemReset() will do a soft reset of the device, // reloading the program. But to support offline testing this flag needs to be // cleared so that the software doesn't continuously attempt to reboot itself. From 499d7522c276c834e0123a3f03f19cdbb7f0892a Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 25 Jun 2016 21:22:10 +1000 Subject: [PATCH 3/5] Re-enabling i2c overclocking (lower CPU usage) --- src/main/drivers/bus_i2c_stm32f10x.c | 11 +- src/main/drivers/bus_i2c_stm32f30x.c | 273 +++++++++++++-------------- src/main/target/common.h | 8 +- 3 files changed, 148 insertions(+), 144 deletions(-) diff --git a/src/main/drivers/bus_i2c_stm32f10x.c b/src/main/drivers/bus_i2c_stm32f10x.c index a444332aba..c7e972b2d7 100644 --- a/src/main/drivers/bus_i2c_stm32f10x.c +++ b/src/main/drivers/bus_i2c_stm32f10x.c @@ -82,10 +82,10 @@ static void i2cUnstick(IO_t scl, IO_t sda); #endif static i2cDevice_t i2cHardwareMap[] = { - { .dev = I2C1, .scl = IO_TAG(I2C1_SCL), .sda = IO_TAG(I2C1_SDA), .rcc = RCC_APB1(I2C1), .overClock = false, .ev_irq = I2C1_EV_IRQn, .er_irq = I2C1_ER_IRQn }, - { .dev = I2C2, .scl = IO_TAG(I2C2_SCL), .sda = IO_TAG(I2C2_SDA), .rcc = RCC_APB1(I2C2), .overClock = false, .ev_irq = I2C2_EV_IRQn, .er_irq = I2C2_ER_IRQn }, + { .dev = I2C1, .scl = IO_TAG(I2C1_SCL), .sda = IO_TAG(I2C1_SDA), .rcc = RCC_APB1(I2C1), .overClock = I2C1_OVERCLOCK, .ev_irq = I2C1_EV_IRQn, .er_irq = I2C1_ER_IRQn }, + { .dev = I2C2, .scl = IO_TAG(I2C2_SCL), .sda = IO_TAG(I2C2_SDA), .rcc = RCC_APB1(I2C2), .overClock = I2C2_OVERCLOCK, .ev_irq = I2C2_EV_IRQn, .er_irq = I2C2_ER_IRQn }, #ifdef STM32F4 - { .dev = I2C3, .scl = IO_TAG(I2C3_SCL), .sda = IO_TAG(I2C3_SDA), .rcc = RCC_APB1(I2C3), .overClock = false, .ev_irq = I2C3_EV_IRQn, .er_irq = I2C3_ER_IRQn } + { .dev = I2C3, .scl = IO_TAG(I2C3_SCL), .sda = IO_TAG(I2C3_SDA), .rcc = RCC_APB1(I2C3), .overClock = I2C2_OVERCLOCK, .ev_irq = I2C3_EV_IRQn, .er_irq = I2C3_ER_IRQn } #endif }; @@ -396,7 +396,7 @@ void i2cInit(I2CDevice device) i2cUnstick(scl, sda); // Init pins -#if defined(STM32F40_41xxx) || defined(STM32F411xE) +#ifdef STM32F4 IOConfigGPIOAF(scl, IOCFG_I2C, GPIO_AF_I2C); IOConfigGPIOAF(sda, IOCFG_I2C, GPIO_AF_I2C); #else @@ -416,8 +416,7 @@ void i2cInit(I2CDevice device) if (i2c->overClock) { i2cInit.I2C_ClockSpeed = 800000; // 800khz Maximum speed tested on various boards without issues - } - else { + } else { i2cInit.I2C_ClockSpeed = 400000; // 400khz Operation according specs } diff --git a/src/main/drivers/bus_i2c_stm32f30x.c b/src/main/drivers/bus_i2c_stm32f30x.c index 8f9225ef74..c324d03e7a 100644 --- a/src/main/drivers/bus_i2c_stm32f30x.c +++ b/src/main/drivers/bus_i2c_stm32f30x.c @@ -54,8 +54,8 @@ static volatile uint16_t i2cErrorCount = 0; //static volatile uint16_t i2c2ErrorCount = 0; static i2cDevice_t i2cHardwareMap[] = { - { .dev = I2C1, .scl = IO_TAG(I2C1_SCL), .sda = IO_TAG(I2C1_SDA), .rcc = RCC_APB1(I2C1), .overClock = false }, - { .dev = I2C2, .scl = IO_TAG(I2C2_SCL), .sda = IO_TAG(I2C2_SDA), .rcc = RCC_APB1(I2C2), .overClock = false } + { .dev = I2C1, .scl = IO_TAG(I2C1_SCL), .sda = IO_TAG(I2C1_SDA), .rcc = RCC_APB1(I2C1), .overClock = I2C1_OVERCLOCK }, + { .dev = I2C2, .scl = IO_TAG(I2C2_SCL), .sda = IO_TAG(I2C2_SDA), .rcc = RCC_APB1(I2C2), .overClock = I2C2_OVERCLOCK } }; /////////////////////////////////////////////////////////////////////////////// @@ -64,190 +64,189 @@ static i2cDevice_t i2cHardwareMap[] = { uint32_t i2cTimeoutUserCallback(void) { - i2cErrorCount++; - return false; + i2cErrorCount++; + return false; } void i2cInit(I2CDevice device) { - i2cDevice_t *i2c; - i2c = &(i2cHardwareMap[device]); + i2cDevice_t *i2c; + i2c = &(i2cHardwareMap[device]); - I2C_TypeDef *I2Cx; - I2Cx = i2c->dev; + I2C_TypeDef *I2Cx; + I2Cx = i2c->dev; - IO_t scl = IOGetByTag(i2c->scl); - IO_t sda = IOGetByTag(i2c->sda); + IO_t scl = IOGetByTag(i2c->scl); + IO_t sda = IOGetByTag(i2c->sda); - RCC_ClockCmd(i2c->rcc, ENABLE); - RCC_I2CCLKConfig(I2Cx == I2C2 ? RCC_I2C2CLK_SYSCLK : RCC_I2C1CLK_SYSCLK); + RCC_ClockCmd(i2c->rcc, ENABLE); + RCC_I2CCLKConfig(I2Cx == I2C2 ? RCC_I2C2CLK_SYSCLK : RCC_I2C1CLK_SYSCLK); - IOConfigGPIOAF(scl, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_OD, GPIO_PuPd_NOPULL), GPIO_AF_4); - IOConfigGPIOAF(sda, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_OD, GPIO_PuPd_NOPULL), GPIO_AF_4); + IOConfigGPIOAF(scl, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_OD, GPIO_PuPd_NOPULL), GPIO_AF_4); + IOConfigGPIOAF(sda, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_OD, GPIO_PuPd_NOPULL), GPIO_AF_4); - I2C_InitTypeDef i2cInit = { - .I2C_Mode = I2C_Mode_I2C, - .I2C_AnalogFilter = I2C_AnalogFilter_Enable, - .I2C_DigitalFilter = 0x00, - .I2C_OwnAddress1 = 0x00, - .I2C_Ack = I2C_Ack_Enable, - .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit, - .I2C_Timing = 0x00E0257A, // 400 Khz, 72Mhz Clock, Analog Filter Delay ON, Rise 100, Fall 10. - //.I2C_Timing = 0x8000050B; - }; + I2C_InitTypeDef i2cInit = { + .I2C_Mode = I2C_Mode_I2C, + .I2C_AnalogFilter = I2C_AnalogFilter_Enable, + .I2C_DigitalFilter = 0x00, + .I2C_OwnAddress1 = 0x00, + .I2C_Ack = I2C_Ack_Enable, + .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit, + .I2C_Timing = i2c->overClock ? + 0x00500E30 : // 1000 Khz, 72Mhz Clock, Analog Filter Delay ON, Setup 40, Hold 4. + 0x00E0257A, // 400 Khz, 72Mhz Clock, Analog Filter Delay ON, Rise 100, Fall 10. + //.I2C_Timing = 0x8000050B; + }; - if (i2c->overClock) { - i2cInit.I2C_Timing = 0x00500E30; // 1000 Khz, 72Mhz Clock, Analog Filter Delay ON, Setup 40, Hold 4. - } - I2C_Init(I2Cx, &i2cInit); + I2C_Init(I2Cx, &i2cInit); - I2C_Cmd(I2Cx, ENABLE); + I2C_Cmd(I2Cx, ENABLE); } uint16_t i2cGetErrorCounter(void) { - return i2cErrorCount; + return i2cErrorCount; } bool i2cWrite(I2CDevice device, uint8_t addr_, uint8_t reg, uint8_t data) { - addr_ <<= 1; + addr_ <<= 1; - I2C_TypeDef *I2Cx; - I2Cx = i2cHardwareMap[device].dev; + I2C_TypeDef *I2Cx; + I2Cx = i2cHardwareMap[device].dev; - /* Test on BUSY Flag */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_BUSY) != RESET) { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Test on BUSY Flag */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_BUSY) != RESET) { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Configure slave address, nbytes, reload, end mode and start or stop generation */ - I2C_TransferHandling(I2Cx, addr_, 1, I2C_Reload_Mode, I2C_Generate_Start_Write); + /* Configure slave address, nbytes, reload, end mode and start or stop generation */ + I2C_TransferHandling(I2Cx, addr_, 1, I2C_Reload_Mode, I2C_Generate_Start_Write); - /* Wait until TXIS flag is set */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TXIS) == RESET) { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Wait until TXIS flag is set */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TXIS) == RESET) { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Send Register address */ - I2C_SendData(I2Cx, (uint8_t) reg); + /* Send Register address */ + I2C_SendData(I2Cx, (uint8_t) reg); - /* Wait until TCR flag is set */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TCR) == RESET) - { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Wait until TCR flag is set */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TCR) == RESET) + { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Configure slave address, nbytes, reload, end mode and start or stop generation */ - I2C_TransferHandling(I2Cx, addr_, 1, I2C_AutoEnd_Mode, I2C_No_StartStop); + /* Configure slave address, nbytes, reload, end mode and start or stop generation */ + I2C_TransferHandling(I2Cx, addr_, 1, I2C_AutoEnd_Mode, I2C_No_StartStop); - /* Wait until TXIS flag is set */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TXIS) == RESET) { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Wait until TXIS flag is set */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TXIS) == RESET) { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Write data to TXDR */ - I2C_SendData(I2Cx, data); + /* Write data to TXDR */ + I2C_SendData(I2Cx, data); - /* Wait until STOPF flag is set */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_STOPF) == RESET) { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Wait until STOPF flag is set */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_STOPF) == RESET) { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Clear STOPF flag */ - I2C_ClearFlag(I2Cx, I2C_ICR_STOPCF); + /* Clear STOPF flag */ + I2C_ClearFlag(I2Cx, I2C_ICR_STOPCF); - return true; + return true; } bool i2cRead(I2CDevice device, uint8_t addr_, uint8_t reg, uint8_t len, uint8_t* buf) { - addr_ <<= 1; + addr_ <<= 1; - I2C_TypeDef *I2Cx; - I2Cx = i2cHardwareMap[device].dev; + I2C_TypeDef *I2Cx; + I2Cx = i2cHardwareMap[device].dev; - /* Test on BUSY Flag */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_BUSY) != RESET) { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Test on BUSY Flag */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_BUSY) != RESET) { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Configure slave address, nbytes, reload, end mode and start or stop generation */ - I2C_TransferHandling(I2Cx, addr_, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write); + /* Configure slave address, nbytes, reload, end mode and start or stop generation */ + I2C_TransferHandling(I2Cx, addr_, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write); - /* Wait until TXIS flag is set */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TXIS) == RESET) { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Wait until TXIS flag is set */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TXIS) == RESET) { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Send Register address */ - I2C_SendData(I2Cx, (uint8_t) reg); + /* Send Register address */ + I2C_SendData(I2Cx, (uint8_t) reg); - /* Wait until TC flag is set */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TC) == RESET) { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Wait until TC flag is set */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_TC) == RESET) { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Configure slave address, nbytes, reload, end mode and start or stop generation */ - I2C_TransferHandling(I2Cx, addr_, len, I2C_AutoEnd_Mode, I2C_Generate_Start_Read); + /* Configure slave address, nbytes, reload, end mode and start or stop generation */ + I2C_TransferHandling(I2Cx, addr_, len, I2C_AutoEnd_Mode, I2C_Generate_Start_Read); - /* Wait until all data are received */ - while (len) { - /* Wait until RXNE flag is set */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_RXNE) == RESET) { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Wait until all data are received */ + while (len) { + /* Wait until RXNE flag is set */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_RXNE) == RESET) { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Read data from RXDR */ - *buf = I2C_ReceiveData(I2Cx); - /* Point to the next location where the byte read will be saved */ - buf++; + /* Read data from RXDR */ + *buf = I2C_ReceiveData(I2Cx); + /* Point to the next location where the byte read will be saved */ + buf++; - /* Decrement the read bytes counter */ - len--; - } + /* Decrement the read bytes counter */ + len--; + } - /* Wait until STOPF flag is set */ - i2cTimeout = I2C_LONG_TIMEOUT; - while (I2C_GetFlagStatus(I2Cx, I2C_ISR_STOPF) == RESET) { - if ((i2cTimeout--) == 0) { - return i2cTimeoutUserCallback(); - } - } + /* Wait until STOPF flag is set */ + i2cTimeout = I2C_LONG_TIMEOUT; + while (I2C_GetFlagStatus(I2Cx, I2C_ISR_STOPF) == RESET) { + if ((i2cTimeout--) == 0) { + return i2cTimeoutUserCallback(); + } + } - /* Clear STOPF flag */ - I2C_ClearFlag(I2Cx, I2C_ICR_STOPCF); + /* Clear STOPF flag */ + I2C_ClearFlag(I2Cx, I2C_ICR_STOPCF); - /* If all operations OK */ - return true; + /* If all operations OK */ + return true; } #endif diff --git a/src/main/target/common.h b/src/main/target/common.h index 9a8d6aede7..dbe2c3a374 100644 --- a/src/main/target/common.h +++ b/src/main/target/common.h @@ -17,13 +17,19 @@ #pragma once +#define I2C1_OVERCLOCK true +#define I2C2_OVERCLOCK true + + +/* STM32F4 specific settings that apply to all F4 targets */ #ifdef STM32F4 #define TASK_GYROPID_DESIRED_PERIOD 125 #define SCHEDULER_DELAY_LIMIT 10 #define USE_SLOW_SERIAL_CLI +#define I2C3_OVERCLOCK true -#else +#else /* when not an F4 */ #define TASK_GYROPID_DESIRED_PERIOD 1000 #define SCHEDULER_DELAY_LIMIT 100 From a28a2d28817757372607793c3cf7ded245e9c48b Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 25 Jun 2016 21:29:18 +1000 Subject: [PATCH 4/5] Removed OS125 reconfig call from i2c_bst --- src/main/target/COLIBRI_RACE/i2c_bst.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/target/COLIBRI_RACE/i2c_bst.c b/src/main/target/COLIBRI_RACE/i2c_bst.c index 304db985ec..10c99ccc01 100644 --- a/src/main/target/COLIBRI_RACE/i2c_bst.c +++ b/src/main/target/COLIBRI_RACE/i2c_bst.c @@ -1545,7 +1545,6 @@ void taskBstMasterProcess(void) bstMasterWriteLoop(); if (isRebootScheduled) { stopMotors(); - handleOneshotFeatureChangeOnRestart(); systemReset(); } resetBstChecker(); @@ -1555,12 +1554,14 @@ void taskBstMasterProcess(void) static uint8_t masterWriteBufferPointer; static uint8_t masterWriteData[DATA_BUFFER_SIZE]; -static void bstMasterStartBuffer(uint8_t address) { +static void bstMasterStartBuffer(uint8_t address) +{ masterWriteData[0] = address; masterWriteBufferPointer = 2; } -static void bstMasterWrite8(uint8_t data) { +static void bstMasterWrite8(uint8_t data) +{ masterWriteData[masterWriteBufferPointer++] = data; masterWriteData[1] = masterWriteBufferPointer; } From 7317f9138a9b5ba3b694d354d4afce21b936e7df Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 25 Jun 2016 21:41:24 +1000 Subject: [PATCH 5/5] FIXED: SIRINFPV default_features defined twice in target file. --- src/main/target/SIRINFPV/target.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/target/SIRINFPV/target.h b/src/main/target/SIRINFPV/target.h index 07f7343574..1700d13cf9 100644 --- a/src/main/target/SIRINFPV/target.h +++ b/src/main/target/SIRINFPV/target.h @@ -135,7 +135,7 @@ // Performance logging for SD card operations: // #define AFATFS_USE_INTROSPECTIVE_LOGGING -#define DEFAULT_FEATURES (FEATURE_BLACKBOX | FEATURE_RX_SERIAL | FEATURE_OSD | FEATURE_VTX) + #define USE_ADC #define BOARD_HAS_VOLTAGE_DIVIDER @@ -150,7 +150,7 @@ #define USE_SERVOS #define DEFAULT_RX_FEATURE FEATURE_RX_PPM -#define DEFAULT_FEATURES FEATURE_BLACKBOX +#define DEFAULT_FEATURES (FEATURE_BLACKBOX | FEATURE_RX_SERIAL | FEATURE_OSD | FEATURE_VTX) #define USE_SERIAL_4WAY_BLHELI_INTERFACE