Topics

#gpio ESP32: Could not able to toggle gpio pin [i.e stuck at LOW(0) all time though we set to 1 (HIGH)] #gpio

Praneeth
 

Hello Everyone,
 
I am new to embedded programming (ESP32 microcontroller and Zephyr OS).
By following documentation, I sucessfully executed Helo World! Program on ESP32.
 
I plan to start demo project as an IoT project (temperature monitoring solution) using ESP32 board but to understand basics i am trying sample projects (e.g: blinky default program). 
I could not able to blink LED but it looks i can configure gpio as OUT/IN. If gpio is configured as OUT then by default value is set to HIGH(1) but writing LOW(0) doesn't have any impact on LED (LED stuck at HIGH). So i don't see blink in LED. I also tried with other pin 2.
 
Hardware used: NodeMCU ESP-WROOM-32
Zephyr Build: 1.12.0
GPIO PIN: 5 or 2
Host OS: Windows
 
Code follows:
------
board.h (defined in header file).
---------------------------------
#define LED0_GPIO_PORT CONFIG_GPIO_ESP32_0_NAME
#define LED0_GPIO_PIN 2
 
main.c (source file)
---------------------------------
/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */
 
#include <zephyr.h>
#include <board.h>
#include <device.h>
#include <gpio.h>
#include <misc/printk.h>
 
/* Change this if you have an LED connected to a custom port */
#ifndef LED0_GPIO_CONTROLLER
#define LED0_GPIO_CONTROLLER LED0_GPIO_PORT
#endif
 
#define LED_PORT LED0_GPIO_CONTROLLER
 
/* Change this if you have an LED connected to a custom pin */
#define LED LED0_GPIO_PIN
 
/* 1000 msec = 1 sec */
#define SLEEP_TIME 1000
 
void main(void)
{
int cnt = 0;
struct device *dev;
 
dev = device_get_binding(CONFIG_GPIO_ESP32_0_NAME);
if (!dev) {
return -EINVAL;
}
/* Set LED pin as output */
gpio_pin_configure(dev, LED, GPIO_DIR_OUT);
 
while (1) {
/* Set pin to HIGH/LOW every 1 second */
gpio_pin_write(dev, LED, cnt % 2);
cnt++;
printk("cnt: %d \n", cnt);
k_sleep(SLEEP_TIME);
}
}
 
To verify driver behaviour i tried 'tests\drivers\gpio\gpio_basic_api' project and the result is FAIL (refer below),
 
using 'make monitor' command (serial output)
-----------------------------
***** Booting Zephyr OS v1.12.0-841-g5d1b57ff9 *****
Running test suite gpio_basic_test
===================================================================
starting test - test_gpio_pin_read_write
device=GPIO_0, pin1=4, pin2=2
write: 1
read: 1
write: 1
read: 1
write: 0
read: 1
 
    Assertion failed at ../src/test_pin_rw.c:45: test_gpio_pin_read_write: (val_
write == val_read is false)
Inconsistent GPIO read/write value
FAIL - test_gpio_pin_read_write
===================================================================
starting test - test_gpio_callback_edge_high
check enabled callback
FAIL - test_callback@90. not trigger callback correctly
 
    Assertion failed at ../src/test_callback_trigger.c:117: test_gpio_callback_e
dge_high: test_callback(GPIO_INT_EDGE | GPIO_INT_ACTIVE_HIGH) == TC_PASS is fals
e
 
FAIL - test_gpio_callback_edge_high
===================================================================
starting test - test_gpio_callback_edge_low
check enabled callback
FAIL - test_callback@90. not trigger callback correctly
 
    Assertion failed at ../src/test_callback_trigger.c:124: test_gpio_callback_e
dge_low: test_callback(GPIO_INT_EDGE | GPIO_INT_ACTIVE_LOW) == TC_PASS is false
 
FAIL - test_gpio_callback_edge_low
===================================================================
starting test - test_gpio_callback_level_high
check enabled callback
FAIL - test_callback@98. not trigger callback correctly
 
    Assertion failed at ../src/test_callback_trigger.c:131: test_gpio_callback_l
evel_high: test_callback(GPIO_INT_LEVEL | GPIO_INT_ACTIVE_HIGH) == TC_PASS is fa
lse
 
FAIL - test_gpio_callback_level_high
===================================================================
starting test - test_gpio_callback_add_remove
FAIL - test_callback_add_remove@82. not trigger callback correctly
 
    Assertion failed at ../src/test_callback_manage.c:155: test_gpio_callback_ad
d_remove: test_callback_add_remove() == TC_PASS is false
 
FAIL - test_gpio_callback_add_remove
===================================================================
starting test - test_gpio_callback_enable_disable
FAIL - test_callback_enable_disable@123. not trigger callback correctly
 
    Assertion failed at ../src/test_callback_manage.c:161: test_gpio_callback_en
able_disable: test_callback_enable_disable() == TC_PASS is false
 
FAIL - test_gpio_callback_enable_disable
===================================================================
starting test - test_gpio_callback_level_low
check enabled callback
FAIL - test_callback@98. not trigger callback correctly
 
    Assertion failed at ../src/test_callback_trigger.c:138: test_gpio_callback_l
evel_low: test_callback(GPIO_INT_LEVEL | GPIO_INT_ACTIVE_LOW) == TC_PASS is fals
e
 
FAIL - test_gpio_callback_level_low
===================================================================
===================================================================
PROJECT EXECUTION FAILED
 
Could you please help me in understanding basics of gpio?
 
Thanks,
Praneeth