Establishing stm32 development environment under ubuntu: GCC installation and project Makefile establishment

Publisher:星光小狐狸Latest update time:2018-10-13 Source: eefocusKeywords:ubuntu  stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

environment:

              ubuntu 13.10

              stm32f103zet6

 1. STM 32 GCC Installation

stm32 belongs to the arm cortex-m series thumb instruction set, so arm-none-eabi is enough for arm. First, download

Download address: https://launchpad .NET /gcc-arm-embedded/+download

Download gcc-arm-none-eabi-version-linux.tar.bz2

Unzip to a directory you know will produce a gcc-arm-none-eabi folder

Add the compiler to your environment: sudo gedit ~/.bashrc


Add to the last line: Because I have added the Raspberry Pi compiler before, it is actually like this:
export PATH=$PATH:/your_pi_gcc_dir/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/:/your_stm_gcc_dir/gcc-arm-none-eabi-4_8-2013q4/bin
 
The two compiler environments are separated by a colon;

Test after logout : arm-none-eabi-gcc -v

You can check the version of the compiler, which means it is OK.


2. Establishment of Engineering Environment

Create a new project folder and its directory:
             mkdir stm_project 
             cd stm_project 
             mkdir libs 
             mkdir src 
             mkdir inc

Download and install the official library:


The registers of stm32 are not as few as those of 51 avr and other microcontrollers. You can just write the library and memorize the registers by yourself. Therefore, ST company provides their official library. In order to avoid reinventing the wheel, we directly use their library. The library version is STM32_USB-FS-Device_Lib_V4.0.0. This library has more USB support. If you want to download it, go to the st official website and search for stm32f10x.


Download link: http://download.csdn.net/detail/canyue102/6778837

Here are the places that need to be modified. According to the chip model, select the corresponding RAM FLASH size

MEMORY { 
        //Adust LENGTH to RAMsize of target MCU: 
        //STM32F103RBT --> 20K 
        //RAM (RWX) : ORIGIN = 0x20000000 , LENGTH = 20K 
        //STM32F103RET --> 64K 
        //STM32F103ZET --> 64K 
        RAM (RWX) : ORIGIN = 0x20000000 , LENGTH = 64K 
        EXTSRAM (RWX) : ORIGIN = 0x68000000 , LENGTH = 0 
        //Adust LENGTH to (FLASHsize - FeePROMsize) of target MCU: 
        //STM32F103RBT --> 126K 
        FLASH (RX) : ORIGIN = 0x08000000 , LENGTH = 126K 
        //STM32F103RET --> 508K 
        //FLASH (RX) : ORIGIN = 0x08000000 , LENGTH = 508K 
        //STM32F103ZET --> 508K 
        FLASH (RX) : ORIGIN = 0x08000000 , LENGTH = 508K 
        //Adust ORIGIN to (0x08000000 + (FLASHsize-FeePROMsize)) of target MCU 
        //and adust LENGTH to FeePROMsize allocated: 
        //STM32F103RBT --> 0x08000000+126K, 2K 
        EEMUL (RWX) : ORIGIN = 0x08000000+126K, LENGTH = 2K 
        //STM32F103RET --> 0x08000000+508K, 4K 
        //EEMUL (RWX) : ORIGIN = 0x08000000+508K, LENGTH = 4K 
    }


Create a new Makefile in the project root directory:
    # general Makefile 
     
    include Makefile.common 
    LDFLAGS=$(COMMONFLAGS) -fno-exceptions -ffunction-sections -fdata-sections -L$(LIBDIR) -nostartfiles -Wl,--gc-sections,-Tlinker.ld 
     
    LDLIBS+=-lm 
    LDLIBS+=-lstm32 
     
    STARTUP=startup.c 
     
    all: libs src 
        $(CC) -o $(PROGRAM).elf $(LDFLAGS) \ 
            -Wl,--whole-archive \ 
                src/app.a \ 
            -Wl,--no-whole-archive \ 
                $(LDLIBS) 
        $(OBJCOPY) -O ihex $(PROGRAM).elf $(PROGRAM).hex 
        $(OBJCOPY) -O binary $(PROGRAM).elf $(PROGRAM).bin 
    #Extract info contained in ELF to readable text-files: 
        arm-none-eabi-readelf -a $(PROGRAM).elf > $(PROGRAM). info_elf 
        arm-none-eabi-size -d -B -t $(PROGRAM).elf > $(PROGRAM).info_size 
        arm-none-eabi-objdump -S $(PROGRAM).elf > $(PROGRAM).info_code 
        arm-none-eabi-nm -td -S --size-sort -s $(PROGRAM).elf > $(PROGRAM).info_symbol 
     
    .PHONY: libs src clean tshow 
     
    libs: 
        $(MAKE) -C libs $@ 
    src: 
        $(MAKE) -C src $@ 
    clean: 
        $(MAKE) -C src $@ 
        $(MAKE) -C libs $@ 
        rm -f $(PROGRAM).elf $(PROGRAM).hex $(PROGRAM).bin $(PROGRAM).info_elf $(PROGRAM).info_size 
        rm -f $(PROGRAM).info_code 
        rm -f $(PROGRAM).info_symbol 
    tshow: 
            @echo "################################### ################################################ ################" 
            @echo "################ optimize settings: $(InfoTextLib), $(InfoTextSrc)" 
            @echo "################################################# ################################################## ###" 

It's almost done, add the test source code in src

Mainly startup.c and main.c, I won't explain them here, you can view the pdf or go to my resource download

http://download.csdn.net/detail/canyue102/6778885

Then enter the main directory of the project and download make.

make clean 
make OptLIB=0 OptSRC=0 all tshow


Then, it's done. For more information about burning programs to stm32 under ubuntu, please see the next blog


Keywords:ubuntu  stm32 Reference address:Establishing stm32 development environment under ubuntu: GCC installation and project Makefile establishment

Previous article:Establishing stm32 development environment under ubuntu: burning program openocd+openjtag
Next article:STM32CubeMX Tutorial Series

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号