MKL02Z PTA2(SWD_DIO) GPIO setup

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MKL02Z PTA2(SWD_DIO) GPIO setup

3,813 Views
OilCastle
Contributor II

hi i have question about MKL02Z.

now i try PTA2 is gpio output

but output is not change

why?

is there anythig i miss?

plz, thx for your help

have a nice day.

0 Kudos
10 Replies

3,433 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi

You can find different examples of configuration like GPIO, in the next link

http://www.nxp.com/webapp/sps/download/license.jsp?colCode=KL02-SC&location=null&Parent_nodeId=13690...

If you are using KSDK, the next example could help you with the configuration

/* enable clock for PORTs */

         CLOCK_SYS_EnablePortClock(PORTA_IDX);

         CLOCK_SYS_EnablePortClock(PORTB_IDX);

         configure_gpio_pins( PORTA_IDX );

         configure_gpio_pins( PORTB_IDX );

         GPIO_DRV_OutputPinInit(&gpioPins[0]);

         GPIO_DRV_OutputPinInit(&ledPins[1]);

/* This for loop should be replaced. By default this loop allows a single stepping. */

for (;;)

{

      GPIO_DRV_TogglePinOutput( kGpioLED1);

      GPIO_DRV_TogglePinOutput( GPIO_MAKE_PIN(GPIOA_IDX,  2));

}

Hope it helps

Mario

0 Kudos

3,433 Views
OilCastle
Contributor II

thanks very much for your reply, but...

i think it is not helpful for me.

cause, i don`t use KSDK,

and i did setup gpio output on PTA2 so sure.

i`m still working on it

PTA2 is only gpio output cannot change output in my case.

any other output works so fine.

PTA2 input works fine.

only output is problem

anyway, thanks for your kindness

have a nice day

0 Kudos

3,433 Views
btruden
Contributor I

Hi Jun-Young Lee,

how are you?

Have you solved this problem?? I've just got stuck on this same issue.

I try to configure PTA2 as a simple output but nothig occurs, when I try to set it to "1" there's no change on the pin voltage.

Here the code:

/* pinout configuration variables */
gpio_pin_config_t dc_rseg_config = {kGPIO_DigitalOutput, true};

GPIO_PinInit(kGPIO_PORTA, 2, &dc_rseg_config);

Thanks,

0 Kudos

3,433 Views
mjbcswitzerland
Specialist V

Blas

I don't use the environment that you are working with but taking a quick look I have the feeling that you need to call two different routines to configure it (unless the pin defaults to its GPIO mode).

Try also using PORT_SetPinConfig() before to ensure the MUX is GPIO before configuring it as an output.

Regards

Mark

P.S. In case of continued problems try the uTasker projet (free open source on GitHub with Kinetis simulator to remove guess work) which just needs the following:

_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, (PORTA_BIT2 | PORTA_BIT5), (PORTA_BIT29), (PORT_SRE_SLOW | PORT_DSE_HIGH));

which would completely configure everything needed to set PTA2 and PTA5 to outputs (with certain drive characteristics) and set PTA2 to '1' and PTA5 to '0'.
Reference: http://www.utasker.com/forum/index.php?topic=1875.0

0 Kudos

3,433 Views
btruden
Contributor I

Hi Mark,

Thank you for your prompt reply.

I'm using the MCU Xpresso IDE which is the current option offered by NXP. So I use the driver libraries that comes with that IDE. 

I also tryed this, but same results:

GPIOA->PDDR |= 1<<2;
GPIOA->PSOR |= 1<<2;

What exactly "PORT_SetPinConfig()" function does? I can't find it in the driver library that I'm using.

 

How can I configure the MUX to GPIO in PTA2 at register level? which specific register must I configure?

Below an extract of the "GPIO_PinInit"

typedef enum _gpio_port_num
{
kGPIO_PORTA = 0U,
kGPIO_PORTB,
kGPIO_PORTC,
kGPIO_PORTD,
kGPIO_PORTE,
kGPIO_PORTF,
kGPIO_PORTG,
kGPIO_PORTH,
} gpio_port_num_t;

typedef struct _gpio_pin_config
{
gpio_pin_direction_t pinDirection;          /*!< GPIO direction, input or output */

uint8_t outputLogic;                                  /*!< Set a default output logic, which has no use in input */
} gpio_pin_config_t;

void GPIO_PinInit(gpio_port_num_t port, uint8_t pin, const gpio_pin_config_t *config)
{
assert(config);

uint8_t instance = (uint8_t)port / PORT_NUMBERS_EACH_GPIO;
uint8_t shift = (uint8_t)port % PORT_NUMBERS_EACH_GPIO;
GPIO_Type *base = s_gpioBases[instance];

if (config->pinDirection == kGPIO_DigitalInput)
{
base->PDDR &= ~(1U << ((uint32_t)pin + (shift * PIN_NUMBERS_EACH_PORT)));
base->PIDR &= ~(1U << ((uint32_t)pin + (shift * PIN_NUMBERS_EACH_PORT)));
}
else
{
GPIO_PinWrite(port, pin, config->outputLogic);
base->PDDR |= (1U << ((uint32_t)pin + (shift * PIN_NUMBERS_EACH_PORT)));
base->PIDR |= (1U << ((uint32_t)pin + (shift * PIN_NUMBERS_EACH_PORT)));
}
}

void GPIO_PinWrite(gpio_port_num_t port, uint8_t pin, uint8_t output)
{
uint8_t instance = (uint8_t)port / PORT_NUMBERS_EACH_GPIO;
uint8_t shift = (uint8_t)port % PORT_NUMBERS_EACH_GPIO;
GPIO_Type *base = s_gpioBases[instance];

if (output == 0U)
{
base->PCOR = 1U << ((uint32_t)pin + (shift * PIN_NUMBERS_EACH_PORT));
}
else
{
base->PSOR = 1U << ((uint32_t)pin + (shift * PIN_NUMBERS_EACH_PORT));
}
}

Thanks again.

Best regards.

0 Kudos

3,433 Views
mjbcswitzerland
Specialist V

Blas

I just searched an SDK project and found this function in fsl_port.h

 * @param base   PORT peripheral base pointer.
 * @param pin    PORT pin number.
 * @param config PORT PCR register configuration structure.
 */
static inline void PORT_SetPinConfig(PORT_Type *base, uint32_t pin, const port_pin_config_t *config)
{
    assert(config);
    uint32_t addr = (uint32_t)&base->PCR[pin];
    *(volatile uint16_t *)(addr) = *((const uint16_t *)config);
}

Each pin has a pin mux and some default to GPIO but others to peripheral functions (or disabled). PTA2 on the KL02 defaults to SWD_DIO and so GPIO operatiosn will have no effect until its MUX setting is configured to a port.

The actual command is to write
PORTA_PCR2 = 0x00000100; // set GPIO on PTA2

Beware that programming this pin to output will stop the debugger working....

Regards

Mark

For better, faster, cheaper product developments consider the uTasker developer's version, professional Kinetis support, one-on-one training and complete fast-track project solutions to set you apart from the herd : http://www.utasker.com/support.html

0 Kudos

3,433 Views
btruden
Contributor I

Hi Mark, 

I've finally found the problem. In this MCU the PTA2 pin, when configured as output, is open drain (below an extract from the datasheet):

PTA2 open drain.jpg

So I have to place an external pullup resistor.

Thank you for your time.

Best regards!

0 Kudos

3,433 Views
mjbcswitzerland
Specialist V

Blas

If you had mentioned you were using a KE part and not the KE02 as in the thread I could have immediately told you than.

In the case of the KL02 there is also the same true-open-drain pins, but on PTB3 and PTB4 instead.

Regards

Mark

0 Kudos

3,433 Views
OilCastle
Contributor II

Wow, many replies...

sorry for late. i have a little issue about checking my email.

anyway, I think this is not exactly same problem with mine.

FYI, PTA2 pin of KL02Z is basically SWD interface. This is essential function for develop this MCU.

Blas, accordingly your quoted in datasheet, Mark and You are totally right I think.

However in KL02Z, You need check and fix in startup code for some MCU setting.

- ex. NMI pin function, SWD pin setup, some memory protection...

My memory is very unclear but, in that time, I working with that and successfully use PTA2 as GPIO.
But some sample never recovered, cause SWD interface no longer available by my mistake.
After than, I fix my code, specific sequence  is added for enable SWD pin.

I hope this tiny little help for you guys. :smileyhappy:

Have a good day.

0 Kudos

3,433 Views
mjbcswitzerland
Specialist V

Hi

You need to show your code so that it is possible to see what is missing in it.

However this is how to configure the PTA2 output - maybe you see what is missing in your code from it:

SIM_SCGC5 |= SIM_SCGC5_PORTA; // apply clock to port

PORTA_GPCLR = (((0x04) << 16) | (PORT_MUX_GPIO)); // configure as GPIO

GPIOA_PDDR |= 0x04; // set to output

Regards

Mark

0 Kudos