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

  70. undefined.elf#0000

    `Os`

  71. araki#0000

    Idk about your build system but stm cube gave me 10x less size on release. Also STM32F407 has 128kb ram + additional 64kb core coupled ram, which could be used with some tinkering I think.

  72. undefined.elf#0000

    I have 128KB ram

  73. undefined.elf#0000

    using stm32f446re

  74. undefined.elf#0000

    no extra ram

  75. undefined.elf#0000

    I am using optimization though

  76. undefined.elf#0000

    but the issue is with my data sample’s array and also the model

  77. undefined.elf#0000

    model was approx 58kb

  78. araki#0000

    Well, that itself takes half the ram. Maybe you need to retrain smaller network, with quantization and all

  79. undefined.elf#0000

    also rtos taking some memory itself

  80. araki#0000

    Its just 9% over, so I think you could optimize it

  81. undefined.elf#0000

    well whole firmware is not complete

  82. undefined.elf#0000

    I haven’t created the task and assigned them stack

  83. undefined.elf#0000

    I was just trying to do a test compile

  84. araki#0000

    Oh. I don’t really know about your project so can’t help much. I don’t have experience with rtos either

  85. undefined.elf#0000

    yeah but now I am happy atlease I added `tflite-micro` in it

  86. araki#0000

    Yeah that’s good. I’m still learning. I’m taking a tinyml course and wanted to use tflite-micro on my board. There’s still a long way before I can make any decent project

  87. undefined.elf#0000

    same here too

  88. undefined.elf#0000

    maybe I should move to some nucleo 144 board

  89. undefined.elf#0000

    that have approximately 1MB+ ram

  90. araki#0000

    Yeah, a bigger mcu is best when tinkering. You can focus on functionality first and optimization later

  91. ZacckOsiemo#0000

    So what is happening, did you minimize enough and get inference running.

  92. undefined.elf#0000

    nope it seems there is not much to minimize the code I was compiling it was without assigning stack to each task

  93. undefined.elf#0000

    so there are more code coming

  94. undefined.elf#0000

    also, I haved enabled the grabage collection of linker

  95. undefined.elf#0000

    that also didn’t help much

  96. ZacckOsiemo#0000

    ah so you need to optimize you stack sizes for the tasks? so a freertos issue not a ML issue

  97. undefined.elf#0000

    no no what I am saying is I haven’t even assigned memory for each task before that it already overflowing

  98. ZacckOsiemo#0000

    Ah then where is your memory going?

  99. undefined.elf#0000

    58kb for the model

  100. undefined.elf#0000

    and the rest to freeRTOS

  101. undefined.elf#0000

    normal freeRTOS use to consume around 50kb of my ram and the rest increament wasn’t proportional

  102. ZacckOsiemo#0000

    how much RAM is on the st you are using

  103. undefined.elf#0000

    128KByte

  104. ZacckOsiemo#0000

    so your tasks are taking 70kb?

  105. undefined.elf#0000

    I’m a fool

  106. undefined.elf#0000

    My stack

  107. ZacckOsiemo#0000

    NO no I didn’t say that, I am asking it this is indeed the case

  108. undefined.elf#0000

    I was using default configuration of freeRTOS

  109. undefined.elf#0000

    and that assigned 75kb for heap

  110. ZacckOsiemo#0000

    nuance is key

  111. araki#0000
  112. undefined2001#0

    it’s an interesting MCU but let’s see when we can use it

CONTRIBUTE TO THIS THREAD

Browse other questions tagged