简体   繁体   English

mbed-OS移植到TivaC TM4123,具有动态中断处理功能的Trouple

[英]mbed-OS porting to TivaC TM4123, Trouple with dynamic interrupt handling

Recently I'm trying to port mbed-OS to Tiva-C launchpad TM4C123, I am facing problem with file supplied by mbed which is cmsis_nvic.c and cmsis_nvic.h 最近,我试图将mbed-OS移植到Tiva-C启动板TM4C123,我遇到了mbed提供的文件cmsis_nvic.c和cmsis_nvic.h的问题。

This module is supposed to dynamically allocate the interrupt handler of OS timer to addressable function.(Or as far as I understand). 该模块应该将OS计时器的中断处理程序动态分配给可寻址功能(据我所知)。

What happen is, The software jumps to "Hard Fault Handler" after executing the following line 发生的是,执行以下行后,软件跳至“ Hard Fault Handler”

vectors[i] = old_vectors[i];

Here's files which I use 这是我使用的文件

#include "cmsis_nvic.h"

#define NVIC_RAM_VECTOR_ADDRESS (0x02000000)  // Vectors positioned at start of RAM
#define NVIC_FLASH_VECTOR_ADDRESS (0x0)       // Initial vector position in flash

void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
    uint32_t *vectors = (uint32_t*)SCB->VTOR;
    uint32_t i;

    // Copy and switch to dynamic vectors if the first time called
    if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) {
        uint32_t *old_vectors = vectors;
        vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS;
        for (i=0; i<NVIC_NUM_VECTORS; i++) {
            vectors[i] = old_vectors[i];
        }
        SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS;
    }
    vectors[IRQn + 16] = vector;
}

uint32_t NVIC_GetVector(IRQn_Type IRQn) {
    uint32_t *vectors = (uint32_t*)SCB->VTOR;
    return vectors[IRQn + 16];
}

And here is cmsis_nvic.h 这是cmsis_nvic.h

#ifndef MBED_CMSIS_NVIC_H
#define MBED_CMSIS_NVIC_H

#define NVIC_NUM_VECTORS      (154)   // CORE + MCU Peripherals
#define NVIC_USER_IRQ_OFFSET  16

#include "cmsis.h"

#ifdef __cplusplus
extern "C" {
#endif

void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
uint32_t NVIC_GetVector(IRQn_Type IRQn);

#ifdef __cplusplus
}
#endif

#endif

and I am calling 我正在打电话

NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) NVIC_SetVector(IRQn_Type IRQn,uint32_t矢量)

from file us_ticker.c like this 来自文件us_ticker.c这样

NVIC_SetVector(TIMER0A_IRQn, (uint32_t)us_ticker_irq_handler); NVIC_SetVector(TIMER0A_IRQn,(uint32_t)us_ticker_irq_handler);

(my compiler is ARM GCC, I am using CDT for building, And GDB openOCD for debugging, and integrated all those tools on Eclipse) (我的编译器是ARM​​ GCC,我使用CDT进行构建,使用GDB openOCD进行调试,并将所有这些工具集成到Eclipse上)

Can anyone please let me know what is going wrong here? 有人可以让我知道这里出了什么问题吗? or at least where should I debug or read to help me solve this problem??? 或至少我应该在哪里调试或阅读以帮助我解决此问题???

UPDATE 更新

I figured out part of the problem, The vector is not pointing to the first address of the target SRAM which should be 我发现了问题的一部分,向量没有指向目标SRAM的第一个地址,应该是

#define NVIC_RAM_VECTOR_ADDRESS (0x20000000)

instead of 代替

#define NVIC_RAM_VECTOR_ADDRESS (0x02000000)

So now when calling NVIC_SetVector , the function is executed. 因此,现在在调用NVIC_SetVector时,将执行该函数。 But then when enabling the interrupt, Software still jumps to Hard Fault, I guess(just guessing or might be part of solution) that the defines in the header file are not configured correctly, Can someone explain to me what do they mean? 但是,当启用中断时,软件仍然跳到“硬故障”,我猜(只是猜测,或者可能是解决方案的一部分),头文件中的定义配置不正确,有人可以向我解释它们的意思吗? and how to calculate the number of vector addresses? 以及如何计算向量地址的数量? and what is the USER OFFSET? USER OFFSET是什么?

I have solved this issue, here's what I have found 我已经解决了这个问题,这就是我发现的

1- NVIC_RAM_VECTOR_ADDRESS wasn't the first address of my target RAM which should be `0x20000000' 1- NVIC_RAM_VECTOR_ADDRESS不是我目标RAM的第一个地址,应该是0x20000000

2- Linker file should be update so that the stack pointer shouldn't write over the new copied vector table. 2-链接器文件应进行更新,以使堆栈指针不应覆盖新复制的向量表。 So shift the RAM address by number of bytes that vector table should occupy. 因此,将RAM地址移动向量表应占用的字节数。

3-(THE MAIN CAUSE) inside function NVIC_SetVector , i was declared as uint32_t and then compared to less than 255 pre-processor value. 3-(主要原因)的内部功能NVIC_SetVectori被宣布为uint32_t ,然后相对于小于255预处理器的值。 So compile get confused by comparing uint32_t with uint8_t , by adding UL to the pre-processor value, it solved the whole issue. 因此,通过将uint32_tuint8_t进行比较,将UL添加到预处理器值中,可以使编译感到困惑,从而解决了整个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM