1

私は Geoffrey Brown 著 Discoverying the STM32 Microcontroller book に取り組んできました。STM32 の発見と演習の 1 つ (60 ページ) は、点滅する led プログラムを変更してアサーション違反を引き起こし、gdb を使用して場所を見つけることです。これが発生するコード。これを行う方法が本当にわかりません。1 晩か 2 晩、この場にいたら、どんな助けでも大歓迎です。

アサーション違反が発生するようにプログラムを変更します。たとえば、ピンを初期化するときに 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
4

1 に答える 1

1

試しましたか:

(gdb) break __assert

編集

stm32f10x_conf.hファイルには、 という関数がありますassert_failed

break assert_failed代わりに使用してみて、それが機能するかどうかを確認してください。

于 2014-02-10T22:37:37.293 に答える