STM32F4 board - trying to learn about FreeRTOS - Page 1
Forum section: electronics / general

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: July 28, 2020, 10:29:32 pm
content: Hello.I'm trying to learn about FreeRTOS for the first time and I'm using an STM32F407VET6 board I bought on ebay. It can be checkedhere.I have downloaded FreeRTOS from official site but their version is prepared to run with 3rd party software and my goal was to be able to build a Makefile, exclusively for the files I need for my board. The folder structure is something we need be aware because the ideia is to keep ading files to Makefile as long as 'make' keeps asking for them.I stated building a Makefile but my short experience doesn't allow me to continue further on.I started with this:Code:CC := arm-none-eabi-gccCFLAGS := -Wall -WextraSRCDIR := ../../Source ./OBJDIR := .objDEPDIR := .depend#INCDIR := ../../Source/includeSOURCES := $(wildcard *.c) board/$(wildcard *.c) startup/$(wildcard *.c)OBJECTS := $(patsubst $(SOURCES)/%.c, $(OBJDIR)/%.o, $(SOURCES))DEPENDS := $(patsubst $(SOURCES)/%.c, $(DEPDIR)/%.d, $(SOURCES))-include $(DEPENDS)$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)@echo "Linking $*.c"$(CC) $(CFLAGS) -c -o $@ $<$(DEPDIR)/%.d: $(SRCDIR)/%.c | $(DEPDIR)$(CC) -MM -MG $< | sed 's!^\(.\+\).o:!$(DEPDIR)/\1.d $(OBJDIR)/\1.o:!' > $@$(DEPDIR) $(OBJDIR):mkdir $@#$@ target name: stm32frertos and $^ is the dependency list: $(OBJECTS)#stm32freertos: $(OBJECTS)# $(CC) -o $@ $^#% is to build patterns and represents the same text in target as in dependencies#$* contains the same vale as $%#$< contains the first dependency#%.o: %.c# $(CC) $(CFLAGS) -c -o $@ $<So, I'm trying to build the source files list from the folders at the same level as the Makefile.Then, I'm building the object files from the same sources form above.An lastly I'm trying to build the dependency files, also from the sources I built in the first place.But I'm getting a very early error about one of the files in the current directory:Code:ParTest.c:1: *** missing separator. Stop.ParTest.c is a source file at the same directory as Makefile file is and I'm stuck here.Any help would be much appreciated.

author: ataradov
author_rank: Super Contributor
timestamp: July 28, 2020, 11:59:59 pm
content: Attach a Makefile as is, do not copy it. make is very sensitive about using tabs instead of spaces in the rules and it is hard to tell from the code, since forum may have stripped them.

author: lucazader
author_rank: Regular Contributor
timestamp: July 29, 2020, 12:00:09 am
content: If you want to get up and running with a very simple setup with a makefile and FreeRTOS you can generate a project with the STM32CubeIt can generate the project with only the files you need for your board, with freertos all setup and ready to go and being built using a makefile (if the correct setting is selected).You can then poke around what is generated including the makefile to see how everything goes together and learn how to use FreeRTOS on the stm processor series.

author: newbrain
author_rank: Super Contributor
timestamp: July 29, 2020, 09:21:29 am
content: Quote from: psysc0rpi0n on July 28, 2020, 10:29:32 pmIs this a make error or a compiler error? What's the content of that file?Quote from: lucazader on July 29, 2020, 12:00:09 amIt works (I am using it on an STMf072 based project -so a smallish thing), but with some caveats:It forces to define at least one task in the tool - I don't like this, especially due to the point belowThe generated code is not directly using FreeRTOS API, rather the CMSIS (V1 or V2), almost pointless, abstraction layer.Your code can freely call FreeRTOS though and completely forget about CMSIS RTOS.Only a subset of FreeRTOS configuration options is available, you might need to add some others directly in the code.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: July 29, 2020, 06:02:10 pm
content: Quote from: ataradov on July 28, 2020, 11:59:59 pmOh ok. I forgot about tabs. I'll o it next time I need to show code.Quote from: lucazader on July 29, 2020, 12:00:09 amHum, I see. But I don't have that software installed and I didn't want to install it because I want to use OpenOCD to upload code (I'm also learning about OpenOC, so this is like 2 in 1 learning). But if I fin it too challenging for my level of knowledge, I'll try it.Quote from: newbrain on July 29, 2020, 09:21:29 amThe error happens when I run `make`command. That file is from FreeRTOS. Not my code or anything, so I have to assume this is no error on that files code.Edited;I opened this ParTest.c file and my vim linter complains about a missing header file. Not sure this is the problem because the error says "missing separator".

author: lucazader
author_rank: Regular Contributor
timestamp: July 29, 2020, 07:51:46 pm
content: You can still use openOCD to load and debug the program that will be generated from the STM cube. (i am talking about the stm32cubemx rather than the stm32cubeide)Newbrain does mention some good points about how this generated code does have some drawbacks, most notably the CMSIS RTOS abstraction layer and the forced default task.But as he mentions there are relatively easy to work around.

author: newbrain
author_rank: Super Contributor
timestamp: July 29, 2020, 09:29:45 pm
content: Quote from: psysc0rpi0n on July 28, 2020, 10:29:32 pmMy makefile-fu is not stellar (any more), but I don't think this is going to work:$(SRCDIR)/%.cbecomes../../Source ./%.c, it's probably not what you want.ParTest.c is part of the Demo folder, unfortunately for STM32F407 they provide just the IAR project files...

author: guidoted
author_rank: Newbie
timestamp: August 02, 2020, 10:47:35 pm
content: I agree with Lucazader.Use STM32CubeIDE and generate the project with STM32CubeMX (included in CubeIDE), including FreeRTOS; very quick and simple.Then, if you want, you can go more deeply into the code and program even more "bare metal".Guido

author: asmi
author_rank: Super Contributor
timestamp: August 04, 2020, 05:26:11 pm
content: STM32 has a very good video training series for using RTOS. I definitely recommend watching it!

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: August 04, 2020, 08:12:37 pm
content: Quote from: newbrain on July 29, 2020, 09:29:45 pmSo, does this means I can't do what I wanted?

author: MosherIV
author_rank: Super Contributor
timestamp: August 04, 2020, 09:29:36 pm
content: QuoteNo, the makefile given does not do what you want.The IAR example does not have a makefile provided.You will need to write one yourself.Most modern/commercial development systems for commercial development concentrate on productivity. Having to manually write/manage makfiles is time consumming and rarely adds to the project progress, so they manage this for the developer.By all means, if you want to learn to write makefiles, go ahead.Turn on verbose mode to try and understand what the macros, symbols and substitutions do.Sorry, I cannot be any more help - its been years since I did makefiles. I am a professional/commercial embedded developer. I use what ever makes me more productive, so I have used IDEs to manage project for years now.

author: newbrain
author_rank: Super Contributor
timestamp: August 04, 2020, 09:32:58 pm
content: Quote from: psysc0rpi0n on August 04, 2020, 08:12:37 pmWhat?No, I was just pointing out what appearsto meto be a problem in your makefile!It's probably solvable, how, I cannot now say.PS: Drat, my first job waswriting makefilesfor a quite large project, but that was 30 years ago, with SunOS make...

author: MosherIV
author_rank: Super Contributor
timestamp: August 04, 2020, 09:45:07 pm
content: One thing I would like to point out is that trying to get makefiles to work is distracting you from your goal of 'learning about FreeRTOS'.If you want to just use the IAR examples, there is a free version of IAR Workbench.Just download IAR WB from the web site. When starting IAR it will ask you for license, select option to apply for license on line. One of the options should free size limited (I think it only allows 34KBytes of binary size) This should be enough to build FreeRTOS examples.There should be free version of Atollic TrueStudio as well (cannot stand it myself, cannot stand anything that is Eclipse based)

author: newbrain
author_rank: Super Contributor
timestamp: August 04, 2020, 10:10:59 pm
content: Quote from: MosherIV on August 04, 2020, 09:45:07 pmQFT, on both counts.I'm convinced thateven thisis better for writing code than Eclipse.That said, leaving aside my preferences, and as already suggested by others, a very good way would be to download STM32CubeIDE, and create a FreeRTOS project inside it. The IDE is, in fact, Atollic TrueStudio (now acquired by ST) and include the CubMx startup code generator, so you don't need to bother with toolchains and installations, everything is included, for good or bad...

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: August 05, 2020, 06:48:46 pm
content: Quote from: lucazader on July 29, 2020, 07:51:46 pmOk, however I have a couple of problems right now. I have installed a few softwares and I'm running out of space on my laptop. I have MPLab IDE from Microchip, Matlab, KiCAD, and I already installed STM32CubeIDE using an sh script I downloaded from their site which install a debian package but I don't know how to uninstall it and I don't find any info about how to do it.Quote from: guidoted on August 02, 2020, 10:47:35 pmYes, but my goal was to use only needed files for my board and have a Makefile to build the binary. Not sure if it's possible but that was what I wanted to do.Quote from: asmi on August 04, 2020, 05:26:11 pmDo you have a link for those?Quote from: MosherIV on August 04, 2020, 09:29:36 pmI understand. And if it takes too much time for me to do what I want, I'll have to consider that way too. But wanted to avoid it for now. But I'll consider it, for sure!Quote from: newbrain on August 04, 2020, 09:32:58 pmAh ok. I misunderstood you... Sorry.Quote from: MosherIV on August 04, 2020, 09:45:07 pmIndeed. But it was also my goal to avoid IDEs, so Makefile was kinda mandatory. That's why I started from there.Quote from: newbrain on August 04, 2020, 10:10:59 pmOk, so I guess the Makefile will be a no go. I'll distract myself one way or another. If it's not making a Makefile to work is learning about STM32CubeIE.

author: asmi
author_rank: Super Contributor
timestamp: August 05, 2020, 07:42:01 pm
content: Quote from: psysc0rpi0n on August 05, 2020, 06:48:46 pmHere:Code:https://www.youtube.com/watch?v=QGVAayFI5ZQ&list=PLnMKNibPkDnFeFV4eBfDQ9e5IrGL_dx1Q

author: julian1
author_rank: Frequent Contributor
timestamp: August 05, 2020, 09:05:29 pm
content: QuoteFind out what is installed with,grep /var/log/dpkg.logordpkg --get-selectionsShould be something like this to remove packages,dpkg --purge <>QuoteLook at the example here,https://github.com/ve3wwg/stm32f103c8t6/blob/master/rtos/blinky2/MakefileIt only pulls in local project files for the app, and whatever rtos support files are needed and is stupidly simple. The stm32 variant and board configuration are pulled from the Makefile.incl two dir levels up, which only needs light editing to be setup once - and can then be used across different projects.I use this approach with stm32f4 and rtos on linux without issue.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: August 05, 2020, 10:01:28 pm
content: Quote from: julian1 on August 05, 2020, 09:05:29 pmWill that completely uninstall everything installed by the script? I hope it does.Quote from: julian1 on August 05, 2020, 09:05:29 pmI'll have a look. Thank you a lot.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: August 06, 2020, 07:00:37 pm
content: @julian1 I thought that github was FreeRTOS one.I'm not sure I can use the same approach using FreeRTOS sources I downloaded from github. Folder structure seems to be different and I'm here:https://github.com/FreeRTOS/FreeRTOS/tree/master/FreeRTOS/Demo/CORTEX_M4F_STM32F407ZG-SKand folder structure is completely different.

author: julian1
author_rank: Frequent Contributor
timestamp: August 06, 2020, 08:30:18 pm
content: The freertos dir for the example,https://github.com/ve3wwg/stm32f103c8t6/tree/master/rtos/blinky2/rtosis a snapshot of the standalone freertos projecthttps://github.com/FreeRTOS/FreeRTOS-Kernel/tree/6199b72fbf57a7c5b3d7b195a3bd1446779314cd.You can see queue.c and tasks.c in both. If you don't want to use the snapshot version, then you should just be able to reference the freestanding freertos files and headers by checking out the repo as a subdirectory and then editing the higher level Makefile. The alternative would be to let freertos build your project, but then you become dependent on the freertos Makefile.My experience has been limited to the snapshot, as I only needed the task threading and communication queue functions.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: August 09, 2020, 10:46:15 pm
content: Quote from: julian1 on August 06, 2020, 08:30:18 pmThanks for replying.The underlined part is the one I think I want to focus on. But my knowledge with using and participating in others projects is very limited, as I have never did it. I'm just a guy that enjoys programming, electronics, etc but I have no experience in the field and never worked on this field for living. So please, bare with me. I will need some guidance to make this work in the most simple way possible using only the needed files for my board and a simple and basic Makefile.Isn't it possible to check which files are needed for my board, put them all in one (or more) folders and building a basic Makefile for it?

author: julian1
author_rank: Frequent Contributor
timestamp: August 09, 2020, 11:28:22 pm
content: QuoteYes this is kind of what I was suggesting. Except without the additional step of copying the files into your own dir.Instead, it is better to have the complete freertos repository checked in your local project dir. That way, any fixes or new features in the freertos repo are immediately available to your build, or else you can pin the commit, or have your own branches etc. A lot more maintainable. It is common to use the same approach for libopencm3.But then circumvent the freertos build system and use your own simple Makefile (example from the other github project) and just reference the specific freertos files as needed. That reduces dependencies to a minimum, and freertos basics are minimal anyway.The Makefile.incl should have the necessary defines for architecture - cortex m4, and link script for memory layout etc.That is how I planned to do it, and is on my list of tasks - I just haven't got around to it yet - so I cannot guarantee the method or give futher guidance.I suspect there might be some extra freertos defines etc, that might be necessary. But it should be evident what's needed, given any compiler errors.

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: August 12, 2020, 07:29:20 pm
content: Quote from: julian1 on August 09, 2020, 11:28:22 pmI was almost about to give up on this but now I want to try that solution. I was already starting STM32CubeMX.Ok, so I already have a copy of the entire FreeRTOS source code from github in a folder I created.I think I know the correct folder for my board.This is:https://github.com/FreeRTOS/FreeRTOS/tree/master/FreeRTOS/Demo/CORTEX_M4F_STM32F407ZG-SKfor this board, based on STM32FM4https://www.diymore.cc/products/stm32f4-discovery-stm32f407vgt6-microcontroller-32bit-flash-mcu-arm-cortex-m4-core-development-boardNow I just need to know how to start.I'm going to have a look inside that Makefile.incl and see if I can start!

author: psysc0rpi0n
author_rank: Frequent Contributor
timestamp: August 12, 2020, 08:20:29 pm
content: Weird, I'm usingfindto look for thatMakefile.incland I can't find one.Edited;Well, apparently this is some third party Makefile, no? From that libopencm3 library?Edited 1;Ok, so as I am very unaware about how things works I started comparing some other FreeRTOS projects across github, and apparently, the workflow should be something like:1 - Create my project, by simply creating a folder2 - Clone FreeRTOS repository into this folder I just created3 - Add libopencm3, if needed, as a submodule.I hope this is correct so far. If not, please correct me.After this, I think it's time to use libopencm3 library Makefiles and edit them according to my board and needs.This is where things starts getting more tricky, I guess. So, I would need some help to be able to keep going.