Re: FRDM-K64 GPIO driver name


Maureen Helm
 

Hi Anders,
I took a quick look and ran your code, and it appears that the pinmux for PTB22 is not configured correctly. The register field PORTB_PCR[MUX] is set to 0 when it should be set to 1. You should be able to fix this by pulling in the pinmux driver and changing the pin to function 1.
Maureen

-----Original Message-----
From: Anders Dam Kofoed [mailto:adk(a)accipio.dk]
Sent: Tuesday, March 15, 2016 5:20 AM
To: devel(a)lists.zephyrproject.org
Subject: [devel] Re: Re: FRDM-K64 GPIO driver name

Hi Thomasz,

Yesterday I tried with the following source code - but nothing happens :(
Nothing blinks. I programming it by copying the outdir/zephyr.bin onto the
MBED folder. The board seems to "eat" it as it should but nothing happens -
even after a reset.

GPIO out pin is Port B pin 22. Input is port B pin 9.
What puzzels me the most is that I do not get ANY debug output on the
console (screen /dev/ttyACM0 in Linux). I'd really like it to just show a sign of
life...

--- prj.conf ---
CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y
CONFIG_NANO_TIMERS=y
CONFIG_NANO_TIMEOUTS=y
CONFIG_GPIO=y

---------------
--- main.c ---
#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <sys_clock.h>


#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define PRINT printf
#else
#include <misc/printk.h>
#define PRINT printk
#endif

#define SLEEPTICKS SECONDS(1)

#define GPIO_OUT_PIN 22
#define GPIO_INT_PIN 9
#define GPIO_NAME "GPIO_"
#define GPIO_DRV_NAME CONFIG_GPIO_K64_B_DEV_NAME

void gpio_callback(struct device *port, uint32_t pin) {
PRINT(GPIO_NAME "%d triggered\n", pin); }


void main(void)
{
PRINT("Hello World!\n");
printf("Hello World!\n");

struct nano_timer timer;
void *timer_data[1];
struct device *gpio_dev;
int ret;
int toggle = 0;

nano_timer_init(&timer, timer_data);

gpio_dev = device_get_binding(GPIO_DRV_NAME);
if (!gpio_dev) {
PRINT("Cannot find %s!\n", GPIO_DRV_NAME);
}

/* Setup GPIO output */
ret = gpio_pin_configure(gpio_dev, GPIO_OUT_PIN,
(GPIO_DIR_OUT));
if (ret) {
PRINT("Error configuring " GPIO_NAME "%d!\n",
GPIO_OUT_PIN);
}

/* Setup GPIO input, and triggers on rising edge. */
ret = gpio_pin_configure(gpio_dev, GPIO_INT_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE
| GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE));
if (ret) {
PRINT("Error configuring " GPIO_NAME "%d!\n",
GPIO_INT_PIN);
}

ret = gpio_set_callback(gpio_dev, gpio_callback);
if (ret) {
PRINT("Cannot setup callback!\n");
}

ret = gpio_pin_enable_callback(gpio_dev, GPIO_INT_PIN);
if (ret) {
PRINT("Error enabling callback!\n");
}

while (1) {
PRINT("Toggling " GPIO_NAME "%d\n", GPIO_OUT_PIN);

ret = gpio_pin_write(gpio_dev, GPIO_OUT_PIN, toggle);
if (ret) {
PRINT("Error set " GPIO_NAME "%d!\n",
GPIO_OUT_PIN);
}

if (toggle) {
toggle = 0;
} else {
toggle = 1;
}

nano_timer_start(&timer, SLEEPTICKS);
nano_timer_test(&timer, TICKS_UNLIMITED);
}


}

Join devel@lists.zephyrproject.org to automatically receive all group messages.