你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【原创】【MCU实战经验】+ 可在产品中使用的bootloader程序... 精华  

[复制链接]
wjandsq 发布时间:2014-4-18 09:23
一、BootLoader程序使用说明:

1 BootLoader程序占用11K空间,BootLoader预留空间(0x08000000-0x08004000)。
  用户程序需要设置在0x08004000以后,也可使用分散加载的方法设置用户程序。
  建议用ISP方式并添加写保护,防止BootLoader程序丢失,本BootLoader采用
  一边读一边写的方法,不受内存大小限制。

2 先打开超级终端,设置好波特率,8位数据位,1位停止位,无校验,无流控
  打开需要升级的程序文件,点击发送。RS485方式通讯一般设置波特率为
  230400bps,TTL通讯则可设为921600bps。

3 给下位机上电,在上电500毫秒内,无通讯则跳转至用户程序。若下位机发送
  大写'C',发现超级终端有文件发过来,则下位机的BootLoad程序以Y_Modem协议
  接收升级程序文件,并将文件内容写入APP程序区,然后跳转至APP程序运行。

4 升级程序时,黄色LED灯闪烁,运行APP程序时,绿灯闪烁。BootLoad程序和APP程序都
  开启了看门狗,若有故障,自动复位,红灯一闪而过。

5 跳转至APP程序前,需要关闭所有用到的中断,切记。

6 LED指示灯相关的IO脚没有初始化。
  建议产品设计者添加状态LED指示灯:黄灯闪烁表示程序正在升级中,
  绿灯闪烁表示正常工作中(LED指示灯在循环中闪烁,如果不闪烁表明死机),
  红灯亮表示进入硬件意外挂起函数(如果有看门狗则会复位,否则不掉电一直死机)。
  
7 用户程序的中断向量偏移设置如下:
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000);

; APP程序分散加载的例子
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************

LR_IROM1 0x08004000 0x00040000  {    ; load region size_region
  ER_IROM1 0x08010000 0x00040000  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }
  RW_IRAM1 0x20000000 0x00010000  {  ; RW data
   .ANY (+RW +ZI)
  }
  ;EX_SRAM_DATA  0x68000000 UNINIT 0x00020000  {  ; RW data
  ;  main.o (exsram)                 ; exsram 内存段名称
  ;}
}




二、工程说明

本工程是为实现RS485及CAN的IAP而设计的BootLoad程序,附带了以下几种固件库的
应用代码: RS485,CAN,FSMC,SPI,TIM,AD


Project Targets 设置说明

1.Debug in Ram

  在内存中运行和调试程序,避免Flash的反复擦除和写入,减少芯片寿命

  在Option for 'Debug in Ram'\C/C++\Preprocessor Symbols\Defin 编辑框
  增加VECT_TAB_RAM宏定义, nvic.c的NVIC_Configuration函数中增加如下代码

#ifdef  VECT_TAB_RAM  
    /* Set the Vector Table base location at 0x20000000 */
    NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
    /* Set the Vector Table base location at 0x08000000 */
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif
  这样就把中断向量地址转移到Ram中

  点击Option for 'Debug in Ram'\Utilities\Configure Flash Memu Command\Settings
  在Cortex-M Target Driver Setup对话框,
  选择Flash Download为Do not Erase,Program,Verify
  分配程序空间和数据空间为0x20000000以后, 程序空间在前, 数据空间在后

  IRAM_EXSRAM.sct 分散加载文件:

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

LR_IROM1 0x20000000 0x0000A000  {    ; load region size_region
  ER_IROM1 0x20000000 0x0000A000  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }
  RW_IRAM1 0x2000A000 0x00010000  {  ; RW data
   .ANY (+RW +ZI)
  }
  RW_RAM1 0x68000000 0x00020000  {  ; RW data
   .ANY (EX_SRAM)                   ; EX_SRAM 是声明的内存段名称
  }
}
  RAM.ini 程序放在内部SRAM中进行硬件仿真的初始化文件:

SP = _RDWORD(0x20000000);           // Setup Stack Pointer
PC = _RDWORD(0x20000004);           // Setup Program Counter
_WDWORD(0xE000ED08, 0x20000000);    // Setup Vector Table Offset Register


2.Debug in Flash

  在Flash中运行和调试程序,需要对Flash的反复擦除和写入

  FLASH_EXSRAM.sct 分散加载文件:

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

LR_IROM1 0x08000000 0x00040000  {    ; load region size_region
  ER_IROM1 0x08000000 0x00040000  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }
  RW_IRAM1 0x20000000 0x00010000  {  ; RW data
   .ANY (+RW +ZI)
  }
  EX_SRAM_DATA  0x68000000 UNINIT 0x00020000  {  ; RW data
    main.o (exsram)                 ; exsram 内存段名称
  }
}

  注意: exsram全局变量只能在main.c或 main.h中定义,UNINIT表示不初始化

  SIM_MAP.ini 软件仿真的初始化命令,将区域(0x68000000,0x68020000)设为可读可写:

map 0x68000000,0x68020000 read write exec


三、源代码组织架构
   
文件夹名称: STM32F10x_BootLoad_IAP

固件库版本: V3.6.1

文件目录结构:

STM32F10x_BootLoad_IAP

├─Project
│  │  
│  ├─inc
│  │  │
│  │  │  main.h
│  │  │  hw_config.h
│  │  │  fsmc_sram.h
│  │  └  stm32f10x_conf.h
│  │  
│  ├─src
│  │  │
│  │  │  iwdg.c
│  │  │  rcc.c
│  │  │  gpio.c
│  │  │  nvic.c
│  │  │  tim.c
│  │  │  adc.c
│  │  │  usart.c
│  │  │  can.c
│  │  │  spi.c
│  │  │  dma.c
│  │  │  fsmc_sram.c
│  │  │  hw_config.c
│  │  │  stm32f10x_it.c
│  │  │  main.c
│  │  │  modbus.c
│  │  └  ymodem.c
│  │  
│  └─MDK-ARM
│      │  
│      │  BootLoad_IAP.uvproj
│      │  FLASH_EXSRAM.sct        /* Flash调试,分散加载文件 */
│      │  IRAM_EXSRAM.sct         /* IRAM调试,分散加载文件 */  
│      │  RAM.ini                 /* IRAM调试初始化文件 */  
│      │  SIM_MAP.ini             /* 软件仿真初始化文件 */
│      │  
│      │  
│      ├─ROM /* Debug in Flash */
│      │  │
│      │  ├─rom_List
│      │  │
│      │  └─rom_out
│      │
│      └─RAM /* Debug in Ram */
│          │
│          ├─ram_List
│          │
│          └─ram_out
│      
├─Libraries
│  └─STM32F10x
│      ├─CMSIS
│      │  ├─Device
│      │  │  └─ST
│      │  │      └─STM32F10x
│      │  │          ├─Include
│      │  │          │  │ stm32f10x.h
│      │  │          │  └ system_stm32f10x.h
│      │  │          └─Source
│      │  │              └─Templates
│      │  │                  │ system_stm32f10x.c
│      │  │                  └─arm
│      │  │                      └ startup_stm32f10x_hd.s
│      │  └─Include
│      │      └ core_cm3.h
│      │
│      ├─STM32_USB-FS-Device_Driver
│      │  │
│      │  ├─src
│      │  │  │  usb_core.c
│      │  │  │  usb_init.c
│      │  │  │  usb_int.c
│      │  │  │  usb_mem.c
│      │  │  │  usb_regs.c
│      │  │  └  usb_sil.c
│      │  │  
│      │  └─inc
│      │      │  
│      │      │  usb_core.h
│      │      │  usb_def.h
│      │      │  usb_init.h
│      │      │  usb_int.h
│      │      │  usb_lib.h
│      │      │  usb_mem.h
│      │      │  usb_regs.h
│      │      │  usb_sil.h
│      │      └  usb_type.h
│      │
│      └─STM32F10x_StdPeriph_Driver /* StdPeriph_Driver */
│          │
│          ├─src
│          │  │ misc.c
│          │  │ stm32f10x_adc.c
│          │  │ stm32f10x_bkp.c
│          │  │ stm32f10x_can.c
│          │  │ stm32f10x_cec.c
│          │  │ stm32f10x_crc.c
│          │  │ stm32f10x_dac.c
│          │  │ stm32f10x_dbgmcu.c
│          │  │ stm32f10x_dma.c
│          │  │ stm32f10x_exti.c
│          │  │ stm32f10x_flash.c
│          │  │ stm32f10x_fsmc.c
│          │  │ stm32f10x_gpio.c
│          │  │ stm32f10x_i2c.c
│          │  │ stm32f10x_iwdg.c
│          │  │ stm32f10x_pwr.c
│          │  │ stm32f10x_rcc.c
│          │  │ stm32f10x_rtc.c
│          │  │ stm32f10x_sdio.c
│          │  │ stm32f10x_spi.c
│          │  │ stm32f10x_tim.c
│          │  │ stm32f10x_usart.c
│          │  └ stm32f10x_wwdg.c
│          └─inc
│              │ misc.h
│              │ stm32f10x_adc.h
│              │ stm32f10x_bkp.h
│              │ stm32f10x_can.h
│              │ stm32f10x_cec.h
│              │ stm32f10x_crc.h
│              │ stm32f10x_dac.h
│              │ stm32f10x_dbgmcu.h
│              │ stm32f10x_dma.h
│              │ stm32f10x_exti.h
│              │ stm32f10x_flash.h
│              │ stm32f10x_fsmc.h
│              │ stm32f10x_gpio.h
│              │ stm32f10x_i2c.h
│              │ stm32f10x_iwdg.h
│              │ stm32f10x_pwr.h
│              │ stm32f10x_rcc.h
│              │ stm32f10x_rtc.h
│              │ stm32f10x_sdio.h
│              │ stm32f10x_spi.h
│              │ stm32f10x_tim.h
│              │ stm32f10x_usart.h
│              └ stm32f10x_wwdg.h


└  BootLoad说明.txt

bootloader及256Kb的测试例程打包下载: bootloader_OK.rar (2.18 MB, 下载次数: 1351)
收藏 16 评论33 发布时间:2014-4-18 09:23

举报

33个回答
党国特派员 回答时间:2015-3-23 09:21:42
这个很好,学习。。。 blank.png blank.png blank.png blank.png blank.png blank.png blank.png blank.png blank.png blank.png
党国特派员 回答时间:2015-3-28 13:42:27
学习了。。。 nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png nothing.png
moyanming2013 回答时间:2015-3-27 17:26:35
为什么“固件库的应用代码: RS485,CAN,FSMC,SPI,TIM,AD”也放在了前面11KB的区域中呢?
ysdx06010302 回答时间:2014-4-19 08:20:01

RE:【原创】【MCU实战经验】+ 可在产品中使用的bootloader程序及测试例程打包上传。

学习一下,谢谢版主。
落月枫情 回答时间:2015-3-22 21:05:35
多谢楼主分享,慢慢学习一下
wamcncn 回答时间:2015-3-23 09:04:09
学习一下,不熟悉的情况下 还是不乱用的 好
左岸右岸 回答时间:2015-3-23 22:43:17
路过看看学学
stary666 回答时间:2015-3-26 09:25:19
那个MCU的
bit 回答时间:2015-3-27 18:12:11
帮顶帮顶帮顶
bit 回答时间:2015-3-27 18:14:56
好东东啊  最近正在搞Bootloader呢
拼命三郎 回答时间:2015-3-31 12:54:05
好东西,下载了
liuem 回答时间:2015-3-31 16:58:30
收下了,谢谢。
wyxy163@126.com 回答时间:2015-4-4 21:05:10
提示: 作者被禁止或删除 内容自动屏蔽
wyxy163@126.com 回答时间:2015-4-4 21:05:47
提示: 作者被禁止或删除 内容自动屏蔽
123下一页

所属标签

相似分享

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版