Skip to main content
CBonn.1
Associate
July 28, 2021
Solved

Hello, I'm using STM32l152RCT6 and i have a debugging problem with GPIOx->MODER

In my program I have to change the mode of 2 pin very frequently, I have to get from Input mode (to have an "high impedance" state) to output mode (to use a PP) etc. These pins are PA6 and PA7.

And it's working, no problems to do that, I just use the GPIOA->MODER register and reassign the bits I need to.

But when I do that i have a problem : I can start debugging, charge the program through the board, but then I immediatly lose connexion with it. So I can't do any observation during debbuging (no "step by step", no variable visualisation...).

I have already found that this problem is here when I assign a bit on MODER register, when I don't do this I can debug easily.

I don't change the mode of PA13 and PA14, so the problem is not that I can't use the SWD process anymore (also if it was that, I would not be able to charge the program on the MCU).

Another thing that I don't understand is that depend on where I put this line on my program, it can work (I do a "calibration" cycle before my main loop, and this is when the problem appears)...

Also, if I try to do this on another PIN and use another register (like GPIOC->MODER for example), the problem remains the same...

Does anyone have an idea ? :)

Edit : here the messages I have in the console :

Info : Previous state query failed, trying to reconnect

Error: jtag status contains invalid mode value - communication failure

Polling target STM32L152RCTx.cpu failed, trying to reexamine

Examination failed, GDB will be halted. Polling again in 6300ms

This topic has been closed for replies.
CBonn.1
CBonn.1Best answer
Associate
July 29, 2021

Ok so I've finally found how to solve it :

I tried of course to clean then rebuild the project many time, but it didn't change anything...

I tried one last thing that worked for some reason :

put away all my files, then take them back to the project.

I build the project, start to debugging and now it is working !

13 replies

waclawek.jan
Super User
July 28, 2021

> I just use the GPIOA->MODER register and reassign the bits I need to.

How?

JW

CBonn.1
CBonn.1Author
Associate
July 28, 2021

Hi, my line is :

GPIOA ->MODER |= (BIT12) ; //This put PA6 to output mode

Mike_ST
ST Technical Moderator
July 28, 2021

Hello,

When single stepping, at what line in the code do you loose the SWD connection ?

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
CBonn.1
CBonn.1Author
Associate
July 28, 2021

The problem is I can't single step, when I put my program on the MCU, it disconnect immediatly, I can't even start it "normally, I have to use the reset user button to start it

Mike_ST
ST Technical Moderator
July 28, 2021

That usually happens when you change the functionnality of the debug pins.

Your program is changing PA13 & PA14 configuration somewhere. Review your code.

Reset value for GPIOA->MODER is 0xA800 0000, make sure the 0xA8 part is not changed.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
CBonn.1
CBonn.1AuthorBest answer
Associate
July 29, 2021

Ok so I've finally found how to solve it :

I tried of course to clean then rebuild the project many time, but it didn't change anything...

I tried one last thing that worked for some reason :

put away all my files, then take them back to the project.

I build the project, start to debugging and now it is working !