cancel
Showing results for 
Search instead for 
Did you mean: 

Disable JTag on STM32F4

Martiska.Greg
Associate III
Posted on July 09, 2013 at 06:23

Does anyone know how to disable the JTAG interface on the STM32F4? I want to use the pins for SPI1. For previous STM32s the following was available:

  GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);

This command is not in the STM32F4 firmware library. The reference manual is no help as it says :

For more details on how to disable SWJ-DP port pins, please refer to

Section 7.3.2: I/O pin multiplexer and mapping

.

But there are not details there.

Thanks for your help
9 REPLIES 9
Posted on July 09, 2013 at 11:32

As the referred chapter 7.3.2 states it, too, JTAG/SWD is nothing more than the AF0 setting of the given pins.

Simply set them to the AF you need, as you would do it with any other pin.

JW

Posted on July 09, 2013 at 12:57

Indeed, park the AF mux at some non-JTAG function, or otherwise reconfigure the GPIO

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Martiska.Greg
Associate III
Posted on July 09, 2013 at 14:15

Thanks for the quick reply. I have been trying to achieve what you recommend but it its not working, Here is the code:

RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI1,

ENABLE

);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,

ENABLE

);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI1);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_SPI1);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI1);

GPIO_InitStructure.

GPIO_Pin

= GPIO_Pin_5 | GPIO_Pin_4 | GPIO_Pin_3;

GPIO_InitStructure.

GPIO_Mode

=

GPIO_Mode_AF

;

GPIO_InitStructure.

GPIO_Speed

=

GPIO_Speed_50MHz

;

GPIO_InitStructure.

GPIO_OType

=

GPIO_OType_PP

;

GPIO_InitStructure.

GPIO_PuPd

=

GPIO_PuPd_DOWN

;

GPIO_Init(GPIOB, &GPIO_InitStructure);

SPI_I2S_DeInit(SPI1);

SPI_InitStructure.

SPI_Direction

= SPI_Direction_2Lines_FullDuplex;

SPI_InitStructure.

SPI_Mode

= SPI_Mode_Master;

SPI_InitStructure.

SPI_DataSize

= SPI_DataSize_8b;

SPI_InitStructure.

SPI_CPOL

= SPI_CPOL_Low;

SPI_InitStructure.

SPI_CPHA

= SPI_CPHA_1Edge;

SPI_InitStructure.

SPI_NSS

= SPI_NSS_Soft;

SPI_InitStructure.

SPI_BaudRatePrescaler

= SPI_BaudRatePrescaler_4;

SPI_InitStructure.

SPI_FirstBit

= SPI_FirstBit_MSB;

SPI_InitStructure.

SPI_CRCPolynomial

= 7;

SPI_Init(SPI1, &SPI_InitStructure);

/

SPI_Cmd(SPI1,

ENABLE

);

I have used the SPI with the STM32F2 without issues so I believe the wiring is correct. I also notice that the technical references repeat that the JTAG must be disabled to release them for general GPIO, That is why I thought I am missing something. Reference:

 

You can disable some or all of the JTAG/SWD pins and so release the associated pins for GPIO usage.

Is there something missing in my code?

Posted on July 09, 2013 at 14:59

Is there something missing in my code?

 

Do you have the GPIOB clock enabled? I don't think SYSCFG plays a role in the AF selection on the F2/F4 parts.

Are you using SWD debug?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Martiska.Greg
Associate III
Posted on July 09, 2013 at 15:17

Sorry forgot to put the GPIOB clock statement in the reply. I do have it enabled. I am not using SWD debug. There are two potential problems with the SPI. One is that the SPI is not initializing correctly for Pins PB3,PB4, and PB5. The other is the GPIO on pins PA14 and PA15 are not working. I have two sigma delta ADC's on the SPI. PA14 is chip select and PA15 is a sync pin. I have been using the same setup with the STM32F2 for several years without issue. I will test the PA pins to see if they are working. However everything else on the board is working and only the pins that involve the JTAG/SWD seem to be having problems. Now that I think about it, the problem could be that I am not repmapping pins PA14 and PA15 with a GPIO_PinAFConfig command. Is there a define for just GPIO?

Posted on July 09, 2013 at 16:11

I certainly preferred how the F1 parts worked, some of the docs still seem to infer the older behaviour. There is also an errata related to JTAG, look over the F4 document, it has more detail but another poster's problems suggest it might be present in the F2 as well.

For GPIO mode of the pin, other than AF connectivity, you need to change the GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; to something else. Take a look at the GPIO\GPIO_JTAGRemap example.

Is your complaint that the debug interface still works, or simply that the SPI isn't functioning correctly on those pins?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Martiska.Greg
Associate III
Posted on July 10, 2013 at 03:53

The problem is the SPI does not seem to be functioning. I do not want to use the debugger. Since the email this morning I found some problems with PA14 and PA15 as far as chip select and resolved them but the SPI is still not communicating. I also got the latest firmware library (V1.1) and also tried SPI3 but to no avail. I will scope it tomorrow to see if I am getting a clock output. However with the F1 part I did not have any trouble with the SPI. I also tried changing the spi prescaler think the chip speed (168MHz) might be an issue for the part I am trying to communicate with but this also had no effect. FYI I am not using DMA or interrupts. This is similar to how I used the F1. Any suggestions? I am in for 2 days on this and I can't seem to find anything wrong with the code. Plus other functions are working, like USB, serial port, GPIO.

Posted on July 10, 2013 at 11:21

Take a deep breath, and start from scratch.

Write a simple test program containing NOTHING ELSE just handling of SPI.

JW

Martiska.Greg
Associate III
Posted on July 10, 2013 at 17:23

Eureka. The SPI is working. To be correct it was always working. When I tested it with the oscilloscope, I go a clock and MOSI signal. Just no MISO. Pretty clear that the 2 external ADC chips were not working. They probably burned out when the first F4 chip was put on the board. The power pins of the F4 are not compatible with the F1 exactly (F4 requires a capacitor) so the first F4 failed. This must have taken the ADC chips with it.

Thank you for your responses. These led me to checking and solving a couple of issues with the chip select pins. JW's advice was my next move after testing the pins. However an engineering friend of mine told me to always check the pins first with a scope when you have problems. This had helped me solve many issues. Unfortunately it always seems easier to mess with the code first.