ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Воскресенье
2 июня
1020927 Топик полностью
Гyдвин, волшебник (25.07.2020 20:08, просмотров: 724) ответил Гyдвин на В Keil v5 наткнулся на грабли: Какого-то хрена компилятор вызывает не ту функцию, что требуется (похоже втуливает что то с выравниванием 4). В результате hard fault... Как лечить?
Короче... Особо буйные могут успокоиться, хлебнуть галоперидольчику и скинуть смирительную рубаху. Бага нет! "Нестандартный язык" от ARM все предусмотрел еще в 4 версии. Просто для v5 похоже сменились "умолчания" для ключа компилятора "--pointer_alignment=xxx". Ну или можно описать структуру вот так: 
 __packed  struct IH{                //*************** Äëÿ EEPROM 2 ñòð) ****************************
U16      my_id;          // ID êîìáàéíà, ïðèâÿçàííûé èç äàò÷èêà
U8       type_sens;      // òèï 1 - êîìáàéí, 2 - áóíêåð
U32      conag;          // êîíòðàãåíò (4 ñèìâîëà / U32)
U8       fl_card;        // ôëàã ðàçðåøåíèÿ âûãðóçêè êàðòîé.  Ñèìâîë 1 - ðàçðåøåíî, 0 - íåò
U8       fl_rd;          // ôëàã "Òîëüêî ÷òåíèå ëîãà" (1) 0 - ðàçðåøåíî âñå
U8       fl_zero;        // ôëàã ðàçðåøåíû ïóñòûå âûãðóçêè (1) 0 - çàïðåùåíû ïóñòûå âûãðóçêè
U8       conb_nunb;      // Êîëè÷åñòâî êîìáàéíîâ äëÿ îäíîâðåìåííîé âûãðóçêè
S8       rssi_index;     // 0..9 èíäåêñ â òàáëèöå.  Ãðàíèöà RSSI beacon  äëÿ ïðèíÿòèÿ ðåøåíèÿ î åãî ïðèåìå {-95,-90,-85,-80,-75,-70,-65,-60,-55,-50}; // 0..9 // Signed Char!
U32      conag2;         // äîïîëíèòåëüíûé êîíòðàãåíò (4 ñèìâîëà / U32)
}IH;     // (âñåãî 16 áàéò. ****************************** Äëÿ 2 ñòðàíèöû eeprom) ****************************


И все генерится как надо ( __aeabi_memcpy ()). Код 10-летней давности компилится и работает, как положено...


--pointer_alignment=num
Non-Confidential   ARM DUI0375E
ARM® Compiler v5.04 for µVision armcc User Guide Version 5
 
Home > Compiler Command-line Options > --pointer_alignment=num

7.126 --pointer_alignment=num
Specifies unaligned pointer support required for an application.

Syntax
--pointer_alignment=num
Where num is one of:
1
Accesses through pointers have an alignment of one, that is, byte-aligned or unaligned.
2
Accesses through pointers have an alignment of at most two, that is, at most halfword aligned.
4
Accesses through pointers have an alignment of at most four, that is, at most word aligned.
8
Accesses through pointers have normal alignment, that is, at most doubleword aligned.
If numis unspecified, the compiler faults use of --pointer_alignment.
Usage
This option can help you port source code that has been written for architectures without alignment requirements. You can achieve finer control of access to unaligned data, with less impact on the quality of generated code, using the __packed qualifier.
Restrictions
De-aligning pointers might increase the code size, even on processors with unaligned access support. This is because only a subset of the load and store instructions benefit from unaligned access support. The compiler is unable to use multiple-word transfers or coprocessor-memory transfers, including hardware floating-point loads and stores, directly on unaligned memory objects.
Note
Code size might increase significantly when compiling for processors without hardware support for unaligned access, for example, pre-v6 architectures.
This option does not affect the placement of objects in memory, nor the layout and padding of structures.
Related reference
9.12 __packed
9.91 #pragma pack(n)
4.31 Compiler storage of data objects by natural byte alignment
Non-Confidential   ARM DUI0375E
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.   
Home > Compiler Command-line Options > --pointer_alignment=num