2014-02-10 15 views
1

我一直在通过Geoffrey Brown发现STM32微控制器书的方式工作,其中一个练习(第60页)是修改闪烁的led程序导致断言违规,并使用gdb在发生这种情况的代码中找到位置。我无法弄清楚如何做到这一点。任何帮助将非常感谢在这一晚上或两个。使用GDB查找断言失败(发现STM32微控制器书籍)

修改你的程序会导致断言违规 - 例如在初始化时,引脚将重新GPIOC 66 - 并使用GDB到FI ND库源代码中的断言失败的地方。

#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 
+0

另外我不确定他是否意味着在GPIO_Init函数中应该将GPIOC更改为66. –

回答

1

你尝试:

(gdb) break __assert 

编辑

stm32f10x_conf.h文件有一个名为assert_failed功能。

因此,请尝试使用break assert_failed来代替,看看是否有效。

+0

这不会在每个断言中断裂吗? – dbrank0

+0

使用这个我得到__assert不是一个函数。不知道是否做了什么错误有点新gdb。 –

+1

刚刚编辑过,看看这是否有帮助。老实说,我不熟悉STM32,但理论上它应该工作假设断言启用。此外,您可能需要取消注释'/ * #define USE_FULL_ASSERT 1 * /'并重建断言失败才能正常工作。 –