March 29, 2024, 02:17:11 PM

STM32-P103 makefile problem

Started by Oli1452, July 14, 2016, 06:30:05 PM

Previous topic - Next topic

Oli1452

What is the procedure to add new .c and .h files to the Olimex project in the Olimex makefile ?

I would like to add a "ADC_management.c" and "ADC_management.h" which calls "stm32f10x_adc.h" file.

ADC_management.h: #include "stm32f10x.h"
ADC_management.c: #include "stm32f10x_adc.h" "Gestion_ADC.h"
main.c: #include "stm32f10x_conf.h" #include "stm32f10x.h" #include "Gestion_ADC.h"

Makefile:

#    Makefile for compiling the Getting Started project

#-------------------------------------------------------------------------------
#      User-modifiable options
#-------------------------------------------------------------------------------

# Trace level used for compilation
# (can be overriden by adding TRACE_LEVEL=#number to the command-line)
# TRACE_LEVEL_DEBUG      5
# TRACE_LEVEL_INFO       4
# TRACE_LEVEL_WARNING    3
# TRACE_LEVEL_ERROR      2
# TRACE_LEVEL_FATAL      1
# TRACE_LEVEL_NO_TRACE   0
TRACE_LEVEL = 4

# Optimization level
OPTIMIZATION = -O0

# Output file basename
OUTPUT = main

# Output directories
BIN = .
OBJ = obj

# library dirs
LIBRARYSRC = ./lib/src

STARTUPFILE = ./lib/startup_stm32f10x_md.s

#-------------------------------------------------------------------------------
#      Tools
#-------------------------------------------------------------------------------

# Tool suffix when cross-compiling
CROSS_COMPILE = arm-none-eabi-

CC = $(CROSS_COMPILE)gcc
SIZE = $(CROSS_COMPILE)size
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
LD = $(CROSS_COMPILE)ld
AS = $(CROSS_COMPILE)as

#-------------------------------------------------------------------------------
#      Files
#-------------------------------------------------------------------------------

# include folders
INCLUDES = -I./
INCLUDES += -I./lib/
INCLUDES += -I./lib/inc/
INCLUDES += -I./lib/inc/../../

# Objects built from C source files
C_OBJECTS = $(OBJ)/main.o
C_OBJECTS += $(OBJ)/system_stm32f10x.o
C_OBJECTS += $(OBJ)/stm32f10x_gpio.o
C_OBJECTS += $(OBJ)/stm32f10x_rcc.o
C_OBJECTS += $(OBJ)/stm32f10x_it.o
C_OBJECTS += $(OBJ)/stm32f10x_adc.o #add
C_OBJECTS += $(OBJ)/ADC_management.o #add


# Objects built from Assembly source files
ASM_OBJECTS = $(OBJ)/startup_stm32f10x_md.o

LINKER_SCRIPT = ./lib/stm32_flash.ld
#LINKER_SCRIPT = ./lib/stm32_ram.ld

# Append OBJ and BIN directories to output filename
OUTPUT := $(BIN)/$(OUTPUT)

#-------------------------------------------------------------------------------
#      Rules
#-------------------------------------------------------------------------------

# Flags
CFLAGS = -Wall -fno-common -c -g -mcpu=cortex-m3 -mthumb
CFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -DTRACE_LEVEL=$(TRACE_LEVEL)
ASFLAGS = -g -mapcs-32
LDFLAGS = -g -v -nostartfiles
OBJCOPYFLAGS = -O binary
OBJDUMPFLAGS = -x --syms -S

all: $(BIN) $(OBJ) $(OUTPUT).out

$(BIN) $(OBJ):
   mkdir $@

$(OUTPUT).out: $(C_OBJECTS) $(ASM_OBJECTS) $(LINKER_SCRIPT)
   @ echo "..linking"
   $(LD) $(LDFLAGS) -Map $(OUTPUT).map -T$(LINKER_SCRIPT) -o $(OUTPUT).out $(C_OBJECTS) $(ASM_OBJECTS) libgcc.a
   $(OBJCOPY) $(OBJCOPYFLAGS) $(OUTPUT).out $(OUTPUT).bin
#   $(OBJDUMP) $(OBJDUMPFLAGS) $(OUTPUT).out > $(OUTPUT).list
   @ echo "...completed."
   
$(C_OBJECTS): main.c system_stm32f10x.c
   @ echo ".compiling"
   $(CC) $(CFLAGS) -o $(OBJ)/main.o main.c
   $(CC) $(CFLAGS) -o $(OBJ)/system_stm32f10x.o system_stm32f10x.c
   $(CC) $(CFLAGS) -o $(OBJ)/stm32f10x_it.o stm32f10x_it.c
   @ echo ".compiling libraries"   
   $(CC) $(CFLAGS) -o $(OBJ)/stm32f10x_gpio.o $(LIBRARYSRC)/stm32f10x_gpio.c
   $(CC) $(CFLAGS) -o $(OBJ)/stm32f10x_rcc.o $(LIBRARYSRC)/stm32f10x_rcc.c
   $(CC) $(CFLAGS) -o $(OBJ)/stm32f10x_adc.o $(LIBRARYSRC)/stm32f10x_adc.c #add   
   $(CC) $(CFLAGS) -o $(OBJ)/ADC_management.o $(LIBRARYSRC)/ADC_management.c #add

      
$(ASM_OBJECTS): $(STARTUPFILE)
   @ echo ".assembling"
   $(AS) $(ASFLAGS) -o $(OBJ)/startup_stm32f10x_md.o $(STARTUPFILE)

clean:
   -rm -f $(OBJ)/*.o $(BIN)/*.out $(BIN)/*.bin $(BIN)/*.dmp $(BIN)/*.map

Best regards,
Julien

JohnS

For more info use google but makefile 101 is that a .c normally does not depend on any .h
It is the .o that does.

John


Oli1452

Thank you for your valuable answer John.

I am not familiar with that kind of makefile.

The initial project was:

main:

int main(void)
{
   //volatile uint32_t i;

   /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
    */

   /* GPIOC Periph clock enable */
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

   /* Configure PC12 in output pushpull mode */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOC, &GPIO_InitStructure);

   /* To achieve GPIO toggling maximum frequency, the following  sequence is mandatory.
     You can monitor PD0 or PD2 on the scope to measure the output signal.
     If you need to fine tune this frequency, you can add more GPIO set/reset
     cycles to minimize more the infinite loop timing.
     This code needs to be compiled with high speed optimization option.  */

   while (1)
   {
   
    // Set PC12
    GPIOC->BSRR = 1 << 12;

    i = 1000000;
    while(--i);

    // Reset PC12
    GPIOC->BRR  = 1 << 12;

    i = 2000000;
    while(--i)      

   }
}

The makefile is the previous one I posted without the "#add" notes.

Any ideas on how adding .c and .h files in that kind of project ?

Thanks in advance.

Julien

JohnS

There's no substitute for reading the manuals, other files, etc.

John

Oli1452

I have read the manual, and spent 3 days looking for examples on the Internet. I think I did well with the makefile.

This must remain a minor mistake about specifications of the new files in the Eclipse project (file content, configuration).

Julien