代码之家  ›  专栏  ›  技术社区  ›  Devjeet Mandal

无法闪烁JTDI引脚

  •  2
  • Devjeet Mandal  · 技术社区  · 6 年前

    我正在使用stm32f103rct6闪烁一个连接到pu中的pa15-jtdi的led。

    我的gpio配置如下

    GPIOA->CRH |= GPIO_CRH_MODE15;      //Output mode, max speed 50 MHz.
    GPIOA->CRH &= ~GPIO_CRH_CNF15;      //General purpose output push-pull\
    

    我想这样眨眼

    #define LED_HIGH()  (GPIOA->BSRR    |= GPIO_BSRR_BR15)  //LED High
    #define LED_LOW()   (GPIOA->BSRR    |= GPIO_BSRR_BS15)  //LED LOW
    

    它在数据表中说

    SWJ

    要释放gpio的pin,我们需要用010或100配置swj_cfg[2:0]。因此,我正在配置

    AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_1;     //((uint32_t)0x02000000) as 010
    

    数据表还说,我们需要对ODR/IDR寄存器做一些事情,但是我不知道如何将PA15(或任何JTAG引脚)配置为GPIO。

    afio_mapr中的swj_cfg如下

    enter image description here

    任何建议都会有帮助的。

    提前谢谢你

    2 回复  |  直到 6 年前
        1
  •  2
  •   followed Monica to Codidact    6 年前

    别忘了启用时钟 GPIOA AFIO . 两者都可以在中启用 RCC->APB2ENR . 只要没有启用,寄存器写入就会被忽略。

    RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN;
    
        2
  •  1
  •   Devjeet Mandal    6 年前

    在你们的帮助下我得到了答案。

    整个代码都是用keil v5和cmsis编写的

    #include "stm32f10x.h"
    
    #define LED_LOW()   (GPIOA->BSRR    |= GPIO_BSRR_BR15)          //Led Low
    #define LED_HIGH()  (GPIOA->BSRR    |= GPIO_BSRR_BS15)          //Led High
    
    void GPIO_Init(void);
    void Blink_Led(uint16_t ms);
    void Delay(uint16_t ms);
    
    int main(void)
    {
        GPIO_Init();
        AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_1;          //To Free PA15
        while(1)
        {
            Blink_Led(1000);
        }
    }
    
    /*Random Delay*/ 
    void Delay(uint16_t ms)
    {
        for (int i=0;i<ms;i++)
            for (int j=0;j<5120;j++);
    }
    
    void Blink_Led(uint16_t ms)
    {
        LED_LOW();
        Delay(ms);
        LED_HIGH();
        Delay(ms);
    }
    
    void GPIO_Init()
    {
        RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;     //Clock for Port A - PA15
        RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;     //ENABLE clock for alternate function
    
        GPIOA->CRH |= GPIO_CRH_MODE15;      //Output mode, max speed 50 MHz.
        GPIOA->CRH &= ~GPIO_CRH_CNF15;      //General purpose output push-pull
    }