CQ-STARM with G++Lite (2)
Exsample for testing compiler
Cortex-M3 + GCC ってのはやはり海外サイトの情報が豊富のようで。
Martin Thomas氏のLEDチカチカ的サンプルを改造して使うことにした。
ココ⇒http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/index_cortex.html#stm32_blink
に公開されている"STM32F103VHB6_RevZ_Demo1_Lanchon_20080210.zip"。
Prepare
"STM32F103VHB6_RevZ_Demo1_Lanchon_20080210.zip"を展開後、"CQ-STARM_LEDBlink_Ex01"にフォルダ名改定。
Patch for Makefile
改造点:
--- STM32F103VHB6_RevZ_Demo1/makefile 2008-02-10 21:07:20.000000000 +0900 +++ CQ-STARM_LEDBlink_Ex01/makefile 2008-05-03 01:23:52.421875000 +0900 @@ -14,7 +14,7 @@ ASFLAGS = $(COMPILE_OPTS) -c LD = arm-none-eabi-gcc -LDFLAGS = -Wl,--gc-sections,-Map=$@.map,-cref,-u,Reset_Handler $(INCLUDE_DIRS) $(LIBRARY_DIRS) -T stm32.ld +LDFLAGS = -Wl,--gc-sections,-Map=$@.map,-cref,-u,Reset_Handler $(INCLUDE_DIRS) $(LIBRARY_DIRS) -T stm32_CQ-STARM.ld OBJCP = arm-none-eabi-objcopy OBJCPFLAGS = -O binary @@ -25,10 +25,11 @@ MAIN_OUT = main MAIN_OUT_ELF = $(MAIN_OUT).elf MAIN_OUT_BIN = $(MAIN_OUT).bin +MAIN_OUT_HEX = $(MAIN_OUT).hex # all -all: $(MAIN_OUT_ELF) $(MAIN_OUT_BIN) +all: $(MAIN_OUT_ELF) $(MAIN_OUT_BIN) $(MAIN_OUT_HEX) # main @@ -38,6 +39,8 @@ $(MAIN_OUT_BIN): $(MAIN_OUT_ELF) $(OBJCP) $(OBJCPFLAGS) $< $@ +$(MAIN_OUT_HEX): $(MAIN_OUT_ELF) + $(OBJCP) -O ihex $< $@ # flash @@ -82,4 +85,4 @@ clean: - -rm *.o lib/src/*.o $(LIBSTM32_OUT) $(MAIN_OUT_ELF) $(MAIN_OUT_BIN) + cs-rm -f *.o lib/src/*.o $(LIBSTM32_OUT) $(MAIN_OUT_ELF) $(MAIN_OUT_BIN) $(MAIN_OUT_HEX)
Patch for stm32_CQ-STARM.ld
CQ-STARM用に新規作成。
つってもstm32.ld の Flash位置とサイズを変えただけ :p
--- STM32F103VHB6_RevZ_Demo1/stm32_CQ-STARM.ld 1970-01-01 09:00:00.000000000 +0900 +++ CQ-STARM_LEDBlink_Ex01/stm32_CQ-STARM.ld 2008-05-02 18:47:08.500000000 +0900 @@ -0,0 +1,29 @@ +/* +Linker script for STM32F10x +Copyright RAISONANCE 2007 (modified by Lanchon 1-Feb-2008) +You can use, copy and distribute this file freely, but without any waranty. +Configure memory sizes, end of stack and boot mode for your project here. +*/ + + +/* include the common STM32F10x sub-script */ +INCLUDE "STM32_COMMON.ld" + +/* Memory Spaces Definitions */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K /* also change _estack below */ + FLASH (rx) : ORIGIN = 0x8003000, LENGTH = 116K + FLASHB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0 + EXTMEMB0 (rx) : ORIGIN = 0x00000000, LENGTH = 0 + EXTMEMB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0 + EXTMEMB2 (rx) : ORIGIN = 0x00000000, LENGTH = 0 + EXTMEMB3 (rx) : ORIGIN = 0x00000000, LENGTH = 0 +} + +/* highest address of the user mode stack */ +_estack = 0x20005000; + +/* include the section management sub-script */ +/* (either "STM32_SEC_FLASH.ld" or "STM32_SEC_RAM.ld") */ +INCLUDE "STM32_SEC_FLASH.ld"
Patch for main.c
改造は:
- vector位置 0x08000000 → 0x08003000
- LED接続 GPIOC[4] → GPIOC[6]
--- STM32F103VHB6_RevZ_Demo1/main.c 2008-02-10 20:09:30.000000000 +0900 +++ CQ-STARM_LEDBlink_Ex01/main.c 2008-05-02 23:53:30.000000000 +0900 @@ -45,15 +45,16 @@ /* Configure the system clocks */ RCC_Configuration(); - + /* NVIC Configuration */ NVIC_Configuration(); /* Enable GPIOC clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); - + /* Configure PC.4 as Output push-pull */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; +// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); @@ -61,12 +62,14 @@ while (1) { /* Turn on led connected to PC.4 pin */ - GPIO_SetBits(GPIOC, GPIO_Pin_4); +// GPIO_SetBits(GPIOC, GPIO_Pin_4); + GPIO_SetBits(GPIOC, GPIO_Pin_6); /* Insert delay */ Delay(0xAFFFF); /* Turn off led connected to PC.4 pin */ - GPIO_ResetBits(GPIOC, GPIO_Pin_4); +// GPIO_ResetBits(GPIOC, GPIO_Pin_4); + GPIO_ResetBits(GPIOC, GPIO_Pin_6); /* Insert delay */ Delay(0xAFFFF); } @@ -97,12 +100,12 @@ /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); - + /* HCLK = SYSCLK */ - RCC_HCLKConfig(RCC_SYSCLK_Div1); - + RCC_HCLKConfig(RCC_SYSCLK_Div1); + /* PCLK2 = HCLK */ - RCC_PCLK2Config(RCC_HCLK_Div1); + RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); @@ -110,7 +113,7 @@ /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); - /* Enable PLL */ + /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ @@ -137,12 +140,13 @@ *******************************************************************************/ void NVIC_Configuration(void) { -#ifdef VECT_TAB_RAM - /* Set the Vector Table base location at 0x20000000 */ - NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); +#ifdef VECT_TAB_RAM + /* Set the Vector Table base location at 0x20000000 */ + NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ - /* Set the Vector Table base location at 0x08000000 */ - NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); + /* Set the Vector Table base location at 0x08000000 */ + //NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); + NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x3000); #endif } @@ -169,7 +173,7 @@ * Return : None *******************************************************************************/ void assert_failed(u8* file, u32 line) -{ +{ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */