 |
 |
 |
(you are viewing a thread; or go back to
list of threads)
How to disable JTAG interface on Bluepill using LDmicro32 V6 (by Ziggy)
Hello forum,
I have just hit the wall built by my ignorance.
I wished to get familiar with LDmicro32 and Blue pill micro controller ( STM32f103 ).
I happily went about designing a board for a task based completely oblivious of the fact the JTAG interface is enabled by default.
I am aware it can be switched off and THEN AND ONLY THEN can these pins be used as standard IO pins.
Readily achieved in C.
Is there a way of doing it in LDmicro32?
Earlier versions allowed register access from within LDmicro directly.
So now I have a PCB with disfunctional pin assignment. Sdly it is also populated.
A solution in C (by Ziggy)
A way of disabling JTAG in C is to use the following statement in initialization code, disable JTAG (keep SWD if needed):
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
This keeps SWD active for programming, but frees up PA15, PB3, PB4.
Would like to understand if LDmicro32 supports this kind of functionality natively?
What it looks like (by Ziggy)
The additional instructions should be located in void PlcInit function
as a sample UNMODIFIED PlcInit function
// PLC ports and peripheral init
void PlcInit(void)
{
Gpio_conf('A', 0x8000, MODE_OUT);
Gpio_resetoutputs('A', 0x8000);
Gpio_conf('A', 0x7FFF, MODE_INP);
Gpio_conf('B', 0x4000, MODE_OUT);
Gpio_resetoutputs('B', 0x4000);
Gpio_conf('B', 0xBFFF, MODE_INP);
Gpio_conf('C', 0xFFFF, MODE_INP);
LibTimer_Init(TIM3, 1000, 720);
LibTimer_Interrupts(TIM3, ENABLE);
NVIC_SetPriority(TIM3_IRQn, 0);
}
And now a modified PlcInit function
Note location and content of additional JPEG disable lines
// PLC ports and peripheral init
void PlcInit(void)
{
// Enable clock to AFIO
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
// Disable JTAG, keep SWD active
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
Gpio_conf('A', 0x8000, MODE_OUT);
Gpio_resetoutputs('A', 0x8000);
Gpio_conf('A', 0x7FFF, MODE_INP);
Gpio_conf('B', 0x4000, MODE_OUT);
Gpio_resetoutputs('B', 0x4000);
Gpio_conf('B', 0xBFFF, MODE_INP);
Gpio_conf('C', 0xFFFF, MODE_INP);
LibTimer_Init(TIM3, 1000, 720);
LibTimer_Interrupts(TIM3, ENABLE);
NVIC_SetPriority(TIM3_IRQn, 0);
}
I hope someone finds this of use. Please note the original PlcInit () function is created by LDmicro32.
(no subject) (by José)
Hi Ziggy
That's fine ; you put questions and answer by yourself !
If your instructions:
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
are supported by ARMGCC you can use them.
A better way to implement it would just be to add a function
in a library, for instance original Lib_gpio.h / .c as it frees some GPIO pins, in Libraries/Arm/STM32F1:
void LibGPIO_Disable_Jtag()
{
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
}
Then, you edit the original file Input/plcbase_arm32.c
to add the instruction like that in PlcInit():
void PlcInit(void)
{
LibGPIO_Disable_Jtag();
#insert 1,plcinit.c $
#insert 1,plcdevinit.c $
}
So that the modification is automatical for any new project.
Could you try it and let us know if it works ?
BR
José
(no subject) (by Ziggy)
Hello Jose,
Thank You for the suggestion.
So far i have stuck with the more manual copy paste
void PlcInit(void)
{
// Enable clock to AFIO
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
// Disable JTAG, keep SWD active
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
Gpio_conf('A', 0x8000, MODE_OUT);
...
}
It is working for me and the code is doing what I want it to do...
however the response is SLOOOOOOOOWWWW.
I need to figure out why the micro runing at 72MHz does not produce a quick enough four digit, seven segment LED display.
It is next to useless.
Is there a configuration of IO PIN drivers which which would offer faster response?
Post a reply to this comment:
 |