tonton81 / FlexCAN_T4

FlexCAN (CAN 2.0 / CANFD) Library for Teensy 3.x and 4.0
https://forum.pjrc.com/threads/56035-FlexCAN_T4-FlexCAN-for-Teensy-4
MIT License
196 stars 66 forks source link

ALT pins on Teensy 3.5 and 3.6 are not set to GPIO state. #14

Closed opelpanfan closed 4 years ago

opelpanfan commented 4 years ago

ALT pins not available as GIO pins after CAN started. Pin 29 and 30 affected on Teensy 3.5 and 3.6

PR ALT_35_36 raised with a fix in FlexCAN_T4.tpp lines 576, 579, 644, 647 I believe are wrong as pins set to 0 pins should be reset back to GPIO state using PORT_PCR_MUX(1)

tonton81 commented 4 years ago

default state for gpios is DISABLED, why convert them to GPIO when they (all pins) are disabled by default?

opelpanfan commented 4 years ago

Because if you declared pins in setup before you do CAN init they will be put back to disable state.

On Wed, 8 Jul 2020, 00:13 Antonio Brewer, notifications@github.com wrote:

default state for gpios is DISABLED, why convert them to GPIO when they (all pins) are disabled by default?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tonton81/FlexCAN_T4/issues/14#issuecomment-655186102, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCXV7OAYX7YO3HSYBEQSYDR2OTZJANCNFSM4OTTMP2A .

tonton81 commented 4 years ago

thanks for the info. i would suggest a different method then that won't affect default state (or unset). i will check the RM later to see what conditions we can check first, to see whether the pin was used or was not used by flexcan, or if it was set other than default. i would also imagine it would be similar with T4.x...

tonton81 commented 4 years ago

I just did a commit for the pin configuration validation for T3. Can you let me know what you think?

If the default pin is NOT set, begin uses DEF as default (without overriding alternate pin, as long as it wasn't set to flexcan mux previously). If the default pin was set to GPIO mode, begin() will call ALT automatically. If default and alternate pins are both used, ALT is automatically set and override ALT pin state to take control. using setTX and setRX manually after that is fine and your selections of ALT or DEF are enforced. If the previous pin was forced to flexcan mode, it will be set to 0.

The only other issue is running setTX/setRX before begin(). begin would override with default pins. So to be clear, setRX and setTX must be used AFTER begin() was called. (The first call of setTX/setRX/begin won't touch a used pin, but subsequent calls would enforce it.)

opelpanfan commented 4 years ago

Sounds good. Tested on my board and it works thank you. Closed PR as you did a better job handling this issue :)

tonton81 commented 4 years ago

Excellent. I'll have to add the T4.x ones later on, it's 4AM :P

opelpanfan commented 4 years ago

All sorted for T3.5 and 3.6