Chinaunix首页 | 论坛 | 博客
  • 博客访问: 207453
  • 博文数量: 93
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 978
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-10 15:46
个人简介

青春无悔

文章分类

全部博文(93)

文章存档

2015年(16)

2014年(77)

我的朋友

分类: C/C++

2015-03-05 09:24:48

背景:
1.STM32F030C8芯片使用I2C_IAP升级,跳转APP地址启动(0x08000000+0x4000)+4启动
2.因为没有类似M3或M4的NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000)也没有
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
遇到问题:
不对Vector初始化,若IAP使用中断,则App使用同样的中断就会出错,运行不起来。这就需要充设中断向量表的问题。

解决方法:
1.配置工程的存储空间:

2.main.c里面添加以下代码:

#define FLASH_BOOTLOADER_SIZE       (uint32_t)(0x4000)
#define APPLICATION_ADDRESS         (uint32_t)(0x08000000+FLASH_BOOTLOADER_SIZE)

#if   (defined ( __CC_ARM ))
  __IO uint32_t VectorTable[48] __attribute__((at(0x20000000)));
#elif (defined (__ICCARM__))
#pragma location = 0x20000000
  __no_init __IO uint32_t VectorTable[48];
#elif defined   (  __GNUC__  )
  __IO uint32_t VectorTable[48] __attribute__((section(".RAMVectorTable")));
#elif defined ( __TASKING__ )
  __IO uint32_t VectorTable[48] __at(0x20000000);
#endif


int main(void)
{
    uint32_t i = 0;
    
    /* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/  
    /* Copy the vector table from the Flash (mapped at the base of the application
     load address 0x08003000) to the base address of the SRAM at 0x20000000. */
    for(i = 0; i < 48; i++)
    {
        VectorTable[i] = *(__IO uint32_t*)(APPLICATION_ADDRESS + (i<<2));
    }

    /* Enable the SYSCFG peripheral clock*/
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE);
    /* Remap SRAM at 0x00000000 */
    SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);
 
//以下是自己的代码
...
}

经过以上两个步骤,即可正常使用中断向量表了。





//===================  参考资料 分界线 ===========================
参考资料:stm32f0_programming_usart
参考例程:STM32F0xx_AN4065_FW_V1.0.0\Project\STM32F0xx_IAP\binary_template

参考readme.txt说明:
1. Set the application load address at 0x08003000, using your toolchain linker file
2. To be able to serve the application interrupts, you need to relocate the vector
   table (which contains the interrupt handlers). However, unlike CortexM3 and CortexM4,
   the CortexM0 processor do not support vector table relocation (it is fixed at
   address 0x00000000).
   A solution will be to relocate by software the vector table to the internal SRAM:  
    - Copy the vector table from the Flash (mapped at the base of the application load
      address 0x08003000) to the base address of the SRAM at 0x20000000.
    - Remap SRAM at address 0x00000000, using SYSCFG_MemoryRemapConfig() function
    - Then once an interrupt occurs, the CortexM0 processor will fetch the interrupt
      handler start address from the relocated vector table in SRAM, then it will
      jump to execute the interrupt handler located in the Flash.
   This operation should be done at the initialization phase of the application.    
 


阅读(9748) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~