Unaligned address exception

I’m not sure if I’m at the right place, but I need help. I’m new with
PlatformIO and with the ESP01S.

I’m getting an unaligned address exception and I can not find the reason.
The code is for an ESP01S. It consists of a TCP Server and ringbuffer
for a temperature sensor. A client can read out the ringbuffer. The code is
running for a while, but suddenly I’m getting the exception. It seems
filling the ringbuffer is not the reason for the exception. It seems the
readout or answer of the server to the client causes the issue.

The PlatformIO monitor display gives me the following:

Which other information are required to be able to help?

Thank you.

Unanswerable without the full code and possibly a debugger.

epc1 = 0x40201b9b is indeed an unaligned address.

Thanks, but that sounds not good.

I would like to generate a map file . Maybe there I can identify something.
For that I found something like this for the .ini file.

build_flags = Wl,-Map,output.map

But in my case there is the following

build_flags =${env.build_flags}

Just adding the map sequence seems not to be correct.

What I have to do to get a map file?

Thanks.

Full platformio.ini?

[platformio]
default_envs = esp01

[env]
platform = espressif32
framework = arduino
build_flags = -Wall -Werror -DLOG_LEVEL=LOG_LEVEL_DEBUG
monitor_speed = 115200

[env:esp32dev]
board = esp32dev
build_flags = ${env.build_flags}

[env:esp12]
platform = espressif8266
board = esp12e
build_flags = ${env.build_flags}

[env:esp01]
platform = espressif8266
board = esp01
build_flags = ${env.build_flags}
monitor_filters = esp8266_exception_decoder

So just add -Wl,-Map,output.map there

Thank you very much. I appreciate your quick help.

Now I’m getting a map file , but the unaligned address points to the main loop area.
I try to get some more exceptions to see if it happens always in the same area.
But it takes almost an hour to get the next one. I must be patient.

Thanks again for your help.

I’m still struggling with the exceaption.

Meanwhile I 'm able to duplicate the problem earlier and I found that
after the 8th readout of the ringbuffer the problem occurs.

What causes

" build_type = debug "

in the .ini file please?

If this instraction is in the .ini file , I do not get the exception information
anymore. Just the Reset is visible.

Could I use the Exception Decoder anyhow to look behind the problem?
How is it used my may case ?

Is there another way to narrow the issue anyhow?

Thanks again.

Causes the compiler flags to change from -Os (optimize code for size) to -Og -g3 -ggdb3 (optimize code for debug [i.e. not that much], add debug info).

So, if you have a piece of code that works only when compiler optimizations are turned off, something is wrong with that piece of code. Might be doing undefined behavior, or doing stuff like missing volatile, etc.

Eureka - I got it!

Thanks a lot for your tireless help, but I got it using instrumentalized code.
I used a lot of serial output instructions in the code.

Eventually it was my own mistake. I used a too small buffer size. It
was just a calculation mistake. This causes a buffer overrun and
mislead to the unaligned access exception anyhow.

Now I can finally continue.