반응형

 




참고

https://launchpadlibrarian.net/192227680/readme.txt

https://liviube.wordpress.com/2013/04/22/blink-for-stm32f4-discovery-board-on-linux-with-makefile/

 

구입해놓고 먼지가 잔뜩 쌓여있던 cortex 보드를 개봉했다.

그리고 gcc환경에서 컴파일하고 보드로 올리는 방법들을 찾아봤다.

 

 

ToolChain 설치

$ sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded

$ sudo apt-get update

$ sudo apt-get install gcc-arm-none-eabi

 

webnautes@virtual-machine:~$ arm-none-eabi-gcc --version

arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20141119 (release) [ARM/embedded-4_9-branch revision 218278]

Copyright (C) 2014 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

보드 펌웨어 패키지 및 예제 다운로드

http://www.st.com/web/en/catalog/tools/PF257904 에서 보드 펌웨어 패키지 다운로드

$ unzip stsw-stm32068.zip

$ sudo mv STM32F4-Discovery_FW_V1.1.0/ /opt/

 

예제코드 위치

$ ls /opt/STM32F4-Discovery_FW_V1.1.0/Project/Peripheral_Examples/

ADC3_DMA IO_Toggle Release_Notes.html

ADC_Interleaved_DMAmode2 IWDG SysTick

DAC_SignalsGeneration MEMS TIM_ComplementarySignals

DMA_FLASH_RAM PWR_CurrentConsumption TIM_PWM_Input

EXTI PWR_STANDBY TIM_PWM_Output

FLASH_Program PWR_STOP TIM_TimeBase

FLASH_Write_Protection RCC

 

Stlink 유틸리티 설치

$ git clone https://github.com/texane/stlink.git

$ cd stlink

$ sudo apt-get install autoconf

$ ./autogen.sh

$ ./configure

$ make

$ sudo make install

 

샘플 코드 동작 시켜보기

$ git clone https://github.com/Malkavian/tuts.git

$ cd tuts/stm/blinky

$ ls -l

합계 56

-rwxrwxr-x 1 webnautes webnautes 3816 1월 11 17:37 Makefile

-rw-rw-r-- 1 webnautes webnautes 7700 1월 11 17:37 Readme.md

-rw-rw-r-- 1 webnautes webnautes 5490 1월 11 17:37 main.c

-rwxrwxr-x 1 webnautes webnautes 4823 1월 11 17:37 stm32_flash.ld

-rwxrwxr-x 1 webnautes webnautes 3870 1월 11 17:37 stm32f4xx_conf.h

-rwxrwxr-x 1 webnautes webnautes 21726 1월 11 17:37 system_stm32f4xx.c

 

Makefile 에서 아래 부분을 보드 펌웨어 복사해둔 위치로 수정

STM_DIR=/opt/STM32F4-Discovery_FW_V1.1.0

 

Makefile에서 툴체인 설정 부분도 아래처럼 수정

# The tool we use

CC = arm-none-eabi-gcc

OBJCOPY = arm-none-eabi-objcopy

GDB = arm-none-eabi-gdb

 

컴파일을 해보면 잘됨.

$ make

arm-none-eabi-gcc -I/opt/STM32F4-Discovery_FW_V1.1.0/Utilities/STM32F4-Discovery -I/opt/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include -I/opt/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include -I/opt/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/inc -I. -DUSE_STDPERIPH_DRIVER -ggdb -O0 -Wall -Wextra -Warray-bounds -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Tstm32_flash.ld main.c system_stm32f4xx.c /opt/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c /opt/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c /opt/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/TrueSTUDIO/startup_stm32f4xx.s -o blinky.elf

arm-none-eabi-objcopy -O ihex blinky.elf blinky.hex

arm-none-eabi-objcopy -O binary blinky.elf blinky.bin

 

보드에 올리기 위해서 컴퓨터랑 USB 케이블을 이용하여 연결하고 다음 명령을 실행

$ sudo make flash

sudo: unable to resolve host virtual-machine

st-flash write blinky.bin 0x8000000

2015-01-11T18:31:22 INFO src/stlink-usb.c: -- exit_dfu_mode

2015-01-11T18:31:22 INFO src/stlink-common.c: Loading device parameters....

2015-01-11T18:31:22 INFO src/stlink-common.c: Device connected is: F4 device, id 0x10016413

2015-01-11T18:31:22 INFO src/stlink-common.c: SRAM size: 0x30000 bytes (192 KiB), Flash: 0x100000 bytes (1024 KiB) in pages of 16384 bytes

2015-01-11T18:31:22 INFO src/stlink-common.c: Attempting to write 7304 (0x1c88) bytes to stm32 address: 134217728 (0x8000000)

EraseFlash - Sector:0x0 Size:0x4000

Flash page at addr: 0x08000000 erased

2015-01-11T18:31:23 INFO src/stlink-common.c: Finished erasing 1 pages of 16384 (0x4000) bytes

2015-01-11T18:31:23 INFO src/stlink-common.c: Starting Flash write for F2/F4

2015-01-11T18:31:23 INFO src/stlink-common.c: Successfully loaded flash loader in sram

size: 7304

2015-01-11T18:31:23 INFO src/stlink-common.c: Starting verification of write complete

2015-01-11T18:31:23 INFO src/stlink-common.c: Flash written and verified! jolly good!

 

 

소스코드를 읽어보고 PD12~PD15사이에 LED를 연결해보니 깜빡거리는 것을 확인해볼 수 있음.

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts