Post topics, source code that relate to the Arduino Platform

User avatar
By NardJ
#26866 Hi,

I am trying to upload a sketch to my esp8266-01, but get an error: '.text' will not fit in region íram_0_seq'.
I suspect this means that there is not enough memory, but can't understand why, it has 512kb hasn't it? On an arduino mini pro (32k prog. mem, 2kb sram) it uploads fine and reports the sketch uses 7.6kB prog. mem and 1.8kb sram. I really want to use the esp8266-01 for its high clock-speed.

The sketch is a 6502 cpu (e.g. c64) emulator and has a large rom table (const unsigned char BIOS[10496] and const unsigned char BIOStop[256] ). The original sketch used progmem to put this rom table in flash, but progmem doesn't work om the eps8266, so I removed progmem references. For testing purposes I reduced the rom table to 2 bytes but the error persisted. If I reduce the program code however (there is a large switch statement with all opcodes), the error vanishes.

Do I have to use some specific esp command to load the sketch in the correct memory-part? Or is the esp despite it's large memory of 512kb not as capable as the arduino ATM328 boards? I can't believe this however, and hope I am missing something!

Any help much appreciated! (Banging my head against the wall for two days now and internet is not of much help either.)
User avatar
By martinayotte
#26869 Don't confuse between IRAM and IROM. The fact that you removed the PROGMEM is the main reason why you're getting this message. By why do you say that PROGMEM doesn't work on ESP8266 ? It is certainly working, many people are using it. Maybe you should describes the problems you've originally got when trying to use it.
User avatar
By NardJ
#26893 You are right, the original code (http://forum.arduino.cc/index.php?topic=193216.0) with the progmem vars and the pgm_read_byte_near statements gave at first the following error
Code: Select all  cpu.c:2:26: fatal error: avr/pgmspace.h: No such file or directory
  #include <avr/pgmspace.h>

In cpu.c the second line read "#include <avr/pgmspace.h>".
After removing "avr/" from the include this error disappears and I get the messages

Code: Select allcpu.c:7:0: warning: "NULL" redefined [enabled by default]
 #define NULL (void *) 0
 ^
In file included from c:\users\rosanarden\appdata\roaming\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9\xtensa-lx106-elf\include\string.h:17:0,
                 from C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0/tools/sdk/include/osapi.h:8,
                 from C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\cores\esp8266/pgmspace.h:10,
                 from cpu.c:2:
c:\users\rosanarden\appdata\roaming\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9\lib\gcc\xtensa-lx106-elf\4.8.2\include\stddef.h:402:0: note: this is the location of the previous definition
 #define NULL ((void *)0)
 ^
In file included from cpu.c:2:0:
cpu.c: In function 'read6502':
C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\cores\esp8266/pgmspace.h:81:32: error: 'reinterpret_cast' undeclared (first use in this function)
     const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local)-__offset);   \
                                ^
C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\cores\esp8266/pgmspace.h:98:35: note: in expansion of macro 'pgm_read_byte'
 #define pgm_read_byte_near(addr)  pgm_read_byte(addr)
                                   ^
cpu.c:1066:35: note: in expansion of macro 'pgm_read_byte_near'
     if (BIOSaddr < 0x2900) return(pgm_read_byte_near(BIOS + BIOSaddr));
                                   ^
C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\cores\esp8266/pgmspace.h:81:32: note: each undeclared identifier is reported only once for each function it appears in
     const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local)-__offset);   \
                                ^
C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\cores\esp8266/pgmspace.h:98:35: note: in expansion of macro 'pgm_read_byte'
 #define pgm_read_byte_near(addr)  pgm_read_byte(addr)
                                   ^
cpu.c:1066:35: note: in expansion of macro 'pgm_read_byte_near'
     if (BIOSaddr < 0x2900) return(pgm_read_byte_near(BIOS + BIOSaddr));
                                   ^
C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\cores\esp8266/pgmspace.h:81:49: error: expected expression before 'const'
     const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local)-__offset);   \
                                                 ^
C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\cores\esp8266/pgmspace.h:98:35: note: in expansion of macro 'pgm_read_byte'
 #define pgm_read_byte_near(addr)  pgm_read_byte(addr)
                                   ^
cpu.c:1066:35: note: in expansion of macro 'pgm_read_byte_near'
     if (BIOSaddr < 0x2900) return(pgm_read_byte_near(BIOS + BIOSaddr));
                                   ^
C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\cores\esp8266/pgmspace.h:81:49: error: expected expression before 'const'
     const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local)-__offset);   \
                                                 ^
C:\Users\RosaNarden\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\cores\esp8266/pgmspace.h:98:35: note: in expansion of macro 'pgm_read_byte'
 #define pgm_read_byte_near(addr)  pgm_read_byte(addr)
                                   ^
cpu.c:1067:36: note: in expansion of macro 'pgm_read_byte_near'
     if (BIOSaddr >= 0x3F00) return(pgm_read_byte_near(BIOStop + BIOSaddr - 0x3F00));
                                    ^
Fout bij compileren

line 1067 refers to " if (BIOSaddr >= 0x3F00) return(pgm_read_byte_near(BIOStop + BIOSaddr - 0x3F00));" in code below.

Code: Select allprog_uchar BIOS[10496] PROGMEM = {
   0xA0,0x04,0xB9,0xF6,0xE0,0x99,0x00,0x02,0x88,0x10,0xF7,
       [...snip...]
};
prog_uchar BIOStop[256] PROGMEM = {
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
       [...snip...]
};
uint8_t read6502(uint16_t address) {
  uint16_t BIOSaddr;
  uint8_t tempval = 0;

  if (address == 0xF004) { //EhBASIC simulated ASIC input
    tempval = getkey();
   return(tempval);
  }

  if (address >= 0xC000) {
    BIOSaddr = address - 0xC000;
    if (BIOSaddr < 0x2900) return(pgm_read_byte_near(BIOS + BIOSaddr));
    if (BIOSaddr >= 0x3F00) return(pgm_read_byte_near(BIOStop + BIOSaddr - 0x3F00));
  }
 
  if (address < RAM_SIZE) return(RAM[address]);
  return(0);
}


Any ideas? (I read something about ICACHE_FLASH_ATTR, but didn't quite understand it.)
User avatar
By martinayotte
#26908 Since I'm an old-timer who built its own Apple ][ in WireWrap back in the 198x, I've decided to give it a try ... :ugeek:

First error, is that "pgmspace.h" should not be included directly. I changed that to include "Arduino.h" (which will take care of pgmspace.h properly.
But this is assuming that arduino sketch is C++. there was a mismatch of having both, since cpu.c was present, I've rename cpu.c to cpu.cpp, but also tweak some 'extern "C"' statement that were not relevant any. Finally, 2 fonctions in arduino_6502.ino were define, but no prototype signature present in cpu.cpp, I've added them "extern uint8_t getkey();" and "extern void clearkey();".

Compile went thru. Runtime too, although they are not much memory to create big BASIC program, but it fun to see that ! :D

BTW, beware that all BASIC statement needs to be uppercase, like it was in Apple ][ ... ;)

Here is a copy of my ZIP ...
You do not have the required permissions to view the files attached to this post.