Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Teensy 4.0 - How to access pins? (not with arduino)

  1. #1
    Junior Member
    Join Date
    Aug 2019
    Posts
    2

    Teensy 4.0 - How to access pins? (not with arduino)

    Good morning,

    With the new Teensy that came out, I've challenged myself to do bare-metal programming without the use of Arduino and I am slowly working through the set up. (I'm using rust but that is not important). I believe I've got the program loading onto my board, and I'm now attempting to access the pins (and some of the internal peripherals like the LED used in the blink program in Arduino). I've never done bare-metal programming... I'm used to FPGA's and accessing pins is much easier with that.. so I'm struggling to wrap my head around it.

    I've been reading the documentation on how accessing GPIO works on the new I.MXRT1060, along with looking through the github page for the teensy4.0 to figure out how accessing the pins work. I believe the key sections in the datasheet are chapters 10 and 11.

    From the documentation I have read, this is what i (THINK) I understand:

    To set a pin mode to IN / OUT (I'm not even to the point of changing to I2C or something), I must:
    find the particular IOMUX controlling the pin and set it to GPIO mode. I've seen GPR26 - GPR29(example: 10.4.27) lets me first select which GPIO i wish to access, then I get to the SW_MUX_CTL Register(example: 10.5.1 in the datasheet) that let me select GPIO mode.
    go to that pin's GPIO and set the GDIR register to all zeros or all ones to set read / write, then I can just read / write to the DR depending on what mode its in.

    Now I believe I'm misunderstanding that because there are a few things that don't add up...

    *There are only 8 GPIO's (GPIO1 - GPIO9), so i don't understand how that can control 30+ pins on the board.
    *Why are there so many IOMUXC's for each GPIO? I see that there is a mux for setting GPIO4_IO02, IO03, etc, and I have no idea what each of those are.
    *What is the difference between SW_MUX_CTL 10.5.1 and SW_MUX_CTL in section 10.7.3 (and the many others like that).
    *How are you suppose to know which GPIO / IOMUXC corresponds to what pin? I haven't found anything in the datasheet for that.


    If anyone could help explain how this works to me, has a link to someone explaining it, or has some example code (doesn't matter what language really as long it is accessing memory and showing where / what to access), I would tremendously appreciate it. If I didn't make sense, just let me know and I'll try and explain better....

    Also, can't wait to be told I'm completely misunderstanding how it works, because I'm sure I am LOL.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,443
    You might want to take look at t4 Arduino sources...

    Likewise the t4 beta thread first page as there are listings showing what pin is connected to what

  3. #3
    Junior Member
    Join Date
    Aug 2019
    Posts
    2
    Understood, I'm looking at the beta thread now and its a little enlightening...

    As an example, it says pin0 is GPIO1.3. This somewhat makes sense because I had seen mux's for GPIO1_IO03. is that what they mean by GPIO1.3? If so, this makes way more sense. That's because 10.7.46 is the IOMUXC that has control of GPIO1_IO03.

    Does this also mean that for the 32 bit sections for each GPIO, it is [GPIOx_IO01, GPIOx_IO02, ..., GPIOx_IO32]?. That seems to make it a pain for pins that are in the same GPIO, because you have to access all 32 bits if you want to just change 1 pin. Does anyone know if there is a way around this? From previous readings, I know Teensy3.2 has a bitband such that each GPIO section is [u32; 32] instead of [u32]. This allows you to write to a single bit by writing a u32 bit 1 or 0 in software.

    Thanks!!

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,443
    Again you may want to take closer look at the code and at the different registers and the like>

    I do not believe that they support Bitbanding however, Each of these Pots I believe have a PORTSET and a PORTCLEAR register.

    So if you set a bit in the PORTSET register that pin will be turned to a 1, if you set a bit in the PORTCLEAR register that pins value will be set to zero...

    Take a look at core_pins.h at the functions like: digitalWriteFast...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •