Stm32duino bootloader

Information on the latest releases
User avatar
RogerClark
Posts: 7458
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Stm32duino bootloader

Post by RogerClark » Mon Jun 08, 2015 5:56 am

I've removed the old usb-bootloader code from the repo and added a reference to the stm32duino-bootloader repo as a sub module

If you download the repo via zip you will get the bootloader sources and binaries, however if you use Git, you will need to use git submodule init and git submodule update in order to download the submodules (this will also get the texane stlink submodule)

I've also updated several pages in the wiki related to the bootloader and added a new page specifically for the stm32duino bootloader.

https://github.com/rogerclarkmelbourne/ ... bootloader

One thing I've realised about the bootloader is if you upload onto a clean board (previously unused, or which had sketches uploaded to the base of flash, that the board ends up flashing the led to indicate there is no code to execute.

I will have a go at fixing this, as the board may as well be locked in DFU upload mode if there is no code to execute, rather than just flashing the LED all the time.


I was wrong.

Immediately after installing the bootloader, the longer flashing sequence is the while loop while it waits fro DFU, i.e its in "perpetual bootloader" mode at this point, so no changes are needed to the bootloader :-)

stuartw
Posts: 36
Joined: Mon Jun 01, 2015 8:57 am

Re: Stm32duino bootloader

Post by stuartw » Thu Jun 11, 2015 4:31 am

While it is typically my own incompetence, I have noticed that using the prebuilt stm32duino-bootloader-master in generic_boot20_pc13.bin form (prebuilt) everything is working on my 'generic' board, except that PB12 is not bouncing between startup and execution, so the USB is never transitioning from DFU to serial.

Now, these boards dont have the maple hardware, and therefore as I understand it should be using the 'drop PA12' method, however scoping that
it looks like a rock through the transition. no sign of the drop.
I am running a modded fastblick, that does a Serial.println(); per blink.

If I bounce my jumper that tied the USB bias resistor to power after transition from DFU, then everything does come up perfectly, so I am pretty confident its the PA12 drop that is missing.

I would be able to do better I suspect if my building of the bootloader worked - I suspect my default toolchain is a little out of spec (gcc 4.9 build 221220), but thats a different story.

I just thought I would point it out in case its not just me.. I will try and align my build so I can actually build the bootloader, then see if I can work it out.

If I can get that worked out, my next project is trying to get the W5500 version of the ethernet lib to work, since the default currently included is a modded old version of the W5100 only, and the W5500 is SO much nicer..

User avatar
RogerClark
Posts: 7458
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Stm32duino bootloader

Post by RogerClark » Thu Jun 11, 2015 4:46 am

@stuartw

(Presuming you are on windows)

What I did to build was to put the Arduino ARM compiler into my Windows PATH (env var) . For Make I'm using the WinAVR make file.

Initially I was using MinGW, but all I was really using it for was Make, so after someone pointed out that WinAVR had make, and I already that that installed, I just used that Make instead

Re: PA12 toggling

The code actually pulls PA12 low

Code: Select all

  SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC),
          (GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_OUTPUT_PP << CR_SHITF(USB_DISC));

  gpio_write_bit(USB_DISC_BANK,USB_DISC,0);  /* present ourselves to the host */
I thought PA12 normally has a 1.5k to Vcc

I'm not sure if we can drive it low then high, i.e whether this would overload the STM32's output current on PA12

i.e I think you are saying that your board doesnt have sufficient pull up on PA12 ??

stuartw
Posts: 36
Joined: Mon Jun 01, 2015 8:57 am

Re: Stm32duino bootloader

Post by stuartw » Thu Jun 11, 2015 5:16 am

I do need to check (sorry in the depths of W5500 fun right now) but I do have the usual 1.5k pullup.
(sorry, yes I am on windows, for my sins..)
I just need to juggle my build env between several projects, too many things on the list!


What I am seeing is that PA12 is not being pulled low (sorry, thats what I meant by dropped, poor choice of words).
my PA12 has the usual 22ohm/1.5k pair on it leaving PA12, however the 1.5k has a jumper between it an its power.
Hence I can also send PA12 low by removing the jumper.
If I do that then I do see the USB switch modes.. so it seems as if PA12 is not trying to pull low.. however it could of course
be other things. Perhaps I just miss the low transition and it is too fast for my USB - possible, but I dont normally have a
problem with the normal bootloader on other boards.

I wonder if for some reason the code is not triggering? I am sure many people would see the problem in that case..

I will work on getting the build env up ASAP.

User avatar
RogerClark
Posts: 7458
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Stm32duino bootloader

Post by RogerClark » Thu Jun 11, 2015 5:46 am

Stuart

I'm a bit confused.

If you leave the PA12 jump link in position, doesnt that give you the normal 1.5k to vcc ?

If so, and its not re-enumerating, then I agree it sounds like its not pulling PA12 low

There are 2 places in the code this happens.
One place in the bootloader and one place in the uploaded sketch

All the generic bootloader versions, should compile in the USB reset code, i.e its in the bootloader config.h, whether the board has the maple hardware and in the code

it either uses the DISC pin, which is attached to the maple reset hardware, or it uses PA12

Code: Select all

#ifdef HAS_MAPLE_HARDWARE	
  /* Setup USB DISC pin as output open drain */	
  SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC),(GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_OUTPUT_OD << CR_SHITF(LED_PIN));  
  gpio_write_bit(USB_DISC_BANK,USB_DISC,1);

  /* turn on the USB clock */
  //pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;// done in setupCLK()

  gpio_write_bit(USB_DISC_BANK,USB_DISC,0);  /* present ourselves to the host */
#else
// USE PA12 which is connected to USB pin D-
  SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC),
          (GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_OUTPUT_PP << CR_SHITF(USB_DISC));

  gpio_write_bit(USB_DISC_BANK,USB_DISC,0);  /* present ourselves to the host */
  
  volatile unsigned int delay;
  for(delay = 0;delay<1024;delay++);

  //  volatile unsigned x = 1024; do { ; }while(--x);// wait a moment
  /* turn on the USB clock */
   SET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC),
          (GET_REG(GPIO_CR(USB_DISC_BANK,USB_DISC)) & crMask(USB_DISC)) | CR_INPUT << CR_SHITF(USB_DISC)); //Sets the PA12 as floating input
 //  pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;
#endif  
in the sketch it uses a different #define

in which case, the board in question defines

-DGENERIC_BOOTLOADER

in boards.txt

which in turn is used by this code in the sketch

Code: Select all

#ifdef GENERIC_BOOTLOADER			
			//Reset the USB interface on generic boards - developed by Victor PV
			gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_OUTPUT_PP);
			gpio_write_bit(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit,0);
			
			for(volatile unsigned int i=0;i<256;i++);// Only small delay seems to be needed, and USB pins will get configured in Serial.begin
			gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_INPUT_FLOATING);
#endif
Now I look at the 2 bits of code one after the other, I've noticed that we use a different delay loop in the sketch to the Bootloader

This was not by design.

The should both be the same, but I'm not sure what value they should be

Initually we went with a really long delay e.g 1ms or something, but after some testing, a shorter delay seemed possible (and perhaps even better than a long delay)

The maple hardware just seems to pulse the pin high for a very short period of time, ie just the time taken to call the function to set and reset the pin.
However I think I tried removing the delay entirely and I don't think that worked when controlling PA12

Anyway, if you can determine which of those reset pulses is not working we may be able to sort out a solution

stuartw
Posts: 36
Joined: Mon Jun 01, 2015 8:57 am

Re: Stm32duino bootloader

Post by stuartw » Thu Jun 11, 2015 8:50 am

Aha! I was right from the first post.. the problem was me being an idiot.

I had not realised that of course the sketch needs to know about the difference in hardware, as well as the bootloader.
Hence I was building as maple mini, not generic stm32f103c - and the sketch was trying to use the maple method to drop
the usb - I has assumed (rather foolishly) that the bootloader would reset usb before transfering to the sketch, rather than the
sketch doing that part of the work.

So, several hours of chasing the assumption that perhaps it was a timing issue with my usb3 external hub, or this board, only
to find out as usual it was my incompetence.

The building issue was also related to my 4.9 gcc, the arduino toolchain works fine, as it should.

The hint (thank you for it) was in the line:
"There are 2 places in the code this happens. One place in the bootloader and one place in the uploaded sketch"

Once I thought about it, it was obvious.

User avatar
RogerClark
Posts: 7458
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Stm32duino bootloader

Post by RogerClark » Thu Jun 11, 2015 10:10 am

Stuart,

No worries.

Its also common miss conception that the bootloader handles the USB Serial.

We could probably move both resets into the bootloader, but it normally works OK where it is now.

manu84
Posts: 7
Joined: Wed Aug 09, 2017 9:42 am

Re: Stm32duino bootloader

Post by manu84 » Thu Aug 17, 2017 8:51 pm

Hello Roger,

all link in https://github.com/rogerclarkmelbourne/ ... Bootloader look to be dead (404 error)
Could you tell me wher I could upload the maple_mini_bootloaer_updater.ino sketch?

Regards
Emmanuel
France.

User avatar
Rick Kimball
Posts: 1057
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Stm32duino bootloader

Post by Rick Kimball » Thu Aug 17, 2017 9:23 pm

-rick

User avatar
RogerClark
Posts: 7458
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Stm32duino bootloader

Post by RogerClark » Thu Aug 17, 2017 10:23 pm

I should remove that wiki page in the main repo now that the bootloader is in its own repo.

Post Reply