Skip to content

Commit 238d26b

Browse files
committed
better error messages
1 parent 94f4fb5 commit 238d26b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/drivers/hardware_specific/teensy/teensy4_mcu.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ void xbar_init() {
8787
IMXRT_FLEXPWM_t* get_flexpwm(uint8_t pin){
8888

8989
const struct pwm_pin_info_struct *info;
90-
if (pin >= CORE_NUM_DIGITAL) {
90+
info = pwm_pin_info + pin;
91+
if (pin >= CORE_NUM_DIGITAL || info->type == 2) {
9192
#ifdef SIMPLEFOC_TEENSY_DEBUG
9293
char s[60];
9394
sprintf (s, "TEENSY-DRV: ERR: Pin: %d not Flextimer pin!", pin);
9495
SIMPLEFOC_DEBUG(s);
9596
#endif
9697
return nullptr;
9798
}
98-
info = pwm_pin_info + pin;
9999
// FlexPWM pin
100100
IMXRT_FLEXPWM_t *flexpwm;
101101
switch ((info->module >> 4) & 3) {
@@ -236,17 +236,16 @@ int get_submodule(uint8_t pin, uint8_t pin1){
236236
// 1 - A
237237
// 2 - B
238238
int get_channel(uint8_t pin){
239-
240239
const struct pwm_pin_info_struct *info;
241-
if (pin >= CORE_NUM_DIGITAL){
240+
info = pwm_pin_info + pin;
241+
if (pin >= CORE_NUM_DIGITAL || info->type == 2){
242242
#ifdef SIMPLEFOC_TEENSY_DEBUG
243-
char s[60];
243+
char s[90];
244244
sprintf (s, "TEENSY-DRV: ERR: Pin: %d not Flextimer pin!", pin);
245245
SIMPLEFOC_DEBUG(s);
246246
#endif
247247
return -1;
248248
}
249-
info = pwm_pin_info + pin;
250249
#ifdef SIMPLEFOC_TEENSY_DEBUG
251250
char s[60];
252251
sprintf (s, "TEENSY-DRV: Pin: %d on channel %s.", pin, info->channel==0 ? "X" : info->channel==1 ? "A" : "B");
@@ -598,7 +597,7 @@ void write_pwm_on_pin(IMXRT_FLEXPWM_t *p, unsigned int submodule, uint8_t channe
598597
// we can configure the center-aligned pwm
599598
if((flexpwmA != nullptr) && (flexpwmB != nullptr) && (flexpwmC != nullptr) && (channelA > 0) && (channelB > 0) && (channelC > 0) ){
600599
#ifdef SIMPLEFOC_TEENSY_DEBUG
601-
SIMPLEFOC_DEBUG("TEENSY-DRV: All pins on Flexpwm A or B submodules - Configuring center-aligned pwm!");
600+
SIMPLEFOC_DEBUG("TEENSY-DRV: All pins on Flexpwm A or B channels - Configuring center-aligned pwm!");
602601
#endif
603602

604603
// Configure FlexPWM units
@@ -645,7 +644,7 @@ void write_pwm_on_pin(IMXRT_FLEXPWM_t *p, unsigned int submodule, uint8_t channe
645644
return params;
646645
}else{
647646
#ifdef SIMPLEFOC_TEENSY_DEBUG
648-
SIMPLEFOC_DEBUG("TEENSY-DRV: Not all pins on Flexpwm A and B submodules - cannot configure center-aligned pwm!");
647+
SIMPLEFOC_DEBUG("TEENSY-DRV: Not all pins on Flexpwm A and B channels - cannot configure center-aligned pwm!");
649648
#endif
650649
return SIMPLEFOC_DRIVER_INIT_FAILED;
651650
}

src/drivers/hardware_specific/teensy/teensy_mcu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void* _configure3PWM(long pwm_frequency,const int pinA, const int pinB, const in
6161
if(p != SIMPLEFOC_DRIVER_INIT_FAILED){
6262
return p; // if center aligned pwm is available return the params
6363
}else{ // if center aligned pwm is not available use fast pwm
64+
SIMPLEFOC_DEBUG("TEENSY-DRV: Configuring 3PWM with fast pwm. Please consider using center aligned pwm for better performance!");
6465
_setHighFrequency(pwm_frequency, pinA);
6566
_setHighFrequency(pwm_frequency, pinB);
6667
_setHighFrequency(pwm_frequency, pinC);

0 commit comments

Comments
 (0)