[英]Using GDB to find were assertion failed (Discoverying STM32 Microcontroller book)
我一直在努力浏览Geoffrey Brown的《 发现 STM32单片机》一书, 发现STM32和练习之一(第60页)是修改闪烁的led程序以引起断言冲突,并使用gdb在以下位置查找位置发生这种情况的代码。 我真的不知道该怎么做。 一两个晚上的时间,对您的帮助将不胜感激。
修改程序以引起断言冲突(例如,初始化引脚时将GPIOC替换为66),并使用GDB在断言失败的库源代码中找到位置。
#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
你试过了吗:
(gdb) break __assert
编辑
在stm32f10x_conf.h文件中,有一个称为assert_failed
的函数。
因此,尝试改用break assert_failed
看看是否break assert_failed
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.