Author Topic: Stm32 microcontroller acting weird  (Read 1950 times)

0 Members and 1 Guest are viewing this topic.

Offline tesliniusTopic starter

  • Regular Contributor
  • *
  • Posts: 58
  • Country: nl
Stm32 microcontroller acting weird
« on: February 23, 2022, 08:58:58 pm »
I have a custom designed pcb with stm32f103rct6 (arm cortex m3) microcontroller, i used a 16MHz crystal and 32.768kHz crystal for rtc, i supply it off 3.3v with max. 5mV ac ripple so very clean, i tried programming it with stlink and it works but i noticed that it acts weirdly, it works for a couple of seconds but then it just starts going crazy randomly turning on/off outputs while the 16MHz crystal still works and supply voltage doesn't drop, it doesn't draw any excessive curent (150mA at 12V) and i noticed that the 32.768kHz crystal doesn't oscillate, but that's probably because i don't have the correct loading capacitors, tommorow i'll try changing for the correct ones. My question is can the non functioning rtc 32.768kHz crystal be responsible for this behaviour, it doesn't seem that likely to me because the rtc circuit is probably separated from the main processor part, any other ideas what could cause this behaviour? Oh and i have the boot jumpers both to 0.

My schematic is in the attachment.
 

Offline isometrik

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ca
Re: Stm32 microcontroller acting weird
« Reply #1 on: February 23, 2022, 09:43:00 pm »
Have you tried to trace the firmware execution in debug mode ?
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6271
  • Country: es
Re: Stm32 microcontroller acting weird
« Reply #2 on: February 23, 2022, 09:44:22 pm »
Add a 100nf capacitor to nRST pin.
No need of external pullup.

Wrong code could cause very weird behavior.
+1 learn how to debug it, avoiding (slow and uneefficient) empiric solving.
Maybe you missed enabling the secondary oscillator
« Last Edit: February 23, 2022, 10:40:01 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: thm_w

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 7229
  • Country: ca
  • Non-expert
Re: Stm32 microcontroller acting weird
« Reply #3 on: February 23, 2022, 11:55:37 pm »
150mA at 12V is a lot for a micro, but I assume you have other circuitry hooked up as well.
I would expect less than 5mA at 3.3V.

Check your solder joints?
Post a photo of the PCB?
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline tesliniusTopic starter

  • Regular Contributor
  • *
  • Posts: 58
  • Country: nl
Re: Stm32 microcontroller acting weird
« Reply #4 on: February 27, 2022, 09:30:43 pm »
I removed the 10k pullup resistor and replaced it with a 100nF capacitor, i removed the option of the code being the problem because this started also when i erased the flash, after i replaced the resistor with the cap it's a bit better sometimes it works for like 30min without fail and then it starts acting weird again. So the problem is in hardware the only thing i could come up with being the problem is that it's trying to use the internal crystal but i have external ones connected and that messes it up. I have more experience with atmel microcontrollers and when you upload a bootloader or code there you select if it's using internal or external crystal and at what frequency, so i think that's the problem, i'll try removing the crystals if that fixes it, also another question, where can i find a bootloader for uart communication, because i have an ftdi ft232 chip connected to it, i saw some premade bootloaders and you selected one by which pin it was using for the led, but i have a custom pcb and i found how to adjust it for custom pcb's but i don't exactly how to do it, will have to look it up a bit more.
 

Offline pigrew

  • Frequent Contributor
  • **
  • Posts: 680
  • Country: us
Re: Stm32 microcontroller acting weird
« Reply #5 on: February 27, 2022, 11:48:11 pm »
Your series inductor (L1, 10uH) is not what I normally see on designs, but I don't think it's large enough to cause issues. You may want to replace it with a short or a ferrite bead. Also, it's suggested by ST to provide a 100 nF capacitor for each Vdd pin, and I don't see enough on your schematic. You may want to use an oscilloscope to verify that you are not having large transients on your Vdd bus (preferably using an active low capacitance probe).

The STM32's clock is different than the ATMEGA. STM32 will always default to using the internal RC oscillator (though I believe some bootloaders will transition to a crystal to enable USB mode). The software has to manually enable and select external clocks.

The STM32 has an internal ROM bootloader. See the ST AN2606 document for details (such as how it is activated, often by pulling BOOT0 pin high). The F103's ROM bootloader contains a UART mode, and will interpret commands over UART on pins PA9 and PA10. "XL-density" devices also will activate a second set of pins in bootloader mode. Perhaps you could use extra pins from the FTDI chip to pull BOOT0 high and reset the STM32.
 

Offline tesliniusTopic starter

  • Regular Contributor
  • *
  • Posts: 58
  • Country: nl
Re: Stm32 microcontroller acting weird
« Reply #6 on: March 06, 2022, 10:22:21 pm »
So i did more research and discovered stm32cubemx whicch has nice gui clock settings, i set sources for external crystals, but there is one problem i don't know how to add this code to my code that i'm making in platformio, first of all stm32cubemx has multiple choices for toolchain/ide ewarm, stm32cubeide, mdk-arm, sw4stm32, truestudio, makefile and other toolchains (gpdsc) and i tried ewarm and it generates multiple files which most important is main.c that has clock settings, would really appreciate if someone pointed me in the right direction. Also it says on the datasheet that most of the pins are 5v tolerant, but then i noticed that that is true only in open drain configuration and not for push/pull, is that true?, also the uc went short circuit and i have no idea what caused it, except for this because i have a 5v chip communicating directly to the uc.
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 7229
  • Country: ca
  • Non-expert
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline tesliniusTopic starter

  • Regular Contributor
  • *
  • Posts: 58
  • Country: nl
Re: Stm32 microcontroller acting weird
« Reply #8 on: May 30, 2022, 10:02:52 pm »
Finally found the reason for the weird behaviour, it was unstable supply voltage.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf