Skip to content

Ethernet and SPI #652

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

Closed
palmerr23 opened this issue Sep 14, 2019 · 9 comments
Closed

Ethernet and SPI #652

palmerr23 opened this issue Sep 14, 2019 · 9 comments
Labels
question ❓ Usually converted as a discussion third party library Linked to a third party library

Comments

@palmerr23
Copy link

Frederic,

I'm trying to get a WIZ5100 module working on a Black 407 VET6 (Core V1.6.1). I'm quite familiar with the hardware and SPI/Ethernet.

W5100.cpp in the Arduino core Ethernet libraries calls SPI.Begin() - with no parameters. Perfectly fine, except that the default MISO/MOSI pins are 20/21, which map to (in variant.cpp)
#define PA12 20 // USB_DP
#define PA11 21 // USB_DM

To find which pins are actually being used, I added the following code to your SPI.cpp after setSSEL(...) (equivalent to Paul Stoffregen's extra code in the Teensy version).
//rp added for debug
uint32_t mosiPin(void)
{
return _spi.pin_mosi;
};
uint32_t misoPin(void)
{
return _spi.pin_miso;
};
uint32_t sclkPin(void)
{
return _spi.pin_sclk;
};
uint32_t sselPin(void)
{
return _spi.pin_ssel;
};

at runtime
mosiPin() returns 21
misoPin() returns 20

What I'm having trouble tracing is how the defaults for these pins are set in the STM32 core. The traditional defaults at runtime are:
PIN_SPI_MOSI and MOSI = 6
PIN_SPI_MISO and MISO = 74
... so these aren't the values being used

Can you provide me with a clue of where the SPI defaults are set for the STM32 variants, so that they can be changed to the most sensible values for this board - which would be the standard pins on the NRF24L01 header:
SPI1-MISO PB4
SPI1-MOSI PB5
SPI1-SCK = PB3

Richard

@fpistm
Copy link
Member

fpistm commented Sep 14, 2019

Hi @palmerr23,
The default SPI pins are

#define PIN_SPI_SS PB7 // NRF24 connector
#define PIN_SPI_SS1 PB0 // W25Q16 (on board flash)
#define PIN_SPI_MOSI PB5 // NRF24 connector & W25Q16 (on board flash)
#define PIN_SPI_MISO PB4 // NRF24 connector & W25Q16 (on board flash)
#define PIN_SPI_SCK PB3 // NRF24 connector & W25Q16 (on board flash)

@palmerr23
Copy link
Author

Thanks Frederic,

Those tally with what I'm reading at runtime.

I'll keep digging into the code to see why these aren't translating into the right defaults in SPI.h

Richard

@fpistm
Copy link
Member

fpistm commented Sep 14, 2019

As far as I know it was ok. Maybe a misalignment appears when introduced other black F4 variants.

@palmerr23
Copy link
Author

Frederic,

Basic SPI is working fine on its own, without Ethernet. I can't get the SPI library to control the SSEL line directly, but I'll explore whether that's my misconfiguration or the code, later.

The board mappings look fine - at least the SPI definitions haven't slipped as other boards were added.

After not playing round in the core of Arduino-land for a while, I got confused by the two ways of referring to pins, and forgot about the digitalPinToPinName() mapping. This led me astray while looking for problems.

I'll delve into the Ethernet libraries next to see how they are calling the SPI.

Richard

@fpistm
Copy link
Member

fpistm commented Sep 15, 2019

Hi Richard,
I've also reviewed pins mapping and it is OK.
I've also tested the SPI using the NRF connector with a TFT and SD on SPI and it works fine.
So, I guess issue is in the lib.

Edit:
looking quickly the lib. it seems there is no issue with pins.
https://github.com/arduino-libraries/Ethernet/blob/4f4ac17f296f5ffbe869730db88265ddc3e4fc15/src/utility/w5100.cpp#L40
the SS should be OK.
Anyway, it seems they optimize the SS pin for several target and fallback to default API if not know.
So maybe you will have to port the lib to ensure fast SS write.

@fpistm fpistm added question ❓ Usually converted as a discussion third party library Linked to a third party library labels Sep 15, 2019
@palmerr23
Copy link
Author

Great thanks, Frederic.

I've now got it basically working and the max UDP rate I can get is 1000 pps (60 byte packets), which is a bit poor. No where near even the low end of Paul S's benchmarks (80 kb/Sec on a Uno WIZ5500). I get dropped packets if I don't have a substantial wait on the send side between packets (500+ uS).

I'm going to play with the SPI speeds next to see if this is part of the issue.

I've been using a WIZ5100 board so far, and might try a pair of 5500s to see if they are any better.

Unless you care to track me optimizing Ethernet on STM32, we could close this issue now.

Richard

@fpistm
Copy link
Member

fpistm commented Sep 16, 2019

Fine.
Probably related to #257.
I close this one as I will not invest on this library and I guess willbe covered by #257.

@fpistm fpistm closed this as completed Sep 16, 2019
@uzi18
Copy link

uzi18 commented Sep 16, 2019

You can set CS pin to use with Paul's library.
Please remember Wiznet chips has got some limits, like socket and max spi frequency, Wiznet 5500 has got some boost - sequential reading - dma capabilities.

@palmerr23
Copy link
Author

Thanks uzi18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❓ Usually converted as a discussion third party library Linked to a third party library
Projects
None yet
Development

No branches or pull requests

3 participants