build: Add a main.c, and finish everything. We now build and link!

This commit is contained in:
Solomon Peachy 2013-08-03 20:13:14 -04:00
parent 9478bc2185
commit 6cfcd4e207
7 changed files with 37 additions and 103 deletions

2
.gitignore vendored
View File

@ -16,7 +16,7 @@ inc/version.h
.depend
TAGS
tags
.toolchain

View File

@ -3,7 +3,10 @@
# Configuration and build smarts
include Makefile.common
all: .toolchain version
# Now for the image definition
IMAGE = $(MCU)-main.bin
all: .toolchain version $(IMAGE)
.PHONY: clean distclean version dep
@ -22,7 +25,7 @@ LIBS_OBJS = $(MCU_LIBS_OBJS)
PROGRAM_LIBS = src/core.a
# Generic compilation rules
XXXX.ld: libs/$(MCU).ld.in inc/hw.h $(LIBRARIES)
$(MCU).ld: libs/$(MCU).ld.in inc/$(MCU)_hw.h
@$(E) " GENERATE " $@
$(Q)$(CPP) $(TARGET_LDCPPFLAGS) -I$(TOP) libs/$(MCU).ld.in -P -o $@
@ -34,17 +37,17 @@ XXXX.ld: libs/$(MCU).ld.in inc/hw.h $(LIBRARIES)
@$(E) " CC " $<
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -c $(<:.o=.c) -o $@
%.elf: %.ld $(LIBRARIES) $(PROGRAM_LIBS)
%.elf: $(MCU).ld $(LIBRARIES) $(PROGRAM_LIBS)
@$(E) " LINK " $@
$(Q)$(CC) -o $@ $(LDFLAGS) \
-Wl,--gc-sections,-T$(<:.elf=.ld) \
-Wl,--gc-sections,-T$(MCU).ld \
-Wl,--whole-archive $(PROGRAM_LIBS) \
-Wl,--no-whole-archive $(LIBRARIES)
# -Wl,-allow-multiple-definition -flto=$(JLEVEL)
# Cleaning up..
clean:
${RM} -f $(SRC_OBJS) src/*.a
${RM} -f $(SRC_OBJS) src/*.a $(MCU).ld
distclean: clean
${RM} -f $(DEPFILE) $(VERSION_H)

View File

@ -4,7 +4,7 @@ MCU=stm32f10x
MCU_SUBTYPE=stm32f10x_ld
### _ld, _ld_vl, _md, _md_vl, _hd, _hd_vl, _xl, _cl
TARGET_LDCPPFLAGS = -DMCU=$(MCU) -DFLASH=_FLASH_0
#TARGET_LDCPPFLAGS = -DMCU=$(MCU) -DFLASH=_FLASH_0
#TARGET_CPPFLAGS = -DVECT_TAB_SRAM
#TARGET_CLAGS =

View File

@ -1,80 +0,0 @@
#ifndef __HW_H
#define __HW_H
/* Configuration */
#define USE_CW1200 /* Enable support for wireless module */
#define CALIBRATE_LSI /* Calibrate the onboard clock */
#define USE_CONSOLE /* Enable the interactive serial console */
#define INCLUDE_CONSOLE_HELP
#define USE_WDOG /* Enable the watchdog */
#define USE_RTC /* Enable the RTC */
#define USE_DELAY_TIMER /* Support udelay */
#define USE_USART1 /* Enable USART1 (aka "console") */
#define USE_RC4_PRNG /* Enable RC4 PRNG */
#define SLEEP_DELAY_MS 125
// #define REDUCED_FEATURES
//#define CLOCK_RATE 64
//#define CLOCK_RATE 36
//#define CLOCK_RATE 32
//#define CLOCK_RATE 24
#if defined(SPWF01S)
#define SG1203
#endif
#if defined(SG1088)
#define CLOCK_RATE 36
#define DUAL_IMAGE
#define STM32_RAM_SIZE (32*1024)
#define STM32_FLASH_SIZE (256*1024)
#define STM32_FLASH_BOOTLOADER_SIZE 4096
#define STM32_FLASH_NVSTATS_OFFSET (250*1024)
#define STM32_FLASH_CONFIGDATA_OFFSET (252*1024)
#define STM32_FLASH_IMAGE_SIZE (122*1024)
//#define USE_SPI1
#define USE_SPI2
//#define USE_SPI3
#define USE_USART2 /* Enable USART2 (aka "kraken") */
#define USE_WIFI_SPI2
#define USE_CRC
#define USE_I2C
#endif
#if defined(SG1203)
#define CLOCK_RATE 64
#define STM32_RAM_SIZE (64*1024)
#define STM32_FLASH_SIZE (512*1024)
#define STM32_FLASH_BOOTLOADER_SIZE 8192
#define STM32_FLASH_IMAGE_SIZE (480*1024) // 496 w/o certs.
#define STM32_FLASH_CERTS_SIZE (16*1024)
#define STM32_FLASH_CERTS_OFFSET (490*1024)
#define STM32_FLASH_NVSTATS_OFFSET (506*1024)
#define STM32_FLASH_CONFIGDATA_OFFSET (508*1024)
#define USE_WIFI_SPI1
#define USE_SPI1
//#define USE_SPI2
#define USE_SPI3
#define USE_USART2
#define USE_USART3
#define USE_CRC
#define USE_I2C
#define USE_SPI_FLASH
#define SPI_FLASH_MX25L8005 0xc22014
#endif
//XXX I2C2, ADC0-3, SPI3, DAC, USB?
#define STM32_FLASH_PAGE_SIZE 2048
#define STM32_SRAM_BASE (0x20000000)
#define STM32_FLASH_BASE (0x08000000)
#define STM32_FLASH_BOOTLOADER_OFFSET 0
#define STM32_FLASH_NVDATA_OFFSET (STM32_FLASH_BOOTLOADER_OFFSET + STM32_FLASH_BOOTLOADER_SIZE)
#define STM32_FLASH_PRIMARY_OFFSET (STM32_FLASH_BOOTLOADER_OFFSET + STM32_FLASH_BOOTLOADER_SIZE + STM32_FLASH_PAGE_SIZE)
#endif

14
inc/stm32f10x_hw.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef __STM32F10X_HW_H
#define __STM32F10X_HW_H
/* Configuration */
#define MCU_SRAM_SIZE (64*1024)
#define MCU_SRAM_BASE (0x20000000)
#define MCU_EXTSRAM_SIZE (0)
#define MCU_EXTSRAM_BASE (0x68000000)
#define MCU_FLASH_BASE (0x08000000)
#define MCU_FLASH_SIZE (512*1024)
#define MCU_FLASH_PAGE_SIZE 2048
#define MCU_FLASH_IMAGE_SIZE (510*1024)
#endif

View File

@ -1,20 +1,15 @@
#include "inc/hw.h"
#include "inc/stm32f10x_hw.h"
ENTRY(Reset_Handler)
MEMORY {
RAM (RWX) : ORIGIN = STM32_SRAM_BASE , LENGTH = STM32_RAM_SIZE
EXTSRAM (RWX) : ORIGIN = 0x68000000 , LENGTH = 0
_FLASH_0 (RX) : ORIGIN = STM32_FLASH_BASE , LENGTH = STM32_FLASH_BOOTLOADER_SIZE
_FLASH_A (RX) : ORIGIN = STM32_FLASH_BASE + STM32_FLASH_BOOTLOADER_SIZE + STM32_FLASH_PAGE_SIZE, LENGTH = STM32_FLASH_IMAGE_SIZE
NVDATA (R) : ORIGIN = STM32_FLASH_BASE + STM32_FLASH_NVDATA_OFFSET, LENGTH = STM32_FLASH_PAGE_SIZE
CFGDATA (R) : ORIGIN = STM32_FLASH_BASE + STM32_FLASH_CONFIGDATA_OFFSET, LENGTH = STM32_FLASH_PAGE_SIZE
EEMUL (RWX) : ORIGIN = STM32_FLASH_BASE + STM32_FLASH_SIZE - STM32_FLASH_PAGE_SIZE, LENGTH = STM32_FLASH_PAGE_SIZE
SRAM (RWX) : ORIGIN = MCU_SRAM_BASE , LENGTH = MCU_SRAM_SIZE
EXTSRAM (RWX) : ORIGIN = MCU_EXTSRAM_BASE , LENGTH = MCU_EXTSRAM_SIZE
FLASH (RX) : ORIGIN = MCU_FLASH_BASE , LENGTH = MCU_FLASH_SIZE
EEMUL (RWX) : ORIGIN = MCU_FLASH_BASE + MCU_FLASH_SIZE - MCU_FLASH_PAGE_SIZE, LENGTH = MCU_FLASH_PAGE_SIZE
}
_estack = ORIGIN(RAM)+LENGTH(RAM); /* end of the stack */
_estack = ORIGIN(SRAM)+LENGTH(SRAM); /* end of the stack */
_seemul = ORIGIN(EEMUL); /* start of the eeprom emulation area */
_min_stack = 0x200; /* minimum stack space to reserve for the user app */
@ -33,8 +28,6 @@ SECTIONS {
} >FLASH
.rodata : ALIGN (4) {
saved_cfg = ORIGIN(CFGDATA);
pdata_cfg = ORIGIN(NVDATA);
*(.rodata .rodata.*)
. = ALIGN(4);
@ -100,7 +93,7 @@ SECTIONS {
*(.ramfunc*)
. = ALIGN(4);
_edata = . ; /* exported for the startup function */
} >RAM AT>FLASH
} >SRAM AT>FLASH
/* This is the uninitialized data section */
.bss (NOLOAD): {
@ -115,7 +108,7 @@ SECTIONS {
_ebss = . ; /* exported for the startup function */
_end = .;
__end = .;
} >RAM AT>FLASH
} >SRAM AT>FLASH
/* ensure there is enough room for the user stack */
._usrstack (NOLOAD): {
. = ALIGN(4);
@ -123,7 +116,7 @@ SECTIONS {
. = . + _min_stack ;
. = ALIGN(4);
_eusrstack = . ;
} >RAM
} >SRAM
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }

4
src/main.c Normal file
View File

@ -0,0 +1,4 @@
int main() {
return 0;
}