eddy_em: (hram nauki)
[personal profile] eddy_em
Наконец-то дошло до меня, в чем было дело (скомпилированные прошивки для МКшки или не работали, или вообще не загружались): я забыл в Makefile прописать objcopy!
Простой пример с SysTick заработал. Диодик заморгал. Ура!


Вот сам "подопытный":

#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"

static __IO uint32_t TimingDelay;
void Delay(__IO uint32_t nTime){
	TimingDelay = nTime;
	while(TimingDelay != 0);
}

void SysTick_Handler(void){
	if (TimingDelay != 0x00)
		TimingDelay--;
}

int main(void) {
	GPIO_InitTypeDef GPIOC_init_params;
	SystemInit();
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
	GPIOC_init_params.GPIO_Pin = GPIO_Pin_12;
	GPIOC_init_params.GPIO_Speed = GPIO_Speed_50MHz;
	GPIOC_init_params.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOC, &GPIOC_init_params);
	GPIO_WriteBit(GPIOC,GPIO_Pin_12,Bit_SET);
	if(SysTick_Config(SystemCoreClock / 1000)){
		while (1);
	}
	__enable_irq();
	while(1){
		GPIOC->ODR ^= GPIO_Pin_12;
		Delay(50);
		GPIOC->ODR ^= GPIO_Pin_12;
		Delay(100);
	}
}


А вот — подправленный Makefile:

BIN=testproject

TOOLS_PATH=/usr/arm-none-eabi
TOOLS_PREFIX=arm-none-eabi-

CPFLAGS=-Obinary
ODFLAGS=-S

CFLAGS=-c -mcpu=cortex-m3 -mthumb -Wall  -mapcs-frame -D__thumb2__=1 -O0
CFLAGS+=-msoft-float -gdwarf-2 -mno-sched-prolog -fno-hosted -mtune=cortex-m3
CFLAGS+=-march=armv7-m -mfix-cortex-m3-ldrd -ffunction-sections -fdata-sections
CFLAGS+=-I./cmsis -I./stm32_lib -I.

LDFLAGS=-static -mcpu=cortex-m3 -mthumb -mthumb-interwork -Wl,--start-group
LDFLAGS+=-L$(TOOLS_PATH)/lib/thumb2 -lc -lg -lstdc++ -lsupc++ -lgcc -lm
LDFLAGS+=-Wl,--end-group -Xlinker -Map -Xlinker $(BIN).map -Xlinker
LDFLAGS+=-T ./stm32_lib/device_support/gcc/stm32f100rb_flash.ld -o $(BIN)

ASFLAGS=-mcpu=cortex-m3 -I./cmsis -I./stm32_lib -gdwarf-2 -gdwarf-2


CC=$(TOOLS_PREFIX)gcc
AS=$(TOOLS_PREFIX)as
SIZE=$(TOOLS_PREFIX)size
CP=$(TOOLS_PREFIX)objcopy
OD=$(TOOLS_PREFIX)objdump

CMSISSRC=./cmsis/core_cm3.c

STM32_LIBSRC=stm32_lib/system_stm32f10x.c
#~ STM32_LIBSRC+=stm32_lib/misc.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_adc.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_bkp.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_can.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_cec.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_crc.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_dac.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_dbgmcu.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_dma.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_exti.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_flash.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_fsmc.c
STM32_LIBSRC+=stm32_lib/stm32f10x_gpio.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_i2c.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_it.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_iwdg.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_pwr.c
STM32_LIBSRC+=stm32_lib/stm32f10x_rcc.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_rtc.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_sdio.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_spi.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_tim.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_usart.c
#~ STM32_LIBSRC+=stm32_lib/stm32f10x_wwdg.c

SRC=main.c

OBJ=core_cm3.o system_stm32f10x.o startup_stm32f10x_md_vl.o

#~ OBJ+=misc.o
#~ OBJ+=stm32f10x_adc.o
#~ OBJ+=stm32f10x_bkp.o
#~ OBJ+=stm32f10x_can.o
#~ OBJ+=stm32f10x_cec.o
#~ OBJ+=stm32f10x_crc.o
#~ OBJ+=stm32f10x_dac.o
#~ OBJ+=stm32f10x_dbgmcu.o
#~ OBJ+=stm32f10x_dma.o
#~ OBJ+=stm32f10x_exti.o
#~ OBJ+=stm32f10x_flash.o
#~ OBJ+=stm32f10x_fsmc.o
OBJ+=stm32f10x_gpio.o
#~ OBJ+=stm32f10x_i2c.o
#~ OBJ+=stm32f10x_it.o
#~ OBJ+=stm32f10x_iwdg.o
#~ OBJ+=stm32f10x_pwr.o
OBJ+=stm32f10x_rcc.o
#~ OBJ+=stm32f10x_rtc.o
#~ OBJ+=stm32f10x_sdio.o
#~ OBJ+=stm32f10x_spi.o
#~ OBJ+=stm32f10x_tim.o
#~ OBJ+=stm32f10x_usart.o
#~ OBJ+=stm32f10x_wwdg.o

OBJ+=main.o

all: ccmsis cstm32_lib cc ldall
	$(OD) $(ODFLAGS) $(BIN) > $(BIN).list
	$(SIZE) -B $(BIN)

ccmsis: $(CMSISSRC)
	$(CC) $(CFLAGS) $(CMSISSRC)

cstm32_lib: $(STM32_LIBSRC)
	$(CC) $(CFLAGS) $(STM32_LIBSRC)
	$(AS) $(ASFLAGS) ./stm32_lib/device_support/gcc/startup_stm32f10x_md_vl.S -o startup_stm32f10x_md_vl.o

cc: $(SRC)
	$(CC) $(CFLAGS) $(SRC)

ldall:
	$(CC) $(OBJ) $(LDFLAGS)
	$(CP) $(CPFLAGS) $(BIN) $(BIN).bin



.PHONY: clean load

clean:
	rm -f $(OBJ) $(BIN).map

load: $(BIN)
	st-flash write $(BIN).bin 0x08000000


Все, теперь компилируется и прошивается:

make
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -Wall  -mapcs-frame -D__thumb2__=1 -O0 -msoft-float -gdwarf-2 -mno-sched-prolog -fno-hosted -mtune=cortex-m3 -march=armv7-m -mfix-cortex-m3-ldrd -ffunction-sections -fdata-sections -I./cmsis -I./stm32_lib -I. ./cmsis/core_cm3.c
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -Wall  -mapcs-frame -D__thumb2__=1 -O0 -msoft-float -gdwarf-2 -mno-sched-prolog -fno-hosted -mtune=cortex-m3 -march=armv7-m -mfix-cortex-m3-ldrd -ffunction-sections -fdata-sections -I./cmsis -I./stm32_lib -I. stm32_lib/system_stm32f10x.c stm32_lib/stm32f10x_gpio.c stm32_lib/stm32f10x_rcc.c
arm-none-eabi-as -mcpu=cortex-m3 -I./cmsis -I./stm32_lib -gdwarf-2 -gdwarf-2 ./stm32_lib/device_support/gcc/startup_stm32f10x_md_vl.S -o startup_stm32f10x_md_vl.o
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -Wall  -mapcs-frame -D__thumb2__=1 -O0 -msoft-float -gdwarf-2 -mno-sched-prolog -fno-hosted -mtune=cortex-m3 -march=armv7-m -mfix-cortex-m3-ldrd -ffunction-sections -fdata-sections -I./cmsis -I./stm32_lib -I. main.c
arm-none-eabi-gcc core_cm3.o system_stm32f10x.o startup_stm32f10x_md_vl.o stm32f10x_gpio.o stm32f10x_rcc.o main.o -static -mcpu=cortex-m3 -mthumb -mthumb-interwork -Wl,--start-group -L/usr/arm-none-eabi/lib/thumb2 -lc -lg -lstdc++ -lsupc++ -lgcc -lm -Wl,--end-group -Xlinker -Map -Xlinker testproject.map -Xlinker -T ./stm32_lib/device_support/gcc/stm32f100rb_flash.ld -o testproject
arm-none-eabi-objcopy -Obinary testproject testproject.bin
arm-none-eabi-objdump -S testproject > testproject.list
arm-none-eabi-size -B testproject
   text	   data	    bss	    dec	    hex	filename
   7112	     56	    160	   7328	   1ca0	testproject


make load
st-flash write testproject.bin 0x08000000
2012-10-12T14:02:11 INFO src/stlink-usb.c: -- exit_dfu_mode
2012-10-12T14:02:11 INFO src/stlink-common.c: Loading device parameters....
2012-10-12T14:02:11 INFO src/stlink-common.c: Device connected is: F1 Medium-density device, id 0x20036410
2012-10-12T14:02:11 INFO src/stlink-common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2012-10-12T14:02:11 INFO src/stlink-common.c: Attempting to write 7168 (0x1c00) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08001800 erased
2012-10-12T14:02:11 INFO src/stlink-common.c: Finished erasing 7 pages of 1024 (0x400) bytes
2012-10-12T14:02:11 INFO src/stlink-common.c: Starting Flash write for VL core id
2012-10-12T14:02:11 INFO src/stlink-common.c: Successfully loaded flash loader in sram
  6/7 pages written
2012-10-12T14:02:12 INFO src/stlink-common.c: Starting verification of write complete
2012-10-12T14:02:12 INFO src/stlink-common.c: Flash written and verified! jolly good!


April 2025

S M T W T F S
  1 23 45
67 89101112
13141516171819
20212223242526
27282930   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 22nd, 2025 08:42 pm
Powered by Dreamwidth Studios