Re: ESP32 (classic) RAM size question

2024-04-29 Thread Sebastien Lorquet

Hi,

Random hangs can be related to insufficient stack sizes. Stack size 
requirements are sometimes surprising and the most unexpected. NuttX 
defaults are sometimes quite small and dont include size variations for 
different CPU architectures.


Also, there are tons of stack size parameters, not only per-application 
but also as default for new tasks and pthreads, and the setting for the 
boot task is also separate.


I spent litterally *days* on multiple occasions chasing ghosts, when it 
was just the stack.


in IT it's always DNS.

in RTOS it's always the stack.

Sebastien


On 27/04/2024 18:02, Bernd Walter wrote:

I have had random hangs when doing a ping, however, without a ping the
system seems to be stable.

Re: ESP32 (classic) RAM size question

2024-04-27 Thread Bernd Walter
On Fri, Apr 26, 2024 at 09:17:30PM +0200, Bernd Walter wrote:
> On Fri, Apr 26, 2024 at 07:58:00PM +0200, Tomek CEDRO wrote:
> > Can you please elaborate more on why / how system hangs?

I've found two bugs in my http code related to that.
I have had random hangs when doing a ping, however, without a ping the
system seems to be stable.
Will have to see what happens with a ping.
Maybe it was something unrelated - a browser window was still opened
and did a retry on a critical webpage or something.

The bugs hadn't been in the NuttX code, but since it might trap others
as well.

1. I did write into a const struct.
The server code has a struct to assign file endings to content type.
Something to be assumed const and to save RAM when I converted it from
NutOS I added a const in the declaration.
However, a 3rd entry is a parser function and I assigned some.
On the ARM it was ignored, but not noticed because I never used this
content type.

2. strcmp with NULL parameter, which is undefined and worked on ARM,
but failed on the ESP32
For dynamic data on a main page I used a GET argument to switch between menu
points.
An initial request is without this parameter and the function to return the
value of that argument returned NULL, which I had put into strcmp to check
if a given menu was selected.

Next thing will be to find out on how to use the code flash for configdata.
It seems there is filesystem support for that.
Normaly I would add an 24*16 chip and be done with it, but the ESP32 has
so little available GPIO when using ethernet...

And then trying to get WiFi running.
I do get the following message on the console:
ERROR: Failed to initialize wireless subsystem=-12
But I'm sure that's my fault.

-- 
B.Walter  https://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.


Re: ESP32 (classic) RAM size question

2024-04-26 Thread Bernd Walter
On Fri, Apr 26, 2024 at 07:58:00PM +0200, Tomek CEDRO wrote:
> Can you please elaborate more on why / how system hangs?

Nothing I can easily answer.
I have a complex codebase for a custom SAM4X board that I ported over to
a custom ESP32 board.
As part of that there is running HTTP code that I ported over from NutOS.
during the initializisation of that the system hangs, however, the parts
that created the hangs weren't importand, so I disabled them.
The service is a listen loop, pthread_create for the tasks.
Now I can do multiple requests via wget.
But when I try with a browser the system hangs.
That could be because the first request is a static romfs files, which I
also get with the browser and the browser will continue with dynamic content.
I get nothing on the console when it hangs.

It also hangs after a while when doing a normal ping.

Didn't wanted to hog other peoples time with that.
It probably is a local problem or because of older nuttx.
With the memory question however I checked that the question was still
valid with current git code.

> Do you know the cause?

No, so far I know multiple triggers.
It could be something hidden in my code, but the common points are mostly
memory related, that's why I digged into that first.

> 
> Does that happen only with your firmware or clean examples too?

Clean code won't easily run on my hardware.

> How often hangs happen?
> 
> Do you get any sort of traces or device just gets unresponsive?

So far it just hangs.
I also just have the console uart for debugging.
On the SAM4X board I would have had SWD for gdb.

> What NuttX version do you work on?

Can't say that either - it was a trunk import a while ago.
That project is old, I just gave up because I didn't need it.
At that time it was hard to get the chips needed and was living on
stocked parts, so I did a test board with ethernet alteratives and once
it did some basic functionality I could get chips.
Now I'm reviving the old prototype because I need something with WiFi
as well.
The same NuttX code worked fine on the SAM4X, so my guess would be that
it is just triggered with the ESP32 or ESP32 specific.
Or it is hardware related...

> I also experience random hangs on ESP32. Not using BLE nor WIFI. But I
> suspect EMC related issues (motor control).

I can't imagine that my hardware is a fault, but I don't know either.
It did run stable with Tasmota, but that was without ethernet in WiFi.
So faar I'm just at the beginning to debug.

-- 
B.Walter  https://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.


Re: ESP32 (classic) RAM size question

2024-04-26 Thread Tomek CEDRO
Can you please elaborate more on why / how system hangs?

Do you know the cause?

Does that happen only with your firmware or clean examples too?

How often hangs happen?

Do you get any sort of traces or device just gets unresponsive?

What NuttX version do you work on?

I also experience random hangs on ESP32. Not using BLE nor WIFI. But I
suspect EMC related issues (motor control).

--
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info


Re: ESP32 (classic) RAM size question

2024-04-26 Thread Bernd Walter
On Fri, Apr 26, 2024 at 11:01:20AM -0300, Alan C. Assis wrote:
> Yes, Abdelatif is right, I think only Bluetooth requires a reserved area of
> the RAM.
> 
> For WiFi the driver itself on the NuttX kernel is enough.
> 
> Currently there is no support to direct boot on ESP32 (to avoid using the
> bootloader), only ESP32-C3 and newer chips have support for it.

Well - in my case I needed ethernet.
But unfortunately I'm chasing a problem right now in that the system hangs
after a short while, which is somewhat reproduceable.
That's why my first investigations also went into memory and stack issues.
But I am using an older NuttX, so things might be a local issue.
Additionally I needed local hacks to get ethernet running because of my
hardware hacks to work arround the PHY clock issues.
Not going to love the ESP32 for ethernet.

> Best Regards,
> 
> Alan
> 
> On Fri, Apr 26, 2024 at 9:26 AM Abdelatif Guettouche <
> abdelatif.guettou...@gmail.com> wrote:
> 
> > 200KB should be the remaining SRAM size.
> >
> > BLE uses 32KB of SRAM. I don't remember Wifi having a fixed carevout in
> > SRAM. Then there are other areas used by the ROM bootloader that can be
> > revoked once the system has fully booted.
> >
> >
> > On Fri, Apr 26, 2024 at 2:22 PM Nathan Hartman 
> > wrote:
> >
> > > I recommend to add a comment there, to explain that although the board
> > has
> > > 320KB in total, ~200KB is used for WiFi and BLE.
> > >
> > > On Thu, Apr 25, 2024 at 8:36 PM Alan C. Assis  wrote:
> > >
> > > > Hi Bernd,
> > > >
> > > > You can use 320KB only if you don't need to use WiFi and BLE.
> > > >
> > > > The memory is used but the WiFi/BLE driver!
> > > >
> > > > Do you remember the old days where your video card used to eat your
> > main
> > > > memory and you should define in the BIOS how much memory the video card
> > > > will use?
> > > >
> > > > Same thing here! ;-)
> > > >
> > > > Best Regards,
> > > >
> > > > Alan
> > > >
> > > > On Thu, Apr 25, 2024 at 8:59 PM Bernd Walter 
> > > > wrote:
> > > >
> > > > > The original ESP32 is said to have 320k RAM.
> > > > > All board configs have the following:
> > > > > CONFIG_RAM_SIZE=114688
> > > > >
> > > > > Are RAM sections added later in the startup process or is there
> > another
> > > > > reason?
> > > > >
> > > > > --
> > > > > B.Walter  https://www.bwct.de
> > > > > Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
> > > > >
> > > >
> > >
> >

-- 
B.Walter  https://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.


Re: ESP32 (classic) RAM size question

2024-04-26 Thread Alan C. Assis
Yes, Abdelatif is right, I think only Bluetooth requires a reserved area of
the RAM.

For WiFi the driver itself on the NuttX kernel is enough.

Currently there is no support to direct boot on ESP32 (to avoid using the
bootloader), only ESP32-C3 and newer chips have support for it.

Best Regards,

Alan

On Fri, Apr 26, 2024 at 9:26 AM Abdelatif Guettouche <
abdelatif.guettou...@gmail.com> wrote:

> 200KB should be the remaining SRAM size.
>
> BLE uses 32KB of SRAM. I don't remember Wifi having a fixed carevout in
> SRAM. Then there are other areas used by the ROM bootloader that can be
> revoked once the system has fully booted.
>
>
> On Fri, Apr 26, 2024 at 2:22 PM Nathan Hartman 
> wrote:
>
> > I recommend to add a comment there, to explain that although the board
> has
> > 320KB in total, ~200KB is used for WiFi and BLE.
> >
> > On Thu, Apr 25, 2024 at 8:36 PM Alan C. Assis  wrote:
> >
> > > Hi Bernd,
> > >
> > > You can use 320KB only if you don't need to use WiFi and BLE.
> > >
> > > The memory is used but the WiFi/BLE driver!
> > >
> > > Do you remember the old days where your video card used to eat your
> main
> > > memory and you should define in the BIOS how much memory the video card
> > > will use?
> > >
> > > Same thing here! ;-)
> > >
> > > Best Regards,
> > >
> > > Alan
> > >
> > > On Thu, Apr 25, 2024 at 8:59 PM Bernd Walter 
> > > wrote:
> > >
> > > > The original ESP32 is said to have 320k RAM.
> > > > All board configs have the following:
> > > > CONFIG_RAM_SIZE=114688
> > > >
> > > > Are RAM sections added later in the startup process or is there
> another
> > > > reason?
> > > >
> > > > --
> > > > B.Walter  https://www.bwct.de
> > > > Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
> > > >
> > >
> >
>


Re: ESP32 (classic) RAM size question

2024-04-26 Thread Abdelatif Guettouche
200KB should be the remaining SRAM size.

BLE uses 32KB of SRAM. I don't remember Wifi having a fixed carevout in
SRAM. Then there are other areas used by the ROM bootloader that can be
revoked once the system has fully booted.


On Fri, Apr 26, 2024 at 2:22 PM Nathan Hartman 
wrote:

> I recommend to add a comment there, to explain that although the board has
> 320KB in total, ~200KB is used for WiFi and BLE.
>
> On Thu, Apr 25, 2024 at 8:36 PM Alan C. Assis  wrote:
>
> > Hi Bernd,
> >
> > You can use 320KB only if you don't need to use WiFi and BLE.
> >
> > The memory is used but the WiFi/BLE driver!
> >
> > Do you remember the old days where your video card used to eat your main
> > memory and you should define in the BIOS how much memory the video card
> > will use?
> >
> > Same thing here! ;-)
> >
> > Best Regards,
> >
> > Alan
> >
> > On Thu, Apr 25, 2024 at 8:59 PM Bernd Walter 
> > wrote:
> >
> > > The original ESP32 is said to have 320k RAM.
> > > All board configs have the following:
> > > CONFIG_RAM_SIZE=114688
> > >
> > > Are RAM sections added later in the startup process or is there another
> > > reason?
> > >
> > > --
> > > B.Walter  https://www.bwct.de
> > > Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
> > >
> >
>


Re: ESP32 (classic) RAM size question

2024-04-26 Thread Nathan Hartman
I recommend to add a comment there, to explain that although the board has
320KB in total, ~200KB is used for WiFi and BLE.

On Thu, Apr 25, 2024 at 8:36 PM Alan C. Assis  wrote:

> Hi Bernd,
>
> You can use 320KB only if you don't need to use WiFi and BLE.
>
> The memory is used but the WiFi/BLE driver!
>
> Do you remember the old days where your video card used to eat your main
> memory and you should define in the BIOS how much memory the video card
> will use?
>
> Same thing here! ;-)
>
> Best Regards,
>
> Alan
>
> On Thu, Apr 25, 2024 at 8:59 PM Bernd Walter 
> wrote:
>
> > The original ESP32 is said to have 320k RAM.
> > All board configs have the following:
> > CONFIG_RAM_SIZE=114688
> >
> > Are RAM sections added later in the startup process or is there another
> > reason?
> >
> > --
> > B.Walter  https://www.bwct.de
> > Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
> >
>


Re: ESP32 (classic) RAM size question

2024-04-26 Thread Abdelatif Guettouche
If I remember correctly CONFIG_RAM_SIZE is not used for ESP32. And it was
supposed to be set to 0 to avoid confusion.

For ESP32 only the heap is a bit messed up. Many agents poke holes inside
the SRAM space for their own use. You can check
https://github.com/apache/nuttx/blob/master/arch/xtensa/include/esp32/memory_layout.h
And when SMP is enabled:
https://github.com/apache/nuttx/blob/master/boards/xtensa/esp32/esp32-devkitc/src/esp32_boot.c#L92

Things are better with the ESP32S2 and ESP32C series.

On Fri, Apr 26, 2024 at 5:25 AM Bernd Walter 
wrote:

> On Thu, Apr 25, 2024 at 09:36:25PM -0300, Alan C. Assis wrote:
> > Hi Bernd,
> >
> > You can use 320KB only if you don't need to use WiFi and BLE.
> >
> > The memory is used but the WiFi/BLE driver!
> >
> > Do you remember the old days where your video card used to eat your main
> > memory and you should define in the BIOS how much memory the video card
> > will use?
> >
> > Same thing here! ;-)
>
> 200k is a lot.
> Interestingly I started with the ethernet setup and my intention was
> ethernet
> only, but in the meantime I do need wifi as well.
> Anyways, ethernet is started and wifi compiled in as well.
> There was a problem (in my old nuttx codebase at least) that the ESP32_emac
> code didn't like to be compiled with CONFIG_ARCH_PHY_INTERRUPT, which the
> wifi enable enforced.
> I dissabled that in the esp32_emac code.
>
> However, I have ethernet started and wifi compiled in, but not started and
> that's my meminfo:
>total   used   freelargest  nused  nfree
> Umem: 230384  19120 211264 12995
>
> So some RAM must have been added somewhere else.
>
> >
> > Best Regards,
> >
> > Alan
> >
> > On Thu, Apr 25, 2024 at 8:59 PM Bernd Walter 
> > wrote:
> >
> > > The original ESP32 is said to have 320k RAM.
> > > All board configs have the following:
> > > CONFIG_RAM_SIZE=114688
> > >
> > > Are RAM sections added later in the startup process or is there another
> > > reason?
> > >
> > > --
> > > B.Walter  https://www.bwct.de
> > > Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
> > >
>
> --
> B.Walter  https://www.bwct.de
> Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
>


Re: ESP32 (classic) RAM size question

2024-04-25 Thread Bernd Walter
On Thu, Apr 25, 2024 at 09:36:25PM -0300, Alan C. Assis wrote:
> Hi Bernd,
> 
> You can use 320KB only if you don't need to use WiFi and BLE.
> 
> The memory is used but the WiFi/BLE driver!
> 
> Do you remember the old days where your video card used to eat your main
> memory and you should define in the BIOS how much memory the video card
> will use?
> 
> Same thing here! ;-)

200k is a lot.
Interestingly I started with the ethernet setup and my intention was ethernet
only, but in the meantime I do need wifi as well.
Anyways, ethernet is started and wifi compiled in as well.
There was a problem (in my old nuttx codebase at least) that the ESP32_emac
code didn't like to be compiled with CONFIG_ARCH_PHY_INTERRUPT, which the
wifi enable enforced.
I dissabled that in the esp32_emac code.

However, I have ethernet started and wifi compiled in, but not started and
that's my meminfo:
   total   used   freelargest  nused  nfree
Umem: 230384  19120 211264 12995

So some RAM must have been added somewhere else.

> 
> Best Regards,
> 
> Alan
> 
> On Thu, Apr 25, 2024 at 8:59 PM Bernd Walter 
> wrote:
> 
> > The original ESP32 is said to have 320k RAM.
> > All board configs have the following:
> > CONFIG_RAM_SIZE=114688
> >
> > Are RAM sections added later in the startup process or is there another
> > reason?
> >
> > --
> > B.Walter  https://www.bwct.de
> > Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
> >

-- 
B.Walter  https://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.


Re: ESP32 (classic) RAM size question

2024-04-25 Thread Alan C. Assis
Hi Bernd,

You can use 320KB only if you don't need to use WiFi and BLE.

The memory is used but the WiFi/BLE driver!

Do you remember the old days where your video card used to eat your main
memory and you should define in the BIOS how much memory the video card
will use?

Same thing here! ;-)

Best Regards,

Alan

On Thu, Apr 25, 2024 at 8:59 PM Bernd Walter 
wrote:

> The original ESP32 is said to have 320k RAM.
> All board configs have the following:
> CONFIG_RAM_SIZE=114688
>
> Are RAM sections added later in the startup process or is there another
> reason?
>
> --
> B.Walter  https://www.bwct.de
> Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
>


ESP32 (classic) RAM size question

2024-04-25 Thread Bernd Walter
The original ESP32 is said to have 320k RAM.
All board configs have the following:
CONFIG_RAM_SIZE=114688

Are RAM sections added later in the startup process or is there another
reason?

-- 
B.Walter  https://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.