Bootloader imported in SW4STM32 compiles but stuck after usb_init

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
logd32
Posts: 20
Joined: Thu Sep 07, 2017 8:41 pm

Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by logd32 » Tue Dec 05, 2017 5:00 pm

Hi,
I have setup a SW4STM32 project from the bootloader directory so it is more convenient to work on it, it compiles fine but unfortunately the STM32 stucks at usb_init, precisely as soon as the usb NVIC are setup, if I comment out the usb NVIC setup or the whole usb_init then the STM32 doe not stuck and blink LEDs as it should.
I am pretty sure this is due to specific flags or settings in the makefile that are not reproduced in the SW4STM32 project, i tried to add few proprocessor flags but it did not have any effect so i removed them. The exact same code compiled with the makefile works and does not stuck after usb NVIC setup.
Does anyone have an idea on what i should try to make the SW4STM32 project work?
The SW4STM32 project
bootloader.zip
(99.07 KiB) Downloaded 7 times
has been compiled with GCC 4.8 and 5.6, same result.
Thanks

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

Re: Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by Rick Kimball » Tue Dec 05, 2017 5:08 pm

sw4stm32 uses a newer version of the arm-none-eabi-gcc than arduino. You might try changing the optimization to -O1 or even -Og or even -O0 .. assuming it still fits in the first 8k
-rick

logd32
Posts: 20
Joined: Thu Sep 07, 2017 8:41 pm

Re: Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by logd32 » Tue Dec 05, 2017 8:18 pm

Thanks you for the hint, i tried with GCC 4.8 presumably shipped with XCode, but it didnt helped. I will try to find how to use the Arduino GCC instead. Regarding optimisations i already set to -O0, i wil try 01. Yes it still fits in the 8K

EDIT:Afer a check, current version of Arduino gcc is 4.8.3-2014q1, i have modified the project properties to use this gcc, it compiles fine, but problem persists. apparently it still uses Make from XCode, not sure if it matters

Code: Select all

Building target: bootloader.elf
Invoking: MCU GCC Linker
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -T"/Users/hoel/Documents/workspace/bootloader/LinkerScript.ld" -Wl,-Map=output.map -Wl,--gc-sections -o "bootloader.elf" @"objects.list"   -lm
Finished building target: bootloader.elf
 
/Applications/Xcode.app/Contents/Developer/usr/bin/make --no-print-directory post-build
Generating binary and Printing size information:
arm-none-eabi-objcopy -O binary "bootloader.elf" "bootloader.bin"
arm-none-eabi-size "bootloader.elf"
   text	   data	    bss	    dec	    hex	filename
   6564	   1740	   3184	  11488	   2ce0	bootloader.elf

stevestrong
Posts: 2067
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by stevestrong » Tue Dec 05, 2017 9:12 pm

We are talking about F103, right?
Which board do u use?

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

Re: Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by Rick Kimball » Tue Dec 05, 2017 10:02 pm

I checked out the bootloader source and tried a few things all on ubuntu 16.04.

My default arm-none-eabi-gcc is loaded in /usr/bin ... it is version:
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437]

I used the makefile to build from the command line and did a make generic-pc13. I loaded the build/maple_boot.elf it created on a blue pill using a blackmagic probe. I then un-plugged and re-plugged the device and it enumerated as a maple leaf DFU device. I then used the Arduino IDE to compile and load (w/STM32duino bootloader) a blink sketch. It all worked fine. So I guess it doesn't matter if you use a newer version of arm-none-eabi-gcc.

I then created a new SW4STM32 project selecting the "Make project from existing makefile". I selected the directory of the github source . I was able to create a new build target 'generic-pc13' I did a clean and build. It also worked fine. It isn't a "true" eclipse project but it allows you to use the eclipse environment to edit.

Again this was all on linux so I have no idea how it would work on OS/X
-rick

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

Re: Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by RogerClark » Tue Dec 05, 2017 11:32 pm

FWIW

Some changes were made to the bootloader source code to allow it to compiler and run on newer versions of gcc. The issues and commit history will have more information on this.

I only build from the makefile (on Windows) and generally use the same version of gcc that is installed by the Arduino IDE.

I did try a slightly newer version of gcc at one time and it also seemed to work OK.

However the bootloader code is not guaranteed to work with all versions of GCC hence in the readme, it states which version to use.

Also, if you want to build using some other environment, and it doesnt work, then the obvious conclusion is that there is some difference in your build environment, and that you need to change it to build the code in exactly the same way as the makefile does.

e.g. compiler options are likely to have a big impact on the way the code works (or doesn't work)

logd32
Posts: 20
Joined: Thu Sep 07, 2017 8:41 pm

Re: Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by logd32 » Wed Dec 06, 2017 1:30 am

wow nice, thanks for all the testing, yes we are talking of F103CBT6 here. My bootloader source is outdated so its maybe the problem, I will download last rev and try making a new makefile project.

I try to make a bootloader version for STM32L151C8 and STM32F303CC. I have defined the target rules and modified the makefiles, i also added some .ld files and startup files for the L1 and F3, i found where to reference the .ld files but nothing for others, also not sure where to find the .s and .h macro files for L1 and F3.
Other than referencing these files, do i need to adapt each and every registers reference in hardware.h, and possibly each function of the bootlaoder for L1 and F3?

Once the bootladers are ok i will add the Arduino cores for L151 and F303, current stm32duino F303 core is too outdated to be useful, i found some core that seem complete and working (https://github.com/avikde/koduino for F3 and http://library.radino.cc/Arduino_1_8/ra ... .1.tar.bz2 for L1)

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

Re: Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by RogerClark » Wed Dec 06, 2017 2:21 am

The fix for the compiler versions was done quite a while ago, but I would recommend downloading the latest version

Re: Versions for F3 etc

I think a lot of people would be interested in a version for the F4, but from what I understand, quite a few things are different on the F4

I did see a port to F4 on a Chinese website, but it was one of those site where you have to pay to view the code, so I didn't bother (especially as its an unknown Chinese site, so there was no way I'm giving them my credit card details)

logd32
Posts: 20
Joined: Thu Sep 07, 2017 8:41 pm

Re: Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by logd32 » Wed Dec 06, 2017 9:41 am

yes F3 and F4 should be very close, once these L1 and F3 are done i will try to make L4. Please show the URL of chinese website, i may find a way to get it. Regarding the bootloader, after few tests i can see the registers are different on F3 than those used in bootlader so nothing works, i am in the slow process to rewrite bootloader using stdfperiph function instead of direct register access, once finished if the size is too large (which is not sure) i will rewrite the functions with direct access to avoid stdperiph, but in the end i find a bootlader based on stdperiph would be far more convenient for porting to various targets.
N.B this port already includes F4 https://github.com/avikde/koduino but i am still interrested to know the one you found in case it is more recent

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

Re: Bootloader imported in SW4STM32 compiles but stuck after usb_init

Post by RogerClark » Wed Dec 06, 2017 10:12 am

Re: Code for F4 booloader

I posted a thread about it

viewtopic.php?f=3&t=2104


I suspect the code is completely out of date and would not work unless its with the old version of the compiler and without optimisation turned on, and it will also be larger, as the original LibMaple bootloader was 12k not 8k.
But I merged in some fixes to allow size optimastion to work, and that brought it down to just below 8k

Re: Koduino

I'm aware of Avik's repo. (Koduino) , but its primary focus has was initially just F3 and the F4 was added later, but it doesnt have any support for the F1 (which is what most people use because they are ultra cheap)

As well as Avik's repo, there is the official STM core on github.com/stm32duino, but that uses the HAL, and there is @danielef's core which is also HAL based.


Re: Using SPL for the bootloader.

You may be able to get it to fit in 8k, the bare metal version that we currently use, only just squeezes into 8k, so any bloat at all will push it over that boundary.

Post Reply