无法闪烁 JTDI 引脚

Cannot Blink JTDI pin

我正在使用 STM32F103RCT6 使连接到 PA15 - PU 中的 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

数据表中写着

要释放 GPIO 的引脚,我们需要将 SWJ_CFG[2:0] 配置为 010 或 100。为此,我正在配置

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

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

AFIO_MAPR中的SWJ_CFG给出为

任何建议都会有所帮助。

提前致谢

不要忘记为 GPIOAAFIO 启用时钟。两者都可以在 RCC->APB2ENR 中启用。只要它们未启用,寄存器写入就会被忽略。

RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN;

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

这里的全部代码都是用CMSIS用keil v5写的

#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
}