Commit 9be173fd authored by Mikaël BRIDAY's avatar Mikaël BRIDAY

squelette lab2

parent 1e12ff81
#to compile the project:
# mkdir _build
# cd _build
# cmake -D CMAKE_TOOLCHAIN_FILE=../../sys/cmake/arm-none-eabi.cmake ..
# make
# make flash
cmake_minimum_required(VERSION 3.5)
#project name
project(lab1)
#application sources
set(SRCS
${CMAKE_SOURCE_DIR}/main.c
)
include("../sys/cmake/coroLabs.cmake")
EXEC=test.elf
C_SRCS = main.c
CPP_SRCS =
ASM_SRCS =
SYSTEM_SRCS += ../sys/startup_ARMCM4.c
SYSTEM_SRCS += ../sys/startup_clock.c
C_SRCS += $(SYSTEM_SRCS)
#particular config:
OPTIM=0 #set to 1 to enable C compiler optimizations
USE_TFT=0 #set to 1 to compile tft related files
CFLAGS= #flags to the C compiler
CPPFLAGS= #flags to the C++ compiler
COMMONFLAGS= #common flags to C (CFLAGS) and C++ (CPPFLAGS)
LDFLAGS = #flags to the linker
EXTRA_FILES_CLEAN= $(EXEC) $(EXEC).bin $(EXEC).map
########################################################
#system files
########################################################
#C++ cross compiler
CXX=arm-none-eabi-g++
#C cross compiler
CC=arm-none-eabi-gcc
########################################################
#TFT lib
########################################################
TFT_LIB_DIR = ../lib/tft/
TFT_CPP_SRCS = Print.cpp Adafruit_GFX.cpp Adafruit_SPITFT.cpp Adafruit_ST7735.cpp Adafruit_ST77xx.cpp tft.cpp
TFT_INC += -I$(TFT_LIB_DIR)
TFT_INC += -I$(TFT_LIB_DIR)/Adafruit-GFX-Library
TFT_INC += -I$(TFT_LIB_DIR)/Adafruit-GFX-Library/Fonts
TFT_INC += -I$(TFT_LIB_DIR)/Adafruit-ST7735-Library
TFT_INC += -I$(TFT_LIB_DIR)/arduinoCore
#also requires lib dir for spi.c/h
TFT_C_SRCS += spi.c
ifeq ($(strip $(USE_TFT)),1)
C_SRCS += $(TFT_C_SRCS)
CPP_SRCS += $(TFT_CPP_SRCS)
COMMONFLAGS += $(TFT_INC)
endif
########################################################
# STM32F303 specific flags
########################################################
CMSIS_DIR = ../sys/CMSIS
LIB_DIR = ../lib
COMMONFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DSTM32F303x8 -DARMCM4
COMMONFLAGS += -I$(CMSIS_DIR)/Device/ST/STM32F3xx/Include
COMMONFLAGS += -I$(CMSIS_DIR)/Include
COMMONFLAGS += -I$(LIB_DIR)
CFLAGS += -fstack-usage -ffunction-sections #TODO: a regarder plus en detail.
CFLAGS += -std=gnu99
CFLAGS += $(COMMONFLAGS)
CPPFLAGS += $(COMMONFLAGS)
LDFLAGS += -mthumb -mcpu=cortex-m4 -T../sys/stm32f303K8.ld -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nosys.specs -lm
LDFLAGS += -Wl,--start-group -lm -Wl,--end-group -Wl,--gc-sections
LDFLAGS += -Lsys
LDFLAGS += -Xlinker -Map=$(EXEC).map
ALL: OBJ_DIR_CREATE $(EXEC)
#########################################################
## flash
#########################################################
##extra rules (flash)
$(EXEC).bin: $(EXEC)
arm-none-eabi-objcopy -O binary $(EXEC) $(EXEC).bin
flash: OBJ_DIR_CREATE $(EXEC).bin
@st-flash --reset write $(EXEC).bin 0x8000000
########################################################
# compiler optimisation
########################################################
COMMONFLAGS_DEBUG = -O0 -g -Wall -fexceptions -Wno-deprecated -DDEBUG
COMMONFLAGS_OPTIM = -O3 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing -pipe -ffast-math -fexceptions
ifeq ($(strip $(OPTIM)),1)
CFLAGS += $(COMMONFLAGS_OPTIM)
CPPFLAGS += $(COMMONFLAGS_OPTIM)
msg += "with optimizations "
else
CFLAGS += $(COMMONFLAGS_DEBUG)
CPPFLAGS += $(COMMONFLAGS_DEBUG)
msg += "without optimizations "
endif
########################################################
OBJ_DIR = build
C_SRCS_NODIR = $(notdir $(C_SRCS))
CPP_SRCS_NODIR = $(notdir $(CPP_SRCS))
ASM_SRCS_NODIR = $(notdir $(ASM_SRCS))
OBJ = $(addprefix $(OBJ_DIR)/,$(CPP_SRCS_NODIR:.cpp=.o))
OBJ += $(addprefix $(OBJ_DIR)/,$(C_SRCS_NODIR:.c=.o))
OBJ += $(addprefix $(OBJ_DIR)/,$(ASM_SRCS_NODIR:.S=.o))
DEPFILES = $(addprefix $(OBJ_DIR)/,$(CPP_SRCS_NODIR:.cpp=.dep))
DEPFILES += $(addprefix $(OBJ_DIR)/,$(C_SRCS_NODIR:.c=.dep))
.PHONY: ALL
#ALL: OBJ_DIR_CREATE $(EXEC)
########################################################
.PHONY: clean OBJ_DIR_CREATE
clean:
@rm -rf $(OBJ_DIR) *~ $(EXTRA_FILES_CLEAN)
$(EXEC): $(OBJ)
@echo linking.. $(EXEC)
@$(CXX) -o $@ $(OBJ) $(LDFLAGS)
$(OBJ_DIR)/%.o: ../sys/%.c
@echo c compiling $(msg)$< ...
@$(CC) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(TFT_LIB_DIR)/Adafruit-ST7735-Library/%.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(TFT_LIB_DIR)/Adafruit-GFX-Library/%.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(TFT_LIB_DIR)/arduinoCore/%.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(TFT_LIB_DIR)/%.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(LIB_DIR)/%.c
@echo c compiling $(msg)$< ...
@$(CC) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/%.o: %.c
@echo c compiling $(msg)$< ...
@$(CC) -MD -MF $(OBJ_DIR)/$<.dep -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/%.o: %.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$<.dep -c $(CPPFLAGS) $< -o $@
OBJ_DIR_CREATE:
@if [ ! -d $(OBJ_DIR) ]; then mkdir $(OBJ_DIR); fi;
#include dependancy files.
$(foreach source,$(SRC_NODIR),$(eval -include $(OBJ_DIR)/${source}.dep))
# vim:ft=make
#start st-util from another terminal before running gdb:
#arm-none-eabi-gdb -tui test.elf
tar extended-remote :4242
load
break main
#include "stm32f3xx.h"
void wait() {
volatile int i = 0;
for (i = 0; i < 200; i++)
;
}
void setup() {
RCC->AHBENR |= RCC_AHBENR_GPIOCEN_Msk; // clock for GPIOB
__asm("nop"); // wait until GPIOB clock is Ok.
GPIOC->MODER = 1 << (3 * 2); // PB3 output
}
/* main function */
int main(void) {
setup();
/* Infinite loop */
while (1) {
/* Add application code here */
GPIOC->ODR |= 1 << 3;
// GPIOC->BSRR = 1 << 3; // bit set
// wait();
// GPIOC->BSRR = 1 << (3 + 16); // bit reset
GPIOC->ODR &= ~(1 << 3); // bit reset
// wait();
}
}
......@@ -11,7 +11,8 @@ project(lab2)
#application sources
set(SRCS
${CMAKE_SOURCE_DIR}/main.c
${CMAKE_SOURCE_DIR}/main.c
)
#option(WITH_TFT "add compilation rules for the TFT support" ON)
include("../sys/cmake/coroLabs.cmake")
EXEC=test.elf
C_SRCS = main.c pinAccess.c
CPP_SRCS =
ASM_SRCS =
SYSTEM_SRCS += ../sys/startup_ARMCM4.c
SYSTEM_SRCS += ../sys/startup_clock.c
C_SRCS += $(SYSTEM_SRCS)
#particular config:
OPTIM=0 #set to 1 to enable C compiler optimizations
USE_TFT=0 #set to 1 to compile tft related files
CFLAGS= #flags to the C compiler
CPPFLAGS= #flags to the C++ compiler
COMMONFLAGS= #common flags to C (CFLAGS) and C++ (CPPFLAGS)
LDFLAGS = #flags to the linker
EXTRA_FILES_CLEAN= $(EXEC) $(EXEC).bin $(EXEC).map
########################################################
#system files
########################################################
#C++ cross compiler
CXX=arm-none-eabi-g++
#C cross compiler
CC=arm-none-eabi-gcc
########################################################
#TFT lib
########################################################
TFT_LIB_DIR = ../lib/tft/
TFT_CPP_SRCS = Print.cpp Adafruit_GFX.cpp Adafruit_SPITFT.cpp Adafruit_ST7735.cpp Adafruit_ST77xx.cpp tft.cpp
TFT_INC += -I$(TFT_LIB_DIR)
TFT_INC += -I$(TFT_LIB_DIR)/Adafruit-GFX-Library
TFT_INC += -I$(TFT_LIB_DIR)/Adafruit-GFX-Library/Fonts
TFT_INC += -I$(TFT_LIB_DIR)/Adafruit-ST7735-Library
TFT_INC += -I$(TFT_LIB_DIR)/arduinoCore
#also requires lib dir for spi.c/h
TFT_C_SRCS += spi.c
ifeq ($(strip $(USE_TFT)),1)
C_SRCS += $(TFT_C_SRCS)
CPP_SRCS += $(TFT_CPP_SRCS)
COMMONFLAGS += $(TFT_INC)
endif
########################################################
# STM32F303 specific flags
########################################################
CMSIS_DIR = ../sys/CMSIS
LIB_DIR = ../lib
COMMONFLAGS += -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DSTM32F303x8 -DARMCM4
COMMONFLAGS += -I$(CMSIS_DIR)/Device/ST/STM32F3xx/Include
COMMONFLAGS += -I$(CMSIS_DIR)/Include
COMMONFLAGS += -I$(LIB_DIR)
CFLAGS += -fstack-usage -ffunction-sections #TODO: a regarder plus en detail.
CFLAGS += -std=gnu99
CFLAGS += $(COMMONFLAGS)
CPPFLAGS += $(COMMONFLAGS)
LDFLAGS += -mthumb -mcpu=cortex-m4 -T../sys/stm32f303K8.ld -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nosys.specs -lm
LDFLAGS += -Wl,--start-group -lm -Wl,--end-group -Wl,--gc-sections
LDFLAGS += -Lsys
LDFLAGS += -Xlinker -Map=$(EXEC).map
ALL: OBJ_DIR_CREATE $(EXEC)
#########################################################
## flash
#########################################################
##extra rules (flash)
$(EXEC).bin: $(EXEC)
arm-none-eabi-objcopy -O binary $(EXEC) $(EXEC).bin
flash: OBJ_DIR_CREATE $(EXEC).bin
@st-flash --reset write $(EXEC).bin 0x8000000
########################################################
# compiler optimisation
########################################################
COMMONFLAGS_DEBUG = -O0 -g -Wall -fexceptions -Wno-deprecated -DDEBUG
COMMONFLAGS_OPTIM = -O3 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing -pipe -ffast-math -fexceptions
ifeq ($(strip $(OPTIM)),1)
CFLAGS += $(COMMONFLAGS_OPTIM)
CPPFLAGS += $(COMMONFLAGS_OPTIM)
msg += "with optimizations "
else
CFLAGS += $(COMMONFLAGS_DEBUG)
CPPFLAGS += $(COMMONFLAGS_DEBUG)
msg += "without optimizations "
endif
########################################################
OBJ_DIR = build
C_SRCS_NODIR = $(notdir $(C_SRCS))
CPP_SRCS_NODIR = $(notdir $(CPP_SRCS))
ASM_SRCS_NODIR = $(notdir $(ASM_SRCS))
OBJ = $(addprefix $(OBJ_DIR)/,$(CPP_SRCS_NODIR:.cpp=.o))
OBJ += $(addprefix $(OBJ_DIR)/,$(C_SRCS_NODIR:.c=.o))
OBJ += $(addprefix $(OBJ_DIR)/,$(ASM_SRCS_NODIR:.S=.o))
DEPFILES = $(addprefix $(OBJ_DIR)/,$(CPP_SRCS_NODIR:.cpp=.dep))
DEPFILES += $(addprefix $(OBJ_DIR)/,$(C_SRCS_NODIR:.c=.dep))
.PHONY: ALL
#ALL: OBJ_DIR_CREATE $(EXEC)
########################################################
.PHONY: clean OBJ_DIR_CREATE
clean:
@rm -rf $(OBJ_DIR) *~ $(EXTRA_FILES_CLEAN)
$(EXEC): $(OBJ)
@echo linking.. $(EXEC)
@$(CXX) -o $@ $(OBJ) $(LDFLAGS)
$(OBJ_DIR)/%.o: ../sys/%.c
@echo c compiling $(msg)$< ...
@$(CC) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(TFT_LIB_DIR)/Adafruit-ST7735-Library/%.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(TFT_LIB_DIR)/Adafruit-GFX-Library/%.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(TFT_LIB_DIR)/arduinoCore/%.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(TFT_LIB_DIR)/%.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CPPFLAGS) $< -o $@
$(OBJ_DIR)/%.o: $(LIB_DIR)/%.c
@echo c compiling $(msg)$< ...
@$(CC) -MD -MF $(OBJ_DIR)/$(notdir $<).dep -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/%.o: %.c
@echo c compiling $(msg)$< ...
@$(CC) -MD -MF $(OBJ_DIR)/$<.dep -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/%.o: %.cpp
@echo c++ compiling $(msg)$< ...
@$(CXX) -MD -MF $(OBJ_DIR)/$<.dep -c $(CPPFLAGS) $< -o $@
OBJ_DIR_CREATE:
@if [ ! -d $(OBJ_DIR) ]; then mkdir $(OBJ_DIR); fi;
#include dependancy files.
$(foreach source,$(SRC_NODIR),$(eval -include $(OBJ_DIR)/${source}.dep))
# vim:ft=make
#start st-util from another terminal before running gdb:
#arm-none-eabi-gdb -tui test.elf
tar extended-remote :4242
load
break main
#include "stm32f3xx.h"
void wait()
{
volatile int i=0;
for(i=0;i<200000;i++);
void wait() {
volatile int i = 0;
for (i = 0; i < 2000000; i++)
;
}
void setup()
{
RCC->AHBENR |= RCC_AHBENR_GPIOBEN_Msk; //clock for GPIOB
__asm("nop"); //wait until GPIOB clock is Ok.
GPIOB->MODER = 1 << (3*2); //PB3 output
void setup() {
RCC->AHBENR |= RCC_AHBENR_GPIOBEN_Msk; // clock for GPIOB
__asm("nop"); // wait until GPIO clock is Ok.
// PB0 output
GPIOB->MODER &= ~GPIO_MODER_MODER0_Msk;
GPIOB->MODER |= GPIO_MODER_MODER0_0;
}
/* main function */
int main(void)
{
setup();
/* Infinite loop */
while (1)
{
/* Add application code here */
GPIOB->BSRR = 1<<3; //bit set
wait();
GPIOB->BSRR = 1<<(3+16); //bit reset
wait();
}
int main(void) {
setup();
/* Infinite loop */
while (1) {
/* Add application code here */
GPIOB->ODR |= GPIO_ODR_0; // bit set
wait();
GPIOB->ODR &= ~GPIO_ODR_0; // bit reset
wait();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment