Hi dialog
I am working on a custom board based on DA14681. I am using two buttons on GPIOs to perform some tasks and they are working perfectly.
Then i m using a GPIO, which is directly connected to USB Power. When USB is connected this GPIO goes high and i do a specfic task which is also working perfectly.
Problem is that i am using hibernation mode and i am using This USB Power GPIO for wakeup purposes. When in hibernation mode as soon as i plug in the USB it wakesup and works perfectly but other two buttons stops functioning and then USB is removed then those two buttons start working again. I couldnt undertand this problem.
Here is the code in main.c
pm_system_init(periph_init);
hw_wkup_init(NULL);
hw_wkup_configure_pin(DIS_BUTTON_PORT,DIS_BUTTON_PIN, true, HW_WKUP_PIN_STATE_HIGH); // button 1
hw_wkup_configure_pin(PWR_BUTTON_PORT,PWR_BUTTON_PIN, true, HW_WKUP_PIN_STATE_HIGH); // button 2
hw_wkup_configure_pin(HW_GPIO_PORT_4, HW_GPIO_PIN_0, true, HW_WKUP_PIN_STATE_HIGH); // wakeup with USB-CONNECTION
hw_wkup_set_debounce_time(10);
hw_wkup_set_counter_threshold(1);
hw_wkup_register_interrupt(wkup_cb, 1);
Hi mahmed106,
Could you please indicate if you have the buttons configured in the periph_init(function)? I assume that your device is powered up via a battery, is that correct?
Thanks, PM_Dialog
Yes device is powered via battery and this is my periph_init function, i have defined buttons but no defined usb connection gpio.
static void periph_init(void)
{
#if 1 //defined CONFIG_RETARGET
/*
* Workaround for JLink emulated serial port.
*
* JLink serial port does not set its output UART pin high (UART idle state) unless
* there is something transmitted from PC to board.
* Pin state is kept by level shifter low after board reset.
* Configuring pin as UART_RX does not turn on pull up resistor, hence RX line stays low
* and this state is usually detected as break condition.
* With low state on UART RX, configuration of UART is unsuccessful: as soon as baud rate
* is set up UART goes into busy state, all other settings are ignored.
*
* Workaround sets up pin that will be used as UART RX as output with high state.
* This will result in level shifter holding this state until JLink starts to drive this
* line for transmission.
*/
#if OLD_HARDWARE
hw_gpio_set_pin_function(HW_GPIO_PORT_1, HW_GPIO_PIN_0, HW_GPIO_MODE_OUTPUT,HW_GPIO_FUNC_UART_TX);
#else // same for dry and liquid
REG_SET_BIT (CRG_PER USBPAD_REG USBPAD_EN);
hw_gpio_set_pin_function(HW_GPIO_PORT_2, HW_GPIO_PIN_2, HW_GPIO_MODE_OUTPUT,HW_GPIO_FUNC_UART_TX);
#endif
// hw_gpio_set_pin_function(HW_GPIO_PORT_2, HW_GPIO_PIN_2, HW_GPIO_MODE_OUTPUT,
// HW_GPIO_FUNC_UART_RX);
#endif
hw_gpio_configure_pin(HW_GPIO_PORT_2,HW_GPIO_PIN_3, HW_GPIO_MODE_INPUT_PULLUP,HW_GPIO_FUNC_GPIO, 1);
//hw_gpio_configure_pin(HW_GPIO_PORT_2, HW_GPIO_PIN_3, HW_GPIO_MODE_OUTPUT,HW_GPIO_FUNC_GPIO, 1);
hw_gpio_set_pin_function(HW_GPIO_PORT_1, HW_GPIO_PIN_5,HW_GPIO_MODE_OUTPUT, HW_GPIO_FUNC_UART2_TX);
hw_gpio_set_pin_function(HW_GPIO_PORT_2, HW_GPIO_PIN_3,HW_GPIO_MODE_INPUT_PULLUP, HW_GPIO_FUNC_UART2_RX);
hw_gpio_configure_pin(BUZZ_PORT, BUZZ_PIN, HW_GPIO_MODE_OUTPUT, HW_GPIO_FUNC_GPIO, 0);
hw_gpio_configure_pin(THM_PWR_PORT, THM_PWR_PIN, HW_GPIO_MODE_OUTPUT, HW_GPIO_FUNC_GPIO, 0);
/ / hw_gpio_configure_pin (PELT_PORT PELT_PIN HW_GPIO_MODE_OUTPUT, HW_GPIO_FUNC_GPIO, 0);
//hw_gpio_configure_pin(INFAN_PORT,INFAN_PIN, HW_GPIO_MODE_OUTPUT, HW_GPIO_FUNC_GPIO, 0);
hw_gpio_configure_pin(TH1_PORT, TH1_PIN, HW_GPIO_MODE_OUTPUT, HW_GPIO_FUNC_GPIO, 0);
hw_gpio_configure_pin(TH2_PORT, TH2_PIN, HW_GPIO_MODE_OUTPUT, HW_GPIO_FUNC_GPIO, 0);
hw_gpio_configure_pin(TH3_PORT, TH3_PIN, HW_GPIO_MODE_OUTPUT, HW_GPIO_FUNC_GPIO, 0);
hw_gpio_configure_pin(PWR_BUTTON_PORT,PWR_BUTTON_PIN, HW_GPIO_MODE_INPUT_PULLDOWN,HW_GPIO_FUNC_GPIO, 0);
hw_gpio_configure_pin(DIS_BUTTON_PORT,DIS_BUTTON_PIN, HW_GPIO_MODE_INPUT_PULLDOWN,HW_GPIO_FUNC_GPIO, 0);
hw_gpio_configure_pin(HW_GPIO_PORT_3,HW_GPIO_PIN_7, HW_GPIO_MODE_OUTPUT,HW_GPIO_FUNC_GPIO, 1); // 3.3V Regulator
}
Hi mahmed106,
It’s little bit strange because as soon as the device wakes up from hibernation, it like a cold boot and the periph_init() with your configurations will be executed. Can you please try to use a logic analyzer and track the GPIOs which are connected with the buttons in order to understand if it is a hardware or a software related issue?
Thanks, PM_Dialog