首页 > 解决方案 > CORTEX_M4_0:调试模式下GPIO代码出错

问题描述

每当我尝试使用 Code Composer Studio V 9.1.0 调试我的程序时,我都会遇到此错误:

CORTEX_M4_0:在长度为 0x4 的第 0 页上的 0x400043fc 处读取内存块时遇到问题:发生调试端口错误

我使用的是德州仪器 TM4C123GXL 启动板,它通过 USB 电缆连接到我的笔记本电脑。我可以成功地构建我的程序,但是每当我尝试调试我的程序时就会出现错误。我的程序应该使用 SysTick 中断来连续改变 Elegoo 薄膜开关模块上的电压,以允许程序查看我按下了哪个按钮。我不是 100% 确定我已经正确初始化了 GPIO 输入和输出端口,但错误发生在程序甚至启动并到达我的主循环之前。

这是一些代码和我的错误的屏幕截图:

我的代码

这是一些代码:

void SysTickInit()
{
    NVIC_ST_CTRL_R = 0;
    NVIC_ST_RELOAD_R = 0x0C3500; // delays for 10ms (800,000 in hex) '0x0C3500' is
    // original correct
    NVIC_ST_CURRENT_R = 0;
    NVIC_ST_CTRL_R = 0x07; // activates the systick clock, interrupts and enables it again.
}

void Delay1ms(uint32_t n)
{
    uint32_t volatile time;
    while (n)
    {
        time = 72724 * 2 / 91; // 1msec, tuned at 80 MHz
        while (time)
        {
            time--;
        }
        n--;
    }
}

void SysTick_Handler(void) // this function is suppose to change which port
// outputs voltage and runs every time systick goes
// to zero
{
    if (Counter % 4 == 0)
    {
        Counter++;
        GPIO_PORTA_DATA_R &= 0x00; // clears all of port A ( 2-5)
        GPIO_PORTA_DATA_R |= 0x04; // activates the voltage for PORT A pin 2
        Delay1ms(990);
    }
    else if (Counter % 4 == 1)
    {
        Counter++;
        GPIO_PORTA_DATA_R &= 0x00; // clears all of port A (2-5)
        GPIO_PORTA_DATA_R |= 0x08; // activates voltage for PORT A pin 3
        Delay1ms(990);
    }
    else if (Counter % 4 == 2)
    {
        Counter++;
        GPIO_PORTA_DATA_R &= 0x00; // clears all of port A (2-5)
        GPIO_PORTA_DATA_R |= 0x10; // activates voltage for PORT A pin 4
        Delay1ms(990);
    }
    else if (Counter % 4 == 3)
    {
        Counter++;
        GPIO_PORTA_DATA_R &= 0x00; // clears all of port A (2-5)
        GPIO_PORTA_DATA_R |= 0x20; // activates voltage for PORT A pin 5
        Delay1ms(990);
    }
}

void KeyPadInit()
{
    SYSCTL_RCGCGPIO_R |= 0x03; // turns on the clock for Port A and Port B
    while ((SYSCTL_RCGCGPIO_R) != 0x03) { }; // waits for clock to stabilize

    GPIO_PORTA_DIR_R |= 0x3C; // Port A pins 2-5 are outputs (i think)
    GPIO_PORTA_DEN_R |= 0x3C; // digitally enables Port A pins 2-5

    GPIO_PORTA_DIR_R &= ~0xC0; // makes Port A pin 6 and 7 inputs
    GPIO_PORTA_DEN_R |= 0XC0; // makes Port A pin 6 and 7 digitally enabled

    GPIO_PORTB_DIR_R &= ~0X03; // makes Port B pin 0 and 1 inputs
    GPIO_PORTB_DEN_R |= 0x03; // makes PortB pin 0 and 1 digitally enabled
}

标签: memoryhardwaregpio

解决方案


我发现了我的错误发生的原因。我去找我的教授,他有一个定制的设备来检查我在启动板上的引脚是否正常工作。事实证明,我在端口 A 和 B 上使用的一些引脚消耗了太多电流,并且根据定制设备,被破坏了。换句话说,出现此错误是因为 IDE 检测到我的某些引脚不再可用。


推荐阅读