Optimization level 1 and s do not work with STM32F051 demo

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

bobc
Posts: 10
Joined: Wed Oct 17, 2012 1:36 pm

Optimization level 1 and s do not work with STM32F051 demo

Post by bobc »

Hi there,

I am using the STM32F051-DISCOVERY example. I find that when setting optimization to level 1 or s, the demo does not run. The demo works find when optimization is set to 0 or 2.

I am guessing this is probably similar issue to previous problems caused by optimization (an exception occurs and the demo hangs). I haven't managed to get my debugger going on it, so I am just going by the state of the LEDs.

I using latest ChibiOS from the github master branch. Compiler is "(Sourcery G++ Lite 2011.03-42) 4.5.2".

Are there any ideas of how to resolve this? I would really like to use -Os in my project, there never seems to be enough Flash...

Cheers
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Optimization level 1 and s do not work with STM32F051 de

Post by Giovanni »

Hi,

Thanks for reporting, I found the problem in crt0.c. You can set CRT0_INIT_STACKS=0 as workaround, in the meanwhile I will open a ticket and handle this.

I think this is the cause of all the similar optimizations-related problems.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Optimization level 1 and s do not work with STM32F051 de

Post by Giovanni »

Fixed on the repository.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Optimization level 1 and s do not work with STM32F051 de

Post by barthess »

Does not help me.
Moving __early_init() call after stack initialization code too.
Looks like disabling FLASH_ACR_ICEN or FLASH_ACR_DCEN bits when initializing
flash access in hal_lld.c helps.

UPD:
That bits must be both disabled.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Optimization level 1 and s do not work with STM32F051 de

Post by Giovanni »

You are right, __early_init() must be moved too, I don't understand the issue with those bits, doing so kills the MCU performance.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Optimization level 1 and s do not work with STM32F051 de

Post by barthess »

Giovanni wrote:doing so kills the MCU performance.

hm... for the first look performance does not affected at all.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Optimization level 1 and s do not work with STM32F051 de

Post by Giovanni »

But those bits should not affect anything, so it is possible you are masking the effect but there is another cause.

After moving __early_init() I don't see other problems in all demos I tested, let's wait some more feedback.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Optimization level 1 and s do not work with STM32F051 de

Post by barthess »

From stm32f4 errata:
2.1.1 ART Accelerator prefetch queue instruction is not supported
Description
The ART Accelerator prefetch queue instruction is not supported on revision A devices.
This limitation does not prevent the ART Accelerator from using the cache enable/disable
capability and the selection of the number of wait states according to the system frequency.

Workaround
Revision A devices: none
Revision Z devices: fixed.

Is it our problem?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Optimization level 1 and s do not work with STM32F051 de

Post by Giovanni »

Do you have a revision A device? I am not sure if the unit is simply not functional or if it should not be enabled at all.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Optimization level 1 and s do not work with STM32F051 de

Post by barthess »

Yes, my device is rev.A
Post Reply