Skip to content

Commit 644a162

Browse files
committed
Optimize F031 routines
1 parent 176b336 commit 644a162

File tree

6 files changed

+67
-173
lines changed

6 files changed

+67
-173
lines changed

Inc/targets.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,7 @@
24212421
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_0
24222422
#define INVERTED_EXTI
24232423
#define TARGET_VOLTAGE_DIVIDER 152
2424+
//#define NO_POLLING_START
24242425
#endif
24252426

24262427
/******************** G031 TARGETS ******************************************/
@@ -4291,10 +4292,11 @@
42914292
#define UTILITY_TIMER TIM17
42924293
#define COM_TIMER TIM14
42934294
#define APPLICATION_ADDRESS 0x08001000
4294-
#define TARGET_MIN_BEMF_COUNTS 3
4295+
#define TARGET_MIN_BEMF_COUNTS 2
42954296
// #define USE_SERIAL_TELEMETRY // moved to individual ESCs
42964297
#define USE_ADC
42974298
#define LOOP_FREQUENCY_HZ 20000
4299+
#define POLLING_MODE_THRESHOLD 500
42984300
#endif
42994301

43004302
#ifdef MCU_G071
@@ -4558,4 +4560,6 @@
45584560
#define TIM1_AUTORELOAD ((uint16_t)(CPU_FREQUENCY_MHZ * 1000U * 1000U / NOMINAL_PWM)-1)
45594561
#endif
45604562

4561-
4563+
#ifndef POLLING_MODE_THRESHOLD
4564+
#define POLLING_MODE_THRESHOLD 2000
4565+
#endif

Mcu/f031/Src/comparator.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
*/
77

88
#include "comparator.h"
9-
109
#include "common.h"
1110
#include "targets.h"
1211

13-
uint32_t current_GPIO_PIN;
14-
GPIO_TypeDef* current_GPIO_PORT;
15-
uint32_t current_EXTI_LINE = 0;
1612

1713
void maskPhaseInterrupts()
1814
{
@@ -26,26 +22,6 @@ void enableCompInterrupts() { EXTI->IMR |= (1 << current_EXTI_LINE); }
2622

2723
void changeCompInput()
2824
{
29-
if (step == 1 || step == 4) {
30-
current_GPIO_PIN = PHASE_C_EXTI_PIN;
31-
current_GPIO_PORT = PHASE_C_EXTI_PORT;
32-
current_EXTI_LINE = PHASE_C_EXTI_LINE;
33-
}
34-
if (step == 2 || step == 5) { // in phase two or 5 read from phase A PF
35-
current_GPIO_PIN = PHASE_A_EXTI_PIN;
36-
current_GPIO_PORT = PHASE_A_EXTI_PORT;
37-
current_EXTI_LINE = PHASE_A_EXTI_LINE;
38-
}
39-
if (step == 3 || step == 6) {
40-
current_GPIO_PIN = PHASE_B_EXTI_PIN;
41-
current_GPIO_PORT = PHASE_B_EXTI_PORT;
42-
current_EXTI_LINE = PHASE_B_EXTI_LINE;
43-
}
44-
if (rising) {
45-
EXTI->RTSR |= (1 << current_EXTI_LINE);
46-
EXTI->FTSR &= ~(1 << current_EXTI_LINE);
47-
} else {
48-
EXTI->FTSR |= (1 << current_EXTI_LINE);
49-
EXTI->RTSR &= ~(1 << current_EXTI_LINE);
50-
}
25+
EXTI->RTSR = rising << current_EXTI_LINE;
26+
EXTI->FTSR = !rising << current_EXTI_LINE;
5127
}

Mcu/f031/Src/phaseouts.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "targets.h"
1010

1111
extern char prop_brake_active;
12+
uint32_t current_GPIO_PIN;
13+
GPIO_TypeDef* current_GPIO_PORT;
14+
uint32_t current_EXTI_LINE = 0;
15+
1216

1317
#ifndef PWM_ENABLE_BRIDGE
1418

@@ -300,36 +304,54 @@ void comStep(int newStep)
300304
phaseCFLOAT();
301305
phaseBLOW();
302306
phaseAPWM();
307+
current_GPIO_PIN = PHASE_C_EXTI_PIN;
308+
current_GPIO_PORT = PHASE_C_EXTI_PORT;
309+
current_EXTI_LINE = PHASE_C_EXTI_LINE;
303310
break;
304311

305312
case 2: // C-B
306313
phaseAFLOAT();
307314
phaseBLOW();
308315
phaseCPWM();
316+
current_GPIO_PIN = PHASE_A_EXTI_PIN;
317+
current_GPIO_PORT = PHASE_A_EXTI_PORT;
318+
current_EXTI_LINE = PHASE_A_EXTI_LINE;
309319
break;
310320

311321
case 3: // C-A
312322
phaseBFLOAT();
313323
phaseALOW();
314324
phaseCPWM();
325+
current_GPIO_PIN = PHASE_B_EXTI_PIN;
326+
current_GPIO_PORT = PHASE_B_EXTI_PORT;
327+
current_EXTI_LINE = PHASE_B_EXTI_LINE;
315328
break;
316329

317330
case 4: // B-A
318331
phaseCFLOAT();
319332
phaseALOW();
320333
phaseBPWM();
334+
current_GPIO_PIN = PHASE_C_EXTI_PIN;
335+
current_GPIO_PORT = PHASE_C_EXTI_PORT;
336+
current_EXTI_LINE = PHASE_C_EXTI_LINE;
321337
break;
322338

323339
case 5: // B-C
324340
phaseAFLOAT();
325341
phaseCLOW();
326342
phaseBPWM();
343+
current_GPIO_PIN = PHASE_A_EXTI_PIN;
344+
current_GPIO_PORT = PHASE_A_EXTI_PORT;
345+
current_EXTI_LINE = PHASE_A_EXTI_LINE;
327346
break;
328347

329348
case 6: // A-C
330349
phaseBFLOAT();
331350
phaseCLOW();
332351
phaseAPWM();
352+
current_GPIO_PIN = PHASE_B_EXTI_PIN;
353+
current_GPIO_PORT = PHASE_B_EXTI_PORT;
354+
current_EXTI_LINE = PHASE_B_EXTI_LINE;
333355
break;
334356
}
335357
}

Mcu/f031/Src/stm32f0xx_it.c

Lines changed: 9 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,13 @@
2121
/* Includes
2222
* ------------------------------------------------------------------*/
2323
#include "stm32f0xx_it.h"
24-
2524
#include "main.h"
26-
/* Private includes
27-
* ----------------------------------------------------------*/
28-
/* USER CODE BEGIN Includes */
25+
#include "comparator.h"
2926
#include "ADC.h"
30-
#include "common.h"
3127
#include "targets.h"
32-
/* USER CODE END Includes */
33-
34-
/* Private typedef
35-
* -----------------------------------------------------------*/
36-
/* USER CODE BEGIN TD */
37-
38-
/* USER CODE END TD */
39-
40-
/* Private define
41-
* ------------------------------------------------------------*/
42-
/* USER CODE BEGIN PD */
43-
44-
/* USER CODE END PD */
45-
46-
/* Private macro
47-
* -------------------------------------------------------------*/
48-
/* USER CODE BEGIN PM */
28+
#include "common.h"
4929

50-
/* USER CODE END PM */
5130

52-
/* Private variables
53-
* ---------------------------------------------------------*/
54-
/* USER CODE BEGIN PV */
5531
extern void sendDshotDma(void);
5632
extern void receiveDshotDma(void);
5733
extern void transfercomplete(void);
@@ -60,31 +36,9 @@ extern void PeriodElapsedCallback();
6036
extern void tenKhzRoutine();
6137
extern char servoPwm;
6238

63-
// extern uint32_t gcr[];
64-
// extern uint8_t gcr_size;
6539
int update_interupt = 0;
6640
uint8_t update_count = 0;
6741
uint16_t interrupt_time = 0;
68-
/* USER CODE END PV */
69-
70-
/* Private function prototypes
71-
* -----------------------------------------------*/
72-
/* USER CODE BEGIN PFP */
73-
74-
/* USER CODE END PFP */
75-
76-
/* Private user code
77-
* ---------------------------------------------------------*/
78-
/* USER CODE BEGIN 0 */
79-
80-
/* USER CODE END 0 */
81-
82-
/* External variables
83-
* --------------------------------------------------------*/
84-
85-
/* USER CODE BEGIN EV */
86-
87-
/* USER CODE END EV */
8842

8943
/******************************************************************************/
9044
/* Cortex-M0 Processor Interruption and Exception Handlers */
@@ -168,44 +122,14 @@ void SysTick_Handler(void)
168122
*/
169123
void DMA1_Channel2_3_IRQHandler(void)
170124
{
171-
/* USER CODE BEGIN DMA1_Channel2_3_IRQn 0 */
172-
/* USER CODE BEGIN DMA1_Channel5_IRQn 0 */
173-
if (LL_DMA_IsActiveFlag_HT3(DMA1)) {
174-
if (servoPwm) {
175-
LL_TIM_IC_SetPolarity(IC_TIMER_REGISTER, IC_TIMER_CHANNEL,
176-
LL_TIM_IC_POLARITY_FALLING);
177-
LL_DMA_ClearFlag_HT3(DMA1);
178-
}
179-
}
180125
if (LL_DMA_IsActiveFlag_TC3(DMA1) == 1) {
181126
LL_DMA_ClearFlag_GI3(DMA1);
182-
183127
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_3);
184128
transfercomplete();
185129
input_ready = 1;
186130
} else if (LL_DMA_IsActiveFlag_TE3(DMA1) == 1) {
187131
LL_DMA_ClearFlag_GI3(DMA1);
188132
}
189-
/* USER CODE END DMA1_Channel2_3_IRQn 0 */
190-
if (LL_DMA_IsActiveFlag_TC2(DMA1) == 1) {
191-
/* Clear flag DMA global interrupt */
192-
/* (global interrupt flag: half transfer and transfer complete flags) */
193-
LL_DMA_ClearFlag_GI2(DMA1);
194-
ADC_DMA_Callback();
195-
/* Call interruption treatment function */
196-
// AdcDmaTransferComplete_Callback();
197-
}
198-
199-
/* Check whether DMA transfer error caused the DMA interruption */
200-
if (LL_DMA_IsActiveFlag_TE2(DMA1) == 1) {
201-
/* Clear flag DMA transfer error */
202-
LL_DMA_ClearFlag_TE2(DMA1);
203-
204-
/* Call interruption treatment function */
205-
}
206-
/* USER CODE BEGIN DMA1_Channel2_3_IRQn 1 */
207-
208-
/* USER CODE END DMA1_Channel2_3_IRQn 1 */
209133
}
210134

211135
/**
@@ -333,43 +257,18 @@ void TIM16_IRQHandler(void)
333257
#endif
334258
}
335259

336-
// void EXTI0_1_IRQHandler(void){
337-
// if (LL_EXTI_IsActiveFlag_0_31(PHASE_B_LL_EXTI_LINE) != RESET){
338-
// LL_EXTI_ClearFlag_0_31(PHASE_B_LL_EXTI_LINE);
339-
//
340-
// interruptRoutine();
341-
//
342-
// }
343-
// if (LL_EXTI_IsActiveFlag_0_31(PHASE_A_LL_EXTI_LINE) != RESET)
344-
// {
345-
// LL_EXTI_ClearFlag_0_31(PHASE_A_LL_EXTI_LINE);
346-
//
347-
// interruptRoutine();
348-
//
349-
// }
350-
// }
351260

352261
void EXTI4_15_IRQHandler(void)
353262
{
354-
if (LL_EXTI_IsActiveFlag_0_31(PHASE_C_LL_EXTI_LINE) != RESET) {
355-
LL_EXTI_ClearFlag_0_31(PHASE_C_LL_EXTI_LINE);
356-
263+
EXTI->PR = current_EXTI_LINE;
357264
interruptRoutine();
358-
}
359265
}
360266

361267
// #ifdef BLUE_BOARD
362268
void EXTI0_1_IRQHandler(void)
363-
{ // interrupt_time = UTILITY_TIMER->CNT;
364-
if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_0) != RESET) {
365-
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_0);
269+
{
270+
EXTI->PR = current_EXTI_LINE;
366271
interruptRoutine();
367-
}
368-
if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_1) != RESET) {
369-
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_1);
370-
interruptRoutine();
371-
}
372-
//
373272
}
374273

375274
void EXTI2_3_IRQHandler(void)
@@ -383,20 +282,11 @@ void EXTI2_3_IRQHandler(void)
383282
// #endif
384283
void DMA1_Channel1_IRQHandler(void)
385284
{
386-
if (LL_DMA_IsActiveFlag_HT1(DMA1)) {
387-
if (servoPwm) {
388-
LL_TIM_IC_SetPolarity(IC_TIMER_REGISTER, IC_TIMER_CHANNEL,
389-
LL_TIM_IC_POLARITY_FALLING);
390-
LL_DMA_ClearFlag_HT1(DMA1);
391-
}
392-
}
393285
if (LL_DMA_IsActiveFlag_TC1(DMA1) == 1) {
394-
LL_DMA_ClearFlag_GI1(DMA1);
395-
396-
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1);
397-
398-
transfercomplete();
399-
input_ready = 1;
286+
LL_DMA_ClearFlag_GI1(DMA1);
287+
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1);
288+
transfercomplete();
289+
// input_ready = 1;
400290
} else if (LL_DMA_IsActiveFlag_TE1(DMA1) == 1) {
401291
LL_DMA_ClearFlag_GI1(DMA1);
402292
}

0 commit comments

Comments
 (0)