teensy 3.x: port registers?

Status
Not open for further replies.

seebs

Member
https://www.pjrc.com/teensy/pins.html

This appears to apply to the AVR chips. Is there anything comparable for the ARM chips? For the AVR chips, there's information mapping each pin to bits of port registers, and I don't see anything parallel to that. (Relevant if, for some reason, I wanted to set multiple pins at once in parallel.) I've seen some references to "digitalWriteFast()", and that looks like it's extremely fast for single pin changes.

But for instance, I have an LED controller that is using six pins at a time. With AVR, you make sure those six pins are consecutive pins in a single port, and you have a single operation that sets all six pins. So, 1 cycle = 6 pins set/cleared. With the ARM chips, I'm not seeing a way to do that, and even if I can compile each operation to a single cycle, that's now six cycles minimum, so it's not even faster unless I'm overclocked...

This thread:
https://forum.pjrc.com/threads/23431-Teensy-3-using-IO-pins

Suggests that there's set/clear registers, which would allow writing to multiple pins at once, but I don't see any charts or pinouts that indicate which pins are which?
 
As for are there registers... Yes there are...

There is lots of details in the reference manuals, that you can download the appropriate ones for the board from the Teensy forum: https://www.pjrc.com/teensy/datasheets.html

Example for Teensy 3.2: https://www.pjrc.com/teensy/K20P64M72SF1RM.pdf
Look at chapter 11 which talks about the different port registers. As well as Chapter 10 which talks about how to configure different pins for different functionality (GPIO vs SPI vs I2C...)

Now how to figure out what logical Teensy IO pins map to internal PORT pin numbers. .
If you look at core_pins.h in the core\teensy3 directory.

You find a section for your board. Example T3.2
Code:
#if defined(__MK20DX128__) || defined(__MK20DX256__)

#define CORE_PIN0_BIT		16
#define CORE_PIN1_BIT		17
#define CORE_PIN2_BIT		0
#define CORE_PIN3_BIT		12
#define CORE_PIN4_BIT		13
...
#define CORE_PIN0_PORTREG	GPIOB_PDOR
#define CORE_PIN1_PORTREG	GPIOB_PDOR
#define CORE_PIN2_PORTREG	GPIOD_PDOR
#define CORE_PIN3_PORTREG	GPIOA_PDOR
#define CORE_PIN4_PORTREG	GPIOA_PDOR
#define CORE_PIN5_PORTREG	GPIOD_PDOR
#define CORE_PIN6_PORTREG	GPIOD_PDOR
#define CORE_PIN7_PORTREG	GPIOD_PDOR
#define CORE_PIN8_PORTREG	GPIOD_PDOR
So from this here, you can figure out that for example Arduino pin 0 is actually pine: B16
likewise 1 is B17, 2 is D0...

I keep meaning to create a spreadsheet for all the boards, but I have them for the T3.5/6 which I uploaded as part of the K66 beta thread:
https://forum.pjrc.com/threads/34808-K66-Beta-Test?p=113643&viewfull=1#post113643
 
Yes, that's very helpful. I also have a "breakout" for the teensy 3.2 which adds A10-A14 pins, which I don't see in that chart, but this is certainly closer. It looks like there are at least two registers where I have 8 consecutive bits available on pins, although they don't ever seem to end up contiguous. Still, running wires around a bit isn't a huge problem.

This might be handy info to have on the pinout page (https://www.pjrc.com/teensy/pinout.html), similar to the way it's present for the teensy 2.0/teensy++2.0 pinouts. I found another thread that has this for the 3.1, which so far as I can tell is pretty similar to the 3.2.
 
Status
Not open for further replies.
Back
Top