Become a leader in the IoT community!

New DevHeads get a 320-point leaderboard boost when joining the DevHeads IoT Integration Community. In addition to learning and advising, active community leaders are rewarded with community recognition and free tech stuff. Start your Legendary Collaboration now!

Step 1 of 5

CREATE YOUR PROFILE *Required

Change Email
OR
Step 2 of 5

WHAT BRINGS YOU TO DEVHEADS? *Choose 1 or more

Collaboration & Work ๐Ÿค
Learn & Grow ๐Ÿ“š
Contribute Experience & Expertise ๐Ÿ”ง
Step 3 of 5

WHAT'S YOUR INTEREST OR EXPERTISE? *Choose 1 or more

Hardware & Design ๐Ÿ’ก
Embedded Software ๐Ÿ’ป
Edge Networking โšก
Step 4 of 5

Personalize your profile

Step 5 of 5

Read & agree to our COMMUNITY RULES

  1. We want this server to be a welcoming space! Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism, or hate speech will be tolerated.
  2. If you see something against the rules or something that makes you feel unsafe, let staff know by messaging @admin in the "support-tickets" tab in the Live DevChat menu.
  3. No age-restricted, obscene or NSFW content. This includes text, images, or links featuring nudity, sex, hard violence, or other graphically disturbing content.
  4. No spam. This includes DMing fellow members.
  5. You must be over the age of 18 years old to participate in our community.
  6. Our community uses Answer Overflow to index content on the web. By posting in this channel your messages will be indexed on the worldwide web to help others find answers.
  7. You agree to our Terms of Service (https://www.devheads.io/terms-of-service/) and Privacy Policy (https://www.devheads.io/privacy-policy)
By clicking "Finish", you have read and agreed to the our Terms of Service and Privacy Policy.

How to Build ARM Firmware Using Bazel?

Hey @.araki_ we need some help from you please, we are also in the same boat you were. We are trying to get arm firmware built using bazel and we can’t seem to get that going @undefined2001 is working on this now, could we get some help from you pleae

  1. araki#0000

    I didn’t use bazel. Since I’m using cube ide, I used this generation script: https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/docs/new_platform_support.md#step-1-build-tflm-static-library-with-reference-kernels

    It ouputs a directory that I included in my project and added necessary directories as “includes” folder in build. I still needed to paste further directories from the tflite-micro projects itself as I’m getting error about specific header files being not found when building

  2. araki#0000

    But once I successfully integrated it into my project, I’m getting a lot of errors from the tensorflow code itself. So I temporarily kept my project aside for now. I’m away without my laptop now, but I can answer any questions.

  3. undefined.elf#0000

    I saw that

  4. undefined.elf#0000

    after adding tflite with X-Cube-AI my project won’t even build

  5. undefined.elf#0000

    so I left the cubeide

  6. undefined.elf#0000

    now trying some other `Baaazeeel` way

  7. araki#0000
  8. araki#0000

    I didn’t use X-cube-AI. I tried to just integrate the whole micro directory into my build.
    For me, it seems like they want us to follow their own directory tree and build system instead of using it as a library in another project

  9. ZacckOsiemo#0000

    Ah so Bazel is the way

  10. undefined.elf#0000

    we can change it most probably but we have to change it quite a lot

  11. undefined.elf#0000

    I would say most probably I am at the last stage of success

  12. undefined.elf#0000

    one more error fixed and I am good to go

  13. ZacckOsiemo#0000

    and such his epitaph read

  14. undefined.elf#0000
     /usr/bin/arm-none-eabi-gcc -MD -MF bazel-out/k8-fastbuild/bin/_objs/firmware/main.d '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/firmware/main.o' -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools '-mcpu=cortex-m4' -mthumb '-mfloat-abi=hard' '-mfpu=fpv4-sp-d16' '-mcpu=cortex-m4' -mthumb -g -O2 -ffunction-sections -fdata-sections -DSTM32F446xx -c Sources/main.c -o bazel-out/k8-fastbuild/bin/_objs/firmware/main.o)
    # Configuration: f484d465c2bae92f555f3b567bbd4c38bbdaf165e5a9c796aa82359aca108a23
    # Execution platform: @@local_config_platform//:host
    
  15. undefined.elf#0000

    see my toolchain is now changed

  16. undefined.elf#0000
    Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
    Sources/main.c:1:10: fatal error: stm32f446xx.h: No such file or directory
        1 | #include "stm32f446xx.h"
          |          ^~~~~~~~~~~~~~~
    compilation terminated.
    Target //:firmware failed to build
    INFO: Elapsed time: 0.180s, Critical Path: 0.04s
    

    bad news i was unable to handle this include

  17. undefined.elf#0000

    I tried many ways but sadly it didn’t work

  18. undefined.elf#0000

    I hope it will work by tomorrow morning

  19. ZacckOsiemo#0000

    don’t be weary, issues are finite

  20. daleonpz#0000
  21. daleonpz#0000
  22. undefined.elf#0000

    with cmake we have no issue man

  23. undefined.elf#0000

    but we have to use bazel

  24. ZacckOsiemo#0000

    Hmmm @undefined2001 try finding a guide to migrate from cmake to Bazel

  25. daleonpz#0000
  26. wafa_ath#0000

    @superbike_z , did you try to convert the model to c array

  27. ZacckOsiemo#0000

    the model is converted its running the inference thats an issue

  28. araki#0000

    @undefined2001 I *think* I got it working.
    Run `make -f tensorflow/lite/micro/tools/make/Makefile TARGET=cortex_m_generic TARGET_ARCH=cortex-m4+fp microlite` to create a `libtensorflow-microlite.a` library file.
    Then add it to your stm project and add it as a library to link in build settings. Include the necessary header files as well.

  29. araki#0000

    I just made an inference with their hello world example. I keep getting output 52, which I don’t know is correct or not but atleast it is working.

  30. undefined.elf#0000

    let me look into it

  31. undefined.elf#0000

    bazel is killing me man

  32. undefined.elf#0000

    trying it since last week

  33. undefined.elf#0000

    non stop everyday

  34. undefined.elf#0000

    @.araki_ how you have tried to implement in your project

  35. undefined.elf#0000

    can you please share your github?

  36. araki#0000

    I’m not making any actual project at the moment. I’m just learning and wanted to get TFLM working inside an STM generated project. Here’s a gist on steps I followed:
    https://gist.github.com/arkreddy21/427a97d4cd1431ebc766dd70b5dc8104

  37. araki#0000

    I just solved many errors that happened while tring to make it work. So ask me if there is any specific issue

  38. undefined.elf#0000

    I am getting error related to flatbuffers

  39. undefined.elf#0000

    include headers

  40. araki#0000

    add core/Inc/third_party/flatbuffers/include to the includes directory in build settings

  41. undefined.elf#0000

    there is nothing in it

  42. undefined.elf#0000

    include is empty

  43. undefined.elf#0000

    I compiled the library

  44. undefined.elf#0000

    now after that I have to use that i guess in my project

  45. undefined.elf#0000

    I have a `libtensorflow-microlite.a`

  46. araki#0000

    you also have to generate a file structure and copy it to your project, once see my gist

  47. undefined.elf#0000
    Generate TFLM tree
    Refer: new_platform_support readme
    
    python3 tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \
      -e hello_world \
      -e micro_speech \
      -e person_detection \
      /your/desired/path/tflm-tree
    Run this command to generate tflm-tree directory in your desired path. Copy the tensorflow, third_party and signal folders into your stm32 project includes directory (eg: /core/Inc).
    
    Additional you have to copy fixedpoint and internal directories from the tflite-micro repository that are generated while buiding the library. You can find them in tflite-micro/tensorflow/lite/micro/tools/make/downloads/gemmlowp/ directory. You need to add these to your includes directory (core/Inc) as well.
    
    Note: Only header files are needed. You can run the command find . -type f -name "*.cc" -exec rm -f {} + to remove all .cc files in the current directory.
    
    Additionally, you might also need to add the following as includes directories under Project properties -> C/C++ build -> settings -> MCU/MPU g++ compiler -> include paths
    
    "core/Inc/third_party/flatbuffers/include"
    "core/Inc/third_party/kissfft"
    
  48. undefined.elf#0000

    this portion?

  49. araki#0000

    yep

  50. undefined.elf#0000

    I want to use my custom model what should I do?

  51. undefined.elf#0000

    any idea

  52. araki#0000

    This just sets up everything. To run inference, first convert your model into C array. Then you need to invoke it. I added an example main file to the gist, once refer it.

  53. araki#0000

    You can also look at the generated examples in /tflm-tree

  54. undefined.elf#0000

    I did it to an extent but have you used error reporther?

  55. undefined.elf#0000

    in my case error reporter is misisng

  56. araki#0000

    I did not use error reporter but it seems to be present in tflm-tree.
    0image.png

  57. araki#0000

    Also, be sure to include all the Operations your model needs in the OpResolver. And allocate enough arena size

  58. undefined.elf#0000

    my bad

  59. undefined.elf#0000

    in my case it is also there

  60. undefined.elf#0000

    just the path was a bit different

  61. undefined.elf#0000

    let me fix it too

  62. undefined.elf#0000

    thanks for all the help

  63. undefined.elf#0000

    I will write a detailed guide since I am not doing it with CubeIDE

  64. undefined.elf#0000

    @.araki_ here comes the nightmare
    0image.png

  65. araki#0000

    Ah, I guess rtos and tflm is too much. You’re doing release build right, What board/mcu are you using?

  66. undefined.elf#0000

    I have only 128KB ram

  67. undefined.elf#0000

    I think too much

  68. 32bitSaviour#0000

    I wonder what optimization you will employ now

  69. undefined.elf#0000

    I can make release but that won’t do much