欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

STM32F030 IAP升级编写总结

程序员文章站 2024-02-25 15:00:15
...

现阶段有个STM32F030的项目,要从STM32F105系列移植到STM32F030,就是Cortex M3到Cortex M0  ,这中间还是有很多东西不一样,虽然都是用Keil,看起来差不多。好了,直奔主题吧!  

一、IAP

IAP的MDK设置,地址需要根据实际情况定,IROM为运行代码所用的Flash空间,IRAM为运行的内存空间,我使用的是64K FALSH大小的芯片,IAP程序空间设定12K就够用了,根据我下面设定便可,IROM为12K(3000H),IRAM为8K(2000H)。

 STM32F030 IAP升级编写总结

                                                               图1

注意要勾选“Use Memory Layout From Target Dialog”这个选项,作用就是同步程序烧写的地址、内存大小,不勾选则是使用工程目录下的sct文件。

STM32F030 IAP升级编写总结

                                                                     图2

这是工程目录下的sct文件,不勾选“Use Memory Layout From Target Dialog”选项的,就在sct里面改吧

; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************

LR_IROM1 0x08003000 0x0000B000  {    ; load region size_region
  ER_IROM1 0x08003000 0x0000B000  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }
  RW_IRAM1 0x200000C0 0x00001F40  {  ; RW data
   .ANY (+RW +ZI)
  }
}
#define APPLICATION_ADDRESS     					(uint32_t)0x08003000

void AppProgramRun(void)
{
    if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
    { 
	JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
	Jump_To_Application = (pFunction) JumpAddress;
	__set_MSP(*(__IO uint32_t*) ApplicationAddress);
	Jump_To_Application();
    	}
}

二、APP

首先APP需要设置开始引导启动的中断向量,另外一定要打开总中断开关,也可以使用“CPSIE I”来打开,

	memcpy((void*)0x20000000, (void*)0x8003000, 0xB4);		//startup_stm32f030.s  中断向量总共45个元素,每个元素地址占用4个字节,45*4=180(B4H)
	SYSCFG->CFGR1 |= 0x03;								//相当于Cortex M3的向量索引地址SCB->VTOR = FLASH_BASE | 0x10000;
	SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);
	interrupt_on();	

其次设置MDK,红色数字1代表APP Flash的起始地址,数字2代表SRAM的其实地址

STM32F030 IAP升级编写总结

在编译后生成的MAP文件就能看到__Vectors的设置地址为0x08003000,

  BuildAttributes$$THM_ISAv3M$S$PE$A:L22$X:L11$S22$IEEE1$IW$USESV6$~STKCKD$USESV7$~SHL$OSPACE$EBA8$MICROLIB$REQ8$PRES8$EABIv2 0x00000000   Number         0  anon$$obj.o ABSOLUTE
    __ARM_use_no_argv                        0x00000000   Number         0  main_1.o ABSOLUTE
    __cpp_initialize__aeabi_                  - Undefined Weak Reference
    __cxa_finalize                            - Undefined Weak Reference
    __decompress                              - Undefined Weak Reference
    _clock_init                               - Undefined Weak Reference
    _microlib_exit                            - Undefined Weak Reference
    __Vectors_Size                           0x000000b4   Number         0  startup_stm32f030.o ABSOLUTE
    __Vectors                                0x08003000   Data           4  startup_stm32f030.o(RESET)
    __Vectors_End                            0x080030b4   Data           0  startup_stm32f030.o(RESET)
    __main                                   0x080030b5   Thumb Code     0  entry.o(.ARM.Collect$$$$00000000)
    _main_stk                                0x080030b5   Thumb Code     0  entry2.o(.ARM.Collect$$$$00000001)
    _main_scatterload                        0x080030b9   Thumb Code     0  entry5.o(.ARM.Collect$$$$00000004)
    __main_after_scatterload                 0x080030bd   Thumb Code     0  entry5.o(.ARM.Collect$$$$00000004)
    _main_clock                              0x080030bd   Thumb Code     0  entry7b.o(.ARM.Collect$$$$00000008)
    _main_cpp_init                           0x080030bd   Thumb Code     0  entry8b.o(.ARM.Collect$$$$0000000A)
    _main_init                               0x080030bd   Thumb Code     0  entry9a.o(.ARM.Collect$$$$0000000B)
    __rt_final_cpp                           0x080030c5   Thumb Code     0  entry10a.o(.ARM.Collect$$$$0000000D)
    __rt_final_exit                          0x080030c5   Thumb Code     0  entry11a.o(.ARM.Collect$$$$0000000F)

分配到的内存其实地址0x200000c0是APBAHBPrescTable,这就是引导启动向量在内存的地址

.data                                    0x200000c0   Section       16  stm32f0xx_rcc.o(.data)
    APBAHBPrescTable                         0x200000c0   Data          16  stm32f0xx_rcc.o(.data)
    .data                                    0x200000d0   Section        2  adc.o(.data)
    timerBAT                                 0x200000d0   Data           2  adc.o(.data)
    .data                                    0x200000d2   Section        1  ir_driver.o(.data)
    .data                                    0x200000d4   Section       16  timer.o(.data)
    k                                        0x200000d4   Data           1  timer.o(.data)
    k                                        0x200000d8   Data           2  timer.o(.data)
    k                                        0x200000dc   Data           4  timer.o(.data)
    .data                                    0x200000e4   Section        1  uart.o(.data)
    .data                                    0x200000e5   Section       15  uart.o(.data)
    .data                                    0x200000f4   Section        1  uart.o(.data)
    .data                                    0x200000f5   Section        1  uart.o(.data)
    .data                                    0x200000f6   Section        1  uart.o(.data)
    .data                                    0x200000f7   Section        1  uart.o(.data)
    .data                                    0x200000f8   Section        1  uart.o(.data)
    .data                                    0x200000fa   Section       24  can_app.o(.data)
    uRevStatus                               0x200000ff   Data           1  can_app.o(.data)
    uCarDoorStatus                           0x20000100   Data           1  can_app.o(.data)
    uCarLightingStatus                       0x20000101   Data           1  can_app.o(.data)
    uCarACCStatus                            0x20000102   Data           1  can_app.o(.data)
    Front                                    0x20000103   Data           1  can_app.o(.data)
    rear                                     0x20000104   Data           1  can_app.o(.data)
    left                                     0x20000105   Data           1  can_app.o(.data)
    right                                    0x20000106   Data           1  can_app.o(.data)
    SendFlag                                 0x20000107   Data           1  can_app.o(.data)
    timerDelay1                              0x20000108   Data           2  can_app.o(.data)
    speedList                                0x2000010a   Data           2  can_app.o(.data)
    SenserList                               0x2000010c   Data           2  can_app.o(.data