Browse Source

Split sam3x/sam3n support.

pull/151/merge
Gareth McMullin 12 years ago
committed by Piotr Esden-Tempski
parent
commit
ce3e3dc39b
  1. 2
      Makefile
  2. 4
      include/libopencm3/dispatch/nvic.h
  3. 36
      include/libopencm3/sam/3n/irq.yaml
  4. 60
      include/libopencm3/sam/3n/memorymap.h
  5. 0
      include/libopencm3/sam/3x/irq.yaml
  6. 0
      include/libopencm3/sam/3x/memorymap.h
  7. 7
      include/libopencm3/sam/eefc.h
  8. 2
      include/libopencm3/sam/gpio.h
  9. 20
      include/libopencm3/sam/memorymap.h
  10. 6
      include/libopencm3/sam/pio.h
  11. 2
      include/libopencm3/sam/pmc.h
  12. 22
      include/libopencm3/sam/pwm.h
  13. 2
      include/libopencm3/sam/tc.h
  14. 2
      include/libopencm3/sam/uart.h
  15. 2
      include/libopencm3/sam/usart.h
  16. 2
      include/libopencm3/sam/wdt.h
  17. 4
      lib/dispatch/vector_nvic.c
  18. 36
      lib/sam/3n/Makefile
  19. 0
      lib/sam/3n/libopencm3_sam3n.ld
  20. 6
      lib/sam/3x/Makefile
  21. 106
      lib/sam/3x/libopencm3_sam3x.ld
  22. 2
      lib/sam/common/gpio.c
  23. 4
      lib/sam/common/pmc.c
  24. 4
      lib/sam/common/usart.c

2
Makefile

@ -32,7 +32,7 @@ SHAREDIR = $(DESTDIR)/$(PREFIX)/share/libopencm3/scripts
INSTALL = install
SRCLIBDIR = $(shell pwd)/lib
TARGETS = stm32/f1 stm32/f2 stm32/f4 stm32/l1 lpc13xx lpc17xx lpc43xx lm3s lm4f efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg sam3x
TARGETS = stm32/f1 stm32/f2 stm32/f4 stm32/l1 lpc13xx lpc17xx lpc43xx lm3s lm4f efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg sam/3x sam/3n
# Be silent per default, but 'make V=1' will show all compiler calls.
ifneq ($(V),1)

4
include/libopencm3/dispatch/nvic.h

@ -24,7 +24,9 @@
# include <libopencm3/lpc43xx/nvic.h>
#elif defined(SAM3X)
# include <libopencm3/sam3x/nvic.h>
# include <libopencm3/sam/3x/nvic.h>
#elif defined(SAM3N)
# include <libopencm3/sam/3n/nvic.h>
#elif defined(LM3S) || defined(LM4F)
/* Yes, we use the same interrupt table for both LM3S and LM4F */

36
include/libopencm3/sam/3n/irq.yaml

@ -0,0 +1,36 @@
includeguard: LIBOPENCM3_SAM3N_NVIC_H
partname_humanreadable: Atmel SAM3N series
partname_doxygen: SAM3N
irqs:
- supc
- rstc
- rtc
- rtt
- wdg
- pmc
- eefc0
- reserved0
- uart0
- uart1
- reserved1
- pioa
- piob
- pioc
- usart0
- usart1
- reserved2
- reserved3
- reserved4
- twi0
- twi1
- spi
- reserved5
- tc0
- tc1
- tc2
- tc3
- tc4
- tc5
- adc
- dacc
- pwm

60
include/libopencm3/sam/3n/memorymap.h

@ -0,0 +1,60 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2012 Gareth McMullin <gareth@blacksphere.co.nz>
*
* This library 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 3 of the License, or
* (at your option) any later version.
*
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SAM3N_MEMORYMAP_H
#define SAM3N_MEMORYMAP_H
#include <libopencm3/cm3/common.h>
/* --- SAM3N peripheral space -------------------------------------------- */
#define SPI_BASE (0x40008000)
#define TC0_BASE (0x40010000)
#define TC1_BASE (0x40010040)
#define TC2_BASE (0x40010080)
#define TC3_BASE (0x40014000)
#define TC4_BASE (0x40014040)
#define TC5_BASE (0x40014080)
#define TWI0_BASE (0x40018000)
#define TWI1_BASE (0x4001C000)
#define PWM_BASE (0x40020000)
#define USART0_BASE (0x40024000)
#define USART1_BASE (0x40028000)
#define ADC_BASE (0x40038000)
#define DACC_BASE (0x4003C000)
/* --- SAM3N system controller space ------------------------------------- */
#define SMC_BASE (0x400E0000)
#define MATRIX_BASE (0x400E0200)
#define PMC_BASE (0x400E0400)
#define UART0_BASE (0x400E0600)
#define CHIPID_BASE (0x400E0740)
#define UART1_BASE (0x400E0800)
#define EEFC_BASE (0x400E0A00)
#define PIOA_BASE (0x400E0E00)
#define PIOB_BASE (0x400E1000)
#define PIOC_BASE (0x400E1200)
#define RSTC_BASE (0x400E1400)
#define SUPC_BASE (0x400E1410)
#define RTT_BASE (0x400E1430)
#define WDT_BASE (0x400E1450)
#define RTC_BASE (0x400E1460)
#define GPBR_BASE (0x400E1490)
#endif

0
include/libopencm3/sam3x/irq.yaml → include/libopencm3/sam/3x/irq.yaml

0
include/libopencm3/sam3x/memorymap.h → include/libopencm3/sam/3x/memorymap.h

7
include/libopencm3/sam3x/eefc.h → include/libopencm3/sam/eefc.h

@ -21,9 +21,10 @@
#define SAM3X_EEFC_H
#include <libopencm3/cm3/common.h>
#include <libopencm3/sam3x/memorymap.h>
#include <libopencm3/sam/memorymap.h>
/* --- Convenience macros ------------------------------------------------ */
#define EEFC EEFC_BASE
#define EEFC0 EEFC0_BASE
#define EEFC1 EEFC1_BASE
@ -70,8 +71,12 @@
static inline void eefc_set_latency(u8 wait)
{
#if defined(SAM3X)
EEFC_FMR(EEFC0) = (EEFC_FMR(EEFC0) & ~EEFC_FMR_FWS_MASK) | (wait << 8);
EEFC_FMR(EEFC1) = (EEFC_FMR(EEFC1) & ~EEFC_FMR_FWS_MASK) | (wait << 8);
#elif defined(SAM3N)
EEFC_FMR(EEFC) = (EEFC_FMR(EEFC) & ~EEFC_FMR_FWS_MASK) | (wait << 8);
#endif
}
#endif

2
include/libopencm3/sam3x/gpio.h → include/libopencm3/sam/gpio.h

@ -20,7 +20,7 @@
#ifndef SAM3X_GPIO_H
#define SAM3X_GPIO_H
#include <libopencm3/sam3x/pio.h>
#include <libopencm3/sam/pio.h>
/* flags may be or'd together, but only contain one of
* GPOUTPUT, PERIPHA and PERIPHB */

20
lib/sam3x/pio.c → include/libopencm3/sam/memorymap.h

@ -1,7 +1,7 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2012 Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2013 Gareth McMullin <gareth@blacksphere.co.nz>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -17,12 +17,16 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/sam3x/pio.h>
#ifndef SAM_MEMORYMAP_H
#define SAM_MEMORYMAP_H
void pio_toggle(u32 gpioport, u32 gpios)
{
u32 odsr = PIO_ODSR(gpioport);
PIO_CODR(gpioport) = odsr & gpios;
PIO_SODR(gpioport) = ~odsr & gpios;
}
#if defined(SAM3X)
# include <libopencm3/sam/3x/memorymap.h>
#elif defined(SAM3N)
# include <libopencm3/sam/3n/memorymap.h>
#else
# error "Processor family not defined."
#endif
#endif

6
include/libopencm3/sam3x/pio.h → include/libopencm3/sam/pio.h

@ -17,11 +17,11 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SAM3X_PIO_H
#define SAM3X_PIO_H
#ifndef SAM_PIO_H
#define SAM_PIO_H
#include <libopencm3/cm3/common.h>
#include <libopencm3/sam3x/memorymap.h>
#include <libopencm3/sam/memorymap.h>
/* --- Convenience macros ------------------------------------------------ */

2
include/libopencm3/sam3x/pmc.h → include/libopencm3/sam/pmc.h

@ -21,7 +21,7 @@
#define SAM3X_PMC_H
#include <libopencm3/cm3/common.h>
#include <libopencm3/sam3x/memorymap.h>
#include <libopencm3/sam/memorymap.h>
/* --- Power Management Controller (PMC) registers ----------------------- */

22
include/libopencm3/sam3x/pwm.h → include/libopencm3/sam/pwm.h

@ -21,7 +21,7 @@
#define SAM3X_PWM_H
#include <libopencm3/cm3/common.h>
#include <libopencm3/sam3x/memorymap.h>
#include <libopencm3/sam/memorymap.h>
/* --- Pulse Width Modulation (PWM) registers ----------------------- */
@ -71,12 +71,20 @@
/* 0x01B0:0x01FC - Reserved */
#define PWM_CMR(x) MMIO32(PWM_BASE + 0x0200 + 0x20*(x))
#define PWM_CDTY(x) MMIO32(PWM_BASE + 0x0204 + 0x20*(x))
#define PWM_CDTYUPD(x) MMIO32(PWM_BASE + 0x0208 + 0x20*(x))
#define PWM_CPRD(x) MMIO32(PWM_BASE + 0x020C + 0x20*(x))
#define PWM_CPRDUPD(x) MMIO32(PWM_BASE + 0x0210 + 0x20*(x))
#define PWM_CCNT(x) MMIO32(PWM_BASE + 0x0214 + 0x20*(x))
#define PWM_DT(x) MMIO32(PWM_BASE + 0x0218 + 0x20*(x))
#define PWM_DTUPD(x) MMIO32(PWM_BASE + 0x021C + 0x20*(x))
#if defined(SAM3X)
# define PWM_CDTYUPD(x) MMIO32(PWM_BASE + 0x0208 + 0x20*(x))
# define PWM_CPRD(x) MMIO32(PWM_BASE + 0x020C + 0x20*(x))
# define PWM_CPRDUPD(x) MMIO32(PWM_BASE + 0x0210 + 0x20*(x))
# define PWM_CCNT(x) MMIO32(PWM_BASE + 0x0214 + 0x20*(x))
# define PWM_DT(x) MMIO32(PWM_BASE + 0x0218 + 0x20*(x))
# define PWM_DTUPD(x) MMIO32(PWM_BASE + 0x021C + 0x20*(x))
#elif defined(SAM3N)
# define PWM_CPRD(x) MMIO32(PWM_BASE + 0x0208 + 0x20*(x))
# define PWM_CCNT(x) MMIO32(PWM_BASE + 0x020C + 0x20*(x))
# define PWM_CUPD(x) MMIO32(PWM_BASE + 0x0210 + 0x20*(x))
#else
# error "Processor family not defined."
#endif
static inline void pwm_set_period(int ch, u32 period)
{

2
include/libopencm3/sam3x/tc.h → include/libopencm3/sam/tc.h

@ -21,7 +21,7 @@
#define SAM3X_TC_H
#include <libopencm3/cm3/common.h>
#include <libopencm3/sam3x/memorymap.h>
#include <libopencm3/sam/memorymap.h>
/* --- Timer Counter (TC) registers -------------------------------------- */

2
include/libopencm3/sam3x/uart.h → include/libopencm3/sam/uart.h

@ -21,7 +21,7 @@
#define SAM3X_UART_H
#include <libopencm3/cm3/common.h>
#include <libopencm3/sam3x/memorymap.h>
#include <libopencm3/sam/memorymap.h>
/* --- Universal Asynchronous Receiver Transmitter (UART) registers ------- */
#define UART_CR MMIO32(UART_BASE + 0x0000)

2
include/libopencm3/sam3x/usart.h → include/libopencm3/sam/usart.h

@ -21,7 +21,7 @@
#define SAM3X_USART_H
#include <libopencm3/cm3/common.h>
#include <libopencm3/sam3x/memorymap.h>
#include <libopencm3/sam/memorymap.h>
#define USART0 USART0_BASE
#define USART1 USART1_BASE

2
include/libopencm3/sam3x/wdt.h → include/libopencm3/sam/wdt.h

@ -21,7 +21,7 @@
#define SAM3X_WDT_H
#include <libopencm3/cm3/common.h>
#include <libopencm3/sam3x/memorymap.h>
#include <libopencm3/sam/memorymap.h>
/* --- WDT registers ----------------------------------------------------- */

4
lib/dispatch/vector_nvic.c

@ -24,7 +24,9 @@
# include "../lpc43xx/vector_nvic.c"
#elif defined(SAM3X)
# include "../sam3x/vector_nvic.c"
# include "../sam/3x/vector_nvic.c"
#elif defined(SAM3N)
# include "../sam/3n/vector_nvic.c"
#elif defined(LM3S) || defined(LM4F)
/* Yes, we use the same interrupt table for both LM3S and LM4F */

36
lib/sam/3n/Makefile

@ -0,0 +1,36 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
##
## This library 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 3 of the License, or
## (at your option) any later version.
##
## This library 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 library. If not, see <http://www.gnu.org/licenses/>.
##
LIBNAME = libopencm3_sam3n
PREFIX ?= arm-none-eabi
#PREFIX ?= arm-elf
CC = $(PREFIX)-gcc
AR = $(PREFIX)-ar
CFLAGS = -Os -g -Wall -Wextra -I../../../include -fno-common \
-mcpu=cortex-m3 -mthumb -Wstrict-prototypes \
-ffunction-sections -fdata-sections -MD -DSAM3N
# ARFLAGS = rcsv
ARFLAGS = rcs
OBJS = gpio.o pmc.o usart.o
VPATH += ../../cm3:../common
include ../../Makefile.include

0
lib/sam3x/libopencm3_sam3x.ld → lib/sam/3n/libopencm3_sam3n.ld

6
lib/sam3x/Makefile → lib/sam/3x/Makefile

@ -23,14 +23,14 @@ PREFIX ?= arm-none-eabi
#PREFIX ?= arm-elf
CC = $(PREFIX)-gcc
AR = $(PREFIX)-ar
CFLAGS = -Os -g -Wall -Wextra -I../../include -fno-common \
CFLAGS = -Os -g -Wall -Wextra -I../../../include -fno-common \
-mcpu=cortex-m3 -mthumb -Wstrict-prototypes \
-ffunction-sections -fdata-sections -MD -DSAM3X
# ARFLAGS = rcsv
ARFLAGS = rcs
OBJS = gpio.o pmc.o usart.o
VPATH += ../usb:../cm3
VPATH += ../../usb:../../cm3:../common
include ../Makefile.include
include ../../Makefile.include

106
lib/sam/3x/libopencm3_sam3x.ld

@ -0,0 +1,106 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
*
* This library 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 3 of the License, or
* (at your option) any later version.
*
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
*/
/* Generic linker script for STM32 targets using libopencm3. */
/* Memory regions must be defined in the ld script which includes this one. */
/* Enforce emmition of the vector table. */
EXTERN (vector_table)
/* Define the entry point of the output file. */
ENTRY(reset_handler)
/* Define sections. */
SECTIONS
{
.text : {
*(.vectors) /* Vector table */
*(.text*) /* Program code */
. = ALIGN(4);
*(.rodata*) /* Read-only data */
. = ALIGN(4);
} >rom
/* C++ Static constructors/destructors, also used for __attribute__
* ((constructor)) and the likes */
.preinit_array : {
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
} >rom
.init_array : {
. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;
} >rom
.fini_array : {
. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;
} >rom
/*
* Another section used by C++ stuff, appears when using newlib with
* 64bit (long long) printf support
*/
.ARM.extab : {
*(.ARM.extab*)
} >rom
.ARM.exidx : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >rom
. = ALIGN(4);
_etext = .;
.data : {
_data = .;
*(.data*) /* Read-write initialized data */
. = ALIGN(4);
_edata = .;
} >ram AT >rom
_data_loadaddr = LOADADDR(.data);
.bss : {
*(.bss*) /* Read-write zero initialized data */
*(COMMON)
. = ALIGN(4);
_ebss = .;
} >ram
/*
* The .eh_frame section appears to be used for C++ exception handling.
* You may need to fix this if you're using C++.
*/
/DISCARD/ : { *(.eh_frame) }
. = ALIGN(4);
end = .;
}
PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram));

2
lib/sam3x/gpio.c → lib/sam/common/gpio.c

@ -17,7 +17,7 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/sam3x/gpio.h>
#include <libopencm3/sam/gpio.h>
void gpio_init(u32 port, u32 pins, enum gpio_flags flags)
{

4
lib/sam3x/pmc.c → lib/sam/common/pmc.c

@ -17,8 +17,8 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/sam3x/pmc.h>
#include <libopencm3/sam3x/eefc.h>
#include <libopencm3/sam/pmc.h>
#include <libopencm3/sam/eefc.h>
/** Default peripheral clock frequency after reset. */
u32 pmc_mck_frequency = 4000000;

4
lib/sam3x/usart.c → lib/sam/common/usart.c

@ -17,8 +17,8 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/sam3x/usart.h>
#include <libopencm3/sam3x/pmc.h>
#include <libopencm3/sam/usart.h>
#include <libopencm3/sam/pmc.h>
void usart_set_baudrate(u32 usart, u32 baud)
{
Loading…
Cancel
Save