@@ -87,15 +87,15 @@ void xbar_init() {
8787IMXRT_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
238238int 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 }
0 commit comments