Setup of STM32F103CBT6 (Maple Mini) board

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
User avatar
RogerClark
Posts: 7443
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by RogerClark » Thu Jan 19, 2017 7:54 pm

One think to remember is that the bootloader does not contain the Serial COM device code.
It only contains the DFU upload code.

You need to upload a sketch which uses Serial before you will see a COM port.

victor_pv
Posts: 1739
Joined: Mon Apr 27, 2015 12:12 pm

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by victor_pv » Fri Jan 20, 2017 3:48 am

RogerClark wrote:One think to remember is that the bootloader does not contain the Serial COM device code.
It only contains the DFU upload code.

You need to upload a sketch which uses Serial before you will see a COM port.
Roger, I have updated the modified sketch in my post, in the second page.
Now works as expected, tested it myself.

If the flash write fails, the sketch gives an option to clear the option bytes, which will clear write protect, but not read protect (so will not clear the flash). Once the board is rebooted again the write protect is completely cleared and the flash can be written to by the sketch.

I think you should update the sketch in your repo, for anyone that received a maple clone with write protect set.

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

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by RogerClark » Fri Jan 20, 2017 9:10 am

Thanks victor,

Can you repost you newest version, just so I know which one to use

Phil333
Posts: 23
Joined: Mon Jan 16, 2017 3:26 pm

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by Phil333 » Fri Jan 20, 2017 2:17 pm

@Victor:
Well I'm pretty sure that I did only go to "Edit option bytes" but didnt know what to do there, so I went back and "DUSABLE WRITE PROTECTION". Then I started again and did the "Download to device" an selected the bootloader.

BUT to get there I had to "Remove Protection" before. It was the first window after connecting to the device (screenshot done and attached).
01.PNG
01.PNG (27.32 KiB) Viewed 460 times
02.PNG
02.PNG (37.42 KiB) Viewed 460 times
If this helps you @victor, I can "ENABLE WRITE PROTECTION" and try your sketch again.
Sadly I dont find the original maple bootloader so I cant start from there again.
By the way: is this "ENABLE WRITE PROTECTION" the only thing that the manufacturere made?
If so, then it would be 100% the same condition like I received it :)

@Roger this is the Code that victor is talking about:
Update locked Bootloader

User avatar
ahull
Posts: 1650
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by ahull » Fri Jan 20, 2017 2:35 pm

I suspect that write protection is only enabled on the first page(s) of flash. If this were not the case then it would be impossible to load a sketch.
- Andy Hull -

victor_pv
Posts: 1739
Joined: Mon Apr 27, 2015 12:12 pm

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by victor_pv » Fri Jan 20, 2017 3:05 pm

ahull wrote:I suspect that write protection is only enabled on the first page(s) of flash. If this were not the case then it would be impossible to load a sketch.
Agreed, probably in the first 16KB, I believe that was the size of the original bootloader.

@Phil I think the sketch will not even try to update, since the same version of the bootloader is already installed, so it will never get to the point were it tries to clear the write protection.
If you want to flash the original bootloader, it's available on this link
http://docs.leaflabs.com/static.leaflab ... i_boot.bin
The link is from this page, which contain links to the original leaflabs bootloaders for the different boards they made:
http://docs.leaflabs.com/static.leaflab ... oader.html

If you could test it would be good for a confirmation, since I only tested on one board with an RCT MCU and had to modify the page size for that. I'm confident it will work fine, but if it doesn't, now you have mastered the serial method :D

Phil333
Posts: 23
Joined: Mon Jan 16, 2017 3:26 pm

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by Phil333 » Sat Jan 21, 2017 9:10 am

So I will set write protection for page 0-15 (1K each = 16K).

EDIT:

So I have done that and flashed the original bootloader to it.
I verified its is the original one by flashing the Arduino blink example to it an chose the original bootloader.

I uploaded the sketch of you @viktor but only get this massege again:
**************************************************************************************************
*** This sketch will update the bootloader in the Maple Mini to the STM32duino bootloader ****
*** With this you can use up to 120KB of Flash and 20KB of RAM for a Sketch ****
*** Uploading is also considerably faster on OSX (and possibly faster on Linux) ****
*** ****
*** Only use with Maple mini boards ****
*** ****
*** WARNING. If the update fails your Maple mini may not have a functional bootloder. ****
*** ****
*** YOU UPDATE AT YOUR OWN RISK ****
*** ****
*** ****
*** ****
*** ****
**************************************************************************************************
*** ****
*** ****
*** To confirm and proceed, enter Y ****
*** ****
*** ****

*** WARNING, Update Failed!! It is possible that the flash memory is Write-protected. ****
*** ****
*** We can try clearing the option bytes. ****
*** After that, you will need to do a reset and try again ****
*** ****
**************************************************************************************************
*** ****
*** ****
*** To confirm and proceed, enter Y, to cancel power down now. ****
*** ****
*** The option bytes have been cleared, reboot now and try to update again ****

If I now just reset the board via its button, I cant communicate with it via the serial monitor.
If I unplug and replug the device completely, then I can communicate but it starts from the same point and gives the same messages via the serial monitor...

victor_pv
Posts: 1739
Joined: Mon Apr 27, 2015 12:12 pm

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by victor_pv » Sun Jan 22, 2017 6:40 pm

Phil333 wrote:So I will set write protection for page 0-15 (1K each = 16K).

EDIT:

So I have done that and flashed the original bootloader to it.
I verified its is the original one by flashing the Arduino blink example to it an chose the original bootloader.

I uploaded the sketch of you @viktor but only get this massege again:
**************************************************************************************************
*** This sketch will update the bootloader in the Maple Mini to the STM32duino bootloader ****
*** With this you can use up to 120KB of Flash and 20KB of RAM for a Sketch ****
*** Uploading is also considerably faster on OSX (and possibly faster on Linux) ****
*** ****
*** Only use with Maple mini boards ****
*** ****
*** WARNING. If the update fails your Maple mini may not have a functional bootloder. ****
*** ****
*** YOU UPDATE AT YOUR OWN RISK ****
*** ****
*** ****
*** ****
*** ****
**************************************************************************************************
*** ****
*** ****
*** To confirm and proceed, enter Y ****
*** ****
*** ****

*** WARNING, Update Failed!! It is possible that the flash memory is Write-protected. ****
*** ****
*** We can try clearing the option bytes. ****
*** After that, you will need to do a reset and try again ****
*** ****
**************************************************************************************************
*** ****
*** ****
*** To confirm and proceed, enter Y, to cancel power down now. ****
*** ****
*** The option bytes have been cleared, reboot now and try to update again ****

If I now just reset the board via its button, I cant communicate with it via the serial monitor.
If I unplug and replug the device completely, then I can communicate but it starts from the same point and gives the same messages via the serial monitor...
Thanks, I think I have found the cause.
It seems like the write protection is correctly disabled, but then read protection is enabled, which also causes the updater to fail.
I'll have to use a different method to clear the write protection without altering the read one.

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

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by RogerClark » Sun Jan 22, 2017 11:42 pm

Is it possible to enable read protection on a flash by flash page?
I thought disabling the read protection was for the whole of flash and also erases it, so the code that was in there could not be read as it had been erased.

I can't quite see how you could have a system where each page of flash had its own read protection, unless each page could only be read by code running from within that page, and I don't think the STM32 has a feature quite as complex as that.

Overall, it sounds like the company who is loading the bootloader has no idea what the bootloader does, and that the device should not be read protected.

victor_pv
Posts: 1739
Joined: Mon Apr 27, 2015 12:12 pm

Re: Setup of STM32F103CBT6 (Maple Mini) board

Post by victor_pv » Mon Jan 23, 2017 12:33 am

RogerClark wrote:Is it possible to enable read protection on a flash by flash page?
I thought disabling the read protection was for the whole of flash and also erases it, so the code that was in there could not be read as it had been erased.

I can't quite see how you could have a system where each page of flash had its own read protection, unless each page could only be read by code running from within that page, and I don't think the STM32 has a feature quite as complex as that.

Overall, it sounds like the company who is loading the bootloader has no idea what the bootloader does, and that the device should not be read protected.
Hi Roger, you are right about the read protection, it's for the whole device, and write protection is page by page.
But write protection can be disabled and enabled without clearing the device, while read protection can be enabled any time, but disabling it after wards clears the whole flash.

What was happening with the modified sketch is that while clearing the write protection, it was also enabling the read protection. I have modified it now so it clears the write protection without modifying read protection.

I have updated it in my post in the second page, and tested it a few times with an RCT MCU. I'll ask Phil if he doesn't mind testing it a couple of times with a maple mini to confirm it's all good.

Post Reply