Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: IAR static varaible
Форум разработчиков электроники ELECTRONIX.ru > Сайт и форум > В помощь начинающему > Программирование
snoway
Здравствуйте.
Имею:
- IAR6.21
- STM32F107VC
- ST-LinkV2

Проблема возникает при работе со static переменнымми, например:
Код
int test( int b )
{
  static int hello = 0xAABB;
  hello ++;
  return hello;
}

int main( void )
{
  
  while( 1 )
  {
     for( int i = 0x00; i < 100000; i ++ );
    (void) test( 1 );
  }
}

Почему-то переменная hello инициализируется не значением 0xAABB, а имеет значение 0x20010000. На Asm под отладчиком это выглядит так:
Код
int test( int b )
{
test:
    0x80001dc: 0x0001         MOVS      R1, R0
  hello ++;
    0x80001de: 0x4809         LDR.N     R0, ??DataTable1       ; ??hello
    0x80001e0: 0x6800         LDR       R0, [R0]
    0x80001e2: 0x1c40         ADDS      R0, R0, #1
    0x80001e4: 0x4a07         LDR.N     R2, ??DataTable1       ; ??hello
    0x80001e6: 0x6010         STR       R0, [R2]
  return hello;
    0x80001e8: 0x4806         LDR.N     R0, ??DataTable1       ; ??hello
    0x80001ea: 0x6800         LDR       R0, [R0]
    0x80001ec: 0x4770         BX        LR

     -------------------------
    
??DataTable1:
    0x8000204: 0x0000         MOVS      R0, R0
    0x8000206: 0x2000         MOVS      R0, #0

     -------------------------
SB:
    0x800029a: 0x0000         MOVS      R0, R0
    0x800029c: 0xaabb         ADD       R2, SP, #0x2ec
    0x800029e: 0x0000         MOVS      R0, R0

Скрипт линкера:
Код
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_end__   = 0x080FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__   = 0x20017FFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x900;
define symbol __ICFEDIT_size_heap__   = 0x800;
/**** End of ICF editor section. ###ICF###*/


define memory mem with size = 4G;
define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];

define block CSTACK    with alignment = 8, size = __ICFEDIT_size_cstack__   { };
define block HEAP      with alignment = 8, size = __ICFEDIT_size_heap__     { };

initialize by copy { readwrite };
//initialize by copy with packing = none { section __DLIB_PERTHREAD }; // Required in a multi-threaded application
do not initialize  { section .noinit };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };

place in ROM_region   { readonly };
place in RAM_region   { readwrite, block CSTACK, block HEAP };

Буду благодарен за помощь!
sevastianovd
у меня все работает

CODE

void func(void)
{
static int hello=0x1111;
hello++;
tmp=hello;

}


проверяю по tmp
int tmp - декларирована глобально в main.h, иначе на точке останова действительно видим чушь
XVR
Подозреваю, что ваш 0x20000000 - это адрес переменной, а не ее содержимое. А 0xAABB по адресу 0x800029c - это образ сегмента данных, который копируется из FLASH в RAM при старте
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Invision Power Board © 2001-2025 Invision Power Services, Inc.