STM32F103C8T6 GCC problems in portmacro.h

Hello!

I have problem with compilation FreeRTOS on STM32F103C8T6.

Command for compillator:
/usr/bin/arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -DUSE_STDPERIPH_DRIVER -DSTM32F10X_MD -ISTM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport -ISTM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x -ISTM32F10x_StdPeriph_Lib_V3.5.0/Libraries/inc -ISTM32F10x_StdPeriph_Lib_V3.5.0/Libraries/src -IStartup -IUser -IFreeRTOS/Source/include -IFreeRTOS/Source/portable/GCC/ARM_CM3 -IFreeRTOS/Source -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -std=gnu99 -MMD -MP -MF"trilobozoa.d" -Wa,-a,-ad,-alms=./trilobozoa.lst trilobozoa.c -o trilobozoa.o

Error:
In file included from FreeRTOS/Source/include/portable.h:53:0,
from FreeRTOS/Source/include/FreeRTOS.h:65,
from trilobozoa.c:3:
FreeRTOS/Source/include/portmacro.h:170:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘void’
static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )
^~~~
FreeRTOS/Source/include/portmacro.h:183:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘void’
static portFORCE_INLINE void vPortRaiseBASEPRI( void )
^~~~
FreeRTOS/Source/include/portmacro.h:200:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘void’
static portFORCE_INLINE void vPortClearBASEPRIFromISR( void )
^~~~
FreeRTOS/Source/include/portmacro.h:208:26: error: stray ‘#’ in program
msr basepri, # 0
^
FreeRTOS/Source/include/portmacro.h:165:37: error: unknown type name ‘__forceinline’
#define portFORCE_INLINE __forceinline
^
FreeRTOS/Source/include/portmacro.h:214:12: note: in expansion of macro ‘portFORCE_INLINE’
static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )
^~~~~~~~~~~~~~~~
FreeRTOS/Source/include/portmacro.h:214:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘ulPortRaiseBASEPRI’
static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )
^~~~~~~~~~~~~~~~~~
FreeRTOS/Source/include/portmacro.h:165:37: error: unknown type name ‘__forceinline’
#define portFORCE_INLINE __forceinline
^
FreeRTOS/Source/include/portmacro.h:234:12: note: in expansion of macro ‘portFORCE_INLINE’
static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )
^~~~~~~~~~~~~~~~
FreeRTOS/Source/include/portmacro.h:234:40: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘xPortIsInsideInterrupt’
static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )

I don’t know how fix it problem.

I am not able to use IDE and use GCC + makefile. I try use differents makefile’s but all the time i got this problem. I took the portmacro.h and port.c from Source/portable/GCC/ARM_CM3. I use and try compile code for STM32 “Blue Pill”.

Please, help!

Do you have the definition of portFORCE_INLINE? My guess is it’s something like __attribute__((always_inline)) or even inline __attribute((always_inline)), or should be. It’s possible that the -std=gnu99 may cause the particular inline keyword used in the macro to not be recognized, so it’s treating that as an identifier, in which case it could be a dialect issue. Try changing the dialect to-std=gnu11 and see if it changes the behavior of the compiler.

From the version of portmacro.h I found in an old project (circa 2017 using the version of FreeRTOS provided in the STM32 Cube firmware library for the STM32F7 family):

#define portINLINE	__inline

#ifndef portFORCE_INLINE
	#define portFORCE_INLINE inline __attribute__(( always_inline))
#endif

It could be that you need to be using __inline instead of just inline in there, in which case you ought to define portFORCE_INLINE correctly before the header where portmacro.h is included is included.

I hope this helps you find your compilation problem.

Good afternoon and thank you for response!

I try use:

  1. change -std=gnu99 to -std=gnu11

  2. change portmacro.h:
    it was:
    #define portINLINE __inline

    #ifndef portFORCE_INLINE
    #define portFORCE_INLINE __forceinline
    // __forceinline
    #endif
    it became:
    #ifndef portFORCE_INLINE
    #define portFORCE_INLINE inline attribute(( always_inline))
    #endif

  3. change portmacro.h:
    it was:
    #ifndef portFORCE_INLINE
    #define portFORCE_INLINE inline attribute(( always_inline))
    #endif
    it became:
    #ifndef portFORCE_INLINE
    #define portFORCE_INLINE __inline attribute((always_inline))
    // __forceinline
    #endif

  4. change -std=gnu99 to -std=gnu11 and:
    it was:
    #ifndef portFORCE_INLINE
    #define portFORCE_INLINE inline attribute(( always_inline))
    #endif
    it became:
    #ifndef portFORCE_INLINE
    #define portFORCE_INLINE __inline attribute((always_inline))
    // __forceinline
    #endif

But I not found compilation problem.

I’m applying makefile:

GCCPath

GCC_PATH = /usr/bin

#Target name
TARGET = STM32F103C8T6

#output folder
BUILD_DIR = .

CThe library used by the source is written here.

C_SOURCES =
main.c
led.h
STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.c
STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c
STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport/core_cm3.c
STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c
STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h
FreeRTOS/Source/croutine.c
FreeRTOS/Source/tasks.c
FreeRTOS/Source/list.c
FreeRTOS/Source/queue.c
FreeRTOS/Source/timers.c
FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
FreeRTOS/Source/portable/MemMang/heap_4.c
#Libraries/src/stm32f10x_usart.c
##User/bsp_usart.c
#Libraries/src/misc.c
##User/stm32f10x_it.c
##FreeRTOS/Source/portable/IAR/ARM_CM3/portasm.s \

######################################

######################################
vpath %.h STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport
vpath %.c STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport

vpath %.h STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/
vpath %.c STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/

vpath %.h STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Template/
vpath %.c STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Template/

ASM sources

ASM_SOURCES =
Startup/startup_stm32f10x_md.s

######################################

building variables

######################################

debug build?

DEBUG = 1

optimization

OPT = -Og

#######################################

binaries

#######################################
PREFIX = arm-none-eabi-
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S

#######################################

CFLAGS

#######################################

cpu

CPU = -mcpu=cortex-m3

fpu

NONE for Cortex-M0/M0+/M3

float-abi

mcu

MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)

macros for gcc

AS defines

AS_DEFS =

C defines

C_DEFS =
-DUSE_STDPERIPH_DRIVER
-DSTM32F10X_MD

AS includes

AS_INCLUDES =
-IFreeRTOS\Source

C includes

C_INCLUDES =
-ISTM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport
-ISTM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x
-ISTM32F10x_StdPeriph_Lib_V3.5.0/Libraries/inc
-ISTM32F10x_StdPeriph_Lib_V3.5.0/Libraries/src
-IStartup
-IUser
-IFreeRTOS/Source/include
-IFreeRTOS/Source/portable/GCC/ARM_CM3
-IFreeRTOS/Source

compile gcc flags

ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2 -std=gnu99
endif

Generate dependency information

CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"

#######################################

LDFLAGS

#######################################

link script

LDSCRIPT = STM32F103C8Tx_FLASH.ld

libraries

LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,–cref -Wl,–gc-sections

default action: build all

all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin

#######################################

build the application

#######################################

list of objects

OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))

list of ASM program objects

OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))

$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@

$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@

$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@

$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@

$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@

$(BUILD_DIR):
mkdir $@

#######################################

clean up

#######################################
clean:
-rm -fR $(BUILD_DIR)

#######################################

dependencies

#######################################
-include $(wildcard $(BUILD_DIR)/*.d)

*** EOF ***

It is old version, that i found in the Internet. URL: https
://programmersought.com/article/ 37191392504/

My experience is not enough for solve this problem. I try use differents makefile. If you have makefile for {stm32f103c8t6 + gcc + SPL}, please, share it.

You should not need to change FreeRTOS source files. Where did you get the MakeFile from? Did you generate it using CubeMX or are you trying to write it yourself?

Hello!

Yes, I’m trying it write myself.

I take ALL makefile’s from the internet for FreeRTOS on stm32f103, but just this makefile brought me the closest to a ready-made solution)

If you have FreeRTOS in full complectation on stm32f103c8t6, please, send me. I don’t understand Demo/CORTEX_STM32F103* - in all this demos not there is no makefile! How people it compile?)

You should use CubeMX to get a starting point. Here is the Makefile project that I generated for STM32F103C8T6: FreeRTOSDemo.7z (398.2 KB)

These projects are for different IDE (such as Keil MDK, IAR) and are compiled using those IDEs.

I’m afraid that without more information, I’m probably not going to be much help. The error message you reported in your original post is caused by the compiler thinking that the expansion of the macro portFORCE_INLINE contains an identifier of some sort.

I note that you’ve got #define portFORCE_INLINE __inline attribute((always_inline)). This should be written #define portFORCE_INLINE __inline __attribute__(( always_inline )). I don’t know for sure that the whitespace between parenthesis and the always_inline is significant, but it seems to be the common practice to surround the contents of an __attribute__(( )) qualifier with whitespace.

I am currently not working on any projects that use FreeRTOS or the STM32, so I cannot pull up the current FreeRTOS sources or any of the STM Cube firmware libraries and examples. You will find that it is sometimes hard to make an example work under the CubeMX IDE if for no other reason than that they don’t provide a CubeMX generated IO configuration file (.ioc) and you mostly have to work the IO configuration out for yourself; sometimes the documentation with the sample says what key peripheral settings are, but you must create your own .ioc file to create a usable CubeMX IDE project.

I wish you luck in solving your issues.

I thank you for your help

I just compile your project and it works! I am happy that the problem has been solved.

THANK YOU VERY MUCH!

I ask you to explain to me about the composition of the project. Do I understand correctly that the project that the user is writing should be in the directory?

This is the project as generated by the CubeMX. I think you forgot to mention which directory you are talking about but you can create a new directory parallel to Core and Drivers to keep your code.

1 Like