1—10章节,我称之为stm32移植ecos系列的第一篇章:让Redboot和eCos跑起来。从中可以看到,借助eCos本身带的ST STM3210E EVAL board模板和examples,几乎不需要做什么修改就让eCos在STM32板子上跑起来了。这一方面得意于我的板子与该模板对应的ST官方板子在存储器设计上大同小异,另一方面则是得意于eCos良好的架构设计,使系统移植变得轻而易举。

在展开ecos裁减、配置和驱动编写移植之前,我来说下如何创建和使用自己的模板(Template)。这里可能会有人问了:官方都提供了模板,还需要创建自己板子的模板吗?这不是多此一举吗?

是的,表面上看有点多余,但实际上更符合系统移植方法与步骤。

  • ecos自带的模板一般是基于芯片厂家的评估板而创建的。而我们使用的目标板或多或少与这些板有差异,甚至有比较大的差异,有时,目标板的CPU在ecos中没有相应的模板,这时候只能借鉴相近的模板展开移植,以降低难度和减少工作量;这就使我们有必要根据目标板创建自己的模板;
  • 使用自己的模板可尽量少的去修改ecos本身的代码,这样便于与ecos cvs服务器代码保持同步,而不至于引起代码冲突;
  • 创建自己的模板,更深入了解ecos的模板、package、component、cdl脚本、HAL的概念;

由于ecos优秀的架构设计,所以创建自己的模板也变得很容易。

1. 拷贝模板

在移植系统时,一般都会借鉴使用系统中板子硬件配置尽量相近的模板,linux如此,ecos亦如此。对于使用stm32f10xxx系列CPU的板子,ecos自带有ST STM3210E EVAL board这个模板。因此,移植ecos到stm32开发板时,我们可借鉴使用这个模板。

ecos源码packages\hal\cortexm\stm32\stm3210e_eval对应STM3210E EVAL board,复制stm3210e_eval文件夹,重新命名为:stm32f10xxx(名称自己取)。

2. 修改stm32f10xxx模板中文件名、内容等

拷贝并重命名后,修改其中的CDL及源码、LDI等文件,包括文件名及内容,我修改的时候,凡是遇到与stm3210e_eva相关的单词都替换成了stm32f10xxx。我把几个要修改的地方说明如下。

2.1 修改cdl文件名称及其内容

把cdl文件名称从hal_cortexm_stm32_stm3210e_eval.cdl改为hal_cortexm_stm32_stm32f10xxx.cdl。

修改CDL文件内容。修改之前,最好了解下CDL脚本的语法,不过,也容易,一看便知其意。在这个文件中,凡是STM3210E EVAL都替换成STM32F10XXX,凡是stm3210e_eval都替换成stm32f10xxx,凡是stm3210e eval都替换成stm32f10xxx platform,同时,去掉了CYGHWR_HAL_CORTEXM_STM32_SPIETH_CONTROLLER这个组件,修改了debug串口默认波特率为115200。修改后的CDL文件见下面。

2.2 修改stm32f10xxx\current\include\pkgconf目录下的文件名

把该目录下所有文件名称中的stm3210e_eval都替换成stm32f10xxx。

2.3 修改stm32f10xxx\current\include下plf_arch.h、plf_intr.h、plf_io.h文件中的头文件

这3个文件中,都包含了hal_cortexm_stm32_stm3210e_eval.h这个头文件,这个头文件的名称是在2.1中的CDL中定义的。

2.4 修改stm32f10xxx\current\src目录下的文件名

同样,把该目录下所有文件名称中的stm3210e_eval都替换成stm32f10xxx。同时,该目录下的源文件同样包含了hal_cortexm_stm32_stm3210e_eval.h这个头文件,这个头文件的名称是在2.1中的CDL中定义的。

3. 修改ecos.db,在文件的最后添加:

# added start by gyr 2013.02.22
package CYGPKG_HAL_CORTEXM_STM32_STM32F10XXX {
	alias		{ "ST STM32F10XXX HAL" hal_cortexm_stm32f10xxx }
	directory	hal/cortexm/stm32/stm32f10xxx
	script		hal_cortexm_stm32_stm32f10xxx.cdl
	hardware
        description "
        The stm32f10xxx HAL package provides the support needed to run
        eCos on the ST stm32f10xxx platform board."
}

target stm32f10xxx {
        alias { "ST STM32F10XXX platform board" stm32f10xxx }
        packages { CYGPKG_HAL_CORTEXM
                   CYGPKG_HAL_CORTEXM_STM32
                   CYGPKG_HAL_CORTEXM_STM32_STM32F10XXX                   
                   CYGPKG_DEVS_FLASH_AMD_AM29XXXXX_V2
                   CYGPKG_DEVS_FLASH_STM32
                   CYGPKG_DEVS_FLASH_SPI_M25PXX
                   CYGPKG_IO_SERIAL_CORTEXM_STM32
                   CYGPKG_DEVS_WALLCLOCK_STM32
                   CYGPKG_IO_SPI
                   CYGPKG_DEVS_SPI_CORTEXM_STM32
                   CYGPKG_DEVS_ADC_CORTEXM_STM32
                   CYGPKG_IO_USB
                   CYGPKG_IO_USB_SLAVE
                   CYGPKG_DEVS_USB_CORTEXM_STM32
                   CYGPKG_IO_FLASH            
                 }
        description "The stm32f10xxx target provides the packages needed
        to run eCos on the STM32F10XXX platform board."
}
# added end by gyr 2013.02.22

上述添加的东西是拷贝STM3210E EVAL board模板的(可用STM3210E作为关键字在ecos.db中搜索到这个target),并在此基础上修改了相应名称和描述,以及多加了flash包:CYGPKG_IO_FLASH。

到此,完成了模板的创建。重新打开ecos图形配置工具,则看到我们创建的模板“ST STM32F10XXX platform board”了。重新生成redboot.ecc和ecos.ecc(注意生成redboot时,不能使用misc目录下的redboot_ROM.ecm配置文件了,否则图形配置工具会闪退,原因不知)。

对这个模板进行了验证,生成的redboot(ROM启动),helloworld程序(ROM启动)都可正常启动,但helloworld程序配成RAM启动后,不能用redboot引导内存中的helloworld程序。

附上我修改的CDL文件内容:

##==========================================================================
##
##      hal_cortexm_stm32_stm32f10xxx.cdl
##
##      Cortex-M STM32F10XXX platform HAL configuration data
##
##==========================================================================
## ####ECOSGPLCOPYRIGHTBEGIN####                                            
## -------------------------------------------                              
## This file is part of eCos, the Embedded Configurable Operating System.   
## Copyright (C) 2008, 2012 Free Software Foundation, Inc.
##
## eCos is free software; you can redistribute it and/or modify it under    
## the terms of the GNU General Public License as published by the Free     
## Software Foundation; either version 2 or (at your option) any later      
## version.                                                                 
##
## eCos is distributed in the hope that it will be useful, but WITHOUT      
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
## for more details.                                                        
##
## You should have received a copy of the GNU General Public License        
## along with eCos; if not, write to the Free Software Foundation, Inc.,    
## 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
##
## As a special exception, if other files instantiate templates or use      
## macros or inline functions from this file, or you compile this file      
## and link it with other works to produce a work based on this file,       
## this file does not by itself cause the resulting work to be covered by   
## the GNU General Public License. However the source code for this file    
## must still be made available in accordance with section (3) of the GNU   
## General Public License v2.                                               
##
## This exception does not invalidate any other reasons why a work based    
## on this file might be covered by the GNU General Public License.         
## -------------------------------------------                              
## ####ECOSGPLCOPYRIGHTEND####                                              
##==========================================================================
#######DESCRIPTIONBEGIN####
##
## Author(s):    reille
## Date:         2013-02-22
##
######DESCRIPTIONEND####
##
##==========================================================================

cdl_package CYGPKG_HAL_CORTEXM_STM32_STM32F10XXX {
    display       "ST STM32F10XXX Development Board HAL"
    parent        CYGPKG_HAL_CORTEXM_STM32
    requires      { CYGHWR_HAL_CORTEXM_STM32_FAMILY == "F1" }
    requires      { CYGHWR_HAL_CORTEXM_STM32_F1 == "F103ZE" }
    define_header hal_cortexm_stm32_stm32f10xxx.h
    include_dir   cyg/hal
    hardware
    description   "
        The STM32F10XXX HAL package provides the support needed to run
        eCos on the ST stm32f10xxx platform board."

    compile       stm32f10xxx_misc.c

    define_proc {
        puts $::cdl_system_header "#define CYGBLD_HAL_TARGET_H   <pkgconf/hal_cortexm.h>"
        puts $::cdl_system_header "#define CYGBLD_HAL_VARIANT_H  <pkgconf/hal_cortexm_stm32.h>"
        puts $::cdl_system_header "#define CYGBLD_HAL_PLATFORM_H <pkgconf/hal_cortexm_stm32_stm32f10xxx.h>"
	puts $::cdl_header "#define HAL_PLATFORM_CPU    \"Cortex-M3\""
        puts $::cdl_header "#define HAL_PLATFORM_BOARD  \"ST STM32F10XXX\""
        puts $::cdl_header "#define HAL_PLATFORM_EXTRA  \"\""
    }

    cdl_component CYG_HAL_STARTUP {
        display       "Startup type"
        flavor        data
        default_value {"RAM"}
        legal_values  {"RAM" "SRAM" "ROM" "JTAG"}
	no_define
	define -file system.h CYG_HAL_STARTUP
        description   "
            When targetting the ST STM32F10XXX platform board it is possible to
            build the system for either RAM bootstrap or ROM bootstrap.
            Select 'RAM' when building programs to load into RAM using onboard
            debug software such as RedBoot or eCos GDB stubs.  Select 'ROM'
            when building a stand-alone application which will be put
            into ROM. The 'JTAG' type allows programs to be downloaded using a
            JTAG debugger such as a BDI3000 or PEEDI. The 'SRAM' type allows
            programs to be downloaded via a JTAG debugger into on-chip SRAM."
    }

    cdl_component CYGHWR_MEMORY_LAYOUT {
        display "Memory layout"
        flavor data
        no_define
        calculated    { (CYG_HAL_STARTUP == "RAM" ) ? 
                        (CYGMEM_HAL_CORTEXM_STM32_STM32F10XXX_EXTRA_BASE_RAM ?
                        "cortexm_stm32f10xxx_extrabaseram" : "cortexm_stm32f10xxx_ram")      :
                        (CYG_HAL_STARTUP == "SRAM") ? "cortexm_stm32f10xxx_sram"     :
                        (CYG_HAL_STARTUP == "ROM" ) ? "cortexm_stm32f10xxx_rom"      :
                        (CYG_HAL_STARTUP == "JTAG") ? "cortexm_stm32f10xxx_jtag"     :
                                                      "undefined" }

        cdl_option CYGMEM_HAL_CORTEXM_STM32_STM32F10XXX_EXTRA_BASE_RAM {
            display       "Additional reserved space at base of RAM"
            flavor        booldata
            default_value 0
            active_if     {CYG_HAL_STARTUP == "RAM"}
            legal_values  0 to 0x80000
            description   "
                If you are using a RedBoot with additional components enabled,
                such as networking, RedBoot may be occupying additional RAM.
                In such cases, an eCos application loaded by RedBoot must
                reserve additional space at the base of RAM to accommodate
                RedBoot's extra RAM requirements. This option, specified in
                bytes, allows the amount of extra reserved space to be
                increased beyond the default."
        }

        cdl_option CYGHWR_MEMORY_LAYOUT_LDI {
                display "Memory layout linker script fragment"
                flavor data
                no_define
                define -file system.h CYGHWR_MEMORY_LAYOUT_LDI
                calculated { "<pkgconf/mlt_" . CYGHWR_MEMORY_LAYOUT . ".ldi>" }
        }

        cdl_option CYGHWR_MEMORY_LAYOUT_H {
                display "Memory layout header file"
                flavor data
                no_define
                define -file system.h CYGHWR_MEMORY_LAYOUT_H
                calculated { "<pkgconf/mlt_" . CYGHWR_MEMORY_LAYOUT . ".h>" }
        }

    }

    cdl_option CYGARC_HAL_CORTEXM_STM32_INPUT_CLOCK {
        display         "Input Clock frequency"
        flavor          data
        default_value   8000000
        legal_values    0 to 1000000000
        description     "Main clock input."
    }

    cdl_component CYGHWR_HAL_CORTEXM_STM32_FLASH {
        display         "Flash support"
        parent          CYGPKG_IO_FLASH
        active_if       CYGPKG_IO_FLASH
        compile         -library=libextras.a stm32f10xxx_flash.c
        default_value   1
        description     "Control flash device support for stm32f10xxx platform board."

        cdl_option CYGHWR_HAL_CORTEXM_STM32_FLASH_INTERNAL {
            display         "Internal flash support"
            default_value   1
            description     "This option enables support for the internal flash device."
        }

        cdl_option CYGHWR_HAL_CORTEXM_STM32_FLASH_NOR {
            display         "External NOR flash support"
            default_value   1
            description     "This option enables support for the external NOR flash device."
        }

    }

    # Both UARTs 0 and 1 are available for diagnostic/debug use.
    implements CYGINT_HAL_STM32_UART0
    implements CYGINT_HAL_STM32_UART1

    implements      CYGINT_IO_SERIAL_FLOW_CONTROL_HW
    implements      CYGINT_IO_SERIAL_LINE_STATUS_HW

    cdl_option CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS {
        display      "Number of communication channels on the board"
        flavor       data
        calculated   2
    }

    cdl_option CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL {
        display          "Debug serial port"
        active_if        CYGPRI_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL_CONFIGURABLE
        flavor data
        legal_values     0 to CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS-1
        default_value    0
        description      "
            The ST STM32F10XXX platform board has two serial ports. This option
            chooses which port will be used to connect to a host
            running GDB."
     }

     cdl_option CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL {
         display          "Diagnostic serial port"
         active_if        CYGPRI_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_CONFIGURABLE
         flavor data
         legal_values     0 to CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS-1
         default_value    0
         description      "
            The ST STM32F10XXX has two serial ports. This option
            chooses which port will be used for diagnostic output."
     }

    cdl_option CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD {
        display       "Console serial port baud rate"
        flavor        data
        legal_values  9600 19200 38400 57600 115200
        default_value 115200
        description   "
            This option controls the default baud rate used for the
            console connection.
            RedBoot usess polling to transfer data over this port and
            might not be able to keep up with baud rates above the
            default, particularly when doing XYZmodem downloads. The
            interrupt-driven device driver is able to handle these
            baud rates, so any high speed application transfers should
            use that instead.
            Note: this should match the value chosen for the GDB port if the
            diagnostic and GDB port are the same."
    }

    cdl_option CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL_BAUD {
        display       "GDB serial port baud rate"
        flavor        data
        legal_values  9600 19200 38400 57600 115200
        default_value 115200
        description   "
            This option controls the default baud rate used for the
            GDB connection.
            RedBoot usess polling to transfer data over this port and
            might not be able to keep up with baud rates above the
            default, particularly when doing XYZmodem downloads. The
            interrupt-driven device driver is able to handle these
            baud rates, so any high speed application transfers should
            use that instead.
            Note: this should match the value chosen for the console port if the
            console and GDB port are the same."
    }

    cdl_component CYGBLD_GLOBAL_OPTIONS {
        display "Global build options"
        flavor  none
        parent  CYGPKG_NONE
        description   "
	    Global build options including control over
	    compiler flags, linker flags and choice of toolchain."

        cdl_option CYGBLD_GLOBAL_COMMAND_PREFIX {
            display "Global command prefix"
            flavor  data
            no_define
            default_value { "arm-eabi" }
            description "
                This option specifies the command prefix used when
                invoking the build tools."
        }

        cdl_option CYGBLD_GLOBAL_CFLAGS {
            display "Global compiler flags"
            flavor  data
            no_define
            default_value { CYGBLD_GLOBAL_WARNFLAGS . "-mcpu=cortex-m3 -mthumb -g -O2 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions" }
            description   "
                This option controls the global compiler flags which are used to
                compile all packages by default. Individual packages may define
                options which override these global flags."
        }

        cdl_option CYGBLD_GLOBAL_LDFLAGS {
            display "Global linker flags"
            flavor  data
            no_define
            default_value { "-mcpu=cortex-m3 -mthumb -Wl,--gc-sections -Wl,-static -Wl,-n -g -nostdlib" }
            description   "
                This option controls the global linker flags. Individual
                packages may define options which override these global flags."
        }
    }

    cdl_component CYGPKG_HAL_CORTEXM_STM32_STM32F10XXX_OPTIONS {
        display "stm32f10xxx HAL build options"
                flavor  none
                description   "
                        Package specific build options including control over
                        compiler flags used only in building this HAL."

                cdl_option CYGPKG_HAL_CORTEXM_STM32_STM32F10XXX_CFLAGS_ADD {
                        display "Additional compiler flags"
                        flavor  data
                        no_define
                        default_value { "-Werror" }
                        description   "
                                This option modifies the set of compiler flags
                                for building this HAL. These flags are used
                                in addition to the set of global flags."
                        }
                cdl_option CYGPKG_HAL_CORTEXM_STM32_STM32F10XXX_CFLAGS_REMOVE {
                        display "Suppressed compiler flags"
                        flavor  data
                        no_define
                        default_value { "" }
                        description   "
                                This option modifies the set of compiler flags
                                for building this HAL. These flags are
                                removed from the set of global flags if
                                present."
                }
        }

    cdl_option CYGSEM_HAL_ROM_MONITOR {
        display       "Behave as a ROM monitor"
        flavor        bool
        default_value 0
        parent        CYGPKG_HAL_ROM_MONITOR
        requires      { CYG_HAL_STARTUP == "ROM" || CYG_HAL_STARTUP == "JTAG" }
        requires      { CYGDBG_HAL_CRCTABLE_LOCATION == "ROM" }
        description   "
            Enable this option if this program is to be used as a ROM monitor,
            i.e. applications will be loaded into RAM on the board, and this
            ROM monitor may process exceptions or interrupts generated from the
            application. This enables features such as utilizing a separate
            interrupt stack when exceptions are generated."
    }

    cdl_option CYGSEM_HAL_USE_ROM_MONITOR {
         display       "Work with a ROM monitor"
         flavor        booldata
         legal_values  { "Generic" "GDB_stubs" }
         default_value { CYG_HAL_STARTUP == "RAM" ? "GDB_stubs" : 0 }
         parent        CYGPKG_HAL_ROM_MONITOR
         requires      { CYG_HAL_STARTUP == "RAM" }
         description   "
             Support can be enabled for different varieties of ROM monitor.
             This support changes various eCos semantics such as the encoding
             of diagnostic output, or the overriding of hardware interrupt
             vectors.
             Firstly there is \"Generic\" support which prevents the HAL
             from overriding the hardware vectors that it does not use, to
             instead allow an installed ROM monitor to handle them. This is
             the most basic support which is likely to be common to most
             implementations of ROM monitor.
             \"GDB_stubs\" provides support when GDB stubs are included in
             the ROM monitor or boot ROM."
     }

    cdl_component CYGPKG_REDBOOT_HAL_OPTIONS {
        display       "Redboot HAL options"
        flavor        none
        no_define
        parent        CYGPKG_REDBOOT
        active_if     CYGPKG_REDBOOT
        description   "
            This option lists the target's requirements for a valid Redboot
            configuration."

        requires { CYGNUM_REDBOOT_FLASH_BASE == 0x64000000 }
        requires { CYGBLD_REDBOOT_MAX_MEM_SEGMENTS == 2 }

        cdl_option CYGBLD_BUILD_REDBOOT_BIN {
            display       "Build Redboot ROM binary images"
            active_if     CYGBLD_BUILD_REDBOOT
            default_value 1
            no_define
            description "This option enables the conversion of the Redboot ELF
                         image to binary image formats suitable for ROM programming."

            make -priority 325 {
                <PREFIX>/bin/redboot.bin : <PREFIX>/bin/redboot.elf
                $(OBJCOPY) --strip-debug $< $(@:.bin=.img)
                $(OBJCOPY) -O srec $< $(@:.bin=.srec)
                $(OBJCOPY) -O binary $< $@
            }
        }
    }

    cdl_component CYGBLD_HAL_CORTEXM_STM32F10XXX_GDB_STUBS {
        display "Create StubROM SREC and binary files"
        active_if CYGBLD_BUILD_COMMON_GDB_STUBS
        no_define
        calculated 1
        requires { CYG_HAL_STARTUP == "ROM" }

        make -priority 325 {
                <PREFIX>/bin/stubrom.srec : <PREFIX>/bin/gdb_module.img
                $(OBJCOPY) -O srec $< $@
        }
        make -priority 325 {
                <PREFIX>/bin/stubrom.bin : <PREFIX>/bin/gdb_module.img
                $(OBJCOPY) -O binary $< $@
        }

        description "This component causes the ELF image generated by the
                     build process to be converted to S-Record and binary
                     files."
    }
}
» 文章出处: reille博客—http://velep.com , 如果没有特别声明,文章均为reille博客原创作品
» 郑重声明: 原创作品未经允许不得转载,如需转载请联系reille#qq.com(#换成@)
分享到:

  4 Responses to “stm32移植ecos #11,使用自己的模板(Template)”

  1. 请问那些中断怎样配置?谢谢

  2. 期待你弄个不用外部存储器的STM32配置。我已经在linux系统上搭好环境了,不过只能选一种stm32配置,而且必须有外部nor sram的。

 Leave a Reply

(必须)

(我会替您保密的)(必须)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

   
© 2012 velep.com | reille blog | 管理| 粤ICP备15065318号-2| 谷歌地图| 百度地图| Suffusion theme|Sayontan Sinha

无觅相关文章插件,快速提升流量