I spent hours trying to figure out why the program doesn t work. I checked voltages, looked on the Scope at the values but nothing worked.
Then I decided to use BDT to find out what is going on.
To do it I did the following:
I defined pins: PD4, PB1 and PC2 as GPIO, Input with 1M pullup.
I defined: bool state1, state2, state3;
void app_task(void){
app_key_handler();
localPermitJoinState();
state1 = drv_gpio_read(GPIO_PD4);
if(state1 == TRUE){
led_on(LED_B);
} else{
led_off(LED_B);
}
state2 = drv_gpio_read(GPIO_PB1);
if(state2 == FALSE){
led_on(LED_G);
}
else{
led_off(LED_G);
}
state3 = drv_gpio_read(GPIO_PC2);
if(state3 == FALSE){
led_on(LED_R);
}
else{
led_off(LED_R);
}
Because nothing was connected to the pins, from the above code I expected:
LED_B to be ON, LED_G to be OFF, LED_R to be OFF.
But all Leds were OFF!
I checked voltages and on all input pins the voltage was 3.1V
I short pin PD4 to ground - LED_B still OFF
I short pin PB1 to ground - LED_G turns ON
I short pin PC2 to ground - LED_R turns ON
So, LED_B never comes on.
I looked at the definition of drv_gpio_read() and return value should be boolean, but it doesn t work:
bool drv_gpio_read(u32 pin)
{
#if defined(MCU_CORE_826x) || defined(MCU_CORE_8258) || defined(MCU_CORE_8278)
return gpio_read(pin);
#elif defined(MCU_CORE_B91)
return gpio_get_level(pin);
#endif
}
But it only works if you use check the result like this:
if(state3 == FALSE){
led_on(LED_R);
}
else{
led_off(LED_R);
}
If you try to check for result to be TRUE it doesn t work:
if(state1 == TRUE){
led_on(LED_B);
} else{
led_off(LED_B);
}
I looked at the values in BDT and here are the results for state1, state2 and state3. They show that pins are high, so LED_B should be ON!
Looking in the types.h:
#ifndef TRUE
#define TRUE (!FALSE)
#endif
#ifndef bool
#define bool u8
In Telink BLE SDK in gcc\lib\tc-32-elf\... folder, stdbool.h has the following definition:
/*
* ISO C Standard: 7.16 Boolean type and values
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
I think it should be fixed?
I decided to use gpio_read() function which returns unsigned int, so I know what to expect.
No related topics |
Hi,
just use gpio_read().
Here is a simple fix if someone wants to use drv_gpio_read() function.
In function drv_gpio_read(u32 pin) replace:
return gpio_read(pin);
with:
return (0==gpio_read(pin) ? FALSE : TRUE);
Hopefully Telink will fix boolean definition soon.