Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] Constant 3D Array declaration problem in Keil

Status
Not open for further replies.

hm_fa_da

Full Member level 5
Joined
Sep 16, 2003
Messages
287
Helped
10
Reputation
20
Reaction score
4
Trophy points
1,298
Activity points
3,217
Hi,

I am new in C programming language, but experienced in asm for 8051 and AVR ...
I'm trying to drive a segment LCD in Stm32L476 discovery board, i could do it well but i see a problem when using bitmap table, i use a table to assign true active segments for each number.

i used a 3D array for this purpose:

Code:
const  	uint32_t		Table[6][8][10] = {{ { 0x00400010, ....
when i declare this constant "upper" than main() function (in global space), it works fine.
but when i declare it "in" main() function it works only if the size of array be decreased to :
Code:
const 	uint32_t		Table[2][8][10] = {{ { 0x00400010, .....
( first dimension decreased from 6 to 2)

otherwise if i use more than 2 in first dimension, the Code compiles without any Error but it doesn't run at MCU !

i just put a simple LED on command at the first line of code to test.

What's the problem ?!
is there anything related to size limitation ?


i'm using Keil V5.2 compiler.
 

It is no sense to put constant arrays inside voids. They anyway will requere a flash memory.

Indeed, this would make sense just with RAM variables, unless the OP's purpose is just to enclose that array within a specific funcion ( which isn't also recomended ). Perhaps should think of about using the far model.
 

I suggest to check linker listing also. Where compilier stores this data? Probably, in case of declare in main it is trying to store it in RAM somehow. Just a suggestion.
 

the chip has 1MB flash and 128KB SRAM, the table has just less than 2KB volume.
so even if it uses SRAM to store constants, it shouldn't make problem ...
anyway, why the compiler doesn't show any error or warning ?
it just compiles and writes on chip, the code is not executed or maybe distorted ...

the first line of code is turning an LED on, the code is not even related to table consts !
 

You did not show the complete code.
In general runtime errors are due to access violation with pointers.
 

Code:
#include "main.h"
#include "stm32l4xx_hal.h"
#include "gpio.h"

void SystemClock_Config(void);
void Error_Handler(void);

int main(void)
{
		const 	int		Bitmap[3][8][10] = {{{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0}},
																	{{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0}},
																	{{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0},{1,2,3,4,5,6,7,8,9,0}}};
	

  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  while (1)
  {
		HAL_GPIO_TogglePin(LD_G_GPIO_Port,LD_G_Pin);
		HAL_GPIO_WritePin(LD_R_GPIO_Port, LD_R_Pin, GPIO_PIN_RESET);
		HAL_Delay(500);
	 }

}

This is the whole code, i have used StmCube, Hal functions are made by it ...
 

This is the whole code, i have used StmCube, Hal functions are made by it ...

The array Bitmap[] inst being instantiated anywhere on this code. Did you check if compiler performed some kind of optimization by just not putting this array on binary ? You can quickly check this by just comparing both HEX files size, the one with the array inside main() and the other outside main().
 

When i put it out of main() and don't use it in my code, it deletes the const.
but when i put it in main() and even not use it in code, it compiles it.

in the sample code i sent, i didn't use the Bitmap in code, but in another code which i used it, same thing happens.

when i put it out of main(), it works fine but when i put it in main(), when size of dimensions increase, it compiles without any error or warning but doesn't run on MCU ... !

- - - Updated - - -

i sent the first code because of being smaller, this is the complete code which uses Table:

Code:
#include "main.h"
#include "stm32l4xx_hal.h"
#include "lcd.h"
#include "gpio.h"

void SystemClock_Config(void);
void Error_Handler(void);

const		uint32_t	Table[6][8][10] = {{ {0x00400010, 0x00400000, 0x00F0001F, 0x00F0000F, 0x00F0000F, 0x0080000F, 0x0080001F, 0x00400000, 0x00F0001F, 0x00F0000F},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00F00018, 0x00800000, 0x00400010, 0x00F00010, 0x00800008, 0x00F00018, 0x00F00018, 0x00F00000, 0x00F00018, 0x00F00018},
{0x0000fff0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000fff0, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}},
{ {0x00400010, 0x00400000, 0x00F0001F, 0x00F0000F, 0x00F0000F, 0x0080000F, 0x0080001F, 0x00400000, 0x00F0001F, 0x00F0000F},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00F00018, 0x00800000, 0x00400010, 0x00F00010, 0x00800008, 0x00F00018, 0x00F00018, 0x00F00000, 0x00F00018, 0x00F00018},
{0x0000fff0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000fff0, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}},
{0x00400010, 0x00400000, 0x00F0001F, 0x00F0000F, 0x00F0000F, 0x0080000F, 0x0080001F, 0x00400000, 0x00F0001F, 0x00F0000F},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00F00018, 0x00800000, 0x00400010, 0x00F00010, 0x00800008, 0x00F00018, 0x00F00018, 0x00F00000, 0x00F00018, 0x00F00018},
{0x0000fff0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000fff0, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}},
{ {0x00400010, 0x00400000, 0x00F0001F, 0x00F0000F, 0x00F0000F, 0x0080000F, 0x0080001F, 0x00400000, 0x00F0001F, 0x00F0000F},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00F00018, 0x00800000, 0x00400010, 0x00F00010, 0x00800008, 0x00F00018, 0x00F00018, 0x00F00000, 0x00F00018, 0x00F00018},
{0x0000fff0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000fff0, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}},
{ {0x00400010, 0x00400000, 0x00F0001F, 0x00F0000F, 0x00F0000F, 0x0080000F, 0x0080001F, 0x00400000, 0x00F0001F, 0x00F0000F},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00F00018, 0x00800000, 0x00400010, 0x00F00010, 0x00800008, 0x00F00018, 0x00F00018, 0x00F00000, 0x00F00018, 0x00F00018},
{0x0000fff0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000fff0, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}},
{ {0x00400010, 0x00400000, 0x00F0001F, 0x00F0000F, 0x00F0000F, 0x0080000F, 0x0080001F, 0x00400000, 0x00F0001F, 0x00F0000F},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00F00018, 0x00800000, 0x00400010, 0x00F00010, 0x00800008, 0x00F00018, 0x00F00018, 0x00F00000, 0x00F00018, 0x00F00018},
{0x0000fff0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000fff0, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}}};
																																				
int main(void)
{
 	uint32_t	i,j;
 
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_LCD_Init();
  while (1)
  {
		HAL_GPIO_WritePin(LD_R_GPIO_Port, LD_R_Pin, GPIO_PIN_SET);
		HAL_LCD_Init(&hlcd);
		HAL_LCD_MspInit(&hlcd);
		HAL_LCD_Clear(&hlcd);
		j = 0;
			while( 1 )
				{
				for(i=0 ; i<8 ; i++){
					HAL_LCD_Write(&hlcd, i, Table[5][i][j], Table[5][i][j]);			
					}		
					HAL_LCD_UpdateDisplayRequest(&hlcd);
				HAL_Delay(1000);
					j++;
					if ( j == 10 ) j=0;
				}

		HAL_GPIO_WritePin(LD_R_GPIO_Port, LD_R_Pin, GPIO_PIN_RESET);
	
		while(1);
  }

}


This code works fine, but when i move the Table to main(), it compiles but doesn't run. but if i change size of constant in main() i.e from "Table[6][8][10]" to "Table[2][8][10]", it runs well on MCU.
 

When you move the table to main() maybe stack is overflowing.

Code:
code const uint32_t Array[10][10][10] = { {...}, {...}, {...}};

or

Code:
const code uint32_t Array[10][10][10] = { {...}, {...}, {...}};
 

shouldn't the const values go in flash ?
stack uses RAM as i know, so why should it overflow ?

anyway the problem seems something related to size ... !

maybe when i use it in main(), it doesn't go to flash ?!!
 

when you use it in main() or other function then it will be in RAM and not ROM. It will be declared as constant whose value doesn't change. To place the constant in ROM you have to declare it as global.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top