stm32(三) STM32(STM32F217XX) 分段程序下载以及其运行原理

来源:互联网 发布:python urlretrieve 编辑:程序博客网 时间:2024/05/16 16:58

作者:tutb12345

来自:http://blog.csdn.net/tutb12345/article/details/7765008


1.在STM32中经常出现IAP下载,我们通常采用的策略是把程序分成两段。

    (A段)运行其主程序并且判断是否需要进行IAP下载,以及IAP下载的程序。
    (B段)用户的程序。也可以说是通过IAP升级的程序。
    通常我们把这两段程序分别存储在FLASH的不同的地址空间。
    例如:STM32的flash的存储布局是:
    name              block bass address      size
    sector 0       0x08000000 - 0x08003fff     16k
    sector 1       0x08004000 - 0x08007fff     16k
    sector 2       0x08000000 - 0x08003fff     16k
    sector 3       0x08004000 - 0x08007fff     16k
    sector 4       0x08000000 - 0x08003fff     64k
    sector 5       0x08004000 - 0x08007fff     128k
    sector 6       0x08000000 - 0x08003fff     128k
    sector 7       0x08004000 - 0x08007fff     128k
    sector 8       0x08000000 - 0x08003fff     128k
    sector 9       0x08004000 - 0x08007fff     128k
    sector 10      0x08004000 - 0x08007fff     128k
    sector 11      0x08004000 - 0x08007fff     128k
   
    system memory  0x1fff0000 - 0x1fff77ff     30k
    OTP            0x1fff7800 - 0x1fff7a0f     528b
    Option bytes   0x1fffc000 - 0x1fffc00f     16b
  我的做法是把:
    sector 0 作为我的A段程序存储
    sector 1 以及以后的内容作为B段程序存储
   
  2.在A段程序中要注意的是:
    typedef void (*usercode)(void);//                            
    usercode EnterApp;                                           
    int main()                                                   
    {                                                            
     SCB->VTOR = 0x08004000;//重新定位中断向量表                        
     EnterApp = (usercode)(*(unsigned int *)(0x08004000 + 0x04));//0x08004000这里存放的是第堆栈的地址
     EnterApp();//在这里调用第二段程序                                                
    }   
原创粉丝点击