1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 00:35:39 +03:00

Fix DMA for F3 // New Dshot limits (safety)

This commit is contained in:
borisbstyle 2017-01-09 16:45:38 +01:00
parent 590defb9ad
commit fb576df846
2 changed files with 13 additions and 3 deletions

View file

@ -84,6 +84,7 @@ void pwmWriteDigital(uint8_t index, uint16_t value)
packet <<= 1; packet <<= 1;
} }
DMA_Cmd(motor->timerHardware->dmaChannel, DISABLE);
TIM_DMACmd(motor->timerHardware->tim, motor->timerDmaSource, DISABLE); TIM_DMACmd(motor->timerHardware->tim, motor->timerDmaSource, DISABLE);
DMA_SetCurrDataCounter(motor->timerHardware->dmaChannel, MOTOR_DMA_BUFFER_SIZE); DMA_SetCurrDataCounter(motor->timerHardware->dmaChannel, MOTOR_DMA_BUFFER_SIZE);
DMA_CLEAR_FLAG(motor->dmaDescriptor, DMA_IT_TCIF); DMA_CLEAR_FLAG(motor->dmaDescriptor, DMA_IT_TCIF);
@ -172,7 +173,6 @@ void pwmDigitalMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t
dmaInit(timerHardware->dmaIrqHandler, OWNER_MOTOR, RESOURCE_INDEX(motorIndex)); dmaInit(timerHardware->dmaIrqHandler, OWNER_MOTOR, RESOURCE_INDEX(motorIndex));
motor->dmaDescriptor = getDmaDescriptor(channel); motor->dmaDescriptor = getDmaDescriptor(channel);
DMA_Cmd(channel, DISABLE);
DMA_DeInit(channel); DMA_DeInit(channel);
DMA_StructInit(&DMA_InitStructure); DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)timerChCCR(timerHardware); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)timerChCCR(timerHardware);

View file

@ -1051,6 +1051,13 @@ void validateAndFixGyroConfig(void)
if (gyroConfig()->gyro_use_32khz) { if (gyroConfig()->gyro_use_32khz) {
#ifdef GYRO_SUPPORTS_32KHZ #ifdef GYRO_SUPPORTS_32KHZ
samplingTime = 0.00003125; samplingTime = 0.00003125;
// F1 and F3 can't handle high pid speed.
#if defined(STM32F1)
pidConfig()->pid_process_denom = constrain(pidConfig()->pid_process_denom, 16, 16);
#endif
#if defined(STM32F3)
pidConfig()->pid_process_denom = constrain(pidConfig()->pid_process_denom, 4, 16);
#endif
#else #else
gyroConfig()->gyro_use_32khz = false; gyroConfig()->gyro_use_32khz = false;
#endif #endif
@ -1080,9 +1087,12 @@ void validateAndFixGyroConfig(void)
motorUpdateRestriction = 0.0001f; motorUpdateRestriction = 0.0001f;
break; break;
case (PWM_TYPE_DSHOT150): case (PWM_TYPE_DSHOT150):
motorUpdateRestriction = 0.000125f; motorUpdateRestriction = 0.000250f;
break; break;
case (PWM_TYPE_DSHOT300): case (PWM_TYPE_DSHOT300):
motorUpdateRestriction = 0.0001f;
break;
case (PWM_TYPE_DSHOT600):
motorUpdateRestriction = 0.0000625f; motorUpdateRestriction = 0.0000625f;
break; break;
default: default:
@ -1093,7 +1103,7 @@ void validateAndFixGyroConfig(void)
pidConfig()->pid_process_denom = motorUpdateRestriction / (samplingTime * gyroConfig()->gyro_sync_denom); pidConfig()->pid_process_denom = motorUpdateRestriction / (samplingTime * gyroConfig()->gyro_sync_denom);
// Prevent overriding the max rate of motors // Prevent overriding the max rate of motors
if(motorConfig()->useUnsyncedPwm) { if(motorConfig()->useUnsyncedPwm && (motorConfig()->motorPwmProtocol <= PWM_TYPE_BRUSHED)) {
uint32_t maxEscRate = lrintf(1.0f / motorUpdateRestriction); uint32_t maxEscRate = lrintf(1.0f / motorUpdateRestriction);
if(motorConfig()->motorPwmRate > maxEscRate) if(motorConfig()->motorPwmRate > maxEscRate)