Teensy 3.6 pinMode and DSE and SRE configuration for GPIOs

Status
Not open for further replies.

ElkinDiaz

Member
Dear PJRC community,

We have a project based on the Teensy 3.6, we would need to modify or configure the Drive Strength Enable DSE and the Slew Rate Enable SRE options for a particular GPIO. As far as I understand, the K66 implementation on the Arduino IDE has functions that set this parameters, for example the "pinMode" function, is it possible to modify this options?

Is it possible that someone can share the way to enable or disable this options?

We are facing issues with the EMC tests on this prototypes, and we wanted to reduce the bandwidth on the GPIO ports.

Cordially,
 
for example the "pinMode" function, is it possible to modify this options?

Yes, if you really want to edit the code, you can. The file is {Arduino}/hardware/teensy/avr/cores/teensy3/pins_teensy.c. If using Windows, the default Arduino location is C:/Program Files (x86)/Arduino.

In the current version, pinMode is at line 1080.

If you edit this file, please be aware installing any new version will overwrite it. Best to make a backup copy.

Is it possible that someone can share the way to enable or disable this options?

We are facing issues with the EMC tests on this prototypes, and we wanted to reduce the bandwidth on the GPIO ports.

Probably the simplest way would be to just modify the bits in the PORT config register for the pin you're using.

The core_pins.h file defines convenient names. So if you're using pin 2, you can use CORE_PIN2_CONFIG rather than looking up the native name, which is PORTD_PCR0.

The register is documented in the MK66 reference manual starting on page 220.

For example, if you want to turn off the DSE bit to put the pin into low drive mode, you would use something like this:

Code:
    CORE_PIN2_CONFIG &= ~PORT_PCR_DSE;
 
DSE and SRE configurations

Probably the simplest way would be to just modify the bits in the PORT config register for the pin you're using.

The core_pins.h file defines convenient names. So if you're using pin 2, you can use CORE_PIN2_CONFIG rather than looking up the native name, which is PORTD_PCR0.

The register is documented in the MK66 reference manual starting on page 220.

For example, if you want to turn off the DSE bit to put the pin into low drive mode, you would use something like this:

Code:
    CORE_PIN2_CONFIG &= ~PORT_PCR_DSE;

Thanks for the fast reply, I want to be able to enable or disable this options for the GPIO, so as I could understand, if I want to modify this I can directly modify the CORE_PIN#_CONFIG register using the already defined PORT_PCR_DSE and PORT_PCR_DSE variables.

Can you please confirm how to enable and disable them?

I would for sure prefer to don't modify the Arduino files, if its possible to do this in a simpler way. I will call the pinMode function, and after that in my arduino, using only 4 pins as an example, then following your example, I will call to the following two functions:


void disable_DSE()
{
CORE_PIN0_CONFIG &= ~PORT_PCR_DSE;
CORE_PIN1_CONFIG &= ~PORT_PCR_DSE;
CORE_PIN2_CONFIG &= ~PORT_PCR_DSE;
CORE_PIN3_CONFIG &= ~PORT_PCR_DSE;
CORE_PIN4_CONFIG &= ~PORT_PCR_DSE;
}
void disable_SRE()
{
CORE_PIN0_CONFIG &= ~PORT_PCR_SRE;
CORE_PIN1_CONFIG &= ~PORT_PCR_SRE;
CORE_PIN2_CONFIG &= ~PORT_PCR_SRE;
CORE_PIN3_CONFIG &= ~PORT_PCR_SRE;
CORE_PIN4_CONFIG &= ~PORT_PCR_SRE;
}

Can you please confirm about it?

Thanks a lot!
 
Is it possible that someone can share the way to enable or disable this options?

A couple of years ago I did a short header only lib, mainly to get to know the GPIO system in more detail. You can find it here https://github.com/luni64/pins With it you can do things like this:

Code:
#include "pins.h"
using namespace pins;

pin<1> myFirstPin(OUTPUT);
pin<5> mySecondPin(OUTPUT_OPENDRAIN);
pin<13> LED(OUTPUT);

void setup()
{
  myFirstPin.driveStrengthEnable(true);
  mySecondPin.slowSlewRateEnable(true);

  pin<17>::driveStrengthEnable(true);  
  

  // move Serial1 on a T3.2 from its standard pins 0 and 1 to the alternative pins 21 and 5 (those pins which are grayed out on the pinout cards):
  pin<21>::setMUX(ALT3);  // Set alternative function of pin21 to ALT3
  pin<5>::setMUX(ALT3);   // Set alternative function of pin5 to ALT3
}

void loop()
{
  LED.toggle();
  delay(100);
}

It doesn't disable or influence the standard methods like digitalWrite etc.. So, if you like you can just drop the header into your sketch folder, do the pin settings as you need and use the standard functions afterwards.

https://forum.pjrc.com/threads/43881-Fun-with-pins
 
Last edited:
Hi Paul / All,

I've been playing around with what was suggested above to enable/disable the slew rate on digital pins of a Teensy 3.6. I can easily do this in a sketch by simply changing the port configuration register after my call to pinMode as follows to enable/disable the feature:

Code:
void setup(){
   uint8_t pin = 13;
   pinMode(pin, OUTPUT);
   volatile uint32_t* config = portConfigRegister(pin);     // setup pointer
   *config |= PORT_PCR_SRE;                                                     // disable slew rate

   // or to disable slew rate use the following line instead
   //*config &= ~PORT_PCR_SRE;                                               // disable slew rate

   bool pulse = true;
   while (true) {
      if (pulse) digitalWriteFast(pin, HIGH);
      else digitalWriteFast(pin, LOW);
      pulse = !pulse;
   }
}

void loop(){
   // never reached
}

I'm doing this on pin 13 because as a test as I want to try and implement the same when using this pin as the SCLK line for my SPI1 bus to a TFT. When I setup the sketch as noted above, I can clearly see the effect of this on my oscilloscope (200MHz). With slew rate turned off there is significant enough over/under shoot on the PWM signal, whereas when slew rate is enabled, this practically disappears (similar to what Paul and others have shown in the links above).

Now I come to my problem, I'm getting some significant EMI issues from my setup when communicating with an FT813 display due to ringing or higher order harmonics of this over/undershoot issue with the PWM signal on SCLK and MOSI lines. So, since the sketch above was so successful in eliminating it, I'm trying to do the same when the pin is setup in SPI1 mode. Searching through the core I found the SPI1 setup procedure is different to a normal digitalWrite procedure as I believe it is described in the SPCR1.enable_pins() function of avr_emulation.h. I don't see any calls to enable slew rate while these pins are being initialized for SPI operation, so I tried adding similar code to that above after calling SPI.being(), however the pins appear to be operating with slew rate disabled regardless of whether my code tries to enable it or not.

I also did some searching on the K66 manual to see if I could find more information on it and it looked like it's possible there might be an issue using it while SPI mode is active (possibly due to using other internal hardware). So my question is, can slew rate be enabled when SPI1 mode is active? Any help or advice on how to enable it or even to tell me it isn't possible would be greatly appreciated.
Thanks.
 
Status
Not open for further replies.
Back
Top