how do we program the STM32F042K6T6 micrcontroller? - Page 1
Forum section: electronics / general

author: zenerbjt
author_rank: Regular Contributor
timestamp: August 23, 2020, 10:36:43 am
content: Dear Engineers,We need to program the STM32F042K6T6 microcontroller. (LQFP32 footprint)STM32F042K6T6 datasheet:https://www.st.com/resource/en/datasheet/stm32f042k6.pdfDo you know to which pins should the programmer be connected?Also, do you know if there are standard programming connectors/applicators for it? (eg sprung pin arrays). Is there, say, a "Pickit2" type thing for the STM32F042K6T6?We have been asked to put SMD pads of 1.27mm pitch on the PCB in two rows of three….but wonder which pad to connect to which pin on the micro?

author: rhodges
author_rank: Frequent Contributor
timestamp: August 23, 2020, 11:49:26 am
content: On page 34, the datasheet shows pin 23 (A13) as SWDIO and pin 24 (A14) as SWCLK.The common ST-LINK V2 USB device should work fine.Here is a HOWTO where I show how to program and debug the STM32F030 (and STM32F103) on FreeBSD. The OpenOCD target script stm32f0x.cfg might "just work" with your STM32F042.https://www.eevblog.com/forum/microcontrollers/howto-hardware-debugging-stm32f030-and-stm32f103-with-st-link-v2-on-freebsd/msg3097865/#msg3097865

author: voltsandjolts
author_rank: Unknown
timestamp: August 23, 2020, 12:20:59 pm
content: It quite easy once you get started.Sometime's you just can't see the wood for the treez.

author: zenerbjt
author_rank: Regular Contributor
timestamp: August 23, 2020, 01:30:41 pm
content: Thankyou,The ST-Link looks like a good programmer...We have no room for a header on the board with the STM32 micro...so we only have programming pads on there. Are there any "program pin applicators" (eg pogo pins)for STM32 which we can connect up to the ST-LINK and then program the micro via these pads?...................................................................................The below programming lead looks like what they must have been using on the PCB that i am updating...i can see 6 pads on the pcb and this connector looks like it contacts to such a SMD pad array.....but i cant find the part number or datasheet for the below...do you know it?Programming leadhttps://www.tag-connect.com/product/tc2030-swim-nl....i am guessing that the long grey pins are locators which are sprung and press down and retract...and the gold pins are presumably pogo pin programming pin connectors?..............................................................................The missing info needed is what pin on the ST-LINK programmer connects to what pin on the STM32F042K6T6 microcontroller?Also, what is the part number of the connector on the ST-LINK programmer?

author: AndyC_772
author_rank: Super Contributor
timestamp: August 23, 2020, 03:14:44 pm
content: The grey pins are locating pins which pass through holes in the PCB, and the gold pins are sprung. You can either hold the connector in place during programming, or attach a clip to the locating pins on the back of the PCB to retain it. The clip is a Tag-connect part, quite small and fiddly but useful if you're keeping the connector attached for any length of time.As to the pinout, there's no standard, so you'll need to check the schematic and wire it up accordingly. If you're designing the board yourself, then I'd suggest choosing a pinout which is easy to remember.I'd also recommend the ST-Link v2 and the ST-Link Flash utility:https://www.st.com/en/development-tools/stsw-link004.html

author: zenerbjt
author_rank: Regular Contributor
timestamp: August 23, 2020, 04:24:24 pm
content: QuoteThanks,.....bang goes that idea then...there is a micro on the other side of the board to the programming pads, so the locators would bash into it...so this means we can not now use that connector.Please, do you think that the attached is the pinout for programming the STM32F042K6T6 micro from the ST LINK/V2 programmer?

author: rhodges
author_rank: Frequent Contributor
timestamp: August 23, 2020, 05:34:21 pm
content: Here is the cheap ST-LINK V2 that I use. I just bought five more two months ago. (I like leaving projects connected to the USB device.) The pinout is printed on the side.https://www.ebay.com/itm/392606580352Just a few minutes ago, I verified that it works with an STM32F030F4. Ran OpenOCD, then arm-gdb, programmed it, and stepped through it some with hardware debugging.

author: AndyC_772
author_rank: Super Contributor
timestamp: August 23, 2020, 06:04:41 pm
content: That's the header for programming STM8, not STM32. You'll need to connect to the larger header.

author: rhodges
author_rank: Frequent Contributor
timestamp: August 23, 2020, 06:10:38 pm
content: Quote from: AndyC_772 on August 23, 2020, 06:04:41 pmAfter looking at the photo, I see STM8 and STM32 are molded into the plastic.

author: zenerbjt
author_rank: Regular Contributor
timestamp: August 24, 2020, 06:31:57 am
content: Thanks, i wondered if you know the part number of the 20 pin connector for the ST LINK V2? I noticed its not in the user manual.

author: bobaruni
author_rank: Regular Contributor
timestamp: August 24, 2020, 01:01:16 pm
content: If you just want to upload firmware, some variants of the STM32F042 have a built in DFU boot loader so that you can program it with it's built in USB peripheral, just connect USB while pulling the BOOT0 pin high to enter the boot mode then upload your firmware using the ST DfU upload tool.I do however recall the bootloader wasn't factory pre-programmed in early revisions of STM32F042 so YMMV.If you want to debug and upload firmware then you will need an ST-Link/V2 or similar.