Commit e0036d90 authored by Mikaël BRIDAY's avatar Mikaël BRIDAY
Browse files

lab3

parent 7adae683
......@@ -11,7 +11,8 @@ project(lab3)
#application sources
set(SRCS
${CMAKE_SOURCE_DIR}/main.cpp
${CMAKE_SOURCE_DIR}/main.cpp
${CMAKE_SOURCE_DIR}/sw.cpp
)
option(WITH_TFT "add compilation rules for the TFT support" ON)
......
EXEC=test.elf
C_SRCS = adc.c pinAccess.c
CPP_SRCS = main.cpp
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=1 #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 += -lstdc++_nano
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 -fno-exceptions -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
#! /usr/bin/env python3
# -*- coding: UTF-8 -*-
from math import *
nbVal = 256 #nb values for 90°
nbDataPerLine = 8 #number of values per row
print('/* sin 0 to 90 degree. 256 values')
print(' * format fixed point: 1.15')
print(' **/')
print("const int16_t sinTab["+str(nbVal)+"] = {\n\t",end='')
for idx in range (nbVal):
val = 0 #TODO - update this line -
print('0x{val:04x}'.format(val=val),end='')
if idx != (nbVal-1): #except last value
print(', ',end="")
if idx % nbDataPerLine == (nbDataPerLine-1):
print('\n\t',end='')
print('\n};')
#start st-util from another terminal before running gdb:
#arm-none-eabi-gdb -tui test.elf
tar extended-remote :4242
load
break main
File added
#include "stm32f3xx.h"
#include "sw.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ST7735.h"
#include "adc.h"
#include "tft.h"
void setup()
{
Tft.setup();
Tft.setTextCursor(4, 1); //col,line
Tft.print("Hello World! ");
ADCInit();
void setup() {
SWInit();
Tft.setup();
}
//this is a simple application that uses the TFT display.
// => it first write a string in the top of the screen (in setup)
// => it writes the ADC value of the potentiometer in green, and
// refreshes it each time the value differs more than 5.
int main()
{
static int prevPot = -1;
setup();
while(1)
{
//potentiometer
int pot = ADCRead(); //12 bits -> 4096 -> 4 digits
//update only we value changes significantly
if(abs(prevPot - pot) > 5)
{
//set cursor centered on line 4.
Tft.setTextCursor(Tft.getTextWidth()/2-2,4);
Tft.eraseText(4); //remove previous value (4 digits)
Tft.print(pot);
prevPot = pot;
}
}
int main(void) {
volatile int temps;
setup();
Tft.setTextCursor(5,0);
SWReset();
Tft.print("ITII ");
temps = SWGet();
Tft.print(temps);
/* Infinite loop */
while (1) {
}
}
#include "stm32f3xx.h"
void SWInit() //init stopwatch
{
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
__asm("nop");
RCC->APB1RSTR |= RCC_APB1RSTR_TIM2RST;
RCC->APB1RSTR &= ~RCC_APB1RSTR_TIM2RST;
// configure TIM6
TIM2->PSC = 0; // full speed: 64MHz
TIM2->EGR = TIM_EGR_UG; // update event => load PSC
TIM2->CNT = 0;
TIM2->CR1 = TIM_CR1_CEN; //enable, all other fields to 0
}
void SWReset() { // reset CNT
TIM2->CNT = 0;
}
uint32_t SWGet() { // get value;
return TIM2->CNT;
}
#ifndef __sw_h__
#define __sw_h__
#include <stdint.h>
/* Init stopwatch. Should be called first (during setup)
* Works at CPU clock speed (64MHz) to count instruction cycles
* */
void SWInit();
/* Reset stopwatch. It will restart counter from 0 */
void SWReset();
/* Get the 32 bit value of the stopwatch
* Expire in ~67s
* */
uint32_t SWGet();
#endif
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