Skip to content

Commit

Permalink
better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
askuric committed Feb 29, 2024
1 parent 94f4fb5 commit 238d26b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/drivers/hardware_specific/teensy/teensy4_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ void xbar_init() {
IMXRT_FLEXPWM_t* get_flexpwm(uint8_t pin){

const struct pwm_pin_info_struct *info;
if (pin >= CORE_NUM_DIGITAL) {
info = pwm_pin_info + pin;
if (pin >= CORE_NUM_DIGITAL || info->type == 2) {
#ifdef SIMPLEFOC_TEENSY_DEBUG
char s[60];
sprintf (s, "TEENSY-DRV: ERR: Pin: %d not Flextimer pin!", pin);
SIMPLEFOC_DEBUG(s);
#endif
return nullptr;
}
info = pwm_pin_info + pin;
// FlexPWM pin
IMXRT_FLEXPWM_t *flexpwm;
switch ((info->module >> 4) & 3) {
Expand Down Expand Up @@ -236,17 +236,16 @@ int get_submodule(uint8_t pin, uint8_t pin1){
// 1 - A
// 2 - B
int get_channel(uint8_t pin){

const struct pwm_pin_info_struct *info;
if (pin >= CORE_NUM_DIGITAL){
info = pwm_pin_info + pin;
if (pin >= CORE_NUM_DIGITAL || info->type == 2){
#ifdef SIMPLEFOC_TEENSY_DEBUG
char s[60];
char s[90];
sprintf (s, "TEENSY-DRV: ERR: Pin: %d not Flextimer pin!", pin);
SIMPLEFOC_DEBUG(s);
#endif
return -1;
}
info = pwm_pin_info + pin;
#ifdef SIMPLEFOC_TEENSY_DEBUG
char s[60];
sprintf (s, "TEENSY-DRV: Pin: %d on channel %s.", pin, info->channel==0 ? "X" : info->channel==1 ? "A" : "B");
Expand Down Expand Up @@ -598,7 +597,7 @@ void write_pwm_on_pin(IMXRT_FLEXPWM_t *p, unsigned int submodule, uint8_t channe
// we can configure the center-aligned pwm
if((flexpwmA != nullptr) && (flexpwmB != nullptr) && (flexpwmC != nullptr) && (channelA > 0) && (channelB > 0) && (channelC > 0) ){
#ifdef SIMPLEFOC_TEENSY_DEBUG
SIMPLEFOC_DEBUG("TEENSY-DRV: All pins on Flexpwm A or B submodules - Configuring center-aligned pwm!");
SIMPLEFOC_DEBUG("TEENSY-DRV: All pins on Flexpwm A or B channels - Configuring center-aligned pwm!");
#endif

// Configure FlexPWM units
Expand Down Expand Up @@ -645,7 +644,7 @@ void write_pwm_on_pin(IMXRT_FLEXPWM_t *p, unsigned int submodule, uint8_t channe
return params;
}else{
#ifdef SIMPLEFOC_TEENSY_DEBUG
SIMPLEFOC_DEBUG("TEENSY-DRV: Not all pins on Flexpwm A and B submodules - cannot configure center-aligned pwm!");
SIMPLEFOC_DEBUG("TEENSY-DRV: Not all pins on Flexpwm A and B channels - cannot configure center-aligned pwm!");
#endif
return SIMPLEFOC_DRIVER_INIT_FAILED;
}
Expand Down
1 change: 1 addition & 0 deletions src/drivers/hardware_specific/teensy/teensy_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void* _configure3PWM(long pwm_frequency,const int pinA, const int pinB, const in
if(p != SIMPLEFOC_DRIVER_INIT_FAILED){
return p; // if center aligned pwm is available return the params
}else{ // if center aligned pwm is not available use fast pwm
SIMPLEFOC_DEBUG("TEENSY-DRV: Configuring 3PWM with fast pwm. Please consider using center aligned pwm for better performance!");
_setHighFrequency(pwm_frequency, pinA);
_setHighFrequency(pwm_frequency, pinB);
_setHighFrequency(pwm_frequency, pinC);
Expand Down

0 comments on commit 238d26b

Please sign in to comment.