From e50e2f8c62a262c6ee109204b30b485a5bb3c074 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 18 Nov 2010 23:55:58 +0100 Subject: simtrace: Commit Makefile changes to support build of simtrace WARNING These changes will enable the simtrace firmware to be built like this: make -f Makefile.dfu BOARD=OLIMEX make BOARD=SIMTRACE DEBUG=1 TARGET=main_simtrace --- firmware/Makefile | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'firmware/Makefile') diff --git a/firmware/Makefile b/firmware/Makefile index 08126c1..9b75b3a 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -42,8 +42,8 @@ FLASH_TOOL = AT91FLASH # MCU name and submodel MCU = arm7tdmi -#SUBMDL = AT91SAM7S64 -SUBMDL = AT91SAM7S128 +SUBMDL = AT91SAM7S64 +#SUBMDL = AT91SAM7S128 USE_THUMB_MODE = NO #USE_THUMB_MODE = YES @@ -70,7 +70,7 @@ PATH_TO_LINKSCRIPTS=link/ # Target file name (without extension). TARGET:=main_reqa -USBSTRINGS=src/picc/usb_strings_app.h src/pcd/usb_strings_app.h +USBSTRINGS=src/picc/usb_strings_app.h src/pcd/usb_strings_app.h src/simtrace/usb_strings_app.h # List C source files here. (C dependencies are automatically generated.) # use file-extension c for "c-only"-files @@ -112,6 +112,11 @@ SRCARM += src/picc/tc_fdt.c src/picc/ssc_picc.c src/picc/adc.c \ SRCARM += src/picc/$(TARGET).c endif +ifeq ($(BOARD), SIMTRACE) +SRCARM += src/simtrace/iso7816_uart.c src/simtrace/tc_etu.c +SRCARM += src/simtrace/$(TARGET).c +endif + # List C++ source files here. # use file-extension cpp for C++-files (use extension .cpp) @@ -202,6 +207,12 @@ CDEFS += -DPCD CINCS = -Isrc/pcd endif +ifeq ($(BOARD),SIMTRACE) +CDEFS += -DSIMTRACE +CINCS = -Isrc/simtrace +endif + + # Place -I options here CINCS += -Iinclude -Isrc -- cgit v1.2.3 From ff741ee31fe2a6b25f8f7fcfb1397bb0c82616d6 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 16 Jun 2011 21:00:02 +0200 Subject: simtrace: add more definitions regarding real hw prototype --- firmware/Makefile | 2 ++ firmware/Makefile.dfu | 8 ++++++++ firmware/src/simtrace.h | 20 +++++++++++++++++++- firmware/src/start/Cstartup.S | 3 +++ 4 files changed, 32 insertions(+), 1 deletion(-) (limited to 'firmware/Makefile') diff --git a/firmware/Makefile b/firmware/Makefile index 9b75b3a..57c983e 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -113,6 +113,8 @@ SRCARM += src/picc/$(TARGET).c endif ifeq ($(BOARD), SIMTRACE) +SUBMDL = AT91SAM7S256 +TARGET := main_simtrace SRCARM += src/simtrace/iso7816_uart.c src/simtrace/tc_etu.c SRCARM += src/simtrace/$(TARGET).c endif diff --git a/firmware/Makefile.dfu b/firmware/Makefile.dfu index 45a042e..dbe9b35 100644 --- a/firmware/Makefile.dfu +++ b/firmware/Makefile.dfu @@ -174,6 +174,14 @@ ADEFS += -DPCD CINCS = -Isrc/pcd endif +ifeq ($(BOARD),SIMTRACE) +SUBMDL = AT91SAM7S256 +CDEFS += -DSIMTRACE +ADEFS += -DSIMTRACE +CINCS = -Isrc/simtrace +endif + + # Place -I options here CINCS += -Iinclude -Isrc diff --git a/firmware/src/simtrace.h b/firmware/src/simtrace.h index e787dff..d7faa96 100644 --- a/firmware/src/simtrace.h +++ b/firmware/src/simtrace.h @@ -4,13 +4,31 @@ #ifdef SIMTRACE #define OPENPCD_PIO_LED2 AT91C_PIO_PA17 #define OPENPCD_PIO_LED1 AT91C_PIO_PA18 -#define OPENPCD_PIO_UDP_CNX AT91C_PIO_PA24 +#define OPENPCD_PIO_UDP_CNX AT91C_PIO_PA29 #define OPENPCD_PIO_UDP_PUP AT91C_PIO_PA16 #define USB_PRODUCT_ID SIMTRACE_PRODUCT_ID #else #error "unknown PCB" #endif +/* 7816 UART for SIM-card side */ #define SIMTRACE_PIO_CLK AT91C_PA2_SCK0 #define SIMTRACE_PIO_IO AT91C_PA6_TXD0 #define SIMTRACE_PIO_nRST AT91C_PIO_PA7 +#define SIMTRACE_PIO_SW_SIM AT91C_PIO_PA8 + +/* 7816 UART for phone side */ +#define SIMTRACE_PIO_nRST_PH AT91C_PIO_PA24 +#define SIMTRACE_PIO_CLK_PH AT91C_PIO_PA23 +#define SIMTRACE_PIO_IO_PH AT91C_PIO_PA22 + +/* bus switch for SIM card connection */ +#define SIMTRACE_PIO_SC_SW AT91C_PIO_PA20 +#define SIMTRACE_PIO_IO_SW AT91C_PIO_PA19 + +/* SPI flash */ +#define PIO_SPIF_nWP AT91C_PIO_PA15 +#define PIO_SPIF_SCK AT91C_PIO_PA14 +#define PIO_SPIF_MOSI AT91C_PIO_PA13 +#define PIO_SPIF_MISO AT91C_PIO_PA12 +#define PIO_SPIF_nCS AT91C_PIO_PA11 diff --git a/firmware/src/start/Cstartup.S b/firmware/src/start/Cstartup.S index a28b400..e262b8f 100644 --- a/firmware/src/start/Cstartup.S +++ b/firmware/src/start/Cstartup.S @@ -98,6 +98,9 @@ /* Olimex SAM7-Pxxx boards have a button B1 on PA19 that is low-active */ .equ PIO_BOOTLDR, (1 << 19) #define CONFIG_DFU_SWITCH_INV +#elif defined(SIMTRACE) + .equ PIO_BOOTLDR, (1 << 31) +#define CONFIG_DFU_SWITCH_INV #else #error please define PIO_BOOTLDR for your board #endif -- cgit v1.2.3 From cda126a7ef6fbb54a18a4786c15117800a13f7b3 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 16 Jun 2011 21:16:13 +0200 Subject: simtrace: add support for the analog bus switch --- firmware/Makefile | 3 +- firmware/src/os/dbgu.c | 2 +- firmware/src/simtrace/main_simtrace.c | 11 ++++- firmware/src/simtrace/sim_switch.c | 76 +++++++++++++++++++++++++++++++++++ firmware/src/simtrace/sim_switch.h | 7 ++++ 5 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 firmware/src/simtrace/sim_switch.c create mode 100644 firmware/src/simtrace/sim_switch.h (limited to 'firmware/Makefile') diff --git a/firmware/Makefile b/firmware/Makefile index 57c983e..9a95d44 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -115,7 +115,8 @@ endif ifeq ($(BOARD), SIMTRACE) SUBMDL = AT91SAM7S256 TARGET := main_simtrace -SRCARM += src/simtrace/iso7816_uart.c src/simtrace/tc_etu.c +SRCARM += src/simtrace/iso7816_uart.c src/simtrace/tc_etu.c \ + src/simtrace/sim_switch.c SRCARM += src/simtrace/$(TARGET).c endif diff --git a/firmware/src/os/dbgu.c b/firmware/src/os/dbgu.c index 026b56b..28d86a4 100644 --- a/firmware/src/os/dbgu.c +++ b/firmware/src/os/dbgu.c @@ -147,7 +147,7 @@ void AT91F_DBGU_Init(void) sysirq_register(AT91SAM7_SYSIRQ_DBGU, &DBGU_irq_handler); AT91F_DBGU_Printk("\n\r"); - AT91F_DBGU_Printk("(C) 2006 by Harald Welte \n\r" + AT91F_DBGU_Printk("(C) 2006-2011 by Harald Welte \n\r" "This software is FREE SOFTWARE licensed under GNU GPL\n\r"); AT91F_DBGU_Printk("Version " COMPILE_SVNREV " compiled " COMPILE_DATE diff --git a/firmware/src/simtrace/main_simtrace.c b/firmware/src/simtrace/main_simtrace.c index 740d35d..581fd59 100644 --- a/firmware/src/simtrace/main_simtrace.c +++ b/firmware/src/simtrace/main_simtrace.c @@ -31,6 +31,7 @@ #include #include +#include void _init_func(void) { @@ -38,6 +39,7 @@ void _init_func(void) pio_irq_init(); iso_uart_init(); tc_etu_init(); + sim_switch_init(); usbtest_init(); @@ -55,7 +57,9 @@ static void help(void) "c: toggle clock master/slave\r\n" "l: set nRST to low (active)\r\n" "h: set nRST to high (inactive)\r\n" - "o: set nRST to input\r\n"); + "o: set nRST to input\r\n" + "s: disconnect SIM bus switch\r\n" + "S: connect SIM bus switch\r\n"); } int _main_dbgu(char key) @@ -64,6 +68,11 @@ int _main_dbgu(char key) DEBUGPCRF("main_dbgu"); switch (key) { + case 's': + sim_switch_mode(0, 0); + break; + case 'S': + sim_switch_mode(1, 1); case 'r': iso_uart_rx_mode(); break; diff --git a/firmware/src/simtrace/sim_switch.c b/firmware/src/simtrace/sim_switch.c new file mode 100644 index 0000000..4f5621c --- /dev/null +++ b/firmware/src/simtrace/sim_switch.c @@ -0,0 +1,76 @@ +/* + * (C) 2011 by Harald Welte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "../simtrace.h" +#include "../openpcd.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +void sim_switch_mode(int connect_io, int connect_misc) +{ + if (connect_io) + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_IO_SW); + else + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_IO_SW); + + if (connect_misc) + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SC_SW); + else + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SC_SW); +} + +static void sw_sim_irq(u_int32_t pio) +{ + + if (!AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, pio)) + DEBUGPCR("SIM card inserted"); + else + DEBUGPCR("SIM card removed"); +} + +void sim_switch_init(void) +{ + DEBUGPCR("ISO_SW Initializing"); + + /* make sure we get clock from the power management controller */ + AT91F_US0_CfgPMC(); + + /* configure both signals as output */ + AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SC_SW | + SIMTRACE_PIO_IO_SW); + + /* configure sim card detect */ + AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SIMTRACE_PIO_SW_SIM); + AT91F_PIO_CfgInputFilter(AT91C_BASE_PIOA, SIMTRACE_PIO_SW_SIM); + pio_irq_register(SIMTRACE_PIO_SW_SIM, &sw_sim_irq); + pio_irq_enable(SIMTRACE_PIO_SW_SIM); +} diff --git a/firmware/src/simtrace/sim_switch.h b/firmware/src/simtrace/sim_switch.h new file mode 100644 index 0000000..01a6a66 --- /dev/null +++ b/firmware/src/simtrace/sim_switch.h @@ -0,0 +1,7 @@ +#ifndef SIMTRACE_ISO_SW_H +#define SIMTRACE_ISO_SW_H + +void sim_switch_mode(int connect_io, int connect_misc); +void sim_switch_init(void); + +#endif -- cgit v1.2.3 From dda0896d875ec2d33b6de94df818a2f94526272b Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 30 Jul 2011 00:34:59 +0200 Subject: use gcc/ld flags -ffunction-sections and --gc-sections This will discard unused functions from the resulting binary --- firmware/Makefile | 4 ++-- firmware/link/AT91SAM7S128-ROM-sam7dfu-app.ld | 10 +++++----- firmware/link/AT91SAM7S256-ROM-sam7dfu-app.ld | 10 +++++----- firmware/link/AT91SAM7S64-ROM-sam7dfu-app.ld | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) (limited to 'firmware/Makefile') diff --git a/firmware/Makefile b/firmware/Makefile index 9a95d44..b085c33 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -249,7 +249,7 @@ CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow CFLAGS += -Wbad-function-cast -Wsign-compare -Waggregate-return CFLAGS += -Wa,-adhlns=$(subst $(suffix $<),.lst,$<) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -#CFLAGS += -ffunction-sections -fdata-sections +CFLAGS += -ffunction-sections -fdata-sections # flags only for C CONLYFLAGS += -Wnested-externs @@ -315,7 +315,7 @@ LDFLAGS += -lc -lgcc LDFLAGS += $(CPLUSPLUS_LIB) LDFLAGS += $(patsubst %,-L%,$(EXTRA_LIBDIRS)) LDFLAGS += $(patsubst %,-l%,$(EXTRA_LIBS)) -#LDFLAGS += --gc-sections +LDFLAGS += -Wl,--gc-sections -Wl,--entry=_startup # Set Linker-Script Depending On Selected Memory and Controller ifeq ($(RUN_MODE),RUN_FROM_RAM) diff --git a/firmware/link/AT91SAM7S128-ROM-sam7dfu-app.ld b/firmware/link/AT91SAM7S128-ROM-sam7dfu-app.ld index ebac6d4..7db540e 100644 --- a/firmware/link/AT91SAM7S128-ROM-sam7dfu-app.ld +++ b/firmware/link/AT91SAM7S128-ROM-sam7dfu-app.ld @@ -16,8 +16,8 @@ SECTIONS . = 0x00000000; /* first section is .text which is used for code */ .text 0x00104000: AT ( 0x00000000 ) { - src/start/Cstartup_app.o (.text) - * (.text) + src/start/Cstartup_app.o (.text*) + * (.text*) * (.rodata*) . = ALIGN(4); } >FLASH @@ -28,8 +28,8 @@ SECTIONS /* 0x00200000 ... */ .data 0x00200028: AT ( ADDR(.text) + SIZEOF(.text) - ADDR(.text) ) { _data = . ; - * (.fastrun) - * (.data) + * (.fastrun*) + * (.data*) . = ALIGN(4); } >DATA @@ -40,7 +40,7 @@ SECTIONS .bss : { __bss_start = . ; __bss_start__ = . ; - *(.bss) + *(.bss*) *(COMMON) } >DATA diff --git a/firmware/link/AT91SAM7S256-ROM-sam7dfu-app.ld b/firmware/link/AT91SAM7S256-ROM-sam7dfu-app.ld index 85bf7b8..7ec2089 100644 --- a/firmware/link/AT91SAM7S256-ROM-sam7dfu-app.ld +++ b/firmware/link/AT91SAM7S256-ROM-sam7dfu-app.ld @@ -16,8 +16,8 @@ SECTIONS . = 0x00000000; /* first section is .text which is used for code */ .text 0x00104000: AT ( 0x00000000 ) { - src/start/Cstartup_app.o (.text) - * (.text) + src/start/Cstartup_app.o (.text*) + * (.text*) * (.rodata*) . = ALIGN(4); } >FLASH @@ -28,8 +28,8 @@ SECTIONS /* 0x00200000 ... */ .data 0x00200028: AT ( ADDR(.text) + SIZEOF(.text) - ADDR(.text) ) { _data = . ; - * (.fastrun) - * (.data) + * (.fastrun*) + * (.data*) . = ALIGN(4); } >DATA @@ -40,7 +40,7 @@ SECTIONS .bss : { __bss_start = . ; __bss_start__ = . ; - *(.bss) + *(.bss*) *(COMMON) } >DATA diff --git a/firmware/link/AT91SAM7S64-ROM-sam7dfu-app.ld b/firmware/link/AT91SAM7S64-ROM-sam7dfu-app.ld index de24dd8..d45f691 100644 --- a/firmware/link/AT91SAM7S64-ROM-sam7dfu-app.ld +++ b/firmware/link/AT91SAM7S64-ROM-sam7dfu-app.ld @@ -16,8 +16,8 @@ SECTIONS . = 0x00000000; /* first section is .text which is used for code */ .text 0x00104000: AT ( 0x00000000 ) { - src/start/Cstartup_app.o (.text) - * (.text) + src/start/Cstartup_app.o (.text*) + * (.text*) * (.rodata*) . = ALIGN(4); } >FLASH @@ -28,8 +28,8 @@ SECTIONS /* 0x00200000 ... */ .data 0x00200028: AT ( ADDR(.text) + SIZEOF(.text) - ADDR(.text) ) { _data = . ; - * (.fastrun) - * (.data) + * (.fastrun*) + * (.data*) . = ALIGN(4); } >DATA @@ -40,7 +40,7 @@ SECTIONS .bss : { __bss_start = . ; __bss_start__ = . ; - *(.bss) + *(.bss*) *(COMMON) } >DATA -- cgit v1.2.3 From 5a8cd9feca7d0d09aee736ff804be4967828aefd Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 30 Jul 2011 00:37:04 +0200 Subject: add new RUN_FROM_RAM run-mode for direct DFU-to-RAM support --- firmware/Makefile | 4 +- firmware/link/AT91SAM7S128-RAM-sam7dfu-app.ld | 94 +++++++++++++++++++++++++++ firmware/src/os/req_ctx.c | 2 +- firmware/src/start/Cstartup_app.S | 2 + 4 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 firmware/link/AT91SAM7S128-RAM-sam7dfu-app.ld (limited to 'firmware/Makefile') diff --git a/firmware/Makefile b/firmware/Makefile index b085c33..68ff85f 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -49,7 +49,7 @@ USE_THUMB_MODE = NO #USE_THUMB_MODE = YES ## Create ROM-Image (final) -RUN_MODE=RUN_FROM_ROM +RUN_MODE:=RUN_FROM_ROM ## Create RAM-Image (debugging) - not used in this example #RUN_MODE=RUN_FROM_RAM @@ -319,7 +319,7 @@ LDFLAGS += -Wl,--gc-sections -Wl,--entry=_startup # Set Linker-Script Depending On Selected Memory and Controller ifeq ($(RUN_MODE),RUN_FROM_RAM) -LDFLAGS +=-T$(PATH_TO_LINKSCRIPTS)$(SUBMDL)-RAM.ld +LDFLAGS +=-T$(PATH_TO_LINKSCRIPTS)$(SUBMDL)-RAM$(IMGTYPE).ld else LDFLAGS +=-T$(PATH_TO_LINKSCRIPTS)$(SUBMDL)-ROM$(IMGTYPE).ld endif diff --git a/firmware/link/AT91SAM7S128-RAM-sam7dfu-app.ld b/firmware/link/AT91SAM7S128-RAM-sam7dfu-app.ld new file mode 100644 index 0000000..674ee00 --- /dev/null +++ b/firmware/link/AT91SAM7S128-RAM-sam7dfu-app.ld @@ -0,0 +1,94 @@ +/* Memory Definitions */ + +MEMORY +{ + /* reserve 16K DFU area on top of flash */ + /* FLASH (rx) : ORIGIN = 0x00104000, LENGTH = (0x00020000 - 0x4000 - 0x400) */ + /* reserve 1k DFU area on top of RAM */ + DATA (rw) : ORIGIN = 0x00200400, LENGTH = (0x00008000 - 0x400) + STACK (rw) : ORIGIN = 0x00208000, LENGTH = 0x00000000 +} + + +/* Section Definitions */ + +SECTIONS +{ + . = 0x00000000; + /* first section is .text which is used for code */ + .text 0x00200400: AT ( 0x00000000 ) { + src/start/Cstartup_app.o (.text) + * (.text) + * (.rodata*) + . = ALIGN(4); + + _etext = . ; + PROVIDE (etext = .); + + _data = . ; + * (.fastrun) + * (.data) + . = ALIGN(4); + } >DATA + + _edata = . ; + PROVIDE (edata = .); + + /* .bss section which is used for uninitialized data */ + .bss : { + __bss_start = . ; + __bss_start__ = . ; + *(.bss) + *(COMMON) + } >DATA + + . = ALIGN(4); + __bss_end__ = . ; + __bss_end__ = . ; + + PROVIDE (main = .); + + _end = . ; + + . = ALIGN(4); + .int_data : { + *(.internal_ram_top) + } >STACK + + PROVIDE (end = .); + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + +} diff --git a/firmware/src/os/req_ctx.c b/firmware/src/os/req_ctx.c index 0e4816e..cc8d57b 100644 --- a/firmware/src/os/req_ctx.c +++ b/firmware/src/os/req_ctx.c @@ -28,7 +28,7 @@ /* FIXME: locking, FIFO order processing */ -#ifdef __AT91SAM7S64__ +#if defined(__AT91SAM7S64__) || defined(RUN_FROM_RAM) #define NUM_RCTX_SMALL 16 #define NUM_RCTX_LARGE 1 #else diff --git a/firmware/src/start/Cstartup_app.S b/firmware/src/start/Cstartup_app.S index 448cc93..197be66 100644 --- a/firmware/src/start/Cstartup_app.S +++ b/firmware/src/start/Cstartup_app.S @@ -79,6 +79,7 @@ .global _startup .func _startup _startup: +#ifndef RUN_FROM_RAM /* Relocate .data section (copy from Flash to RAM) */ ldr r1, =_etext ldr r2, =_data @@ -87,6 +88,7 @@ loop_r: cmp r2, r3 ldrlo r0, [r1], #4 strlo r0, [r2], #4 blo loop_r +#endif /* Clear .bss section (Zero init) */ mov r0, #0 -- cgit v1.2.3 From 9f120cdf57b9dc2ca8112cbb89587f77df4facd2 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 30 Jul 2011 00:38:20 +0200 Subject: Makefile: SIMtrace uses SAM7S128, not 256 --- firmware/Makefile | 2 +- firmware/Makefile.dfu | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'firmware/Makefile') diff --git a/firmware/Makefile b/firmware/Makefile index 68ff85f..1f2f7ed 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -113,7 +113,7 @@ SRCARM += src/picc/$(TARGET).c endif ifeq ($(BOARD), SIMTRACE) -SUBMDL = AT91SAM7S256 +SUBMDL = AT91SAM7S128 TARGET := main_simtrace SRCARM += src/simtrace/iso7816_uart.c src/simtrace/tc_etu.c \ src/simtrace/sim_switch.c diff --git a/firmware/Makefile.dfu b/firmware/Makefile.dfu index dbe9b35..3c797ef 100644 --- a/firmware/Makefile.dfu +++ b/firmware/Makefile.dfu @@ -175,7 +175,7 @@ CINCS = -Isrc/pcd endif ifeq ($(BOARD),SIMTRACE) -SUBMDL = AT91SAM7S256 +SUBMDL = AT91SAM7S128 CDEFS += -DSIMTRACE ADEFS += -DSIMTRACE CINCS = -Isrc/simtrace -- cgit v1.2.3 From de0d7e35eed67bab478fda9eee7cb9edb1f34f04 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 30 Jul 2011 00:39:22 +0200 Subject: simtrace: add some early spi flash utility routines This also adds a new 'main_factory' target for simtrace --- firmware/Makefile | 2 +- firmware/src/simtrace/main_factory.c | 80 +++++++++++++++++++ firmware/src/simtrace/spi_flash.c | 144 +++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 firmware/src/simtrace/main_factory.c create mode 100644 firmware/src/simtrace/spi_flash.c (limited to 'firmware/Makefile') diff --git a/firmware/Makefile b/firmware/Makefile index 1f2f7ed..3f7a2e9 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -116,7 +116,7 @@ ifeq ($(BOARD), SIMTRACE) SUBMDL = AT91SAM7S128 TARGET := main_simtrace SRCARM += src/simtrace/iso7816_uart.c src/simtrace/tc_etu.c \ - src/simtrace/sim_switch.c + src/simtrace/sim_switch.c src/simtrace/spi_flash.c SRCARM += src/simtrace/$(TARGET).c endif diff --git a/firmware/src/simtrace/main_factory.c b/firmware/src/simtrace/main_factory.c new file mode 100644 index 0000000..3585fa6 --- /dev/null +++ b/firmware/src/simtrace/main_factory.c @@ -0,0 +1,80 @@ +/* SIMtrace factory programming + * (C) 2011 by Harald Welte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + + +#include +#include +#include +#include +#include +#include +#include +#include "../openpcd.h" +#include "../simtrace.h" +#include +#include + +#include +#include +#include + +void _init_func(void) +{ + /* low-level hardware initialization */ + pio_irq_init(); + spiflash_init(); + + /* high-level protocol */ + //opicc_usbapi_init(); + led_switch(1, 0); + led_switch(2, 1); +} + +static void help(void) +{ + DEBUGPCR("f: read flash ID\r\n"); +} + +int _main_dbgu(char key) +{ + static int i = 0; + DEBUGPCRF("main_dbgu"); + + switch (key) { + case 'f': + spiflash_id(); + break; + case '?': + help(); + break; + } + + return -EINVAL; +} + +void _main_func(void) +{ + /* first we try to get rid of pending to-be-sent stuff */ + usb_out_process(); + + /* next we deal with incoming requests from USB EP1 (OUT) */ + usb_in_process(); + + udp_unthrottle(); +} diff --git a/firmware/src/simtrace/spi_flash.c b/firmware/src/simtrace/spi_flash.c new file mode 100644 index 0000000..98bc369 --- /dev/null +++ b/firmware/src/simtrace/spi_flash.c @@ -0,0 +1,144 @@ +/* Driver for a SST25VF040B spi flash attached to AT91SAM7 SPI + * (C) 2011 by Harald Welte + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "../simtrace.h" +#include "../openpcd.h" + +#define DEBUGPSPI DEBUGP +//#define DEBUGPSPI(x, y ...) do { } while (0) + +static const AT91PS_SPI pSPI = AT91C_BASE_SPI; + +void spiflash_write_protect(int on) +{ + if (on) + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, PIO_SPIF_nWP); + else + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, PIO_SPIF_nWP); +} + +#define SPI_PERIPHA (PIO_SPIF_SCK|PIO_SPIF_MOSI|PIO_SPIF_MISO|PIO_SPIF_nCS) + +static __ramfunc void spi_irq(void) +{ + u_int32_t status = pSPI->SPI_SR; + + AT91F_AIC_ClearIt(AT91C_BASE_AIC, AT91C_ID_SPI); +} + +void spiflash_init(void) +{ + DEBUGP("spiflash_init\r\n"); + + /* activate and enable the write protection */ + AT91F_PIO_CfgPullupDis(AT91C_BASE_PIOA, PIO_SPIF_nWP); + AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, PIO_SPIF_nWP); + spiflash_write_protect(1); + + /* Configure PIOs for SCK, MOSI, MISO and nCS */ + AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, SPI_PERIPHA, 0); + + AT91F_SPI_CfgPMC(); + /* Spansion flash in v1.0p only supprts Mode 3 or Mode 0 */ + /* Mode 3: CPOL=1 nCPHA=0 CSAAT=0 BITS=0(8) MCK/2 */ + AT91F_SPI_CfgCs(AT91C_BASE_SPI, 0, AT91C_SPI_CPOL | + AT91C_SPI_BITS_8 | + (64 << 8)); + + /* SPI master mode, fixed CS, CS = 0 */ + AT91F_SPI_CfgMode(AT91C_BASE_SPI, AT91C_SPI_MSTR | + AT91C_SPI_PS_FIXED | + (0 << 16)); + + /* configure interrupt controller for SPI IRQ */ + AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_SPI, + OPENPCD_IRQ_PRIO_SPI, + AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, &spi_irq); + //AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_SPI); + + /* Enable the SPI Controller */ + AT91F_SPI_Enable(AT91C_BASE_SPI); + AT91F_SPI_EnableIt(AT91C_BASE_SPI, AT91C_SPI_MODF | + AT91C_SPI_OVRES | + AT91C_SPI_ENDRX | + AT91C_SPI_ENDTX); +} + +static int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len, + u_int8_t *rx_data, u_int16_t *rx_len) +{ + u_int16_t tx_cur = 0; + u_int16_t rx_len_max = 0; + u_int16_t rx_cnt = 0; + + DEBUGPSPI("spi_transceive: enter(tx_len=%u) ", tx_len); + + if (rx_len) { + rx_len_max = *rx_len; + *rx_len = 0; + } + + //AT91F_SPI_Enable(pSPI); + while (1) { + u_int32_t sr = pSPI->SPI_SR; + u_int8_t tmp; + if (sr & AT91C_SPI_RDRF) { + tmp = pSPI->SPI_RDR; + rx_cnt++; + if (rx_len && *rx_len < rx_len_max) + rx_data[(*rx_len)++] = tmp; + } + if (sr & AT91C_SPI_TDRE) { + if (tx_len > tx_cur) + pSPI->SPI_TDR = tx_data[tx_cur++]; + } + if (tx_cur >= tx_len && rx_cnt >= tx_len) + break; + } + //AT91F_SPI_Disable(pSPI); + if (rx_data) + DEBUGPSPI(" leave(%02x %02x)\r\n", rx_data[0], rx_data[1]); + else + DEBUGPSPI("leave()\r\n"); + + return 0; +} + +void spiflash_id(void) +{ + const u_int8_t tx_data[] = { 0x9f, 0, 0, 0 }; + u_int8_t rx_data[] = { 0,0,0,0 }; + u_int16_t rx_len = sizeof(rx_data); + + spi_transceive(tx_data, sizeof(tx_data), rx_data, &rx_len); + DEBUGP("SPI ID: %02x %02x %02x\n", rx_data[1], rx_data[2], rx_data[3]); +} -- cgit v1.2.3