uController is running out of memory or something else ...

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
PICfan
Posts: 27
Joined: 09 Dec 2012 03:28

uController is running out of memory or something else ...

#1 Post by PICfan » 23 Dec 2012 04:27

Hi there,

I have been trying to write an example wherein I can use all the Mmc_FAT16 function of the Mmc_FAT16 library, for learning purpose. However, when I tried to use the following function (Rename_folder()), I get an error which leads me to belief the my Micro runs out of RAM or Flash memories. Even I ordered new microcontrollers with higher memories. Is it really lack of memories that I get the following errors? I am not sure why these function should take or require so much memory? Thanks
I use easyPIC 7 with PIC18F45k22 microcontroller.

Code: Select all



void Rename_folder()
{
  if (Mmc_Fat_RenameDir("FOLDER_A", "FOLDER_B") == 0)   // if rename operation was successful...
  {                                                     // 1 - if directory name is invalid
                                                        // 2 - if there is no directry with the old name
                                                        // 3 - if an entry with the new name already exits
                                                        // 4 - if an error occurred during renaming
                                                        // 0 - if renaming was successful
     UART1_Write_Text("Renaming folder was successful\r\n");
  }
  else if (Mmc_Fat_RenameDir("FOLDER_A", "FOLDER_B") == 1)
  {
     UART1_Write_Text("Folder name is invalid\r\n");
  }
  else if (Mmc_Fat_RenameDir("FOLDER_A", "FOLDER_B") == 2)
  {
     UART1_Write_Text("No folder with the old name exist\r\n");
  }
  else if (Mmc_Fat_RenameDir("FOLDER_A", "FOLDER_B") == 3)
  {
     UART1_Write_Text("Folder with the new name already exits\r\n");
  }
  else if (Mmc_Fat_RenameDir("FOLDER_A", "FOLDER_B") == 4)
  {
       UART1_Write_Text("An error occurred during renaming\r\n");
  }
}




void main()
{


           while(1)
           {
             if(PORTB.RB0 == 1)
             {
               MakeFolder();
             }
             else if(PORTB.RB1 == 1)
             {
               DeleteFolder();
             }
             else if(PORTB.RB2 == 1)
             {
                //Does_it_exist();
                Rename_folder();
             }
             
            }
     }
}

Messages from compiler

Code: Select all

0 1 mikroCPIC1618.exe -MSF -DBG -pP18F45K22 -DL -O11111114 -fo8 -N"E:\My PIC Programs\mmc sd card tests\mmc sd card tests 2\mmc sd card tests.mcppi" -SP"C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for PIC\uses\P18\" -SP"E:\My PIC Programs\mmc sd card tests\mmc sd card tests 2\" -SP"E:\My PIC Programs\mmc sd card tests 2\" -SP"E:\My PIC Programs\mmc sd card tests\" "mmc sd card tests.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_MemManager.mcl" "__Lib_Conversions.mcl" "__Lib_Sprintf.mcl" "__Lib_PrintOut.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_D.mcl" "__Lib_EEPROM_256.mcl" "__Lib_FLASH_w64_e64.mcl" "__Lib_I2C_c34d01.mcl" "__Lib_PWM_c21.mcl" "__Lib_PWM_b5d1e2.mcl" "__Lib_SPI_c345d014.mcl" "__Lib_UART_c67d67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_CFFat16.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_Mmc.mcl" "__Lib_MmcFat16.mcl" "__Lib_MmcFat16Constants.mcl" "__Lib_RS485.mcl" "__Lib_S1D13700.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl" "__Lib_TFT.mcl" "__Lib_TFT_Defs.mcl" "__Lib_TFT_16bit.mcl" "__Lib_TFT_16bit_Defs.mcl" "__Lib_TouchPanel_TFT.mcl" "__Lib_EthEnc24j600.mcl" "__Lib_TouchPanel.mcl"  
0 1501 Specified search path does not exist: 'E:\My PIC Programs\mmc sd card tests 2'  
0 1139 Available RAM: 1515 [bytes], Available ROM: 32768 [bytes]  
0 126 All files Preprocessed in 47 ms  
0 122 Compilation Started mmc sd card tests.c
83 1509 Generated baud rate is 19231 bps (error = 0.16 percent) mmc sd card tests.c
94 1503 Result is not defined in function: 'show_menu_UART' mmc sd card tests.c
262 123 Compiled Successfully mmc sd card tests.c
0 127 All files Compiled in 63 ms  
899 362 Not enough RAM 'd' __Lib_MmcFat16.c
898 362 Not enough RAM 's' __Lib_MmcFat16.c
1078 362 Not enough RAM 'd' __Lib_MmcFat16.c
1056 362 Not enough RAM 'dir' __Lib_MmcFat16.c
1057 362 Not enough RAM 'buf' __Lib_MmcFat16.c
1116 362 Not enough RAM 'd' __Lib_MmcFat16.c
134 362 Not enough RAM 'fname' __Lib_MmcFat16.c
136 362 Not enough RAM 'slen' __Lib_MmcFat16.c
136 362 Not enough RAM 'i' __Lib_MmcFat16.c
137 362 Not enough RAM 'dot' __Lib_MmcFat16.c
138 362 Not enough RAM 'pch' __Lib_MmcFat16.c
183 362 Not enough RAM 'old' __Lib_MmcFat16.c
185 362 Not enough RAM 'i' __Lib_MmcFat16.c
0 362 Not enough RAM '?FLOC___Lib_MmcFat16_nameToUpper' __Lib_MmcFat16.c
795 362 Not enough RAM 'cl' __Lib_MmcFat16.c
797 362 Not enough RAM 'i' __Lib_MmcFat16.c
798 362 Not enough RAM 'nbEnt' __Lib_MmcFat16.c
800 362 Not enough RAM 'free' __Lib_MmcFat16.c
801 362 Not enough RAM 'ss' __Lib_MmcFat16.c
675 362 Not enough RAM 'd' __Lib_MmcFat16.c
677 362 Not enough RAM 'nbEnt' __Lib_MmcFat16.c
678 362 Not enough RAM 'ldir' __Lib_MmcFat16.c
679 362 Not enough RAM 's' __Lib_MmcFat16.c
993 362 Not enough RAM 'offset' __Lib_MmcFat16.c
995 362 Not enough RAM 'next' __Lib_MmcFat16.c
638 362 Not enough RAM 'dir' __Lib_MmcFat16.c
640 362 Not enough RAM 'd' __Lib_MmcFat16.c
63 362 Not enough RAM 'data_' __Lib_UART_c67d67.c
98 362 Not enough RAM 'ctype' __Lib_Mmc.c
99 362 Not enough RAM 'cnt' __Lib_Mmc.c
100 362 Not enough RAM 'response' __Lib_Mmc.c
100 362 Not enough RAM 'response2' __Lib_Mmc.c
1022 362 Not enough RAM 'newName' __Lib_MmcFat16.c
507 362 Not enough RAM 'maxClust' __Lib_MmcFat16.c
508 362 Not enough RAM 'cl' __Lib_MmcFat16.c
510 362 Not enough RAM 's' __Lib_MmcFat16.c
511 362 Not enough RAM 'clEntry' __Lib_MmcFat16.c
428 362 Not enough RAM 'c' __Lib_MmcFat16.c
430 362 Not enough RAM 's' __Lib_MmcFat16.c
143 362 Not enough RAM 's' __Lib_CString.c
76 362 Not enough RAM 'character' __Lib_CType.c
456 362 Not enough RAM 'v' __Lib_MmcFat16.c
458 362 Not enough RAM 'i' __Lib_MmcFat16.c
459 362 Not enough RAM 'o' __Lib_MmcFat16.c
460 362 Not enough RAM 's' __Lib_MmcFat16.c
568 362 Not enough RAM 'd' __Lib_MmcFat16.c
570 362 Not enough RAM 'i' __Lib_MmcFat16.c
572 362 Not enough RAM 'nbEnt' __Lib_MmcFat16.c
573 362 Not enough RAM 'ldir' __Lib_MmcFat16.c
571 362 Not enough RAM 's' __Lib_MmcFat16.c
454 362 Not enough RAM 'dbuff' __Lib_Mmc.c
455 362 Not enough RAM 'i' __Lib_Mmc.c
0 362 Not enough RAM '?FLOC__Mmc_Multi_Read_Sector' __Lib_Mmc.c
231 362 Not enough RAM 'dbuff' __Lib_Mmc.c
232 362 Not enough RAM 'i' __Lib_Mmc.c
233 362 Not enough RAM 'byte_start' __Lib_Mmc.c
0 362 Not enough RAM '?FLOC__Mmc_Read_Sector' __Lib_Mmc.c
469 362 Not enough RAM 'response' __Lib_Mmc.c
470 362 Not enough RAM 'timeout' __Lib_Mmc.c
276 362 Not enough RAM 'dbuff' __Lib_Mmc.c
277 362 Not enough RAM 'i' __Lib_Mmc.c
278 362 Not enough RAM 'byte_start' __Lib_Mmc.c
210 362 Not enough RAM 'd' __Lib_MmcFat16.c
212 362 Not enough RAM 'p1' __Lib_MmcFat16.c
212 362 Not enough RAM 'p2' __Lib_MmcFat16.c
213 362 Not enough RAM 'i' __Lib_MmcFat16.c
0 362 Not enough RAM '?FLOC___Lib_MmcFat16_f16_DirentToDir' __Lib_MmcFat16.c
87 362 Not enough RAM 's' __Lib_MmcFat16.c
89 362 Not enough RAM 'fn' __Lib_MmcFat16.c
90 362 Not enough RAM 'ptr' __Lib_MmcFat16.c
91 362 Not enough RAM 'olds' __Lib_MmcFat16.c
30 362 Not enough RAM 'n' __Lib_CString.c
434 362 Not enough RAM 'sector' __Lib_Mmc.c
435 362 Not enough RAM 'byte_start' __Lib_Mmc.c
44 362 Not enough RAM 'n' __Lib_CString.c
77 362 Not enough RAM 'crc' __Lib_Mmc.c
78 362 Not enough RAM 'response' __Lib_Mmc.c
79 362 Not enough RAM 'timeout' __Lib_Mmc.c
122 362 Not enough RAM 's2' __Lib_CString.c
35 362 Not enough RAM 'character' __Lib_CType.c
84 362 Not enough RAM 'n' __Lib_CString.c
55 362 Not enough RAM 's' __Lib_MmcFat16.c
72 362 Not enough RAM 's' __Lib_MmcFat16.c
140 362 Not enough RAM 'buffer' __Lib_SPI_c345d014.c
71 362 Not enough RAM 'buffer' __Lib_SPI_c345d014.c
0 102 Finished (with errors): 22 Dec 2012, 22:05:30 mmc sd card tests.mcppi





PICfan
Posts: 27
Joined: 09 Dec 2012 03:28

Re: uController is running out of memory or something else .

#2 Post by PICfan » 23 Dec 2012 05:26

PICfan wrote:Hi there,

I have been trying to write an example wherein I can use all the Mmc_FAT16 function of the Mmc_FAT16 library, for learning purpose. However, when I tried to use the following function (Rename_folder()), I get an error which leads me to belief the my Micro runs out of RAM or Flash memories. Even I ordered new microcontrollers with higher memories. Is it really lack of memories that I get the following errors? I am not sure why these function should take or require so much memory? Thanks
I use easyPIC 7 with PIC18F45k22 microcontroller.

While I was experimenting, I noticed that the more line of UART1_Write_Text( I have, I get that RAM error. When I try to run more than 5 of the following code, I get the error of 31 362 Not enough RAM 'f16_sector' __Lib_MmcFat16Constants.c. Is there a better way of displaying a menu?

Code: Select all

void show_menu_UART()
{
  UART1_Write_Text("\r\nMake a choice:\r\n");
  UART1_Write_Text("1.Make Folder/Directory (B0)\r\n");
  UART1_Write_Text("2.Delete folder (B1)\r\n");
  UART1_Write_Text("3.Rename a folder (B2)\r\n");
  UART1_Write_Text("4.Make Folder/Directory (B0)\r\n");
 /* UART1_Write_Text("5.Delete folder (B1)\r\n");
  UART1_Write_Text("6.Rename a folder (B2)\r\n");
  UART1_Write_Text("7.Make Folder/Directory (B0)\r\n");
  UART1_Write_Text("8.Delete folder (B1)\r\n");
  UART1_Write_Text("9.Rename a folder (B2)\r\n");
  UART1_Write_Text("10.Rename a folder (B2)\r\n");
  UART1_Write_Text("11.Make Folder/Directory (B0)\r\n");
  UART1_Write_Text("12.Delete folder (B1)\r\n");
  UART1_Write_Text("13.Rename a folder (B2)\r\n");
  UART1_Write_Text("14.Make Folder/Directory (B0)\r\n");
  UART1_Write_Text("15.Delete folder (B1)\r\n");
  UART1_Write_Text("16.Rename a folder (B2)\r\n");        */
}


User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: uController is running out of memory or something else .

#3 Post by janko.kaljevic » 24 Dec 2012 16:07

Hello,

This code takes RAM memory for each string because String Literals are stored in RAM in this case.
Literal strings are not always stored in RAM. Compiler will store them in flesh memory if you pass them to const char pointers.
You could make wrapper routines for library functions.

Code: Select all

void UART_Write_const(const char *txt){
char loc_text[__MAX_STRING_LENGTH];
char * dst;

  dst = loc_text;
  while (*dst++ = *txt++)
    ;

  UART1_Write_Text( loc_text);
}
Best regards.

PICfan
Posts: 27
Joined: 09 Dec 2012 03:28

Re: uController is running out of memory or something else .

#4 Post by PICfan » 25 Dec 2012 02:14

janko.kaljevic wrote:Hello,

This code takes RAM memory for each string because String Literals are stored in RAM in this case.
Literal strings are not always stored in RAM. Compiler will store them in flesh memory if you pass them to const char pointers.
You could make wrapper routines for library functions.

Code: Select all

void UART_Write_const(const char *txt){
char loc_text[__MAX_STRING_LENGTH];
char * dst;

  dst = loc_text;
  while (*dst++ = *txt++)
    ;

  UART1_Write_Text( loc_text);
}
Best regards.


Thanks for you response. Your function is a little bit complicated for me for now. I will try that later. However, you gave me good idea of putting the strings in a constant. Well I put them in a constant but I got errors and then just put them in character var, as shown below. The problem of RAM seems gone. Thanks

Code: Select all


void show_menu_UART()
{
  char MakeChoice[22]="\r\nMake a choice:\r\n";
  char MakeFolder[32]="1.Make Folder/Directory (B0)\r\n";
  char DeleteFolder[24]="2.Delete folder (B1)\r\n";
  char RenameFolder[26]= "3.Rename a folder (B2)\r\n";
  
  
  UART1_Write_Text(&MakeChoice);
  UART1_Write_Text(&MakeFolder);
  UART1_Write_Text(&DeleteFolder);
  UART1_Write_Text(&RenameFolder);
}



PICfan
Posts: 27
Joined: 09 Dec 2012 03:28

Re: uController is running out of memory or something else .

#5 Post by PICfan » 28 Dec 2012 02:58

Thanks for you response. Your function is a little bit complicated for me for now. I will try that later. However, you gave me good idea of putting the strings in a constant. Well I put them in a constant but I got errors and then just put them in character var, as shown below. The problem of RAM seems gone. Thanks

Code: Select all


void show_menu_UART()
{
  char MakeChoice[22]="\r\nMake a choice:\r\n";
  char MakeFolder[32]="1.Make Folder/Directory (B0)\r\n";
  char DeleteFolder[24]="2.Delete folder (B1)\r\n";
  char RenameFolder[26]= "3.Rename a folder (B2)\r\n";
  
  
  UART1_Write_Text(&MakeChoice);
  UART1_Write_Text(&MakeFolder);
  UART1_Write_Text(&DeleteFolder);
  UART1_Write_Text(&RenameFolder);
}


[/quote]



The above saves RAM but the following saves considerably more.

Code: Select all


void show_menu_UART()
{
  const char MakeChoice[22]="\r\nMake a choice:\r\n";
  const char MakeFolder[32]="1.Make Folder/Directory (B0)\r\n";
  const char DeleteFolder[24]="2.Delete folder (B1)\r\n";
  const char RenameFolder[26]= "3.Rename a folder (B2)\r\n";
 
 
  UART1_Write_Text(MakeChoice[22]);
  UART1_Write_Text(MakeFolder[32]);
  UART1_Write_Text(DeleteFolder[24]);
  UART1_Write_Text(RenameFolder[26]);
}



Pugnator
Posts: 70
Joined: 03 May 2011 17:20
Location: Moscow, Russia

Re: uController is running out of memory or something else .

#6 Post by Pugnator » 28 Dec 2012 16:13

You can also store all your text strings in eeprom (internal or external)
I have to output a lot of texts without sd card.
I write simple program for PC that converts all text to eeprom with 0x00 byte separator. I read it from memory with simple function with search by CRC16 hash

It save a looot of RAM and ROM and allow to use single pointer variable for all strings


Post Reply

Return to “mikroC PRO for PIC General”