Skip to main content
MMini.1
Associate
February 28, 2021
Solved

STM32CUBEID debug crashes when configuring MODER register

  • February 28, 2021
  • 2 replies
  • 1199 views

Hello. Im using STM32L476RG nucleo. Im trying to debug bare metal code. Sadly my debug stops working when it gets to line where MODER register is configured.

Console says following: Target is not responding, retrying...

It keeps saying that until debugger loses connection.

The line where debuggur loses connection: GPIOA->MODER = 0x400;

However when i write same line with OR debugger is fine: GPIOA->MODER |= 0x400;

As soon as i remove OR(|) it crashes. The problem is with OR it won't change register values and my code won't work. Any solution?

#include "stm32l4xx.h" // Device header
 
void delayMs(int delay);
 
int main(void)
{
	RCC->AHB2ENR |= 1; // enable GPIOA clock, 00000000000000000000000000000001
 
	GPIOA->MODER = 0x400; // set PA5 as output, 0b 0000 0000 0000 0000 0000 0100 0000 0000, default value //0xABFFF7FF?
 
	while(1){
 
		GPIOA->ODR = 0x20; // set PA5 output data register 1, 0b .... 0010 0000
		delayMs(100);
		GPIOA->ODR &=~ 0x20;
		delayMs(100);
	}
}
 
void delayMs(int delay)
{
	int i;
	for(; delay>0; delay--){
		for(i = 0; i<3195; i++);
	}
}

This topic has been closed for replies.
Best answer by waclawek.jan

PA13 and PA14 are SWDIO and SWCLK, i.e. the pins through which you run the debugger. Don't change the GPIO settings for them from the default (see GPIO chapter in RM), otherwise you lose the debugging capability.

JW

2 replies

waclawek.jan
waclawek.janBest answer
Super User
February 28, 2021

PA13 and PA14 are SWDIO and SWCLK, i.e. the pins through which you run the debugger. Don't change the GPIO settings for them from the default (see GPIO chapter in RM), otherwise you lose the debugging capability.

JW

MMini.1
MMini.1Author
Associate
March 1, 2021

Thanks a lot. I never thought about it. The answer was so easy and obvious. It is working now. Thanks again for pointing this out.