cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CUBEID debug crashes when configuring MODER register

MMini.1
Associate

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++);
	}
}

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

2 REPLIES 2

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

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.