SRAM初始化和设置NVIC中断表偏移

//=====================================================================
//TITLE:
//    SRAM初始化和设置NVIC中断表偏移
//AUTHOR:
//    norains
//DATE:
//    Friday  8-October-2010
//Environment:
//    KEIL MDK 4.0
//    .NET Micro Framework Porting 4.1
//    RedCow Board
//=====================================================================

 

 

     关于SRAM的初始化和NVIC的设置,其实在叶帆的《【.Net Micro Framework PortingKit - 05】SRAM初始化&设置NVIC中断表偏移》(http://blog.csdn.net/yefanqiu/archive/2010/01/03/5125786.aspx)已经有过详细的描述,只不过我并不太喜欢直接在微软的代码上直接修改,所以才有了本文的一系列繁琐的设置。两种方法各有利弊,大家可以随自己的喜好进行选择。另外,在此注明一下,本文所涉及到的所有代码部分,都来源于叶帆的文章。

 

    1.在我们自己的Solution下以此路径建立一系列文件夹:./Solutions/[MySolution]/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit

 


    2.将./Solution /DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit/dotNetMF.proj拷贝到./Solutions/[MySolution]/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit,将dotNetMF.proj文件中相关联地路径改为绝对路径。可能修改有点麻烦,现在将完整的内容列举如下,需要注意的是STM32F103ZE_RedCow是我的Solution名字,请各位读者根据实际情况进行改写。完整内容如下:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AssemblyName>cpu_prestackinit_stubs</AssemblyName>
    <ProjectGuid>{19b183cc-474f-47ce-a544-390acc3e2b62}</ProjectGuid>
    <Size>
    </Size>
    <Description>Pre stack initialization stub driver</Description>
    <Level>HAL</Level>
    <LibraryFile>cpu_prestackinit_stubs.$(LIB_EXT)</LibraryFile>
    <ProjectPath>$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInitdotNetMF.proj</ProjectPath>
    <ManifestFile>cpu_prestackinit_stubs.$(LIB_EXT).manifest</ManifestFile>
    <Groups>Processor/stubs</Groups>
    <LibraryCategory>
      <MFComponent xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="PreStackInit_HAL" Guid="{5A9E3217-7D6D-40de-A685-28BA44D31E9A}" ProjectPath="" Conditional="" xmlns="">
        <VersionDependency xmlns="
http://schemas.microsoft.com/netmf/InventoryFormat.xsd">
          <Major>4</Major>
          <Minor>0</Minor>
          <Revision>0</Revision>
          <Build>0</Build>
          <Extra />
          <Date>2009-04-30</Date>
          <Author>Microsoft</Author>
        </VersionDependency>
        <ComponentType xmlns="
http://schemas.microsoft.com/netmf/InventoryFormat.xsd">LibraryCategory</ComponentType>
      </MFComponent>
    </LibraryCategory>
    <Documentation>
    </Documentation>
    <PlatformIndependent>False</PlatformIndependent>
    <CustomFilter>
    </CustomFilter>
    <Required>False</Required>
    <IgnoreDefaultLibPath>False</IgnoreDefaultLibPath>
    <IsStub>True</IsStub>
    <HasLibraryCategory>True</HasLibraryCategory>
    <Directory>/Solutions/STM32F103ZE_RedCow/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit</Directory>
    <PlatformIndependentBuild>false</PlatformIndependentBuild>
    <Version>4.0.0.0</Version>
  </PropertyGroup>
  <Import Project="$(SPOCLIENT)/tools/targets/Microsoft.SPOT.System.Settings" />
  <PropertyGroup>
    <OutputType  >Library</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="$(SPOCLIENT)/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit/$(AS_SUBDIR)/PreStackInit_stub.s" />
  </ItemGroup>
  <ItemGroup />
  <Import Project="$(SPOCLIENT)/tools/targets/Microsoft.SPOT.System.Targets" />
</Project>

 


    3.打开NativeSample.proj文件,将依赖的工程做修改。

 

原语句:
<RequiredProjects Include="$(SPOCLIENT)/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit/dotNetMF.proj" />

 

更改为:
<RequiredProjects Include="$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit/dotNetMF.proj" />

 修改完毕之后,最后调用msbuild命令来编译一次,以确定修改正确。当确定修改正确之后,我们就可以进入下一步了。

 


    4.将./DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit/RVD_S/PreStackInit_stub.S文件拷贝到./Solutions/STM32F103ZE_RedCow/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit/RVDS路径。然后再次用文本编辑器打开之前我们修改好的./Solutions/[MySolution]/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit/dotNetMF.proj文件,并做如下修改。

 

     原语句:
<Compile Include="$(SPOCLIENT)/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit/$(AS_SUBDIR)/PreStackInit_stub.s" />

 

     修改为:
<Compile Include="$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/Drivers/Stubs/Processor/stubs_PreStackInit/RVDS/PreStackInit_stub.s" />

 

    修改完毕后,再一次编译NativeSample工程,以确保路径修改正确。当这一步也能够正常编译通过之后,那么接下来我们就可以着手修改PreStackInit_stub.s文件了。

 


    5. 用文本编辑器打开拷贝过来的PreStackInit_stub.s文件,完善PreStackInit函数。为了简单起见,这里直接将所有的源代码贴出来:

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Microsoft Corporation.  All rights reserved.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    EXPORT  PreStackInit

    IMPORT  PreStackInit_Exit_Pointer

    PRESERVE8

    AREA SectionForBootstrapOperations, CODE, READONLY

    ENTRY

    ; ARM directive is only valid for ARM/THUMB processor, but not CORTEX
    IF :DEF:COMPILE_ARM :LOR: :DEF:COMPILE_THUMB 
    ARM
    ENDIF   

PreStackInit


    ;*************************************************************************
    ;
    ; TODO: Enter your pre stack initialization code here (if needed)
    ;       e.g. SDRAM initialization if you don't have/use SRAM for the stack
    ;
   
    ;Initialize the SRAM
  ; Enable FSMC clock
  LDR R0,= 0x00000114
  LDR R1,= 0x40021014
  STR R0,[R1]                 
                
  ; Enable GPIOD, GPIOE, GPIOF and GPIOG clocks
  LDR R0,= 0x000001E0
  LDR R1,= 0x40021018
  STR R0,[R1]     
 
  ; SRAM Data lines, NOE and NWE configuration
  ; SRAM Address lines configuration
  ; NOE and NWE configuration 
  ; NE3 configuration
  ; NBL0, NBL1 configuration
 
  LDR R0,= 0x44BB44BB
  LDR R1,= 0x40011400
  STR R0,[R1]           
         
  LDR R0,= 0xBBBBBBBB
  LDR R1,= 0x40011404
  STR R0,[R1]           
         
  LDR R0,= 0xB44444BB
  LDR R1,= 0x40011800
  STR R0,[R1]           
 
  LDR R0,= 0xBBBBBBBB
  LDR R1,= 0x40011804
  STR R0,[R1]           
 
  LDR R0,= 0x44BBBBBB
  LDR R1,= 0x40011C00
  STR R0,[R1]      
 
  LDR R0,= 0xBBBB4444
  LDR R1,= 0x40011C04
  STR R0,[R1]      
 
  LDR R0,= 0x44BBBBBB
  LDR R1,= 0x40012000
  STR R0,[R1]           
 
  LDR R0,= 0x44444B44
  LDR R1,= 0x40012004
  STR R0,[R1]    
                                            
  ; FSMC Configuration 
  ; Enable FSMC Bank1_SRAM Bank
                 
  LDR R0,= 0x00001000
  LDR R1,= 0xA0000010
  STR R0,[R1]    
 
  LDR R0,= 0x00000200
  LDR R1,= 0xA0000014
  STR R0,[R1]    
    
  LDR R0,= 0x0FFFFFFF
  LDR R1,= 0xA0000114
  STR R0,[R1]    
    
  LDR R0,= 0x00001001
  LDR R1,= 0xA0000010
  STR R0,[R1]    
      
  ; Reset the vector list address to the begin of SRAM which is 0x20000000
  IF TargetLocation="RAM"
      LDR R0,= 0x20000000
      LDR R1,= 0xE000ED08
      STR R0,[R1]    
  ENDIF

    ;*************************************************************************
    ; DO NOT CHANGE THE FOLLOWING CODE! we can not use pop to return because we
    ; loaded the PC register to get here (since the stack has not been initialized). 
    ; Make sure the PreStackInit_Exit_Pointer is within range and
    ; in the SectionForBootstrapOperations
    ; go back to the firstentry(_loader) code
    ;
    ;
PreStackEnd
    B     PreStackInit_Exit_Pointer

    ;
    ;**************************************************************************
    IF :DEF:COMPILE_THUMB 
    THUMB
    ENDIF  


    END

 

posted @ 2010-10-08 11:02  我的一天  阅读(796)  评论(0编辑  收藏  举报