logo elektroda
logo elektroda
X
logo elektroda

STM32, programming - [STM32] Program own PCB using STM32L Discovery SWD

Mishella 20112 26
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 13324522
    Mishella
    Level 9  
    Hello,
    I'm really becomin a pain in the ass here, but I got one new problem here. Lately I designed my own PCB, it's simple board to communicate via USB with my PC and receive data through NRF24L01. The MCU on board is STM32L152RBT6, the same one mounted on STM32L Discovery kit I wanna use to program it. So I have this 5pin output on my PCB to connect to SWD on discovery kit. From what I get, it should be simple to just connect this 5 pins directly to kit pins and remove jumpers from CN3 on discovery kit.
    The problem comes as I try to flash my program to it. I use ST-LINK V2, as I try to "CONNECT TO THE TARGET". It fails with

    11:42:28 : Can not connect to target!
    Please select "Connect Under Reset" mode from Target->Settings menu and try again.
    11:42:30 : Internal command error

    I have no problem connecting to my discovery kit. All settings are okey, SWD is set, connection mode is normal and debug in low power is enabled.
    I enclose my schematic, PCB design and product, maybe something wrong with my design.

    STM32, programming - [STM32] Program own PCB using STM32L Discovery SWD STM32, programming - [STM32] Program own PCB using STM32L Discovery SWD STM32, programming - [STM32] Program own PCB using STM32L Discovery SWD
  • ADVERTISEMENT
  • #2 13324559
    tadzik85
    Level 38  
    Remove capacitor on NRTS?
    CPU is new, never programed?
  • #3 13324575
    alagner
    Level 26  
    Are jumpers on discovery board properly set?
  • #4 13324596
    BlueDraco
    MCUs specialist
    Is the board powered? Note that SWD connector on Discovery board doesn't provide power to the programmed board. Actually only three wires are required for programming the fresh MCU - GND, SWDIO & SWCLK.
  • #5 13324603
    SeerKaza
    Level 20  
    What program are you using to connect with board, openOCD or STMutility ? First try connect with STMutility This program always works if connections are correct. With openOCD you can have problem with wrong configuration.

    Dodano po 4 [minuty]:

    I guess u using STMutility when i look yours logs. So you should try do what programs says. Change in Target-Settings connections mode. I had the same problem with by board.
  • #6 13324619
    Mishella
    Level 9  
    tadzik85 wrote:
    Remove capacitor on NRTS?
    CPU is new, never programed?

    Yes, it's new MCU, freshly mounted after ariving from farnell. I refered to http://www.st.com/st-web-ui/static/active/en/...technical/document/user_manual/DM00027954.pdf while designing reset button, is it wrong and the capacitor needs to be removed?

    alagner wrote:
    Are jumpers on discovery board properly set?

    CN3 is removed to enable SWD flashing external application, don't know if something else has to be done here :/
  • ADVERTISEMENT
  • #7 13324627
    SeerKaza
    Level 20  
    Important is in what order u power up your devices. First power up your board later stlinkv2
  • #8 13324629
    Freddie Chopin
    MCUs specialist
    Mishella wrote:
    is it wrong and the capacitor needs to be removed?

    It's not wrong, the capacitor is perfectly OK and I highly recommend to leave it where it is (;

    4\/3!!
  • ADVERTISEMENT
  • #9 13324638
    tadzik85
    Level 38  
    [quote="Mishella"]
    tadzik85 wrote:
    Remove capacitor on NRTS?
    CPU is new, never programed?

    Yes, it's new MCU, freshly mounted after ariving from farnell. I refered to http://www.st.com/st-web-ui/static/active/en/...technical/document/user_manual/DM00027954.pdf while designing reset button, is it wrong and the capacitor needs to be removed?

    I just look on discovery schematic, it's can be.

    Double check conections.

    Bad soldering?
  • #10 13324640
    Mishella
    Level 9  
    BlueDraco wrote:
    Is the board powered? Note that SWD connector on Discovery board doesn't provide power to the programmed board. Actually only three wires are required for programming the fresh MCU - GND, SWDIO & SWCLK.

    It's connected to USB and the power LED is on, I guess it's all okay.

    SeerKaza wrote:
    I guess u using STMutility when i look yours logs. So you should try do what programs says. Change in Target-Settings connections mode.

    It's ST-Link V2 ... and I tried the suggested and it ended up with another error saying:
    12:30:41 : ST-LINK Firmware version : V2J14S0
    12:30:41 : Connected via SWD.
    12:30:41 : Connetion mode : Connect Under Reset.
    12:30:41 : Debug in sleep and stop mode enabled.
    12:30:41 : Device ID:0x416
    12:30:41 : Device flash Size : 128KBytes
    12:30:41 : Device family :STM32L1xx medium density
    12:30:41 : Can not connect to device!

    Is it possible it can't be flsahed, cause windows won't recognize it? As I plug it in USB, Windows says it's unrecognized device.
  • #11 13324742
    Freddie Chopin
    MCUs specialist
    Mishella wrote:
    Is it possible it can't be flsahed, cause windows won't recognize it? As I plug it in USB, Windows says it's unrecognized device.

    It does not matter.

    4\/3!!
  • ADVERTISEMENT
  • #12 13325080
    Mishella
    Level 9  
    I feel lost now, dont know what else should i try, considering I have no access to oscilloscope :/
  • #13 13325135
    Freddie Chopin
    MCUs specialist
    Use a multimeter and test all of the connections for shorts or lack of connection. Remember to touch the pins/pads/whatever really gently, because if you press the probe hard, you may "fix" the connection temporarily (for example you push the pin of IC to the trace on PCB and the test is OK, but as soon as you let go the pin bends up again).

    Also try to connect using some othe boot mode (BOOT0 and BOOT1 pins) or when pressing down reset. Or try to use OpenOCD - it doesn't bite (that hard [; ).

    4\/3!!
  • #14 13325435
    Mishella
    Level 9  
    I'm about to try anything to make it work ... in fact I never used OpenOCD, so I'm just heading to check it, hope it's easy enough for lame like me :D
  • #15 13325767
    el2010tmp
    Level 25  
    Where is BOOT1 ??? [set HIGH on PB2]
  • #16 13325859
    Mishella
    Level 9  
    el2010tmp wrote:
    Where is BOOT1 ??? [set HIGH on PB2]

    I didn't used it on my board ... I only used BOOT0. Is it a big mistake? I assume as I only meant to use BOOT0, I forgot to pull up it with 10K :/
  • #17 13325944
    el2010tmp
    Level 25  
    Mishella wrote:
    Is it a big mistake?


    No, it is not necessary. :)

    It is necessary to Vcc from Your board to discover board [pin 1 SWD].
  • #18 13326008
    Mishella
    Level 9  
    el2010tmp wrote:
    It is necessary to Vcc from Your board to discover board [pin 1 SWD].

    I use all 5 pins for SWD: VCC/SWDCLK/GND/SWDIO/NRST as it is declared in schematic.
    So this should not be the problem. My board is profesionally made and I extra paid for 100% e-test, even I tried to check routes and all of them seem to be OK.
  • #19 13326534
    SeerKaza
    Level 20  
    I still thing that is problems with power up order. I had the same. When I power up stlink first and later board i had problems with connection. Try power up u board from STlink (connect VCC from yours JP1 with VDD on STMdiscovery) When you will be have all conections betwen STlink and your board then connect STMdiscovery to computer and try connect with STMutility (both options in setting normal and under reset)

    PS. Sorry my grammar isn't perfect :P
  • #20 13326714
    Anonymous
    Level 1  
  • #21 13326938
    alagner
    Level 26  
    One more thing that might be the case: some faulty Eagle libraries for STM32 chips are available on the net so check your design carefully for package's misplaced pins etc.
  • #22 13329154
    Mishella
    Level 9  
    So ... I checked all of the traces and all of them are fine, connections are 100%. I got both devices powered, mine and discovery kit. All 5 of SWD pins are connected between devices and sometimes I get so lucky, I get a connection in ST-Link. I am able to erase flash, program it and run code, but I can't see anything on my device :/ I wanted to blink LEDS for start, nothing happens. I can see device memory is filled with the code that works okey with my discovery kit, diodes are on ste same pins as on kit. It stays dead :/

    btw. PCB has so many vias cause of the size, it has to be fitted to 5cm length max. to be cheap.
  • #23 13329749
    Anonymous
    Level 1  
  • #24 13329799
    alagner
    Level 26  
    And how about reducing debugger's clock speed?
  • #25 13331935
    Mishella
    Level 9  
    Okay, there is only one small difference between schematic and PCB and it's LDO used, I mounted TPS76933. That's what you can see on the board, I changed it after my PCB was already ordered.
    LED3 in fact works fine, after I power PCB, it lights on. Other 2 LEDS i tried with multimeter seems to be OK. Still, I can't see anything happen after I flash my program into MCU, I can see it in memory and can't see anything on the board, the LEDS should only blink ...
    The code was compiled in IAR and checked on discovery kit, should be ok.
  • #26 13334517
    alagner
    Level 26  
    What is the forward voltage of those leds? Try for example setting some MCU pins (preferably the ones connected to the leds) in high state for some time, long enough to measure it with the voltmeter.
    Is your circuit properly powered?
  • #27 13402986
    Mishella
    Level 9  
    Okey, after I finally got to school to osciloscope and could measure all, I found out my 32k crystal was not working. It was brand new one, but after replacing it the PCB works as charm ;) The leds are blinkin and I encounter no more problems. That was it, no wonder because the mentioned crystal provides base clock for MCU.

    I wanna say big thanks to everyone trying to help me out, I really appreciate it :)

Topic summary

The discussion revolves around programming a custom PCB designed for USB communication and NRF24L01 data reception, utilizing the STM32L152RBT6 microcontroller. The user encounters issues while attempting to flash the program using an ST-LINK V2, receiving connection errors. Various troubleshooting steps are suggested, including checking power connections, jumper settings, and the order of powering devices. The importance of ensuring proper SWD connections and the potential need for a reset capacitor are highlighted. After several attempts and suggestions, the user discovers that a faulty 32k crystal was the root cause of the problem, which, once replaced, allowed the PCB to function correctly, including LED blinking as intended.
Summary generated by the language model.
ADVERTISEMENT