2
\$\begingroup\$

Background

I am working on a school project where I have designed a prototype PCB with the core being a STM32F042K6T6 microcontroller. I am using the ST-Link from a Nucleo STM32F401RE card to program it.

Problem

When programming the device with some simple code to light an LED, the LED wouldn't light up. While troubleshooting, I accidentally realized that the LED would light up after a fresh "power on" (without changing code or reprogramming the MCU), simply pulling the power supply and then reconnecting it.

This lead me to believe something was wrong with the reseting of the device after the programming. To test this I started from a shining LED after power-on, and then pressing the reset button for a hardware reset. As suspected the LED would go dark and then not light up again. Then when I disconnect the power and reconnect it again it lights up.

Further observations I reckon might get asked.

  • The voltage levels of the device seems good, decoupling is placed according to data sheet.
  • Reset is implemented with external pull up with a 10k resistor to 3.3V and then a button for shorting to ground on reset and a parallel cap of 100 nF down to ground. (This is connected to the NRST pin on the MCU as well as the NRST pin on the programming connector).
  • The LED is a simple SMD led with a 180 ohms series resistance put on GPIO PB5. (Actually have 3 different status LEDs on the board, and can start them all in code

I have probed the "analog" signal of the reset pin, and to me the signal seems fine, dropping low when I click/hold the reset button. And as the LED turns off when clicking the reset button, I believe it starts to restart the program. However it doesn't seem to fully reinitialize and start executing code from the start of 'main()`? As the code actually works to light the LED after a power-on reset. Therefore the correct instructions seems to have been uploaded to the program memory, but the resets (both while programming and on clicking the reset button) seems to somehow fail to reinitialize the .

Any assistance would be greatly appreciated.

\$\endgroup\$
  • 1
    \$\begingroup\$ Have you got boot0 pulled low? \$\endgroup\$ – Aleksi Torhamo Oct 5 '16 at 18:17
  • \$\begingroup\$ Mattias - Hi - This type of behaviour can be caused by design problems which are not near the reset pin. Please supply the schematic for your design. \$\endgroup\$ – SamGibson Oct 5 '16 at 18:46
  • 1
    \$\begingroup\$ Mattias - I'm assuming your LED is actively driven by a GPIO. You said: "And as the LED turns off when clicking the reset button, I believe it starts to restart the program." I don't agree that the program is restarted, just because you see the LED go off. Normal GPIOs go "Hi-Z" when Reset is driven low, before the user program is (re)started. Press and hold the reset button and you will see your LED goes off while the button is down (and the MCU is held in reset), so the program cannot be starting at that point. See what I mean? I agree your problem seems like the MCU is staying in reset. \$\endgroup\$ – SamGibson Oct 5 '16 at 19:10
  • \$\begingroup\$ @SamGibson I might add a schematic if you think it will help. However, as it stands what currently is soldered to the board is really the mcu and peripherals to it (leds/reset button/decoupling/pin connectors), however not in a position to do that in this instant. \$\endgroup\$ – Mattias Wallin Oct 5 '16 at 20:17
  • 2
    \$\begingroup\$ "high-Z" = high impedance (Z is the usual symbol for impedance). When an IO pin is driven high or low, the pin has a low impedance to the positive supply or ground, respectively. When the microcontroller is reset, all the IO pins become undriven by hardware (no code is involved in this), so the impedance becomes high to both the supply and ground. \$\endgroup\$ – jms Oct 5 '16 at 22:35
3
\$\begingroup\$

My bet is on boot0; Check that you've got it pulled low.

The boot0 pin selects where the MCU will start executing code from when it boots up, ie. comes out of reset. If boot0 is low, it'll execute your code from flash, but if it's high, it'll execute the internal bootloader from the system memory.

My guess is that you have left boot0 floating, and when you're doing a cold boot (ie. disconnecting and reconnecting power), it'll be close to zero, so the MCU will boot your code from flash, but when you do a warm boot with the reset signal, the pin will have floated to a higher value, is read as high, and the MCU will boot to the internal bootloader from system memory instead of your code.

This explanation assumes you haven't touched the boot-related option bytes, which would change the behaviour. Also, in case you'll be working with different STM32 MCUs at some point, please note that they can have slightly different behaviour. Some have different boot-related option bytes. All I've seen so far have had a boot0 pin which behaves identically, but some also have a boot1 pin (which might be shared with a gpio pin) that you might also have to set correctly. In the MCUs I remember seeing, though, boot1 is only relevant if you want to be able to boot from system memory or SRAM.

\$\endgroup\$
  • \$\begingroup\$ It seems your answer is spot on. Thank you very much! I feel silly for forgetting about boot0. I will admit I haven't designed many PCBs / MCU circuits, and while I knew the boot0 pin existed, it wasn't something I had in the back of my head as something I must make sure to check. (Like making sure I have correct supply and decoupling etc). Guess it comes with experience aswell, hopefully I will never forget it again with a lesson like this :) \$\endgroup\$ – Mattias Wallin Oct 6 '16 at 11:18
  • 1
    \$\begingroup\$ @Mattias Most of the cases there should be an application note about getting started with hardware development (with the MCU). There are one for the STM32F0 series as well. Getting started with STM32F0x1/x2/x8 hardware development. Many more application note here, worth a look. \$\endgroup\$ – Bence Kaulics Oct 6 '16 at 11:29
  • \$\begingroup\$ @bencekaulics Yes, I actually have been using that exact PDF, that is why I find it embarrassing how I could have missed that pin... And application notes is my general go-to for how to inplement really any components, simply as you don't have time to read a full data sheet for every component in a time limited project. \$\endgroup\$ – Mattias Wallin Oct 6 '16 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.