Arduino Teensy 4.1

I want to know which pins are connected to which GPIO in Arduino Teensy 4.1.
As want to use GPIOx_DR_SET and GPIOx_DR_CLEAR register instead of GPIOC_PDOR which is used for teensy 3.6.

I have not been to the Teensy site in a while, but I am 99.99999% sure there is a datasheet and/or pinout.
I had it bookmarked, here is the link https://www.pjrc.com/store/teensy41.html

Probably best to ask up on the PJRC forum: Here is an image of one of the pages of my Excel document that shows all of the pins...

Note the GPIO columns show the IO pins in their normal speed mode, however the startup code on the Teensy 4.x switches the pins into high speed mode.
In Normal modes the Ports are (1-5) in high Speed mode they are 6-9.
Port 1 in this table is typically Port 6 in your code. So pin 0 which shows as 1.3
Is Pin 3 on Port 6. I have the pins marked in my document using pin 1, as that is how they are marked throughout the NXP reference manual.

Note: Very recently Paul Stoffregen uploaded an annotated version of the NXP reference manual which shows more of the information of mapping of processor pins to which pin it is on the different teensy boards. You can download it from the page that @sonofcy mentioned.

Code wise, you could also simply use digitalWriteFast (or digitalToggleFast) which if you passed in a fixed pin number like digitalWriteFast(1, HIGH) the code generated would boil down to probably 1 instruction.

Edit - Might help you if I mentioned how I generated the excel document.
In your Teensy release open the file (\cores\teensy4\core_pins.h

Look for the section: #elif defined(IMXRT1062) && defined(ARDUINO_TEENSY41)
In the version I am looking at it is like 553

Now you will see a section like:

#define CORE_PIN0_BIT		3
#define CORE_PIN1_BIT		2
#define CORE_PIN2_BIT		4
#define CORE_PIN3_BIT		5
#define CORE_PIN4_BIT		6
#define CORE_PIN5_BIT		8
#define CORE_PIN6_BIT		10
#define CORE_PIN7_BIT		17
#define CORE_PIN8_BIT		16
#define CORE_PIN9_BIT		11

A little way farther down you will see:

// Fast GPIO
#define CORE_PIN0_PORTREG	GPIO6_DR
#define CORE_PIN1_PORTREG	GPIO6_DR
#define CORE_PIN2_PORTREG	GPIO9_DR
#define CORE_PIN3_PORTREG	GPIO9_DR
#define CORE_PIN4_PORTREG	GPIO9_DR
#define CORE_PIN5_PORTREG	GPIO9_DR
#define CORE_PIN6_PORTREG	GPIO7_DR
#define CORE_PIN7_PORTREG	GPIO7_DR
#define CORE_PIN8_PORTREG	GPIO7_DR
#define CORE_PIN9_PORTREG	GPIO7_DR

From this you can extract pin 9 is on port 7 pin 11

1 Like

Is that spreadsheet feely available somewhere, or is it your own creation?

It is my own creation...
But it is up on github:

I never encountered github in my professional software life, but I think it's possible to make a local copy (I have gitHub desktop). How do I do that so I will know if you change it?

I believe with most browsers, you can simply download the file.

On windows you can probably just right click on the link above and choose command like
save link as..

And it will download the file...

Or just click on it, which brings you up to the github page:
and click on the button:

I did manage to figure out the download part, I was just wondering how to use my desktop gitHub to tell me if the file is changed. I THINK it can do that.

On my windows machine I typically use windows desktop.
Download GitHub Desktop | GitHub Desktop

Once it is installed, I typically browse to a github project like the parent of the link I showed for the document.

There I click on the code button and then choose the open with github desktop.

What I don't remember is if you need to be a verified user with...
to be able to clone a project... I know you do if you wish to do anything that writes to github, like to create a project, or to do forks and then push changes up to github...

That's it. Thanks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.