eldarkg / emdr1986x-std-per-lib

Milandr MCU 1986x Standard Peripherals Library. Mirror:
https://code.launchpad.net/~eldar/emdr1986x-std-per-lib/+git/emdr1986x-std-per-lib
46 stars 29 forks source link

MDR32F9Qx: don't inline EEPROM programming functions #53

Closed AndreySV closed 5 years ago

AndreySV commented 5 years ago

it some cases GCC decided to inline EEPROM programming functions, that results in non-working firmware.

Tested with arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]

Here are parts from *.lss files showing missing empty .ramfunc section without 'noinline' attribute. Pay attention to size of .ramfunc section.

[-------------------- no 'noinline' attribute ----------------------] Sections: Idx Name Size VMA LMA File off Algn 0 .eeprom 00000000 f0000000 f0000000 00011736 20 CONTENTS 1 .text 00001736 00000000 00000000 00010000 24 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .text.align 00000002 00001736 00001736 00011736 20 ALLOC, CODE 3 .data 00000000 20000000 20000000 00011736 20 CONTENTS, ALLOC, LOAD, DATA 4 .ramfunc 00000000 20100000 20100000 00011736 2**0 CONTENTS

[-------------------- with 'noinline' attribute ----------------------] Sections: Idx Name Size VMA LMA File off Algn 0 .eeprom 00000000 f0000000 f0000000 000201cc 20 CONTENTS 1 .text 0000155a 00000000 00000000 00010000 24 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .text.align 00000006 0000155a 0000155a 0001155a 20 ALLOC, CODE 3 .data 00000000 20000000 20000000 000201cc 20 CONTENTS, ALLOC, LOAD, DATA 4 .ramfunc 000001cc 20100000 00001560 00020000 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE

eldarkg commented 5 years ago

@AndreySV Is it related with #18?

eldarkg commented 5 years ago

@AndreySV Is it workaround of a compiler bug? Are you have any links for info?

AndreySV commented 5 years ago

@AndreySV Is it related with #18?

It's not. #18 looks for me like hardware-specific behavior. Like flash prefetch or instruction pipeline isn't flushed and requires another unconditional jump/long call.

@AndreySV Is it workaround of a compiler bug? Are you have any links for info?

Here is link to discussion on arm-embedded bug tracker. Link to GCC upstream bug tracker. Developers said that 'noinline' attribute isn't workaround and this is correct solution if the code have to be placed only in mentioned section.

I

AndreySV commented 5 years ago

Zephyr project defines ramfunc macro in a similar way: https://github.com/zephyrproject-rtos/zephyr/blob/master/include/toolchain/gcc.h#L127

eldarkg commented 5 years ago

@AndreySV Can you add this fix for other microcontrollers too? And then I merge your commits. Thank u

AndreySV commented 5 years ago

Updated. It looks like SPL for 1986ВЕ8(1)Т doesn't have any code work with EEPROM.

eldarkg commented 5 years ago

@AndreySV Good work. Thank u