Author Topic: [Stm32F401] Target not detected after setting MODER register!  (Read 1755 times)

0 Members and 1 Guest are viewing this topic.

Offline kgavionicsTopic starter

  • Regular Contributor
  • *
  • Posts: 195
  • Country: ca
[Stm32F401] Target not detected after setting MODER register!
« on: August 04, 2022, 11:29:46 pm »
Hi guys
I have a weird problem that is my blackpill ( based on STM32F401 chip) is not detected after initializing the MODER register. Here's my code:
Code: [Select]
   RCC->AHB1ENR |=(1<<0); //Enable GPIOA clock
  GPIOA->MODER =0; //clear MODER register
  GPIOA->MODER=0X555; //PA0-PA5 AS OUTPUT
Right after, I flash the board, I get the error that my blackpill is not detected ( see picture 1).The solution, I found to get my board working again is by keep pressing on BOOT0 switch and erasing the chip using stm link utility.
The weird thing, if  I comment the two last lines out  in my code above and flash again, my board is still working fine ( see picture 2).
I'm really lost, because the problem happens even with another blackpill I have.
Does someone have an idea what's going on?
Thanks in advance
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11262
  • Country: us
    • Personal site
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #1 on: August 04, 2022, 11:50:48 pm »
This code disables SWD alternate function on the SWD pins. You can't clear or overwrite the whole register, you need to keep the values for the PA13/PA14 intact.
Alex
 
The following users thanked this post: kgavionics, thm_w

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #2 on: August 05, 2022, 12:00:02 am »
the debug pins are also in PORTA

try changing only the bits controlling the pins you want to use, so you don't change the settings of the debug pins


 
The following users thanked this post: kgavionics

Offline kgavionicsTopic starter

  • Regular Contributor
  • *
  • Posts: 195
  • Country: ca
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #3 on: August 05, 2022, 12:05:27 am »
Thank you guys for your help, I really didn't think about the debug pins!
 

Offline kgavionicsTopic starter

  • Regular Contributor
  • *
  • Posts: 195
  • Country: ca
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #4 on: August 06, 2022, 12:28:59 pm »
Just out of curiosity, are the alternate functions set by the PORTA reset value ? In my case, the reset value is 0x0C000000, and it's not appearing to set PA13 nor PA14 as alternate functions. Can someone shed some light on that please?
« Last Edit: August 06, 2022, 01:04:25 pm by kgavionics »
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #5 on: August 06, 2022, 12:57:40 pm »
Check the manuals here: https://www.st.com/en/microcontrollers-microprocessors/stm32f401.html#documentation

The reference manual on page 158 will shed some light on things, but it is a bit weird. Pin A13 is set to analog mode :-//

The datasheet on page 44 does show that AF00 for PA13 and PA14 is for the SWD interface :-//

Needs more investigation |O

Edit1: Try to read the value of the MODER register with a debugger. Maybe the manual is wrong.

Edit2: The reference manual for the F411 shows the reset value to be 0xA8000000 for port A, which makes more sense because that also enables the JTAG pin JTDI on PA15.
« Last Edit: August 06, 2022, 01:10:29 pm by pcprogrammer »
 
The following users thanked this post: kgavionics

Offline wek

  • Frequent Contributor
  • **
  • Posts: 495
  • Country: sk
 
The following users thanked this post: kgavionics, pcprogrammer

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #7 on: August 06, 2022, 05:26:54 pm »
Just connect nRST instead only SWD/SWC, that way the programmer will use hardware reset, will always work.
Software reset can only work if the debugging pins are enabled, that's exactly the issue you're having by disabling those pins, breaks the debugging interface.
« Last Edit: August 06, 2022, 05:29:30 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline kgavionicsTopic starter

  • Regular Contributor
  • *
  • Posts: 195
  • Country: ca
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #8 on: August 06, 2022, 09:16:37 pm »
Just connect nRST instead only SWD/SWC, that way the programmer will use hardware reset, will always work.
Software reset can only work if the debugging pins are enabled, that's exactly the issue you're having by disabling those pins, breaks the debugging interface.
we are not talking about the nRST here, we talk about the MODER register reset value!
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #9 on: August 06, 2022, 09:22:51 pm »
What? In the original message he's talking about the MCU no longer being detected after modifying MODER, requiring to set boot0 to program it again.
Connecting nRST will solve this, no matter the MODER value.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: kgavionics

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11262
  • Country: us
    • Personal site
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #10 on: August 06, 2022, 09:23:32 pm »
we are not talking about the nRST here, we talk about the MODER register reset value!
Having nRST connected would eliminate your issue. You can write whatever you want into MODER and the debugger would be able to connect. Debugger will connect while nRST is asserted and the register value is default (whatever it is), making SWD pins be assigned their SWD function..
Alex
 

Offline kgavionicsTopic starter

  • Regular Contributor
  • *
  • Posts: 195
  • Country: ca
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #11 on: August 06, 2022, 11:34:55 pm »
I tried to use the nRST on the stm link dongles , but  for an unknown reason, they are  not seem to work,that’s why I’m using the software reset.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11262
  • Country: us
    • Personal site
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #12 on: August 07, 2022, 12:14:56 am »
In Keil you may need to experiment with "Connect and Reset Options" in the dialog you show.

I'm not sue how Keil behaves exactly here, but generally it is always possible to connect to the target if nRST is connected.
Alex
 
The following users thanked this post: kgavionics

Offline gamalot

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: au
  • Correct my English
    • Youtube
Re: [Stm32F401] Target not detected after setting MODER register!
« Reply #13 on: August 07, 2022, 02:06:54 am »
A debug port with nRST connected is best practice, you never know when will you need it.

I used to get some STM32 MCUs from Chinese sellers that looked brand new but were actually pre-programmed and locked, you couldn't erase and rewrite them without the nRST connected.
 
The following users thanked this post: kgavionics


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf