Author Topic: STM32 only running after programming/debugging and hangs when powercycling  (Read 2792 times)

0 Members and 1 Guest are viewing this topic.

Offline evglabsTopic starter

  • Contributor
  • Posts: 35
First off, I'm VERY new to microcontrollers and am trying to teach myself. So, I'm sorry for this (most likely very stupid) problem.

I've got an STM32L021K4Tx on a custom PCB I've made. I can upload the program fine and debug it, but when I remove power from the board (and reapply the power), it hangs and I have to re-program.

I'm powering it from a CR2032, and my plan is to just slip out the battery when I'm not using it (no power switch).

I'm pretty sure it's something to do with the NRST (Pulled high) and BOOT0 (Pulled low) pins, but I can't figure it out. I can't even find the data in the datasheet.

Just how stupid am I being?

Thanks.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Could be NRST - related problem. You would want to read datasheet, chapter "6.3.14 NRST pin characteristics". NRST pin needs 0.1uF capacitor to GND and do not need any external pull-up resistor. Some add 10k pull-up and some don't, it works both ways.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Yeah, first we need to know what you mean by "pulled high" for NRST. If it's pulled up with a resistor of reasonable value (ie. not too low), that should work although it's not required. The external cap is not strictly required either AFAIK (it helps being more robust to parasitics). But if the pull up resistor has too low a value (or worse, if you even connected it directly to VDD), then it can't reset on its own, so I would suspect that first.
 

Offline evglabsTopic starter

  • Contributor
  • Posts: 35
NRST has a 10k resistor to VDD and BOOT0 is connected straight to GND
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
External NRST pull-up is not required and capacitor is.

 
The following users thanked this post: Siwastaja

Offline evglabsTopic starter

  • Contributor
  • Posts: 35
Thanks, I'll try that.

Just to make sure I'm thinking correctly. I should be able to just pull the battery to turn it off and put it back in to turn it on, right?
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
I should be able to just pull the battery to turn it off and put it back in to turn it on, right?

Yes. Considering that you have decoupling capacitor(s) on VCC and bulk electrolytic/tantalum >=10uF as well. Also I would recommend to add start-up delay in the very beginning of your init code, 100ms is enough.
 

Offline evglabsTopic starter

  • Contributor
  • Posts: 35
10uf, Okay. Right now I've got the battery going to a 100nF and 10nF cap.

For the start-up delay, would it just be like HAL_Delay(100) at the top of main()?

BTW, thank you very much for the help!
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
10uf, Okay. Right now I've got the battery going to a 100nF and 10nF cap.
For the start-up delay, would it just be like HAL_Delay(100) at the top of main()?

AFAIK SysTick needs to be running in order to use HAL_Delay(). I missed that you mention CR2032 battery which means extensive use of deep sleep. In such case 10uF could be too much of the wait to reset sleeping MCU. Leave your 100+10nF and see how it goes, then 10ms delay will be good enough. Startup delay is suggested in removable battery devices because during battery change MCU can experience repeated brownouts. It is much better that brownouts happens during start-up delay rather than during initialization of important hardware.
 

Offline evglabsTopic starter

  • Contributor
  • Posts: 35
Yep! Thanks, it's working!
 
The following users thanked this post: ogden


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf