cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot access STM32F051 via SWD after first download

oko
Associate II
Posted on November 30, 2015 at 00:06

Hello,

I have self-designed board with STM32F051 (48-pin). After assembling I could detect the core using J-Link and downloaded my firmware by IAR debugger but debugger lost the CPU immediately and cannot access it anymore. J-Link itself also cannot detect CPU (however it finds SWD-DP). I also changed CPU phisically and same story - download ones and then it stops.

About HW: Vdd=2,9V (tried 3,3V with same result), Vdda connected to Vdd, BOOT0 pin is not connected (however similar boards run well with BOOT0 not connected), NRST connected to SWD connector only (no external pull-up). Unfortunately USART2 is not used in this project and pins are connected to LEDs so it is very difficult to use BOOT0 and USART and terminal. I'd rather change CPU on my board. 

About SW: I checked that GPIOA13 and 14 are not touched in the program. In general SW implements touch-keys (TSL library from ST) and few LEDs. I do not use any of power-down modes, CPU is always in RUN state.

So... what I missed? First I do not understand why I lose communication to the debugger. Second I do not understand why J-Link cannot detect core if I have nRST pin connected to the J-Link. What can I do to access the CPU again (USART2 and terminal solution is almost impossible) and what to look for in source code to find possible reason of such behabior?

#rtfm
6 REPLIES 6
Posted on November 30, 2015 at 00:16

If you can connect/erase with BOOT0 pulled high, then it's definitely something in your code. I'd start with looking at all the pin/gpio code, and then for low power or standby modes.

Doing a ''connect under reset'' is usually an option. Consider adding code to break out of normal operation, ie check button, and enter a while loop.

I usually solve by inspection, not guessing.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
megahercas6
Senior
Posted on November 30, 2015 at 11:32

Don't know full story, but if you use PA13 or PA14 (SWDIO and SWDCLK) pins as your GPIO after program is loaded, you will not be able to connect, unless you will hold MCU in reset by shorting Reset to ground, and starting flashing new code, and releasing RESET pin. So you will be able to debug up until the moment, you set your SWD pin'as as GPIO or any AF in code.

Second problem i had is incorrect PLL reconfig, so same trick with holding in reset just before flashing was able to download code. ( as example, CPU was running at 400Mhz while it can only run on 200MHz) Or short crystal to ground, it shoul enable internal 16MHz oscilator

oko
Associate II
Posted on December 02, 2015 at 23:34

I connected BOOT pin to Vcc and tried to connect with J-Link (also J-Link SW tool) but it still cannot identify CPU:

----

Info: Found SWD-DP with ID 0x0BB11477

No device found on SWD.

Did not find any core.

----

by HW there is no external oscillator, it is designed to run from internal RC-generator.

This is strange that device doesn't respond to debugger with BOOT pin high. Reset pin is phisically connected. Not shure if J-Link really uses it or not, cannot find how to check it. And afraid to connect reset pin directly to GND because afraid to burn J-Link output RST.

Don't have any other ideas how to bring CPU to life again. Before problem occur I connected to it with J-Link and loaded my program so seems HW was OK and I didn't change since that time except BOOT pin.

Any other suggestions? 

oko
Associate II
Posted on December 03, 2015 at 01:00

Thanks a LOT karpavicius.linas! Your suggestion works. I pulled-down reset pin with 200 Ohm resistor, trying to load my program with IAR and during this process dissconnected pull-down resistor and then debugger cought CPU. Then with step-by-step debugging I found a place with wrong GPIO initialization (GPIOA_OTYPER was initialized with trash). This was really very easy as debugger lost CPU after wrong line. So I fixed this point and now board runs.

Thank you very much karpavicius.linas!

The one point left for me is to find out why J-Link doesn't use HW reset line.

Posted on December 03, 2015 at 02:37

https://www.segger.com/admin/uploads/productDocs/UM08001_JLink.pdf

Try pg 199 from the ''Reset Strategies'' section. Type 2 : ResetPin

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
oko
Associate II
Posted on December 03, 2015 at 21:57

Thank you, Clive! Now it runs. I use Reset Type 3 (Connect under reset). I set it in JLink commander with command ''RSetType 3''