[英]Cortex-M3 realtime interrupt vector remap
我將GCC 4.9(arm-none-eabi)與STM32結合使用,並希望將中斷表放入數組中,以便在代碼中需要時更改Interrup處理程序的地址。
我閱讀了現有的手冊和文章,並進行了以下操作:
我必須對齊數組,因此我更改了鏈接描述文件,以在RAM中添加自定義部分並將其放置到0x20001000,以便自動對齊它
.vectorsSection 0x20001000 :
{
KEEP(*(.vectorsSection))
} >RAM
聲明要放置IVT的數組,我在標頭和.cc中將其聲明為extern:
volatile word __attribute__((section (".vectorsSection"))) _vectors_[64] = {0};
檢查數組是否在正確的地址:
arm-none-eabi-nm program.elf | grep _vectors_
20001000 d _ZL9_vectors_
現在是將表重新分配到RAM的時候了。 我寫了這個功能
void (*new_code_entry)(void);
.......
static void remap_vector_table (void)
{
//VTOR is 0 on startup, so we change VTOR only once
if(SCB->VTOR)
return;
new_code_entry = (void (*)(void))((word)&_vectors_ + sizeof(word) + 1);//Skip SP and jump to Reset
memcpy((void*)_vectors_, (void*)SCB->VTOR, sizeof _vectors_);
SCB->VTOR = 0x1FFFFF80ul & (word)(&_vectors_); //Set VTOR offset
__DSB(); //Complete all memory requests
new_code_entry(); //Jump to new code
}
我從啟動代碼創建了枚舉,以便於訪問數組。
最后一次跳轉后,代碼從頭開始,VTOR為4096。
數組包含正確的地址,其順序與啟動代碼中的順序相同。
但是當涉及到
__enable_irq();
__ISB();
它掛在第一個異常上,更具體地說,這是調用棧
5 <symbol is not available> 0x697b617a
4 <signal handler called>() 0xfffffff9
3 <symbol is not available> 0x200011f8
2 remap_vector_table() main.cc:31 0x08000cd4
1 main() main.cc:46 0x08000d32
200011f4: tickcounter+0 movs r0, r0
200011f6: tickcounter+2 movs r0, r0
200011f8: ; <UNDEFINED> instruction: 0xf0d3e321
tickcounter來自肯定被首先調用的SysTick_Handler。 也許我應該對堆棧指針做些什么? 我不知道這是怎么了。
根本原因很簡單:
根據手冊第29位顯示了基本偏移量:RAM或FLASH。
SCB-> VTOR | = 1 << SCB_VTOR_TBLBASE_Pos;
這解決了問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.