Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAX_SOCK_NUM is faulty determined in combination with Mega board #70

Open
BertHav opened this issue Oct 1, 2018 · 16 comments
Open

MAX_SOCK_NUM is faulty determined in combination with Mega board #70

BertHav opened this issue Oct 1, 2018 · 16 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@BertHav
Copy link

BertHav commented Oct 1, 2018

It seems that the number of sockets is determined in ethernet.h based on RAMSTART and RAMEND. But these facts are both defined for the mega chip instead of the W5100.
They are both defined in arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/avr/include/avr/iom2560.h Due to the fact that the Arduino Mega has more than 2048 bytes RAM the W5100 is faulty defined with 8 sockets.
Arduino IDE 1.8.7 Ethernet library 2.0.0

@Rotzbua
Copy link
Contributor

Rotzbua commented Oct 1, 2018

I agree that this misbehavior should be documented. I already mentioned it at #68 (comment) .

The reason is the chip type detection while run time and this do not work with variables while compile time ...

@SapientHetero
Copy link

Similarly, RAMSTART and RAMEND are not defined at all for the Adafruit Metro M4, which causes the library to allocate only 4 sockets for the W5500 instead of 8.

@PaulStoffregen
Copy link
Contributor

Are you sure about that? The code is:

#if defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048)
#define MAX_SOCK_NUM 4
#else
#define MAX_SOCK_NUM 8
#endif

On SAMD or any board where either of these aren't defined, the first 2 checks should be false and it should end up as 8. All 3 have to be true for only 4.

@SapientHetero
Copy link

SapientHetero commented Oct 2, 2018 via email

@PaulStoffregen
Copy link
Contributor

Regarding this:

Due to the fact that the Arduino Mega has more than 2048 bytes RAM the W5100 is faulty defined with 8 sockets.

The difficult design problem is Ethernet really does now support 8 sockets on Arduino Mega, if you connect a shield with the W5200 or W5500 chips.

@SapientHetero

This comment was marked as off-topic.

@PaulStoffregen

This comment was marked as resolved.

@BertHav
Copy link
Author

BertHav commented Oct 3, 2018

Due to the fact that the Arduino Mega has more than 2048 bytes RAM the W5100 is faulty defined with 8 sockets.

The difficult design problem is Ethernet really does now support 8 sockets on Arduino Mega, if you connect a shield with the W5200 or W5500 chips.

Yes indeed, but the number of sockets does not depend on the processor type. So to my opinion this is a nice try, but a bogus definition. I also agree MAX_SOCK_NUM is widely spread, so removing is not an option. My proposal would be to let it static defined, as it was. The developer who applies an 8 socket chip understands how she/he can define 8 sockets. The socket definition in the current implementation method is weird and produces unpredictable results/instability.

@PaulStoffregen
Copy link
Contributor

My proposal would be to let it static defined, as it was.

Could you be more specific?

Are you suggesting to forever make only half the sockets of the current generation chips available on all boards, without going into edit the library source?

@SapientHetero
Copy link

SapientHetero commented Oct 3, 2018 via email

@PaulStoffregen
Copy link
Contributor

I still have no idea what you're specifically suggesting.

@BertHav
Copy link
Author

BertHav commented Oct 4, 2018

Are you suggesting to forever make only half the sockets of the current generation chips available on all boards, without going into edit the library source?

Yes, for instance for the next 3 years. It is very easy to (re)define to 8 sockets. Defaulting to 4 breaks nothing, defaulting to 8 produces errors and bogus information in a 4 socket chip.

@SapientHetero
Copy link

SapientHetero commented Oct 4, 2018 via email

@SapientHetero
Copy link

Are you sure about that? The code is:

#if defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048)
#define MAX_SOCK_NUM 4
#else
#define MAX_SOCK_NUM 8
#endif

On SAMD or any board where either of these aren't defined, the first 2 checks should be false and it should end up as 8. All 3 have to be true for only 4.

Just realized why this logic doesn't work.

"Conditionals written like this: #if defined BUFSIZE && BUFSIZE >= 1024 can generally be simplified to just #if BUFSIZE >= 1024, since if BUFSIZE is not defined, it will be interpreted as having the value zero. "

https://gcc.gnu.org/onlinedocs/cpp/Defined.html

@PaulStoffregen
Copy link
Contributor

Remove the RAMSTART logic

If we do this, users with Arduino Uno & Nano (the most popular boards) will have too much RAM used. Those chips have only 2K RAM.

@SapientHetero
Copy link

SapientHetero commented Oct 8, 2018 via email

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

5 participants