Skip to main content
Visitor II
July 7, 2020
Question

Cheap way to add Wifi+Ethernet to an STM32 project

  • July 7, 2020
  • 13 replies
  • 9999 views

Hi dear community! :)

My project is based on an STM32, probably one in the F range (have not decided fully yet).

I would like to add Ethernet and WiFi to my project, ideally in a cheap way (in terms of manufacturing costs, for let's say 1000 units), I was thinking there must exist an IC which could do that? Ideally I would also like to have both 2.4GHz and 5Ghz for the WiFi chip.

So far my best solution is to use Wiznet w5500 for Ethernet (about 2$/chip) and ESP8089 for WiFi (about 1$/chip). Unfortunately the ESP can only manage 2.4GHz but it clearly seems to be the cheapest on the market.

I also know some of the STM32 have integrated Ethernet MAC, but I would still need an external PHY and another chip for the WiFi, which I was thinking will raise the cost.

So a lot of debatting, hence why I would love to hear your thoughts on this!

Thank you!

Simon

    This topic has been closed for replies.

    13 replies

    SLasn.1Author
    Visitor II
    July 7, 2020

    I forgot to mention that Gigabit is not a requirement for the Ethernet, 100Mbits is fine :)

    Graduate II
    July 7, 2020

    For Ethernet an integrated MAC will give the highest possible performance and flexibility. PHY chip at 1000 units from DigiKey - KSZ8081 and DP83825 costs 0,78 and 0,63 USD respectively. Most likely lower cost can be achieved only by a mass order of some RealTek or similar PHY chips.

    SLasn.1Author
    Visitor II
    July 7, 2020

    Thank you for the reply Piranha this is great info :)

    I am currently looking at my possibilities to find an STM32 with integrated Ethernet MAC but also what I need for the rest of the project (among others USB Host, SDIO, and SAI or I2S able to handle an 8 channel DAC).

    Super User
    July 7, 2020

    > I would like to add Ethernet and WiFi to my project, ideally in a cheap way 

    WiFi is a terribly complex thing. It depends on what do you really want - to be only a station or WiFi-direct peer, what sort of performance and standard compliance is needed ...

    Besides of the ESP, if you get the ethernet working, you can look for WiFi devices with ethernet interface - basically, small routers.

    Maybe such routers exist also with USB/CDC interface - I don't know.

    Or, abandon STM32 and look for higher class chips that include wi-fi MAC.

    -- pa

    SLasn.1Author
    Visitor II
    July 7, 2020

    Thanks for the reply Pavel.

    I am a bit confused by your answer though, do you mean using an external device? If so it will not work, my device/project needs to be able to handle WiFi and Ethernet on its own.

    Other than that I do not have strong requirements for WiFi (the 5GHz one is only for practical situations - I have seen some places where there is only 5GHz WiFi), the device will only send and receive commands over WiFi so there is absolutely no need for high speed. And only WiFi client ("station") would be enough, but ideally having the possibility to be a WiFi Access Point would be better.

    Graduate II
    July 7, 2020

    The Ethernet is present on F1, F2, F4, F7 and H7. F1 is probably the cheapest, but also the oldest and least recommended. For 8 audio channels I highly recommend using SAI peripheral(s), not SPI/I2S. SAI is present starting from F4 (and up). Most likely you will use either TDM mode or 4 x I2S lines. For the latter case you need 2 instances of SAI peripherals. Yes 2, because each of them has 2 separate streams. For 2 SAI peripherals you need at least F7.

    To me the cheapest and easiest option seems to be some STM32F42x with TDM capable DAC.

    Super User
    July 7, 2020

    > my device/project needs to be able to handle WiFi and Ethernet on its own

    AFAIK, no STM32 has internal WiFi controller or is even remotely capable of it.

    So, only external solution. Not even mentioning RF part, antennas...

    ST has this: https://www.st.com/resource/en/datasheet/spwf01sa.pdf (never seen anyone using it).

    > the 5GHz one is only for practical situations - I have seen some places where there is only 5GHz WiFi)

    TL;DR the bottom line, if you are budget-oriented, go for 2.4 GHz.

    5 GHz only can work either within limited range and direct line of sight to the access point.

    Consider also which security protocol your wi-fi should support (up-to-date = more pricey, cheaper = hackable or harder to configure or both).

    -- pa

    SLasn.1Author
    Visitor II
    July 7, 2020

    Thanks again guys this is really helpful!

    @Piranha​  F4 / F7 is also what I had in mind. Fully agree with not using SPI/I2S especially since I will probably need the SPI lines for something else anyways (like communication with the WiFi chip f.x.). Did not know about TDM, I'll investigate! You got any suggestions for a DAC chip? Only requirements are 8 separate channels and able to handle at least 48kHz PCM audio.

    @Pavel A.​  I think I understand what you meant with "external solution" - yes using another chip is perfectly fine. I just want it all in the same device (in the same "box" literally). My knowledge in the RF world is very limited, so yes I'll have to think about antennas and like - my first idea was to simply use a trace on the PCB for that.

    Good point about the security protocols, even though again I am not that fuss as long as it will work in most "typical/home" environments. And yes ok maybe I'll stick to 2.4GHz, in this case the best solution seems to be an STM32 with integrated MAC + Ethernet Phy + ESP8089 for WiFi.

    Super User
    July 8, 2020

    If so, for Ethernet consider something like ksz8851 (you need a PHY anyway) - and happily bypass the STM32 ethernet programming experience -

    that @Piranha​ surely wants to describe to you in colors ;)

    -- pa

    Graduate II
    July 8, 2020

    KSZ8851 doesn't solve anything. One will have to write a driver for an external MAC connected on SPI or even custom parallel interface. If one can do that, then writing a driver for internal MAC is easier and you have more examples on the Internet. Take a note that here I'm talking about the Ethernet driver (L2), not the IP stack (L3+).

      

    Is this some religion with a commandment: "Thou shalt not write a driver for STM32 peripherals"? I've said it multiple times - for STM32 writing ETH driver is harder than for USART, but easier than for I2C. Take the reference manual and this example as a starting point and you'll get a basic working driver in a few hours! But most likely you haven't even tried to do it...

      

    As for the whole networking thing, the hardest part is not an Ethernet driver, but an IP stack! In essence the complexity is not specific to STM32, Ethernet and not even lwIP, because all decent IP stacks are of non-trivial complexity. The only thing that is specific to STM32, is the fact that it's manufacturer provided code is absolute crap.

      

    My only "political" message here is - don't blame decent hardware for utterly shi11y software's flaws. Does my networking "how to" topic look like I'm describing it "in colors"? The forum is also full of my honest descriptions of HAL/CubeMX code - non-working bloatware made by brainless code monkeys, which is not worth the effort of fixing it, as writing a decent code from the ground up is easier. And it's the polite version of the description the HAL/CubeMX team deserves...

    Graduate II
    July 8, 2020

    As for DAC, first candidates could be PCM1681 and AK4438. There are other options also. But that's not a real recommendation as I have no practical experience with those.

    SLasn.1Author
    Visitor II
    July 8, 2020

    Thanks again guys - very helpful stuff :)

    For the DAC, I was also thinking PCM1681 - very cheap and widely used it seems :)

    Regarding the Ethernet, I am happy you brought IP because that was gonna be my next question: the really nice thing about the Wiznet w5500 is that it takes care of L3 & L4, so I do not have to worry about TCP/IP. I guess in this case I will have to handle all of that on the MCU. Are there no pre-written libraries I could use?