STM32 only running after programming/debugging and hangs when powercycling - Page 1
Forum section: electronics / general

author: evglabs
author_rank: Contributor
timestamp: August 01, 2019, 02:17:34 pm
content: First off, I'mVERYnew 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.

author: ogden
author_rank: Super Contributor
timestamp: August 01, 2019, 02:38:38 pm
content: 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 01, 2019, 02:48:39 pm
content: 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.

author: evglabs
author_rank: Contributor
timestamp: August 01, 2019, 02:50:08 pm
content: NRST has a 10k resistor to VDD and BOOT0 is connected straight to GND

author: ogden
author_rank: Super Contributor
timestamp: August 01, 2019, 02:56:00 pm
content: External NRST pull-up is not required and capacitor is.

author: evglabs
author_rank: Contributor
timestamp: August 01, 2019, 02:59:11 pm
content: 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?

author: ogden
author_rank: Super Contributor
timestamp: August 01, 2019, 03:09:14 pm
content: Quote from: evglabs on August 01, 2019, 02:59:11 pmYes. 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.

author: evglabs
author_rank: Contributor
timestamp: August 01, 2019, 03:20:48 pm
content: 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!

author: ogden
author_rank: Super Contributor
timestamp: August 01, 2019, 04:08:31 pm
content: Quote from: evglabs on August 01, 2019, 03:20:48 pmAFAIK 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.

author: evglabs
author_rank: Contributor
timestamp: August 01, 2019, 07:47:47 pm
content: Yep! Thanks, it's working!