many commenters tell me that the stm32
mcus are great the last time they were
used on this channel
was in video number 11 on july 27
2015 high time
for a closer look crazy youtubers here
is the guy with a swiss accent
with a new episode and fresh ideas
around sensors and microcontrollers
remember if you subscribe you will
always sit in the first row
in video number 340 we discovered
that the adcs of the esp8266
and esp32 are not excellent
there viewers suggested that the stm32
is much better in this respect
they should also be better in interrupt
handling than the esp32
is this true and how about speed
in this video we will check the typical
stm32 boards
we get on the usual platforms have a
look
on how to program stm32 boards with the
arduino ide
compare the features of the small stm32
boards with the esp32 in other videos
i compared the esp32 with the esp8266
and the esp8266 with the arduinos
check out the adc and compare it with
the results in video number 340.
check out interrupts and compare it with
the esp32
check the speed as in video number 11
and see which one is faster
in the end we should be able to see
which mcu is best used for
which project we have to thank roger
clark
for his outstanding work to integrate
the stm32 line of mcu's into the arduino
ide
and the chinese manufacturers to produce
extremely cheap ports
stm recently joined the bandwagon and
released
their own arduino integration which is
good news for makers
unfortunately it did not work with my
mappleboard
so i went with roger's method but i
leave your link in the description
if makers talk about stm32 boards you
usually hear
blue pill i do not know how this relates
to the well-known other blue pills maybe
somebody knows
another board looks similar and is an
ancestor
of the blue pill the maple mini the
differences between the two are mainly a
circuit to enable usb
uploading i'm not sure if this is still
needed today
the form factor and the mcu are very
similar
by the way stm sells a whole range of
stm32 chips
the new arduino ide integration seems to
support most of them
so you are free to choose the chip you
need for your project
the maple and the blue pill use
mainstream chips
another pill the black pill uses an f4
chip
which belongs to the high performance
family
for general purpose it is probably best
to go with a blue pill
in this video i will use the maple mini
because my blue and black pills are
still in the mail
so what are the capabilities of these
cheap boards compared with the esp32
both use 32-bit processors but not the
same architecture
the most significant difference is the
lack of wi-fi
and bluetooth if it matters for your
project
the next difference is the number of
processors
and the size of the flash and ram
also the clock speed of the stm32 chips
used in the blue pills is lower than the
one of the esp32
both offer vast connectivity like
multiple uarts
i square cs and spi busses
both are much much more capable than an
ordinary
arduino nano so it is already clear
the hardware bang for the buck is very
high for both
boards compared with an arduino nano for
example
after the hardware we have to deal with
software
most of us already installed esp8266
or esp32 support in the arduino ide
installing the stm32 support is not
different
enter this string in the preferences tab
go to boards manager and search for
stm32
and install at least the stm32f1x
exports done now you can select the
stm32f103c
or some other series as said before the
new arduino integration offers
support for many more boards but how do
we upload the sketch to the stm32
there we have three options the first is
to use an
ftdi adapter make sure you have one with
3.3 volts not only on the vcc pin
but also on the data pins like this one
the advantage is that you can use it
also for
serial debugging but you have to juggle
with these jumpers
not very comfortable and you have to use
serial one instead of serial in your
sketches
the next option is the st-link for
uploading to the blue pill this is
probably the most comfortable choice
because you do not need to change any
jumpers
and the upload speed is very fast
but if you want to use serial you have
to add an ftdi adapter
to one of the three serial connections
and use
serial 1 serial 2 or serial 3
according to the pins you connected the
ftdi adapter
the third possibility is the one most
compatible with the arduino or the esp32
you install a bootloader on the stm32
board
using the sdm flash loader to do that
successfully
you have to download and install the
flasher from the stm home page
and this bootloader bin file for the
maple
and that one for the blue pill now you
have to wire the boot 1 pin to ground
and boot 0 to vcc and connect an ftdi
adapter to the serial
one pins on the blue pill there are
chompers for that
for the maple mini you have to use
dupont wires
after the start of the flasher you can
select the com port of the ftdi adapter
and click through the menus select the
bin file from before
make sure you allow pin files to show up
and hit next
now the bootloader is uploaded to the
board
remove first the boot jumpers and only
afterwards the power
otherwise you have to redo the whole
procedure again
the last step is to download and start
install
underscore drivers.bat as an
administrator
when you plug the usb plug into the
stm32 board
it should show up either as a dfu device
or as a serial device called maple
now it is ready to program if your
device shows up as a dfu device
the selection of the port is not
essential
only if it shows up as maple serial you
have to select its port
if you select maple mini the bootloader
is automatically selected
if you use the generic stm f103 board
you have to check that the bootloader is
selected
now you can upload like with an arduino
it works with a maple
and should also work with blue pills
maybe somebody can share his experience
the infrastructure is now ready and we
can start our tests
first we make a comparison of the adcs
to see if we find
the differences between the stm32 and
the esp32
mentioned by the viewers the stm32 needs
one microsecond for one reading the
esp32
is six times faster but as we know from
video number 340
this advantage is paid by a lousy
stability
if we connect analog pin 0 to a 2.5
volts reference
we also see variations and outliers as
with the esp32
but they are much smaller if we use a
moving average across 100 values
we get a much smoother line as with the
esp32
with this averaging we get two stable
digits with the esp-32
with the stm32 we get three
so the stm32 is about 10 times more
stable
let's check the offset error when i
ground the analog pin
we get precisely zero very good
and at one volt the voltmeter and the
stm32 values are very close
not like the esp32 which displayed
0.91 volts
and what about the problem of the
arduinos when vcc
changes the stm32 has an internal
reference
but i do not know if it is used for the
adc
because it runs on 3.3 volts it has an
ldo to reduce the voltage from 5 to 3.3
volts
which stabilizes vcc of the chip
so a change on the 5 volt rail does not
hurt the adc
precision same as the esp32
and much better than the arduinos all in
all
viewers were right the stm32 clearly has
much better
adcs it is not as good as the external
ads-1115
but to check battery voltage or to read
an analog sensor
it is good enough the next problem of
the esp32 was the slow reaction on
interrupts in video number
328 it needed more than
three microseconds to react to an
interrupt signal
how does the sdm32 compare we use a
similar sketch
as with the esp32 but because the stm32
does not have two cores
and does not run rtos we do not need the
precautions of the esp32
we just toggle the pin as soon as the
interrupt subroutine is called
here the latency is only 1.3
microseconds
around three times faster than the esp32
also not extremely fast but definitely
much faster
than the esp32 by the way if you want to
know more about interrupts
i strongly suggest watching video number
three to eight
also here the clear winner is the stm32
now we will check the speed as we did in
video number eleven
i used the same sketch used back then to
be comparable
and out of nostalgia ready
go
this was a fast race the two 30-bit
racers
went extremely fast while the older
8-biters are still
on the track the first test is around
input output operations
and integer arithmetics already then
i tested the maple mini interestingly
it was faster back then the result was
609 milliseconds and today it is
735 for 10 000 loops
it seems that the compiler changed from
2015.
fortunately we have flags for compiler
optimization
if we use the fastest option we get 658
which is nearly as fast as back then
in 2015 the esp32 did not exist
so we test it now it performs with 596
which is faster than the stm32
the 735 or 658
of the stm32 can directly be compared
with the 596
of the esp32 now let's compare floating
point calculations
the esp32 needs 356 milliseconds
the stm32 1534
respectively 1359 with optimization
switched on
the esp32 is four times faster
probably because it has a floating point
processor
definitely the esp32 is much faster than
the stm32
and if we need it we still have the
second core
a deciding factor we did not talk about
is
the libraries the standard arduinos
still have the biggest choice of
libraries
they usually are my fallback if i do not
find a library
for the esp32 nor the esp8266
both esp mcu's got good library coverage
over the last years
the stm32 in the arduino environment
probably has less traction
than the esps and unfortunately roger
deleted most of his valuable
stm32 posts on his blog so
google pointed me quite often to
non-existing links
so stick to the wikis and a discord
channel
if you search for information i leave
the links in the description
i do not have a lot of experience with
the availability of stm32 libraries
maybe you can help out in the comments
and tell the others
where you had problems finding a library
next pricing a blue pill costs around
3.50
including shipping the maple mini 4.30
and the esp32 mini my favorite for
projects
costs around 5.10 so we have a lot of
facts together to summarize and see
which mcu to use for which project
the first question is always do we need
wi-fi
or bluetooth if so the esp32
is the right choice in principle you can
add an esp-01
or a bluetooth port to an stm32 project
to get connectivity
but this is probably the exception if
you need
useful adcs or fast interrupt handling
the stm32 definitely is the better
choice
and if every penny counts too
a next question is do we need fast
floating point arithmetic
this can be for example for fast fourier
transformation
then the right choice is the esp32
in all other cases the choice is open
this is when i look into my storage bins
and decide which is the mcu i most
probably will no more need in the future
this is the right choice for those
situations
as always you find the relevant links in
the description
i hope this video was useful or at least
interesting for you
if true please consider supporting the
channel to secure its future existence
thank you bye