Skip to content

Commit 2f5f0d0

Browse files
committed
Merge branch 'betaflight_master' into emuflight-1.0.0-master
2 parents 28dd82e + 1a6fa4d commit 2f5f0d0

File tree

9 files changed

+24
-15
lines changed

9 files changed

+24
-15
lines changed

docs/PID tuning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ An Example: With TPA = 50 (or .5 in the GUI) and `tpa_breakpoint` = 1500 (assume
4040
* At full throttle (2000) the full amount of dampening set in TPA is applied. (50% reduction in this example)
4141
* TPA can lead into increase of rotation rate when more throttle applied. You can get faster flips and rolls when more throttle applied due to coupling of PID's and rates. Only the PID controllers MWREWRITE and LUX are using a linear TPA implementation, where no rotation rates are affected when TPA is being used.
4242

43-
![tpa example chart](https://cloud.githubusercontent.com/assets/1668170/6053290/655255dc-ac92-11e4-9491-1a58d868c131.png "TPA Example Chart")
43+
![tpa example chart](https://user-images.githubusercontent.com/15355893/165317342-9639a7f8-1a05-4584-9b80-3faa2da565cb.png "TPA Example Chart")
4444

4545

4646
**How and Why to use this?**

src/main/common/maths.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
#define ABS(x) \
5656
__extension__ ({ __typeof__ (x) _x = (x); \
5757
_x > 0 ? _x : -_x; })
58+
#define SIGN(x) \
59+
__extension__ ({ __typeof__ (x) _x = (x); \
60+
(_x > 0) - (_x < 0); })
5861

5962
#define Q12 (1 << 12)
6063

src/main/drivers/accgyro/accgyro_mpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static void mpuIntExtiHandler(extiCallbackRec_t *cb)
131131
{
132132
gyroDev_t *gyro = container_of(cb, gyroDev_t, exti);
133133

134-
// Ideally we'd use a time to capture such information, but unfortunately the port used for EXTI interrupt does
134+
// Ideally we'd use a timer to capture such information, but unfortunately the port used for EXTI interrupt does
135135
// not have an associated timer
136136
uint32_t nowCycles = getCycleCounter();
137137
int32_t gyroLastPeriod = cmpTimeCycles(nowCycles, gyro->gyroLastEXTI);

src/main/drivers/accgyro/accgyro_spi_bmi270.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ busStatus_e bmi270Intcallback(uint32_t arg)
294294
void bmi270ExtiHandler(extiCallbackRec_t *cb)
295295
{
296296
gyroDev_t *gyro = container_of(cb, gyroDev_t, exti);
297-
// Ideally we'd use a time to capture such information, but unfortunately the port used for EXTI interrupt does
297+
// Ideally we'd use a timer to capture such information, but unfortunately the port used for EXTI interrupt does
298298
// not have an associated timer
299299
uint32_t nowCycles = getCycleCounter();
300300
gyro->gyroSyncEXTI = gyro->gyroLastEXTI + gyro->gyroDmaMaxDuration;
@@ -338,7 +338,7 @@ static bool bmi270AccRead(accDev_t *acc)
338338
acc->gyro->dev.txBuf[0] = BMI270_REG_ACC_DATA_X_LSB | 0x80;
339339

340340
busSegment_t segments[] = {
341-
{.u.buffers = {NULL, NULL}, 8, true, NULL},
341+
{.u.buffers = {NULL, NULL}, 7, true, NULL},
342342
{.u.link = {NULL, NULL}, 0, true, NULL},
343343
};
344344
segments[0].u.buffers.txData = acc->gyro->dev.txBuf;
@@ -381,7 +381,7 @@ static bool bmi270GyroReadRegister(gyroDev_t *gyro)
381381
case GYRO_EXTI_INIT:
382382
{
383383
// Initialise the tx buffer to all 0x00
384-
memset(gyro->dev.txBuf, 0x00, 14);
384+
memset(gyro->dev.txBuf, 0x00, 13);
385385
#ifdef USE_GYRO_EXTI
386386
// Check that minimum number of interrupts have been detected
387387

@@ -392,7 +392,7 @@ static bool bmi270GyroReadRegister(gyroDev_t *gyro)
392392
if (spiUseDMA(&gyro->dev)) {
393393
gyro->dev.callbackArg = (uint32_t)gyro;
394394
gyro->dev.txBuf[0] = BMI270_REG_ACC_DATA_X_LSB | 0x80;
395-
gyro->segments[0].len = 14;
395+
gyro->segments[0].len = 13;
396396
gyro->segments[0].callback = bmi270Intcallback;
397397
gyro->segments[0].u.buffers.txData = gyro->dev.txBuf;
398398
gyro->segments[0].u.buffers.rxData = gyro->dev.rxBuf;
@@ -416,7 +416,7 @@ static bool bmi270GyroReadRegister(gyroDev_t *gyro)
416416
gyro->dev.txBuf[0] = BMI270_REG_GYR_DATA_X_LSB | 0x80;
417417

418418
busSegment_t segments[] = {
419-
{.u.buffers = {NULL, NULL}, 8, true, NULL},
419+
{.u.buffers = {NULL, NULL}, 7, true, NULL},
420420
{.u.link = {NULL, NULL}, 0, true, NULL},
421421
};
422422
segments[0].u.buffers.txData = gyro->dev.txBuf;

src/main/drivers/dma_reqmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,13 @@ static dmaChannelSpec_t dmaChannelSpec[MAX_PERIPHERAL_DMA_OPTIONS] = {
377377
static const dmaPeripheralMapping_t dmaPeripheralMapping[] = {
378378
#ifdef USE_SPI
379379
// Everything including F405 and F446
380+
#if defined(STM32F745xx) || defined(STM32F746xx) || defined(STM32F765xx)
381+
{ DMA_PERIPH_SPI_MOSI, SPIDEV_1, { DMA(2, 5, 3), DMA(2, 3, 3) } },
382+
{ DMA_PERIPH_SPI_MISO, SPIDEV_1, { DMA(2, 2, 3), DMA(2, 0, 3) } },
383+
#else
380384
{ DMA_PERIPH_SPI_MOSI, SPIDEV_1, { DMA(2, 3, 3), DMA(2, 5, 3) } },
381385
{ DMA_PERIPH_SPI_MISO, SPIDEV_1, { DMA(2, 0, 3), DMA(2, 2, 3) } },
386+
#endif
382387
{ DMA_PERIPH_SPI_MOSI, SPIDEV_2, { DMA(1, 4, 0) } },
383388
{ DMA_PERIPH_SPI_MISO, SPIDEV_2, { DMA(1, 3, 0) } },
384389
{ DMA_PERIPH_SPI_MOSI, SPIDEV_3, { DMA(1, 5, 0), DMA(1, 7, 0) } },

src/main/drivers/persistent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef enum {
3737
#endif
3838
PERSISTENT_OBJECT_RTC_HIGH, // high 32 bits of rtcTime_t
3939
PERSISTENT_OBJECT_RTC_LOW, // low 32 bits of rtcTime_t
40+
PERSISTENT_OBJECT_SERIALRX_BAUD, // serial rx baudrate
4041
PERSISTENT_OBJECT_COUNT,
4142
#ifdef USE_SPRACING_PERSISTENT_RTC_WORKAROUND
4243
// On SPRACING H7 firmware use this alternate location for all reset reasons interpreted by this firmware

src/main/rx/crsf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include "pg/rx.h"
4040

41+
#include "drivers/persistent.h"
4142
#include "drivers/serial.h"
4243
#include "drivers/serial_uart.h"
4344
#include "drivers/system.h"
@@ -639,7 +640,7 @@ bool crsfRxInit(const rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState)
639640
uint32_t crsfBaudrate = CRSF_BAUDRATE;
640641

641642
#if defined(USE_CRSF_V3)
642-
crsfBaudrate = (isMPUSoftReset() && rxConfig->crsf_use_negotiated_baud) ? getCrsfCachedBaudrate() : CRSF_BAUDRATE;
643+
crsfBaudrate = rxConfig->crsf_use_negotiated_baud ? getCrsfCachedBaudrate() : CRSF_BAUDRATE;
643644
#endif
644645

645646
serialPort = openSerialPort(portConfig->identifier,
@@ -667,6 +668,7 @@ bool crsfRxInit(const rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState)
667668
void crsfRxUpdateBaudrate(uint32_t baudrate)
668669
{
669670
serialSetBaudRate(serialPort, baudrate);
671+
persistentObjectWrite(PERSISTENT_OBJECT_SERIALRX_BAUD, baudrate);
670672
}
671673

672674
bool crsfRxUseNegotiatedBaud(void)

src/main/scheduler/scheduler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
// 0 - Gyro task start cycle time in 10th of a us
5959
// 1 - ID of late task
6060
// 2 - Amount task is late in 10th of a us
61-
// 3 - Gyro lock skew in clock cycles
61+
// 3 - Gyro lock skew in 10th of a us
6262

6363
// DEBUG_TIMING_ACCURACY, requires USE_LATE_TASK_STATISTICS to be defined
6464
// 0 - % CPU busy

src/main/telemetry/crsf.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "common/utils.h"
4444

4545
#include "drivers/nvic.h"
46+
#include "drivers/persistent.h"
4647

4748
#include "fc/rc_modes.h"
4849
#include "fc/runtime_config.h"
@@ -103,10 +104,9 @@ typedef struct {
103104

104105
static crsfSpeedControl_s crsfSpeed = {0};
105106

106-
uint32_t crsfCachedBaudrate __attribute__ ((section (".noinit"))); // Used for retaining negotiated baudrate after soft reset
107-
108107
uint32_t getCrsfCachedBaudrate(void)
109108
{
109+
uint32_t crsfCachedBaudrate = persistentObjectRead(PERSISTENT_OBJECT_SERIALRX_BAUD);
110110
// check if valid first. return default baudrate if not
111111
for (unsigned i = 0; i < BAUD_COUNT; i++) {
112112
if (crsfCachedBaudrate == baudRates[i] && baudRates[i] >= CRSF_BAUDRATE) {
@@ -133,8 +133,7 @@ void setCrsfDefaultSpeed(void)
133133
crsfSpeed.confirmationTime = 0;
134134
crsfSpeed.index = BAUD_COUNT;
135135
isCrsfV3Running = false;
136-
crsfCachedBaudrate = getCrsfDesiredSpeed();
137-
crsfRxUpdateBaudrate(crsfCachedBaudrate);
136+
crsfRxUpdateBaudrate(getCrsfDesiredSpeed());
138137
}
139138

140139
bool crsfBaudNegotiationInProgress(void)
@@ -470,8 +469,7 @@ void speedNegotiationProcess(timeUs_t currentTimeUs)
470469
} else if (crsfSpeed.isNewSpeedValid) {
471470
if (cmpTimeUs(currentTimeUs, crsfSpeed.confirmationTime) >= 4000) {
472471
// delay 4ms before applying the new baudrate
473-
crsfCachedBaudrate = getCrsfDesiredSpeed();
474-
crsfRxUpdateBaudrate(crsfCachedBaudrate);
472+
crsfRxUpdateBaudrate(getCrsfDesiredSpeed());
475473
crsfSpeed.isNewSpeedValid = false;
476474
isCrsfV3Running = true;
477475
}

0 commit comments

Comments
 (0)