Devjeet Mandal
Devjeet Mandal

Reputation: 355

Cannot Blink JTDI pin

I am using STM32F103RCT6 to blink a LED which is connected to PA15 - JTDI in PU.

My GPIO Configuration is like this

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

And I am trying to Blink Like this

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

In datasheet it says

SWJ

To free the Pin for GPIO we need to configure SWJ_CFG[2:0] either with 010 or 100. So for that i am configuring

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

Datasheet also says we need to do something with ODR/IDR registers but i am not getting correcty how to configure PA15 (or any JTAG pins) as GPIO.

The SWJ_CFG in AFIO_MAPR is given as

enter image description here

Any suggestion will be helpful.

Thank You in advance

Upvotes: 2

Views: 3124

Answers (2)

Devjeet Mandal
Devjeet Mandal

Reputation: 355

With the help of you guys i got the answer.

The whole code is here written in keil v5 with 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
}

Upvotes: 1

Don't forget to enable the clocks for GPIOA and AFIO. Both can be enabled in RCC->APB2ENR. As long as they are not enabled, register writes are ignored.

RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN;

Upvotes: 2

Related Questions