cancel
Showing results for 
Search instead for 
Did you mean: 

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

CBonn.1
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
CBonn.1
Associate II

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 !

View solution in original post

13 REPLIES 13

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

How?

JW

Mike_ST
ST Employee

Hello,

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

Hi, my line is :

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

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

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.

I've already done that and all is fine for these pins, and I should'nt be able to send my code if these pins are the problem

And even if I use GPIOC->MODER or GPIOB->MODER, the problem is the same

Do you turn off GPIOA clock somewhere ?

No it doesn't happen... But it gives me a question :

When I write something like "GPIOA->MODER |= BIT12", does the MCU test all the regiester's bit to assign the corresponding bit ? And if it is the case, can it be a problem for PA13 & PA14 ?