Author Topic: STM32F09x serial bootloader: does it work?  (Read 6712 times)

0 Members and 3 Guests are viewing this topic.

Offline nctnicoTopic starter

  • Super Contributor
  • ***
  • Posts: 30304
  • Country: nl
    • NCT Developments
STM32F09x serial bootloader: does it work?
« on: November 16, 2016, 04:08:01 pm »
I'm wondering whether anyone has some remarks/suggestions about the serial bootloader in the STM32F09x series. I'm working on a tool which should allow the customer (who also wrote the device's firmware) to do updates over the serial port but so far I don't get any further than the auto-baud handshake (send 0x7F receive 0x79) but after that the communication stops. The serial port signals look and decode good on an oscilloscope.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2178
  • Country: fi
  • Embedded SW/HW.
Re: STM32F09x serial bootloader: does it work?
« Reply #1 on: November 16, 2016, 04:27:21 pm »
I wrote a similar tool on Linux for the STM32F030-series processor. I do not remember details, but it went pretty smoothly after all. Just read the application note AN3155 carefully and proceed step by step adding more functionality as you go www.st.com/resource/en/application_note/cd00264342.pdf The first command implemented was "get device id" or similar. The implementation is a simple state machine which had two main states: connected | disconnected. Each command was also a simple state machine which made the debugging easier. Now as I read the code, it is also easy to follow. I used the Saleae Logic as a debugging tool, which proved to be extremely useful. Using a plain oscilloscope (even with a deep memory) is just frustrating.  Remember to flush the rx buffer before each new command. Good luck!
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2178
  • Country: fi
  • Embedded SW/HW.
Re: STM32F09x serial bootloader: does it work?
« Reply #2 on: November 16, 2016, 04:34:59 pm »
Ps. When you open the serial port, disable the HW and XON/XOFF handshakes.

Edit: I am using 100ms receive timeout ie. If there is no character received within this 100ms timeout period, the receive function will return error.
« Last Edit: November 16, 2016, 04:39:58 pm by Kalvin »
 

Offline nctnicoTopic starter

  • Super Contributor
  • ***
  • Posts: 30304
  • Country: nl
    • NCT Developments
Re: STM32F09x serial bootloader: does it work?
« Reply #3 on: November 16, 2016, 04:54:58 pm »
I did all that but either with my software, ST's own UART flash loader utility or manually with Teraterm I can't get the bootloader to do anything beyond the auto baud stage.
« Last Edit: November 16, 2016, 04:59:46 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2178
  • Country: fi
  • Embedded SW/HW.
Re: STM32F09x serial bootloader: does it work?
« Reply #4 on: November 16, 2016, 04:59:43 pm »
Change the USB to ttl-serial dongle. I have had some problems with the cheap dongles - the signal levels with the 3V devices do not quite match resulting lost or intermittent communication or the baud rate will be a little off or fluctuating which will generate occasional transmission errors. Changing the dongle has been the cure.
« Last Edit: November 16, 2016, 05:21:49 pm by Kalvin »
 

Offline nctnicoTopic starter

  • Super Contributor
  • ***
  • Posts: 30304
  • Country: nl
    • NCT Developments
Re: STM32F09x serial bootloader: does it work?
« Reply #5 on: November 16, 2016, 05:15:24 pm »
Change the USB to ttl-serial dongle.
I did think about doing that but since the signals are OK on an oscilloscope I see very little chance the problem is in the (FTDI) USB-uart converter. Besides that the regular serial communication works just fine with the same converter.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline nctnicoTopic starter

  • Super Contributor
  • ***
  • Posts: 30304
  • Country: nl
    • NCT Developments
Re: STM32F09x serial bootloader: does it work?
« Reply #6 on: November 16, 2016, 06:59:57 pm »
or the baud rate will be a little off or fluctuating which will generate occasional transmission errors. Changing the dongle has been the cure.
How much was the baudrate off? I just made some measurements with the baudrate set at 38400. The USB-UART is spot on but the STM32F09x seems to be at 38600. That is a difference around 0.5% so it is well within general UART tolerance but if the bootloader is somehow using a soft-UART with too strict timing then all bets are off.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 3846
  • Country: gb
Re: STM32F09x serial bootloader: does it work?
« Reply #7 on: November 16, 2016, 07:30:57 pm »
Just to be sure, you could try an FTDI baud rate of 38585 (3e6/77.75)
 

Offline jesuscf

  • Frequent Contributor
  • **
  • Posts: 503
  • Country: ca
Re: STM32F09x serial bootloader: does it work?
« Reply #8 on: November 16, 2016, 11:53:31 pm »
How are you activating the bootloader?  I have a SM32F051 with a push-button connected to BOOT0.  BOOT0 is pulled down with a 330 ohm resistor and connected to 3.3V when the push-button is pressed.  While pressing the push-button at BOOT0 I press and release the push-button connected to NRST and then release the push-button connected to BOOT0.  Also I have a 470uF electrolytic capacitor between 3.3V and GND I don't remember why... Seems to work every time.

I'm wondering whether anyone has some remarks/suggestions about the serial bootloader in the STM32F09x series. I'm working on a tool which should allow the customer (who also wrote the device's firmware) to do updates over the serial port but so far I don't get any further than the auto-baud handshake (send 0x7F receive 0x79) but after that the communication stops. The serial port signals look and decode good on an oscilloscope.
Homer: Kids, there's three ways to do things; the right way, the wrong way and the Max Power way!
Bart: Isn't that the wrong way?
Homer: Yeah, but faster!
 

Offline nctnicoTopic starter

  • Super Contributor
  • ***
  • Posts: 30304
  • Country: nl
    • NCT Developments
Re: STM32F09x serial bootloader: does it work?
« Reply #9 on: November 17, 2016, 12:00:02 am »
The bootloader is activated from software by (AFAIK) writing a special value into a register before resetting the controller. This is a two stage process where the controller is reset twice. First to restart the firmware which then jumps into the bootloader before initialising the peripherals with the second reset. At least that is how it should work but I can't check whether it is implemented correctly.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline jesuscf

  • Frequent Contributor
  • **
  • Posts: 503
  • Country: ca
Re: STM32F09x serial bootloader: does it work?
« Reply #10 on: November 17, 2016, 01:27:24 am »
Maybe the bootloader is not activated. AN2606 (st.com/resource/en/application_note/cd00167594.pdf) describes several ways of activating the bootloader.  Could it be possible in your hardware to try to activate the bootloader using the BOOT(x) pin(s)?

EDIT: AN2606 says: "The STM32F09xxx bootloader is activated by applying pattern6 (described in Table 2: Bootloader activation patterns). The following table shows the hardware resources used by this bootloader."

Pattern6
Boot0(pin) = 1, nBoot1(bit) = 1 and nBoot0_SW(bit) = 1
nBoot0(bit) = 0, nBoot1(bit) = 1 and nBoot0_SW(bit) = 0
Boot0(pin) = 0, nBoot0_SW (bit) = 1 and main flash empty

The STM32F051 is activated using pattern2:
Boot0(pin) = 1 and nBoot1(bit) = 1
« Last Edit: November 17, 2016, 01:47:53 am by jesuscf »
Homer: Kids, there's three ways to do things; the right way, the wrong way and the Max Power way!
Bart: Isn't that the wrong way?
Homer: Yeah, but faster!
 

Offline LHelge

  • Contributor
  • Posts: 21
  • Country: se
    • My project blog
Re: STM32F09x serial bootloader: does it work?
« Reply #11 on: November 22, 2016, 01:31:22 pm »
I know there is an undocumented bug/feature on the STM32F042 chips where the bootloader internally checks the BOOT0-pin on startup and freezes up if it isn't set to 1. This creates a lot of problems if you're trying to jump to the bootloader using software. Perhaps it's the same with the STM32F09x

One thing that works is to conenct a small capacitor to the BOOT0-pin and a weak pull-down resistor. To get to the bootloader you configure the BOOT0-pin as an output and pull it high to charge the capacitor for a short period of time and then reset. The capacitor will keep it high for long enough to get past the part of the bootloader which checks the state of the BOOT0-pin.
My Project Blog
http://www.lhelge.se
 

Offline nctnicoTopic starter

  • Super Contributor
  • ***
  • Posts: 30304
  • Country: nl
    • NCT Developments
Re: STM32F09x serial bootloader: does it work?
« Reply #12 on: January 06, 2017, 01:37:59 pm »
Time to get back on this: it turned out the board I had on loan had been used for other software experiments which for some reason prevented the bootloader from working properly. A different board worked OK.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->