首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用GDB查找断言失败(发现STM32单片机书籍)

使用GDB查找断言失败(发现STM32单片机书籍)
EN

Stack Overflow用户
提问于 2014-02-10 21:39:01
回答 1查看 883关注 0票数 1

我一直在研究杰弗里·布朗( Geoffrey 发现STM32 )的“发现STM32微控制器”一书,其中一项练习(在第60页)是修改闪烁的程序,以导致断言违规,并使用gdb在代码中找到发生这种情况的位置。我真想不出该怎么做。任何帮助都将是非常感谢的,在这一两个晚上。

修改您的程序以导致断言冲突-例如,在初始化引脚时用66重新放置GPIOC,并使用GDB来fi和库源代码中断言失败的位置。

代码语言:javascript
复制
#include <stm32f10x.h>
#include <stm32f10x_rcc.h>
#include <stm32f10x_gpio.h>

int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

//Enable Peripheral Clocks (1)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
//Configure Pins (2)
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
//GPIO_Init(GPIOC, &GPIO_InitStructure);
//Exercise for blinking light program
GPIO_Init(66, &GPIO_InitStructure);

//Configure SysTick Timer (3)
if(SysTick_Config(SystemCoreClock / 1000))
    while(1);
while(1){
    static int ledval = 0;

    //Toggle led (4)
    GPIO_WriteBit(GPIOC, GPIO_Pin_8, (ledval) ? Bit_SET : Bit_RESET);
    ledval = 1 - ledval;
    Delay(250); //Wait 250ms
 }
}

//Timer code (5)
static __IO uint32_t TimingDelay;

void Delay(uint32_t nTime){
   TimingDelay = nTime;
    while(TimingDelay != 0);
}

void SysTick_Handler(void){
    if(TimingDelay != 0x00)
        TimingDelay--;
}

#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line){
    /* Infinite loop*/
    /* Use GDB to find out why we're here*/
    while(1);
}
#endif
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-10 22:37:37

你试过:

代码语言:javascript
复制
(gdb) break __assert

编辑

conf.h文件中有一个名为assert_failed的函数。

因此,尝试使用break assert_failed,看看它是否有效。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21688479

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档