Help with ST32F407 Test Code - Page 1
Forum section: electronics / general

author: ssashton
author_rank: Frequent Contributor
timestamp: November 05, 2022, 03:46:37 pm
content: I've got this 3D printer I'm trying to 'hack' new firmware on which uses the ST32F407. I've got a spare mainboard but I'm not certain it is properly functional.I wondered if anyone could help me out with a .bin that I can flash to the board and would output a repeating message over UART1 at 115200 baud? I'd really appreciate that. No LED for blinky.I'm able to enter bootloader mode and Cube-Programmer says it writes successfully.Also am I right thinking there is nothing more to flashing firmware other than putting MCU in bootloader mode, connecting Cube-Programmer, hitting upload and verify, then back to run mode on the MCU. That's it right?Thank you!

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 05, 2022, 04:10:20 pm
content: What programmer are you using? Do you have st-link?Alternatively you can use UART bootloader. Cube Programmer supports it.Not sure if that board has USB port? If so it shoudl also be able to use DFU mode.Find the mcu pins wherw TX/RX are connected to, so I know which UART periopheral to use, there are a few.EDIT: After zooming in I saw "UART1". Nice.The only way to set it into bootloader mode is to set BOOT0 pin to 1. Is that GIANT switch?Some boards hardwire it to GND, lifting a single pin is not easy job, very risky operation!ST-Link would avoid the need of setting BOOT0 pin.There're leds in the fan outputs, find which pins toggle the transistor gates and it'll be easy!Attached simple project that sends some stuff through UART1 and UART4.Binary placed in Debug folder.

author: ssashton
author_rank: Frequent Contributor
timestamp: November 05, 2022, 04:25:54 pm
content: Thanks for your reply!I've got it to bootloader mode (yes that massive switch). I can connect bootloader both over USB or by UART1 with an FTDI board.But I have no way to know if it's running right. I did try to tell the firmware I'm attempting to install (Klipper) to use UART1 but it doesn't work. Before I accuse the firmware I need to know the MCU is actually working right so a simple .bin that I can confirm a message over UART1 would be ideal.I have a reason to suspect something is not right on the MCU as I know UART-3 is at 1.4V when it should be at 3.3V. IT would be good to know if that is the extent of the issue.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 05, 2022, 04:33:54 pm
content: It could be either the pin sending data (Toggling), or unused (Pin floating), both would explain the strange voltage reading.Edited the previous post adding a test binary!Anyways, track were the uart pins are going. STM32 usually have alternative pins, so it might be working, but not connected to the right pin.

author: ssashton
author_rank: Frequent Contributor
timestamp: November 05, 2022, 05:04:43 pm
content: Thanks I'll give it a try!Header labelled UART1TX = PA9RX = PA10I'm not sure if it matters for the firmware but the crystal is labelled 8.000 so I guess 8MHz?

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 05, 2022, 05:17:54 pm
content: Yes. But the test uses internal oscillator so not important.UART1 matches the test code, should work.

author: ssashton
author_rank: Frequent Contributor
timestamp: November 05, 2022, 06:25:19 pm
content: Is it the .bin file in the debug directory I need to flash? I'm not familiar with all the other project files , never coded for ST32.Is it normal that my board takes about 1:30min after connecting USB to the PC to go 'bing!' and show as a device? I guess it takes a long time because it is sending over the drivers?

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 05, 2022, 10:52:08 pm
content: Normally it's almost instantaneous. But hard to tell having seen that wire messSimply click the Open file tab, open the provided Debug/bin file and program it.If it works, you should see some activity in the UART ports.

author: ssashton
author_rank: Frequent Contributor
timestamp: November 06, 2022, 12:48:06 pm
content: It works, thank you!

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 06, 2022, 12:53:49 pm
content: Ooops, I forgot the new line

author: ssashton
author_rank: Frequent Contributor
timestamp: November 06, 2022, 11:14:52 pm
content: So... I'm going to show my ignorance here. When I erased the flash via Cube-Programmer, will I also have erased the bootloader? I don't mean the built-in DFU one for programming, but the normal run-time bootloader. I suppose the answer is yes.In that case maybe the issue I'm having is that theKlipperfirmware I'm trying to flash is the application only, without a bootloader. Does that sound possible? In most cases I think it is expect to flash the Klipper firmware to an MCU that already boots and has it's pins setup.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 07, 2022, 12:08:54 am
content: Yes, if you deleted the bootloader and the firmware extects it to be there, it won't work.You will first need to flash the bootloader, then use it to flash the firmware.You can also download the sources and compile yourself, doing "make menuconfig", choosing your board options, there must me some parameter to set "No bootloader", in that case it will run right away after flashing with stlink.

author: ssashton
author_rank: Frequent Contributor
timestamp: November 07, 2022, 12:36:53 am
content: Thanks for your invaluable help!Setting no bootloader seems to have helped and I am now connecting klipper and the MCU over UARTWhat I have been trying to do is put Klipper on the Anker M5 printer. This printer has motion controlled by the ST32 board plus a touchscreen interface / Wifi etc run from a Linux board.I flashed the ST32 it using the DFU bootloader but that requires soldering an 0402 resistor which I think most people will not be comfortable doing. I'm sure the original firmware (tweaked marlin) must include a bootloader because the linux board is able to update it over UART.Do you know if there is a way to identify the original bootloader being used by Anker?

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 07, 2022, 12:48:10 am
content: Didn't you read the flash in first place? It looked like that in your first picture?Anyways, All it takes is to check theKlipper Documentation, seems to useSTM32_HID_bootloader, releases availablehere, including HID flash tool for Windows, Linux...This bootloader appears to use 0x4000 offset, so adjust that in Klipper menuconfig.No idea if that's the original bootloader or not.

author: ssashton
author_rank: Frequent Contributor
timestamp: November 07, 2022, 12:51:48 am
content: I think I've confused you. I'm talking about the board before I flashed klipper or anything else on it. It was running Marlin inside the Anker M5 machine, but the flash was read protected, all I could do was erase it.I've now managed to put Klipper on it using DFU mode but most people will not want to hack the board in that way so it would be good to know what bootloader Anker already had on the board before I erased it. Knowing that, other people might be able to flash Klipper on there without having to use DFU.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 07, 2022, 12:52:54 am
content: No idea. Just try that bootloader, might work in the same way. Can't tell!There're some Bigtreetech bootloader backupshere, which also use marlin.

author: darkspr1te
author_rank: Frequent Contributor
timestamp: November 14, 2022, 06:16:57 am
content: Quote from: ssashton on November 07, 2022, 12:51:48 ami have built many types of bootloaders for 407 systems, example here is one that operates updates and bootloading from sd-cardhttps://github.com/darkspr1te/mkstft35_V1_open_bootloaderhttps://github.com/darkspr1te/mksbootloaderhttps://github.com/darkspr1te/stm32f407_vet_bootloaderthey are easily modified for uart/usb uploading of new firmware by replacing the data fetch routinesalso you can alter the arduino bootloader too, you will need to know the new entry/irq vectors for the firmware as they are not always the same so you will have to check the firmware sources for the actual required entry point address in flash , eg. ox7000 is where the ks bootloader starts writing but 0x8000 is where arduino starts writing to flash so a little code diving would be required to set this correctlydarkspr1te