bifravst / cat-tracker-fw

Cat Tracker Firmware
https://bifravst.github.io/
3 stars 3 forks source link

Error in firmware: "bifravst_cloud: topics_populate, error: -12" when building from source #46

Closed TjazVracko closed 4 years ago

TjazVracko commented 4 years ago

I have successfully set up the AWS stack and device-simulator and can see the simulated cat activity on the web GUI.

I am now trying to build and flash onto a nRF9160 DK. I have completed the following steps to set up the device:

  1. Updated modem to latest firmware (mfw_nrf9160_1.1.0)
  2. Flashed cetrificate (as per this guide): Before flashing the certificates via LTE Link Monitor i sent "AT+CFUN=4" and changed the security tag to "42"
  3. Building the firmware: I copied the the whole SDK folder structure and removed the nrf folder. I then cloned the cat-tracker-fw repo into the nrf folder:
    git clone https://github.com/bifravst/cat-tracker-fw.git nrf

    Updated west:

    cd nrf
    west update

    init zephyr:

    source ../../../zephyr/zephyr-env.sh

    Added the mqtt endpoint to prj.conf CONFIG_BIFRAVST_CLOUD_HOST_NAME="<my-endpoint>"

Ran west build:

west build -p -b nrf9160_pca10090ns -d build10090ns

Flashed with command:

nrfjprog -f nrf91 --program ./build10090ns/zephyr/merged.hex --sectoranduicrerase -r

or with the Programmer GUI utility.

  1. Using screen /dev/ttyACM0 115200 and logging the output i have created the attached screenlog.0.txt file. The log contains the follow lines I deem important:
    
    SPM: NS image at 0x18200
    SPM: NS MSP at 0x2002f898
    SPM: NS reset vector at 0x1eb61
    SPM: prepare to jump to Non-Secure image.
    [00:00:00.395,233] <err> ADXL362: Failed: 255
    ***** Booting Zephyr OS build v2.0.99-ncs1-rc1-761-g7e20180c004a *****
    [00:00:00.421,966] <dbg> nrf9160_gps.init: MAGPIO set: AT%XMAGPIO=1,0,0,1,1,1574,1577
    [00:00:00.436,950] <dbg> nrf9160_gps.init: COEX0 set: AT%XCOEX0=1,1,1570,1580
    The cat tracker has started
    Version: 0.0.0-development
    [00:00:00.456,176] <err> bifravst_cloud: topics_populate, error: -12
    Cloud backend could not be initialized, error: -12

Booting Zephyr OS build v2.0.99-ncs1-rc1-761-g7e20180c004a [00:00:00.007,232] mcuboot: Starting bootloader [00:00:00.015,502] mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 [00:00:00.028,411] mcuboot: Scratch: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 [00:00:00.040,618] mcuboot: Boot source: primary slot [00:00:00.051,818] mcuboot: Swap type: none [00:00:00.444,671] mcuboot: Bootloader chainload address offset: 0xc000 [00:00:00.452,301] mcuboot: Jumping to the first image slot Booting Zephyr OS build v2.0.99-ncs1-rc1-761-g7e20180c004a Flash region Domain Permissions

Non-secure callable region 0 placed in flash region 2 with size 32. SRAM region Domain Permissions Peripheral Domain Status ``` The above output repeats indefinitely (see attached log file). Can you tell me what I am doing wrong? Please advise. [screenlog.0.txt](https://github.com/bifravst/bifravst/files/3945424/screenlog.0.txt)
coderbyheart commented 4 years ago

I think this is because right now @simensrostad is in progress of heavy refactoring in the firmware architecture to extract a generic AWS backend which can be used by any application that wants to connect to AWS.

The last version that worked for me was v0.40.0, try that instead for your device.

I also noted down #47, we don't have tests right now and that needs to be addressed.

simensrostad commented 4 years ago

I have tried to recreate the given scenario with little luck. Could you try to re-flash the latest modem firmware? https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF9160-DK/Download

TjazVracko commented 4 years ago

I have tried re-flashing with the latest firmware, as well as building for pca20035 (Thingy91). I get the same output on both.

I then tried to flash the pre-build hex v0.44.0, with generated certificates already on the device. The modem then successfully connected to my AWS broker, and I can see a new "cat" in the interface. How does the device manage to connect, if I didn't specify the mqqt endpoint in prj.conf?(CONFIG_BIFRAVST_CLOUD_HOST_NAME="<my-endpoint>").

The same thing happens on pca20035.

Do you have any pointers on how I might go about debugging this? Is my setup wrong or is it the configuration? The guide is really sparse on how to set up your own build environment for the project, or did I miss this information somewhere?

Thank you for your help.

coderbyheart commented 4 years ago

I verified v0.44.0 with a 91DK and I do not see this error.

I now understand that your issue is failing to build a working firmware from source.

I then tried to flash the pre-build hex v0.44.0, with generated certificates already on the device. The modem then successfully connected to my AWS broker, and I can see a new "cat" in the interface. How does the device manage to connect, if I didn't specify the mqqt endpoint in prj.conf?(CONFIG_BIFRAVST_CLOUD_HOST_NAME="<my-endpoint>").

That cannot work (the pre-build binaries have a hardcoded endpoint, see #29). Are you sure that you flashed the right device and that flashing actually worked?

@simensrostad I think the FW should not have a default value for CONFIG_BIFRAVST_CLOUD_HOST_NAME and fail to build if it is not set. (#48)

The guide is really sparse on how to set up your own build environment for the project, or did I miss this information somewhere?

For now we only can point to the the documentation of NRF Connect FW which this project is based on, especially have a look at the Getting Started Guide.

coderbyheart commented 4 years ago

You might get some pointers on the (rather longish process) to set up a system in order to build from source from our CI workflow.

TjazVracko commented 4 years ago

Thanks, with the help of the above CI workflow I managed to get it working.

For reference, this is is what I did:

mkdir build_test
cd build_test

west init -m https://github.com/bifravst/cat-tracker-fw.git --mr e1f2e0cb1818a8be1159b91d74dc6b48514e2024  # this is version 0.53.0

west update

sudo pip3 install -r zephyr/scripts/requirements.txt
sudo pip3 install -r nrf/scripts/requirements.txt
sudo pip3 install -r mcuboot/scripts/requirements.txt 
# for me, all requirements were already satisfied (from previous attempts)

source zephyr/zephyr-env.sh   # this sets $ZEPHYR_TOOLCHAIN_VARIANT and $GNUARMEMB_TOOLCHAIN_PATH 

cd ./nrf/applications/cat_tracker/

nano prj.conf  # add CONFIG_BIFRAVST_CLOUD_HOST_NAME="<mqtt_endpoint>" setting

west build -p auto -b nrf9160_pca10090ns -d build10090ns
nrfjprog -f nrf91 --program ./build10090ns/zephyr/merged.hex --sectoranduicrerase -r

When using west flash --build-dir build10090ns instead of the above nrfjprog command, I get the original <err> bifravst_cloud: topics_populate, error: -12 error (on the device).

Using nrfjprog gets me a working device that successfully reports to AWS.

Are there some equivalent west flash arguments or is using nrfjprog preferred?

coderbyheart commented 4 years ago

Good to hear that you are able to compile the firmware on your machine. In general I recommend to fork the firmware repo and set up the compilation using GitHub Actions just like we do, that way not every developer has to go through the hassle of getting the system in shape for being able to build.

Are there some equivalent west flash arguments or is using nrfjprog preferred?

Looking at our documentation for the nRF9160, nrfjprog should be used.

TjazVracko commented 4 years ago

Ok, will use nrfjprog from now on.

coderbyheart commented 4 years ago

It's possible to use west flash but it's not as flexible (and calls nrfjprog under the hood anyway).