реклама на сайте
подробности

 
 
> Проблема с константами в классе., В iar всё работает а в GCC нет...
inco
сообщение May 19 2010, 11:57
Сообщение #1


Частый гость
**

Группа: Свой
Сообщений: 161
Регистрация: 26-08-05
Из: Российская Империя
Пользователь №: 7 984



Есть некий базовый класс:

class uart {
protected:
const uint8_t num;
const uint8_t channel;
volatile uint32_t time;
uint8_t rxCount;
uint8_t echoMode;
__uartState state;
uint32_t tx_pointer;
uint32_t rx_pointer;
uint32_t size;
uint32_t txSize;
uint8_t rxEchoSize;
uint8_t error[2];
uint16_t crc;
public:
uart(const uint8_t n, const uint8_t c) : num(n), channel( c) { // Конструктор
time = tx_pointer = rx_pointer = size = 0;
error[0] = error[1] = 0;
};
...

есть от него наследник:

class mco_uart : public uart {
public:
uint8_t buf[2][MCO_BUFF_SIZE];
mco_uart(const uint8_t n, const uint8_t c) : uart (n, c) {}; // Конструктор
...

создаю экземпляры класса:

mco_uart extUart[EXTUART_NUM] = {
mco_uart(0, 4 << 4), mco_uart(0, 5 << 4), mco_uart(0, 6 << 4), mco_uart(0, 7 << 4),
mco_uart(1, 4 << 4), mco_uart(1, 5 << 4), mco_uart(1, 6 << 4), mco_uart(0, 1 << 4),
mco_uart(0, 2 << 4), mco_uart(0, 3 << 4), mco_uart(1, 0 << 4), mco_uart(1, 1 << 4),
mco_uart(1, 2 << 4), mco_uart(1, 3 << 4)
};

В результате переменные num и channel равны 0.
В иаре всё работает то есть значения переменным присваивается правильно, а в gcc присваивания нет.
Что я делаю не так? На плюсах пишу первый раз, до этого писал только на чистом C. Хочется перейти на gcc и не получается!
Компилятор от клёна kgp_arm_eabi_20100509
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
inco
сообщение May 19 2010, 16:13
Сообщение #2


Частый гость
**

Группа: Свой
Сообщений: 161
Регистрация: 26-08-05
Из: Российская Империя
Пользователь №: 7 984



Спасибо за информацию! Буду переваривать! Пока ничего не понял про конструкторы!

Объекты да глобальные.

По результатам отпишусь. Проверю только завтра на работе.

На всякий случай привожу свой скрипт линкера:

__Stack_Size = 1024 ;

PROVIDE ( _Stack_Size = __Stack_Size );

__Stack_Init = _estack - __Stack_Size;

/*"PROVIDE" allows to easily override these values from an object file or the commmand line.*/
PROVIDE ( _Stack_Init = __Stack_Init );

/*
There will be a link error if there is not this amount of RAM free at the end.
*/
_Minimum_Stack_Size = 0x100;


/* include the memory spaces definitions sub-script */
/*
Linker subscript for STM32F10x definitions with 512K Flash and 64K RAM */

/* Memory Spaces Definitions */

MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
}
/* higher address of the user mode stack */
_estack = 0x2000c000;



/* include the sections management sub-script for FLASH mode */

/* Sections Definitions */

SECTIONS
{
/* for Cortex devices, the beginning of the startup code is stored in the .isr_vector section, which goes to FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >SRAM

/* the program code is stored in the .text section, which goes to Flash */
.text :
{
. = ALIGN(4);
*(.text .text.* .gnu.linkonce.t.*)
*(.plt)
*(.gnu.warning)
*(.glue_7t) *(.glue_7) *(.vfp11_veneer)
*(.ARM.extab* .gnu.linkonce.armextab.*)
*(.gcc_except_table)
} >SRAM

.checksum 0x20005ffe :
{
. = ALIGN(2);
KEEP(*(.checksum)) /* Checksum code */
} >SRAM

.eh_frame_hdr : ALIGN (4)
{
KEEP (*(.eh_frame_hdr))
} >SRAM
.eh_frame : ALIGN (4)
{
KEEP (*(.eh_frame))
} >SRAM
/* .ARM.exidx is sorted, so has to go in its own output section. */
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} >SRAM
__exidx_end = .;

.rodata : ALIGN (4)
{
*(.rodata .rodata.* .gnu.linkonce.r.*)

. = ALIGN(4);
KEEP(*(.init))

. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;

. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;

. = ALIGN(4);
KEEP(*(.fini))

. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;

. = ALIGN(4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))

. = ALIGN(4);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))

. = ALIGN(4);
_etext = .;
/* This is used by the startup in order to initialize the .data secion */
_sidata = _etext;
} >SRAM

/* This is the initialized data section
The program executes knowing that the data is in the RAM
but the loader puts the initial values in the FLASH (inidata).
It is one task of the startup to copy the initial values from FLASH to RAM. */
.data : AT ( _sidata )
{
. = ALIGN(4);
/* This is used by the startup in order to initialize the .data secion */
_sdata = . ;
KEEP(*(.jcr))
*(.got.plt) *(.got)
*(.shdata)
*(.data .data.* .gnu.linkonce.d.*)

. = ALIGN(4);
/* This is used by the startup in order to initialize the .data secion */
_edata = . ;
} >SRAM

/* This is the uninitialized data section */
.bss :
{
. = ALIGN(4);
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .;
*(.shbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
/* This is used by the startup in order to initialize the .bss secion */
_ebss = . ;
} >SRAM

PROVIDE ( end = _ebss );
PROVIDE ( _end = _ebss );

/* This is the user stack section
This is just to check that there is enough RAM left for the User mode stack
It should generate an error if it's full. */
._usrstack :
{
. = ALIGN(4);
_susrstack = . ;
. = . + _Minimum_Stack_Size ;
. = ALIGN(4);
_eusrstack = . ;
} >SRAM


/* after that it's only debugging information. */

/* remove the debugging information from the standard libraries */
DISCARD :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}

/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }

note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) }
/DISCARD/ : { *(.note.GNU-stack) }
}

Стартап брал стандартный из библиотеки stm32 версии 3.2
Go to the top of the page
 
+Quote Post
AHTOXA
сообщение May 19 2010, 18:31
Сообщение #3


фанат дивана
******

Группа: Свой
Сообщений: 3 387
Регистрация: 9-08-07
Из: Уфа
Пользователь №: 29 684



Цитата(inco @ May 19 2010, 22:13) *
Стартап брал стандартный из библиотеки stm32 версии 3.2


Этот стартап совершенно точно не вызывает конструкторы глобальных объектов.
Пример рабочего стартапа и линкерного скрипта для C++ можете посмотреть вот в этом примере из scmRTOS.
Проверено с kgp и codesourcery.


--------------------
Если бы я знал, что такое электричество...
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 22nd July 2025 - 15:06
Рейтинг@Mail.ru


Страница сгенерированна за 0.01416 секунд с 7
ELECTRONIX ©2004-2016