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

Zigbee SDK on top of FreeRTOS

Hi

I'm trying to use nRF5 SDK for thread and Zigbee 3.2.0 on top of FreeRTOS 9.0 for a Zigbee coordinator.
Since I could not find any coordinator example on FreeRTOS, I started with adding the files etc as of
"Adding dynamic multiprotocol Zigbee support to BLE examples" and followed the init
"Zigbee Multi Sensor with FreeRTOS Example" to my current project, but ran in some issue
directly when calling ZB_INIT("zdo_zc");

I get the following output from zboss, via zb_osif_serial_put_bytes, after that I get stuck in hard fault.
Len:8 Data:0xdead0e0203000000
Len:8 Data:0x7a00820f00f8ff07

Any clues or ideas of what I missed?

Dev setup:
Win 10
gcc-arm-none-eabi-7-2018-q2
FreeRTOS 9.0
nRF5 SDK for thread and Zigbee 3.2.0
nRF52840-DK

libs:
nrf_radio_driver_softdevice.a
libzboss.a (debug version)
s140_nrf52_6.1.1_softdevice.hex

Defines
SOFTDEVICE_PRESENT
S140
RAAL_SOFTDEVICE=1
FREERTOS
ZB_TRACE_LEVEL=0
ZB_TRACE_MASK=0

Parents
  • I proceeded a bit when changing priorities, but got stuck again.

    My stack trace:

    zb_osif_nvram_erase_async() at zb_nrf52840_nvram.c:405 0x28be4	
    zb_nvram_load() at 0x36186	
    zb_zdo_dev_init() at 0x3b910	
    zdo_dev_start() at 0x3baf4	
    zigbee_main_task() at main.c:511 0x2bc2c	
    

    Where I got stuck:

    zb_ret_t zb_osif_nvram_erase_async(zb_uint8_t page)
    {
      zb_uint32_t flash_addr = 0, i;
      zb_int_t ret = 0;
    
      ZVUNUSED(ret);
    
      if (page >= ZB_NVRAM_PAGE_COUNT)
      {
        return RET_PAGE_NOT_FOUND;
      }
      TRACE_MSG(TRACE_COMMON3, "zb_osif_nvram_erase_async page %hd", (FMT__H, page));
    
      flash_addr = ZB_NVRAM_PAGE_BASE_ADDRESS(page);
    
      for (i = 0; i < ZB_NVRAM_PAGE_SIZE / ZB_NVRAM_FLASH_PAGE_SIZE; ++i)
      {
        while (zb_osif_flash_op_progress())
        {
        }
    
        zb_osif_set_flash_op_progress();
        ret = nrf_fstorage_erase(
                    &nvram_fstorage,   /* The instance to use. */
                    flash_addr,        /* The address of the flash pages to erase. */
                    1,                 /* The number of pages to erase. */
                    NULL               /* Optional parameter, backend-dependent. */
          );
        ZB_ASSERT(ret == NRF_SUCCESS);
        if (ret != NRF_SUCCESS)
        {
          return RET_ERROR;
        }
        /* This call is designed to be asynchronous, but currently it is synchronous. */
    
        /* Wait SOC event handler with NRF_EVT_FLASH_OPERATION_SUCCESS or NRF_FSTORAGE_ERASE_RESULT */
        while (zb_osif_flash_op_progress())   <---- Here is where I got stuck forever
        {
        }
    
        flash_addr += ZB_NVRAM_FLASH_PAGE_SIZE;
      }
      zb_osif_flash_erase_finished(page);
      return RET_OK;
    }

    Any clues?

  • Did any of the fstorage items got written or read successfully? or is this this the first flash event that gets stuck. Seems like there seems to be a deadlock condition created by the app you are working that manages to add flash request to the ATFIFO but somehow the thread that makes this request never sleeps/yields. This could cause the thread that needs to pull the events never execute. I am not a Zigbee expert, but these while loop looks dangerous in my opinion which has no time expiry plugged into it

Reply
  • Did any of the fstorage items got written or read successfully? or is this this the first flash event that gets stuck. Seems like there seems to be a deadlock condition created by the app you are working that manages to add flash request to the ATFIFO but somehow the thread that makes this request never sleeps/yields. This could cause the thread that needs to pull the events never execute. I am not a Zigbee expert, but these while loop looks dangerous in my opinion which has no time expiry plugged into it

Children
  • Thanks!
    I don't like it either, but the code is from the SDK.

  • Hi Vilhelm,

    If you are not planning to use BLE, then starting with the Zigbee multisensor with Freertos example instead and then add the coordinator functionality to the example will be a better approach.

    You will have to remove the ZB_ED_ROLE define, change the startup function (use zb_set_network_coordinator_role(channel)) and the zboss signal handler (see CLI example for that) to add the coordinator functionality.

    I am not sure why you are getting stucked but I think it has to do with the multiprotocol implementation, as zb_osif_nvram_erase_async is waiting for a nRF SoC event (from nrf_soc.h).

    NB! If your goal is to have multiprotocol BLE+Zigbee+FreeRTOS then starting from a FreeRTOS+BLE example will be better, as adding multiprotocol with Zigbee is much easier than choosing appropiate variants of Softdevice handlers, defining sections etc.

    Best regards,

    Marjeris

Related