Author Topic: Help with ST32F407 Test Code  (Read 1197 times)

0 Members and 1 Guest are viewing this topic.

Offline ssashtonTopic starter

  • Regular Contributor
  • *
  • Posts: 220
  • Country: gb
Help with ST32F407 Test Code
« on: November 05, 2022, 03:46:37 pm »
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!
« Last Edit: November 05, 2022, 03:48:09 pm by ssashton »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: Help with ST32F407 Test Code
« Reply #1 on: November 05, 2022, 04:10:20 pm »
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.
« Last Edit: November 05, 2022, 04:32:22 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline ssashtonTopic starter

  • Regular Contributor
  • *
  • Posts: 220
  • Country: gb
Re: Help with ST32F407 Test Code
« Reply #2 on: November 05, 2022, 04:25:54 pm »
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.
« Last Edit: November 05, 2022, 04:28:28 pm by ssashton »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: Help with ST32F407 Test Code
« Reply #3 on: November 05, 2022, 04:33:54 pm »
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.
« Last Edit: November 05, 2022, 04:35:38 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline ssashtonTopic starter

  • Regular Contributor
  • *
  • Posts: 220
  • Country: gb
Re: Help with ST32F407 Test Code
« Reply #4 on: November 05, 2022, 05:04:43 pm »
Thanks I'll give it a try!

Header labelled UART1
TX = PA9
RX = PA10

I'm not sure if it matters for the firmware but the crystal is labelled 8.000 so I guess 8MHz?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: Help with ST32F407 Test Code
« Reply #5 on: November 05, 2022, 05:17:54 pm »
Yes. But the test uses internal oscillator so not important.
UART1 matches the test code, should work.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline ssashtonTopic starter

  • Regular Contributor
  • *
  • Posts: 220
  • Country: gb
Re: Help with ST32F407 Test Code
« Reply #6 on: November 05, 2022, 06:25:19 pm »
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?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: Help with ST32F407 Test Code
« Reply #7 on: November 05, 2022, 10:52:08 pm »
Normally it's almost instantaneous. But hard to tell having seen that wire mess :-DD
Simply 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.
« Last Edit: November 06, 2022, 12:55:18 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline ssashtonTopic starter

  • Regular Contributor
  • *
  • Posts: 220
  • Country: gb
Re: Help with ST32F407 Test Code
« Reply #8 on: November 06, 2022, 12:48:06 pm »
It works, thank you!

 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: Help with ST32F407 Test Code
« Reply #9 on: November 06, 2022, 12:53:49 pm »
Ooops, I forgot the new line  :D
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline ssashtonTopic starter

  • Regular Contributor
  • *
  • Posts: 220
  • Country: gb
Re: Help with ST32F407 Test Code
« Reply #10 on: November 06, 2022, 11:14:52 pm »
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 the Klipper firmware 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.



« Last Edit: November 06, 2022, 11:27:00 pm by ssashton »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: Help with ST32F407 Test Code
« Reply #11 on: November 07, 2022, 12:08:54 am »
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.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline ssashtonTopic starter

  • Regular Contributor
  • *
  • Posts: 220
  • Country: gb
Re: Help with ST32F407 Test Code
« Reply #12 on: November 07, 2022, 12:36:53 am »
Thanks for your invaluable help!

Setting no bootloader seems to have helped and I am now connecting klipper and the MCU over UART :)

What 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?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: Help with ST32F407 Test Code
« Reply #13 on: November 07, 2022, 12:48:10 am »
Didn't you read the flash in first place? It looked like that in your first picture?
Anyways, All it takes is to check the Klipper Documentation, seems to use STM32_HID_bootloader, releases available here, 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.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline ssashtonTopic starter

  • Regular Contributor
  • *
  • Posts: 220
  • Country: gb
Re: Help with ST32F407 Test Code
« Reply #14 on: November 07, 2022, 12:51:48 am »
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.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5913
  • Country: es
Re: Help with ST32F407 Test Code
« Reply #15 on: November 07, 2022, 12:52:54 am »
No idea. Just try that bootloader, might work in the same way. Can't tell!
There're some Bigtreetech bootloader backups here, which also use marlin.
« Last Edit: November 07, 2022, 12:58:38 am 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: ssashton

Online darkspr1te

  • Frequent Contributor
  • **
  • Posts: 290
  • Country: zm
Re: Help with ST32F407 Test Code
« Reply #16 on: November 14, 2022, 06:16:57 am »
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.
i have built many types of bootloaders for 407 systems, example here is one that operates updates and bootloading from sd-card
https://github.com/darkspr1te/mkstft35_V1_open_bootloader
https://github.com/darkspr1te/mksbootloader
https://github.com/darkspr1te/stm32f407_vet_bootloader

they are easily modified for uart/usb uploading of new firmware by replacing the data fetch routines
also 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 correctly

darkspr1te


 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf