Introduction to integrating C++ on bare metal STM32 | VIDEO 47

Поделиться
HTML-код
  • Опубликовано: 31 июл 2024
  • In this video I give a presentation on basics of C++ and how to integrate it into embedded project. I show you demonstration using CMake and STM32CubeIDE.
    Timestamps:
    0:00 Introduction and presentation
    4:40 CMake
    8:00 Makefile
    8:42 Name mangling
    11:40 Connecting C and C++
    13:42 Demonstration with CMake
    15:42 Demonstration with STM32CubeIDE
    18:46 Recommendations and closing remarks
    CMake configuration:
    github.com/prtzl/stm32-cmake
    Previous video on cmake:
    • STM32 project managed ...
  • НаукаНаука

Комментарии • 20

  • @thangnguyentien2313
    @thangnguyentien2313 4 месяца назад +1

    Dear Matej,
    I want to thank you for creating these wonderful videos, it's truly helpful and rare.
    I hope you will continue your passion, thank you very much.

  • @khanhlinhle6428
    @khanhlinhle6428 2 года назад +2

    Thank you for a very useful video.

  • @rick_er2481
    @rick_er2481 2 года назад +1

    Thanks!! Good video!

  • @karama5478
    @karama5478 2 года назад +2

    Hi, could you continue with the series? I need these c++ embedded tutorial very bad.

    •  2 года назад

      I'm compiling (heh) a list of points for a video. Mostly things c++ is better out of the box, features, encapsulation, modern compile time features and so on. I'll try squeezing one out in a week.

  • @WagnerSilva-fq2tu
    @WagnerSilva-fq2tu Год назад

    Hi. Very good channel for embedded world programmers. Will you add any updates to channel content?

    •  11 месяцев назад

      Soon, when I find more time and energy :)

  • @pabloolguin818
    @pabloolguin818 2 года назад

    Hi, Matej! Nice video. I try to implement your code in my project with STM32F446ZE and I did corresponding changes but I have some questions. I have a message that says “not found stddef.h” but my code compile and I can blink to Led, I don't know if I can fix it. My main question is how can I implement class with c++ I want to create a class to manage many sensors and this recourse is necessary for this. I tried to implement it with .cpp file but I had an error saying “class symbol not accepted”.
    If you can help me I will be very grateful!!
    Thanks

    •  2 года назад

      I would advise a coulple of things:
      - the thing with "not found stddef.h": Please confirm that you have completely installed toolchain. Some linux distributions might carry some parts in other packages. If you use windows and you installed the package as in video 48, then you're fine. I would check if your path is active. Just test if compiler is found in cmd or powershell: arm-none-eabi-gcc --version.
      - the one with "class symbol not accepted" might come from using a .c or .h file, that is included in a .c file. You cannot define a class or any c++ only feature in a header file, that is also included in a .c source. Make sure to separate it with some pure functions.
      Also, if you're using CubeIDE, check if you have converted the project to a C++ project. In project includes make sure that you have a path to your C++ headers and source files so that the ide will find them.
      If you follow my cmake example, where I defined a struct with a few methods, you should be good to go.

    • @pabloolguin818
      @pabloolguin818 2 года назад

      @ Hi Matej, thank you for your advice.
      I tell you what I did. First began to write only C code where your videos guided me. I could compile and debug with JLink by VSCode whitout problems. I have I2C accelerometer sensor and I send messages by UART without problems. But my code is large enough and I wanted to create a class to manage the sensor. Then I was guided by your 47 video to implement this. Here is where I have many problems. Is it possible to create a class and call it by main.c ?
      Before I use Mbed OS and CLI 2 to program my STM32 where the main file is .cpp and I could call the class but I found your way by Make is more easy and simple.
      On another side, I run arm-none-eabi-gcc --version and I got this "arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1 20210824 (release)" it seems to be well installed I don't know why I got the error with the "stddef.h" library, in my others projects this works well. I'm using fedora.
      I hope you can help me, you have been my guide in my development in STM and I am very grateful.

    •  2 года назад

      Great.
      Now as I said in my first reply, you cannot use c++ constructs and features in C. They are compatible, but not fully. That's why I created my "second main" file where you can use C++.
      You can also rename main.c to main.cpp but the next time you run cubemx it will add main.c back as it sees it missing (could be solved in future update). Then you will have two main functions and the compiler will shout at you.
      Also I think its much neater to store all mcu peripheral initializations in main.c and use your own vode in "projectMain.cpp".
      So, if you want to use a class, define it in a header, maybe implenentation in a .cpp file and use it in projectMain.cpp.. Follow the example repositort on github "stm32-cmake" and "stm32". All C->C++ "communication" has to be done via C style pure functions. Afain thats why I use prokectMain.cpp.

    • @pabloolguin818
      @pabloolguin818 2 года назад

      @
      Hi Matej!
      Thank you once again for your help. Finally, I'm using "projectMain.cpp" file and create my classes in separate files and I can tell them without any problems.
      My code compiles and debugs without problems but I have problems with the next warning: cannot open source file "stddef.h" . This message red underline #include "main.h" and #include "stdio.h" statements. Do you know how can I fix it?

  • @harunkorkmaz1324
    @harunkorkmaz1324 2 года назад

    Have u ever tried Rust Lang with embedded, i think u might be interested

    • @harunkorkmaz1324
      @harunkorkmaz1324 2 года назад

      Great video btw

    •  2 года назад +9

      I have heard of rust beeing used for embedded, but I don't intend to pick it up any time soon. C++ is, in my opinion, easier step from C, as it more or less adds to the language, rather than beeing a different one. I just happen to use more and more c++ in my career so I'm focusing on that.

  • @user-hv5ol7re9i
    @user-hv5ol7re9i Год назад

    Sorry, but how to use c++ for vs code? I can't do it 2 week, because not search information for settings. I have Linux Ubuntu, gcc-arm-none-eabi, cortex debag extension, for c this setup work is good, but c++, a big problem for me . Compiler mark the c++ code red lines 😢 .

    •  Год назад

      Which part does not work correctly? Compiling or just IDE syntax highlighting?

    • @user-hv5ol7re9i
      @user-hv5ol7re9i Год назад

      @ if compiling from console, is ok. But in vs code, i can't to setting cmake, and syntax highlights.

    • @user-hv5ol7re9i
      @user-hv5ol7re9i Год назад

      if you could do an overview on setting up vs code for c++ it would be very great for many embedders

  • @jugnu361
    @jugnu361 8 месяцев назад +2

    I USE C ON STM32