This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[Zigbee] zigbee_erase_persistent_storage() function erroneously changes the state of the user button configuration.

Hello.

This function from Zigbee SDK 4.0.0 changes configuration of already configured input pin by calling nrf_gpio_cfg_default(ERASE_PIN);

/**@brief Function to set the Erase persistent storage depending on the erase pin
 */
zb_void_t zigbee_erase_persistent_storage(zb_bool_t erase)
{
#if defined (BOARD_PCA10056) || defined (BOARD_PCA10059) || defined (BOARD_PCA10100)
    if (!erase)
    {
        nrf_gpio_cfg_input(ERASE_PIN, NRF_GPIO_PIN_PULLUP);

        int i;
        volatile uint32_t pin_state;

        /* Read a few times to make sure the value in the register has been updated. */
        for (i = 0; i < READ_RETRIES; i++)
        {
            pin_state = nrf_gpio_pin_read(ERASE_PIN);
        }

        if (pin_state == 0)
        {
            erase = ZB_TRUE;
            NRF_LOG_INFO("Forcing flash erasure due to pin state");
        }

        nrf_gpio_cfg_default(ERASE_PIN);
    }
#endif
    zb_set_nvram_erase_at_start(erase);
}

The leds_buttons_init() function in main() configures the GPIO pin for user button, but a subsequent call to the zigbee_erase_persistent_storage() function returns the default configuration, so the button does not work as expected.

/**@brief Function for application main entry.
 */
int main(void)
{
    zb_ret_t       zb_err_code;
    zb_ieee_addr_t ieee_addr;

    /* Initialize timer, logging system and GPIOs. */
    timer_init();
    log_init();
    leds_buttons_init();
    
    /// Unrelated code removed

    zigbee_erase_persistent_storage(ERASE_PERSISTENT_CONFIG);
}

This behavior is present at least in the zigbee/light_control/light_bulb example for the pca10059 board, but I have a suspicion that this works the same way in other examples.

Parents Reply Children
Related