Commit f2acacc5 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

Added UART files

parent e5fc761f
####################################################################
# Makefile #
####################################################################
.SUFFIXES: # ignore builtin rules
.PHONY: all debug release clean
####################################################################
# Definitions #
####################################################################
DEVICE = EFM32GG330F1024
PROJECTNAME = freertos_blink
# Name of interface configuration file used by OpenOCD
OOCD_IFACE ?= stlink-v2-1
OBJ_DIR = build
EXE_DIR = exe
LST_DIR = lst
####################################################################
# Definitions of toolchain. #
# You might need to do changes to match your system setup #
####################################################################
# Change path to the tools according to your system configuration
# DO NOT add trailing whitespace chars, they do matter !
WINDOWSCS ?= GNU Tools ARM Embedded\4.7 2012q4
LINUXCS ?= /opt/gcc-arm-none-eabi-4_8-2014q1
RMDIRS := rm -rf
RMFILES := rm -rf
ALLFILES := /*.*
NULLDEVICE := /dev/null
SHELLNAMES := $(ComSpec)$(COMSPEC)
# Try autodetecting the environment
ifeq ($(SHELLNAMES),)
# Assume we are making on a Linux platform
TOOLDIR := $(LINUXCS)
else
QUOTE :="
ifneq ($(COMSPEC),)
# Assume we are making on a mingw/msys/cygwin platform running on Windows
# This is a convenient place to override TOOLDIR, DO NOT add trailing
# whitespace chars, they do matter !
TOOLDIR := $(PROGRAMFILES)/$(WINDOWSCS)
ifeq ($(findstring cygdrive,$(shell set)),)
# We were not on a cygwin platform
NULLDEVICE := NUL
endif
else
# Assume we are making on a Windows platform
# This is a convenient place to override TOOLDIR, DO NOT add trailing
# whitespace chars, they do matter !
SHELL := $(SHELLNAMES)
TOOLDIR := $(ProgramFiles)/$(WINDOWSCS)
RMDIRS := rd /s /q
RMFILES := del /s /q
ALLFILES := \*.*
NULLDEVICE := NUL
endif
endif
# Create directories and do a clean which is compatible with parallell make
$(shell mkdir $(OBJ_DIR)>$(NULLDEVICE) 2>&1)
$(shell mkdir $(EXE_DIR)>$(NULLDEVICE) 2>&1)
$(shell mkdir $(LST_DIR)>$(NULLDEVICE) 2>&1)
ifeq (clean,$(findstring clean, $(MAKECMDGOALS)))
ifneq ($(filter $(MAKECMDGOALS),all debug release),)
$(shell $(RMFILES) $(OBJ_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
$(shell $(RMFILES) $(EXE_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
$(shell $(RMFILES) $(LST_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
endif
endif
CC = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-gcc$(QUOTE)
LD = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-ld$(QUOTE)
AR = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-ar$(QUOTE)
OBJCOPY = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-objcopy$(QUOTE)
DUMP = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-objdump$(QUOTE)
SIZE = $(QUOTE)$(TOOLDIR)/bin/arm-none-eabi-size$(QUOTE)
####################################################################
# Flags #
####################################################################
# -MMD : Don't generate dependencies on system header files.
# -MP : Add phony targets, useful when a h-file is removed from a project.
# -MF : Specify a file to write the dependencies to.
DEPFLAGS = -MMD -MP -MF $(@:.o=.d)
#
# Add -Wa,-ahld=$(LST_DIR)/$(@F:.o=.lst) to CFLAGS to produce assembly list files
#
override CFLAGS += -D$(DEVICE) -Wall -Wextra -mcpu=cortex-m3 -mthumb \
-mfix-cortex-m3-ldrd -ffunction-sections \
-fdata-sections -fomit-frame-pointer -DGCC_ARMCM3 -DDEBUG_EFM \
$(DEPFLAGS) -Wfatal-errors
override ASMFLAGS += -x assembler-with-cpp -D$(DEVICE) -Wall -Wextra -mcpu=cortex-m3 -mthumb
#
# NOTE: The -Wl,--gc-sections flag may interfere with debugging using gdb.
#
override LDFLAGS += -Xlinker -Map=$(LST_DIR)/$(PROJECTNAME).map -mcpu=cortex-m3 \
-mthumb -T../../common/Device/EnergyMicro/EFM32GG/Source/GCC/efm32gg.ld \
-Wl,--gc-sections
LIBS = -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
INCLUDEPATHS += \
-I../../common/CMSIS/Include \
-I../../common/Device/EnergyMicro/EFM32GG/Include \
-I../../common/emlib/inc \
-I../../common/emdrv/sleep/inc \
-I../uart
####################################################################
# Files #
####################################################################
C_SRC += \
../../common/Device/EnergyMicro/EFM32GG/Source/system_efm32gg.c \
../../common/emlib/src/em_assert.c \
../../common/emlib/src/em_burtc.c \
../../common/emlib/src/em_cmu.c \
../../common/emlib/src/em_emu.c \
../../common/emlib/src/em_gpio.c \
../../common/emlib/src/em_int.c \
../../common/emlib/src/em_rmu.c \
../../common/emlib/src/em_rtc.c \
../../common/emlib/src/em_system.c \
../.../common/emlib/src/em_usart.c \
../../common/emdrv/sleep/src/sleep.c \
../uart/uart.c \
../main.c
#../reptile/FreeRTOS/Source/timers.c \
#../reptile/FreeRTOS/Source/tasks.c \
#../reptile/FreeRTOS/Source/queue.c \
#../reptile/FreeRTOS/Source/list.c \
#../reptile/FreeRTOS/Source/croutine.c \
#../reptile/FreeRTOS/Source/portable/MemMang/heap_1.c \
#../reptile/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c \
#../src/low_power_tick_management.c
s_SRC +=
S_SRC += \
../../common/Device/EnergyMicro/EFM32GG/Source/GCC/startup_efm32gg.S
####################################################################
# Rules #
####################################################################
C_FILES = $(notdir $(C_SRC) )
S_FILES = $(notdir $(S_SRC) $(s_SRC) )
#make list of source paths, sort also removes duplicates
C_PATHS = $(sort $(dir $(C_SRC) ) )
S_PATHS = $(sort $(dir $(S_SRC) $(s_SRC) ) )
C_OBJS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.o))
S_OBJS = $(if $(S_SRC), $(addprefix $(OBJ_DIR)/, $(S_FILES:.S=.o)))
s_OBJS = $(if $(s_SRC), $(addprefix $(OBJ_DIR)/, $(S_FILES:.s=.o)))
C_DEPS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.d))
OBJS = $(C_OBJS) $(S_OBJS) $(s_OBJS)
vpath %.c $(C_PATHS)
vpath %.s $(S_PATHS)
vpath %.S $(S_PATHS)
# Default build is debug build
all: debug
debug: CFLAGS += -DDEBUG -O0 -g
debug: $(EXE_DIR)/$(PROJECTNAME).bin
release: CFLAGS += -DNDEBUG -O3
release: $(EXE_DIR)/$(PROJECTNAME).bin
# Create objects from C SRC files
$(OBJ_DIR)/%.o: %.c
@echo "Building file: $<"
$(CC) $(CFLAGS) $(INCLUDEPATHS) -c -o $@ $<
# Assemble .s/.S files
$(OBJ_DIR)/%.o: %.s
@echo "Assembling $<"
$(CC) $(ASMFLAGS) $(INCLUDEPATHS) -c -o $@ $<
$(OBJ_DIR)/%.o: %.S
@echo "Assembling $<"
$(CC) $(ASMFLAGS) $(INCLUDEPATHS) -c -o $@ $<
# Link
$(EXE_DIR)/$(PROJECTNAME).out: $(OBJS)
@echo "Linking target: $@"
$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $(EXE_DIR)/$(PROJECTNAME).out
# Create binary file
$(EXE_DIR)/$(PROJECTNAME).bin: $(EXE_DIR)/$(PROJECTNAME).out
@echo "Creating binary file"
$(OBJCOPY) -O binary $(EXE_DIR)/$(PROJECTNAME).out $(EXE_DIR)/$(PROJECTNAME).bin
# Uncomment next line to produce assembly listing of entire program
# $(DUMP) -h -S -C $(EXE_DIR)/$(PROJECTNAME).out>$(LST_DIR)/$(PROJECTNAME)out.lst
# Uncomment next line to produce code footprint
$(SIZE) $<
clean:
ifeq ($(filter $(MAKECMDGOALS),all debug release),)
$(RMDIRS) $(OBJ_DIR) $(LST_DIR) $(EXE_DIR)
endif
flash: $(EXE_DIR)/$(PROJECTNAME).bin
openocd -s ../../common/openocd -f interface/$(OOCD_IFACE).cfg -f init.cfg -c "program $(EXE_DIR)/$(PROJECTNAME).bin 0 verify reset"
# include auto-generated dependency files (explicit rules)
ifneq (clean,$(findstring clean, $(MAKECMDGOALS)))
-include $(C_DEPS)
endif
/*
*==============================================================================
* CERN (BE-CO-HT)
* Source file for Main file for UART example
*==============================================================================
*
* author: Theodor Stana (t.stana@cern.ch)
*
* date of creation: 2014-07-07
*
* version: 1.0
*
* description:
*
* dependencies:
*
* references:
*
*==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE
*==============================================================================
* This source file is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This source is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details. You should have
* received a copy of the GNU Lesser General Public License along with this
* source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
*==============================================================================
* last changes:
* 2014-07-07 Theodor Stana t.stana@cern.ch File created
*==============================================================================
* TODO: -
*==============================================================================
*/
#include "uart.h"
#include "em_device.h"
#include "em_cmu.h"
uint32_t msticks = 0;
void SysTick_Handler()
{
msticks++;
}
void delay(uint32_t n)
{
uint32_t curticks;
curticks = msticks;
while ((msticks - curticks) < n)
;
}
int main()
{
uart_init();
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1);
CMU_ClockEnable(cmuClock_HFPER, true);
while (1)
{
uart_puts("supercalifrageristic\n");
delay(500);
}
}
/*
*==============================================================================
* CERN (BE-CO-HT)
* Source file for Freewatch UART library
*==============================================================================
*
* author: Theodor Stana (t.stana@cern.ch)
*
* date of creation: 2014-07-07
*
* version: 1.0
*
* description:
*
* dependencies:
*
* references:
*
*==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE
*==============================================================================
* This source file is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This source is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details. You should have
* received a copy of the GNU Lesser General Public License along with this
* source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
*==============================================================================
* last changes:
* 2014-07-07 Theodor Stana t.stana@cern.ch File created
*==============================================================================
* TODO: -
*==============================================================================
*/
#include "uart.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "em_usart.h"
/*
*==============================================================================
* UART initialization
*
* params:
* * none
*
* returns:
* * none
*
* comments:
* Initializes UART library for selected UART
*
*==============================================================================
*/
void uart_init()
{
/* Configure GPIO pins */
CMU_ClockEnable(cmuClock_GPIO, true);
/* To avoid false start, configure output as high */
GPIO_PinModeSet(UART_TXPORT, UART_TXPIN, gpioModePushPull, 1);
GPIO_PinModeSet(UART_RXPORT, UART_RXPIN, gpioModeInput, 0);
USART_TypeDef *usart = UART_PORT;
USART_InitAsync_TypeDef init = USART_INITASYNC_DEFAULT;
/* Enable peripheral clocks */
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(UART_CLK, true);
/* Configure USART for basic async operation */
init.enable = usartDisable;
USART_InitAsync(usart, &init);
/* Enable pins at UART1 location #2 */
usart->ROUTE = USART_ROUTE_RXPEN | USART_ROUTE_TXPEN | UART_LOC;
/* Clear previous RX interrupts */
USART_IntClear(UART_PORT, USART_IF_RXDATAV);
NVIC_ClearPendingIRQ(UART_IRQN);
/* Enable RX interrupts */
USART_IntEnable(UART_PORT, USART_IF_RXDATAV);
NVIC_EnableIRQ(UART_IRQN);
/* Finally enable it */
USART_Enable(usart, usartEnable);
}
/*
*==============================================================================
* Send character
*
* params:
* * char to send
*
* returns:
* * none
*
* comments:
* Calls the EMLIB function for sending a character over the selected
* UART peripheral.
*
*==============================================================================
*/
void uart_putc(char c)
{
USART_Tx(UART_PORT, c);
}
/*
*==============================================================================
* Send string
*
* params:
* * string to send
*
* returns:
* * number of chars sent
*
* comments:
* Sends the characters in a string over the selected UART peripheral until
* the null character is encountered and returns the number of characters
* sent.
*
*==============================================================================
*/
int uart_puts(char *s)
{
int nc = 0;
for (; *s == '\0'; *s++)
{
uart_putc(*s);
nc++;
}
return nc;
}
/*
*==============================================================================
* CERN (BE-CO-HT)
* Header file for Freewatch UART library
*==============================================================================
*
* author: Theodor Stana (t.stana@cern.ch)
*
* date of creation: 2014-07-07
*
* version: 1.0
*
* description:
*
* dependencies:
*
* references:
*
*==============================================================================
* GNU LESSER GENERAL PUBLIC LICENSE
*==============================================================================
* This source file is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version. This source is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details. You should have
* received a copy of the GNU Lesser General Public License along with this
* source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
*==============================================================================
* last changes:
* 2014-07-07 Theodor Stana t.stana@cern.ch File created
*==============================================================================
* TODO: -
*==============================================================================
*/
#ifndef __UART_H_
#define __UART_H_
#include "em_device.h"
#include "em_usart.h"
/*============================================================================*/
/* Defines */
/*============================================================================*/
#define UART_IRQ_NAME USART0_RX_IRQHandler
#define UART_CLK cmuClock_USART1
#define UART_IRQN USART0_RX_IRQn
#define UART_PORT USART0
#define UART_TX USART_Tx
#define UART_RX USART_Rx
#define UART_LOC USART_ROUTE_LOCATION_LOC0
#define UART_TXPORT gpioPortE
#define UART_TXPIN 10
#define UART_RXPORT gpioPortE
#define UART_RXPIN 11
/*============================================================================*/
/* Function prototypes */
/*============================================================================*/
void uart_init();
void uart_putc(char c);
int uart_puts(char *s);
#endif // __FRW_UART_H_
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