Stacks sys and cont - mhightower83/Arduino-ESP8266-misc GitHub Wiki

Stacks sys and cont

ETS system data RAM starts at 0x3FFFC000 and is 16K bytes (0x4000). The first 8K, 0x3FFFC000 - 0x3FFFE000, is used by the Boot ROM for data and BSS. This 8K block continues to be used after the system has finished booting. Some Boot ROM Services continue to be used by the NONOS SDK and some user libraries. The remaining 8K, 0x3FFFE000 - 0x40000000 is mostly used for the stacks.

The Boot ROM functions that support WPS and aes_unwrap() have fixed buffer addresses toward the beginning of this address space, 0x3FFFE000. By not using WPS and replacing aes_unwrap() with a version that uses malloc() we have a full 8K byte space to support the system (sys) and user (cont) stack, approximately 4K for each. The system stack is roughly in the 0x3FFFE000 - 0x3FFFF000 address space and the user stack in 0x3FFFF000 - 0x40000000.

To use WPS, the user stack needs to move out of this 8K space, allowing the system stack to move up closer to 0x40000000 out of the way of the WPS hardcoded buffers. Placing a call to disable_extra4k_at_link_time() anywhere in your sketch does this. With this configuration, the system stack is about 6K bytes. If you are not using WPS, you get the whole 8K for the system stack. This comes at the expense of 4K of heap space. The user stack is defined in lower user data memory. The heap size is the resulting unused memory below 0x3FFFC000.

When the system stack grows down below 0x3FFFE000, you may see an HWDT or other weird crashes.

When WPS is used without disable_extra4k_at_link_time(), you may see an HWDT or other weird crashes.