Using GDB to find were assertion failed (Discoverying STM32 Microcontroller book)

StackOverflow https://stackoverflow.com/questions/21688479

  •  09-10-2022
  •  | 
  •  

سؤال

I've been working my way through the Discoverying the STM32 Microcontroller book by Geoffrey Brown Discoverying the STM32 and one of the exercises (on page 60) is to modify the blinking led program to cause a assertion violation and use gdb to find the place in the code where this occurs. I can't really figure out how to do this. Any help would be much appreciated been at this for evening or two.

Modify your program to cause an assertion violation – for example re- placing GPIOC with 66 when initializing the pin – and use GDB to find the place in the library source code where an assertion failed.

#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
هل كانت مفيدة؟

المحلول

Did you try:

(gdb) break __assert

EDIT

In the stm32f10x_conf.h file there is a function called assert_failed.

So try using break assert_failed instead and see if that works.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top