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

Thread: Teensy 3.2 programming through Atollic TrueStudio?

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    6

    Teensy 3.2 programming through Atollic TrueStudio?

    Hi all,

    Looking at the information posted about Teensy 3.2, it seems that I should be able to create a hex file through Atollic and load it on to my Teensy 3.2 via the Teensy Loader.

    I have created a simple project in Atollic, just trying to get GPIOs to output a logic high. I'm not sure if the problem is in my code or my process.

    Here is my code. It doesn't set any pins to logic high :-( I appreciate any help I can get.

    main.c
    Code:
    #include "mcu.h"
    #include "LED.h"
    
    int main(void)
    {
    	//SystemInit();
    	LEDInit();
    
        uint32_t i = 0;
    
        /* TODO - Add your application code here */
        while (1)
        {
        	 i++;
        }
    
        return 0;
    }
    LED.c
    Code:
    #include "mcu.h"
    #include "LED.h"
    
    void LEDInit()
    {
    	// Select correct port control (PORT CH11)
    	// A0 is pin 20
    	//PORTA->PCR[0] |= 0b001 << PORT_PCR_MUX_SHIFT;
    	//PORTA->PCR[0] |= PORT_PCR_DSE_MASK;
    
    	for (int i = 0; i < 32; i++) {
    		PORTA->PCR[i] |= 0b001 << PORT_PCR_MUX_SHIFT;
    		PORTA->PCR[i] |= PORT_PCR_DSE_MASK;
    	}
    	for (int i = 0; i < 32; i++) {
    		PORTB->PCR[i] |= 0b001 << PORT_PCR_MUX_SHIFT;
    		PORTB->PCR[i] |= PORT_PCR_DSE_MASK;
    	}
    	for (int i = 0; i < 32; i++) {
    		PORTC->PCR[i] |= 0b001 << PORT_PCR_MUX_SHIFT;
    		PORTC->PCR[i] |= PORT_PCR_DSE_MASK;
    	}
    	for (int i = 0; i < 32; i++) {
    		PORTD->PCR[i] |= 0b001 << PORT_PCR_MUX_SHIFT;
    		PORTD->PCR[i] |= PORT_PCR_DSE_MASK;
    	}
    	for (int i = 0; i < 32; i++) {
    		PORTE->PCR[i] |= 0b001 << PORT_PCR_MUX_SHIFT;
    		PORTE->PCR[i] |= PORT_PCR_DSE_MASK;
    	}
    
    	// Set up GPIO to digital output (GPIO CH49)
    	//PTA->PDDR |= 1 << 0;
    	PTA->PDDR = GPIO_PDDR_PDD_MASK;
    	PTB->PDDR = GPIO_PDDR_PDD_MASK;
    	PTC->PDDR = GPIO_PDDR_PDD_MASK;
    	PTD->PDDR = GPIO_PDDR_PDD_MASK;
    	PTE->PDDR = GPIO_PDDR_PDD_MASK;
    
    	LEDOn();
    }
    
    void LEDOn()
    {
    	//PTA->PSOR |= 1 << 0;
    
    	PTA->PSOR = GPIO_PDDR_PDD_MASK;
    	PTB->PSOR = GPIO_PDDR_PDD_MASK;
    	PTC->PSOR = GPIO_PDDR_PDD_MASK;
    	PTD->PSOR = GPIO_PDDR_PDD_MASK;
    	PTE->PSOR = GPIO_PDDR_PDD_MASK;
    
    	PTA->PDOR = GPIO_PDDR_PDD_MASK;
    	PTB->PDOR = GPIO_PDDR_PDD_MASK;
    	PTC->PDOR = GPIO_PDDR_PDD_MASK;
    	PTD->PDOR = GPIO_PDDR_PDD_MASK;
    	PTE->PDOR = GPIO_PDDR_PDD_MASK;
    }
    
    void LEDOff()
    {
    	PTA->PCOR |= 1 << 0;
    }
    
    void LEDToggle()
    {
    	PTA->PTOR |= 1 << 0;
    }

  2. #2
    Junior Member
    Join Date
    Dec 2017
    Posts
    6
    Bump. Can anyone help me with this? Can you only pass Arduino hex files through the Teensy Loader?

  3. #3
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,624
    You can write lots of stuff to the pin GPIO registers, but you won’t see any effect on the pins until you configure the pin’s MUX to the corresponding I/O mode. This part is missing in your code, so it won’t work.

    And yes, the Teensy loader is designed to upload HEX files. AFAIK, it does even a few verifications if that HEX file has really been built for the target Teensy model, thus it might be that it complains about HEX files built with different toolchains. You’d have to try that out.

  4. #4
    Junior Member
    Join Date
    Dec 2017
    Posts
    6
    Quote Originally Posted by Theremingenieur View Post
    You can write lots of stuff to the pin GPIO registers, but you won’t see any effect on the pins until you configure the pin’s MUX to the corresponding I/O mode. This part is missing in your code, so it won’t work.

    And yes, the Teensy loader is designed to upload HEX files. AFAIK, it does even a few verifications if that HEX file has really been built for the target Teensy model, thus it might be that it complains about HEX files built with different toolchains. You’d have to try that out.
    Hi there, thanks for the reply!

    In LED_Init, I have these lines:
    Code:
    PORTA->PCR[i] |= 0b001 << PORT_PCR_MUX_SHIFT;
    PORTA->PCR[i] |= PORT_PCR_DSE_MASK;
    Aren't these lines changing the pins' usage mux? Is there an additional MUX that I need to worry about?

  5. #5
    Junior Member
    Join Date
    Dec 2017
    Posts
    6
    Oh hey, @Theremingenieur - thanks to you I found my way to Ch 10 of the K20 spec. CH 10 says that clocks to all modules are disabled by default. Enabling the clock for GPIO blocks got me past "Light an LED" sanity check. Thank you!

  6. #6
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,624
    Great that you found it although I pointed you towards a wrong direction. I simply hadn’t seen the MUX line in your code, should read posts (and code) more carefully...

Posting Permissions

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