[Music]
all right
so hello everybody and welcome to our
new raspberry pi
pico class i'm going to remove these
headphones for now
um but i will put them back in the
uh q a session this will be a good
opportunity to charge them
while i'm speaking uh so uh during the
class itself just use the chat to ask
any questions
and we are going to have one hour for
class and then
uh 30 minutes of q a session um
so hi i'm morisha kedd and i'm here to
share with you some of the knowledge
that i gathered about the
uh raspberry pi pico and um
before we get into all the details let
me just share with you
a link to a document and i will use this
document
throughout the uh sessions to share
links and information with you
and it's like a collaborative document
so you can also
comment for the uh on it you can write
uh
where you are from so um this
is our freda the raspberry pi pico you
can
already see i connected a few uh debug
probes to it we are not going to use
those
uh today um actually i think we want to
be using the hardware today because
i've got something else for you yes
we are still going to talk about the
pipe eco don't worry
uh you didn't get into the wrong class
but we are going to use an
online emulator um so
um i know just uh to uh
hey alexander from hey alexander i think
you also
um you also was uh
took part in the avr class so go to
syria again
anyway um let me share my screen
and let's start rolling with this uh new
fella
um and while i'm at it just let me know
if you can
uh see my screen now hopefully you can
and i will open the chat so i can see
any questions
and comments uh two brazilians
already and one from turkey cool so
uh this is uh the document and
um um one fun fact about myself
because before we get started um i'm
also a salsa dance teacher so if you
want to
then salsa later let me know
thanks for letting me know that you can
see the screen
[Music]
so in this class we are going to do uh
most of the practice in an online
emulator that i'm working on
so this is the emulator um it's called
uh walkway this is a project i've been
working on on the
for the last year and a half or so and
this is an arduino emulator
but uh since the pi pico came out
i i was really intrigued and i i decided
i wanted to
um try to create an emulator for it as
well
so that's what i've been doing for the
past three months uh
over a live stream and i was i'm live
streaming those
uh coding sessions where i'm working on
the emulator
and this is also how i learned about uh
all the internals now
this is a brand new board and
i try to learn as much as i can but as
you will see there is
a lot of information to uh ingest and
um i'm still not an expert i'm still
working on it
but uh i would love to share with you uh
whatever i already know and then we can
if you have any questions i will uh be
glad to
look for the answers together with you
and find them together
so this is the simulation environment
and you can see we have a pi
pico here and i'm using the arduino core
for the pi pico
and this is super new so it lets you use
the arduino environment
so if you are coming from our arduino
background
you can see like pinmode digitalread
digital right
it's basically arduino code but uh
the arduino core that lets you
run this code on
raspberry pi pico so let's just start
with the simple blink
and you can see we have an led here it
blinks
um and i think the cool thing about
writing um this in the arduino
environment using the arduino um library
functions
is that we can easily swap the board
let's say we will swap
it to uh arduino
nano and you will see that the same code
still blinks the
uh led and um
other than this uh code editor and this
um like uh diagram you can see there is
also this uh small json file that
defines the parts and the connections
um and right now there is also let's
change the code a bit uh go back to the
pico
there is also like this thing where we
can uh just
uh add components from a drop down this
is new so
um there are there are bugs uh if you
find
them i will be thankful so we can add an
led and you can see it created the
connect the two connections
um and then we can just you know
change the code to blink that led
just so we can see
how it uh affects the uh
now it blinks this led at pin gp1
um gwen is asking whether the simulator
is open for everyone and the answer is
yes
and actually this is the first resource
i'm going to
uh link on
pi pico i'm going to share with you in
this
document so you can also start uh
playing around with it
and um i must say that i worked really
hard today
to get it to a usable state
so there are probably some bugs in the
pipe eco emulation i
literally worked all day so we can use
this today in class
and you will be able to run these
examples oh
i skipped now i spoil the next example
you will be able to run these
examples even if you don't have the pi
pico but
um there are probably some bugs and you
will see a lot of changes
uh in this emulator until we get to the
final class um a link for
google docs so this is the link i will
copy it again to the chat
in case someone missed it um and keep
this link because we'll use it in the
next classes as well all right so
um the first thing i want you to know
about the simulator um we still don't
have usb
and by default the arduino core uses usb
for debug print so if i will do this uh
you're probably using it not serial
service serial
you're really probably used to it uh
from arduino where you use the serial
terminal the serial monitor to print
debug output it doesn't work
because by default this is uses uh this
uses usb
and this would work over a physical pi
but if you wanted uh if you want to use
the serial monitor
in the simulator you can just use serial
one
and serial one uses the hardware serial
that is wired
to this gp0 pin you can see that
i connected it to this virtual serial
monitor
and now if we run the code you can see
that uh we get the output so
um the first thing i want you to
remember and i forget it all the time so
remind me if i forget please do
is that uh we need to use serial one
for now in the emulator probably in a
few weeks we'll also have usb and then
you can uh
you will be able to use serial dot
whatever as well um
and now that we are able to print things
let's start our um journey uh let's
meet our friend for the next few weeks
and my friend for the past uh few months
uh the raspberry pi the rp2040 datasheet
and the rp2040
is like the cheap at the heart of uh
the pipe eco it's a new silicon they
developed
and you can also already see it's like
647 pages this is
enormous um and
before we dive in um i just want to
uh i mean we won't read it
uh er all of it but i will show you how
i
approach uh reading data sheets for new
chips or uh microcontrollers that i want
to get familiar with but before we do
this
let's just make sure that uh everyone is
on the same page with
uh bitwise operators because we are
going to use them a lot in this
uh in this course so
uh i think i posted a link in the course
page so
if you go to the course page there is
like a guide
but i think uh just to make sure that um
there is like this uh notation that lets
you
write a binary number so let's say
value and specify the bits so this is
how
we can write um a value in
binary so zeros and ones in arduino and
if you wanted to convert it to a decimal
value we can just uh
serial println and we would see the
decimal value
in this case 128
and then uh we can do the opposite as
well let's say we have uh
42 and we can ask arduino
to print it as binary
for some reason it doesn't oh yeah
okay and then compile and then we can
see this is like
one zero one zero one zero so this is a
quick way to convert
uh between uh decimal and binary um
in arduino um and also
there is this uh useful uh bit macro so
if i uh use bit eight then i you will
see
it returns a number where the eighth bit
is uh set to one it's actually the ninth
bit
because we are starting from uh zero and
then i can also bitwise or with
bit number one which is the second bit
from uh
the left again we count from zero and
uh we get those two bits uh on
so uh just uh to make sure that
everybody is uh
sort of familiar with uh these syntax
and if you uh tend to forget about
the bitwise operators there is a nice
blog post uh
here i will also put a link with
like those uh gifs that help you
remember
how all those operations work like soar
and or
and everything um so
where was that bitwise gives
just for the sake of it
um and now that we know about
uh bitwise i mean you should probably
have you should have probably read this
before and
uh understand but if you have any
questions then
feel free to ask me in the q and a
session later
so let's start diving into the
documentation
and when
usually when you start working with the
pipe eco
you want to dive right into this data
sheet there is another
nice getting started guide uh we just
tell you
how like to set up things on your
computer and how to set up the sdk
and how to program it and debug it
and um my goal with the
emulator is uh to save you all of these
so
of course if you have an our physical
hardware and you want to do it
then yeah that's i encourage that but
uh if you just want to you know practice
and you don't have access to the
hardware itself then uh you you can
um basically skip this getting started
guide for now
and dive right into coding um
so it this guy doesn't really uh
explain uh about the board or the chip
too much
just you know the basics but it tells
you how to set up
and how to build stuff and see it's
very detailed um so
we're not going to need it today and
probably not going to need it
maybe i will tell you to look at it if
you want to do this or that but
are not going to use it we are going to
use this guide and this guide
is like almost everything you need to
know about the chip and i say almost
everything because around uh class
number three
uh we'll open another data sheet that
has
uh information about the arm instruction
set but
we'll get to that um
so first of all uh i find this uh fun
fact it's
not really important but uh this tells
you like
how the part number s scheme
works so you can see um it has
two cores uh they are uh
cortex m0 so that's the zero
uh that's like the amount of ram it has
log ram divided by 16k
and then that's like the amount of uh
flesh it has it doesn't have um any
flesh built into the chip the flesh is
always external so that's why this is
zero um so this
might be a hint that they are going to
release
other process source with different
amounts of ram or flash or different
kind of
process source um and maybe not
i don't know anyway uh usually when i
uh open a new data sheet data sheet the
first thing
i'm looking at is um
[Music]
this summary and it doesn't give too
much information
uh just very high level overview
you can see like how much ram you have
how many uh
gpio pin so uh we have like 30
gpios but then we have six other gpios
or
ios for the spi flash which
we can also use as gpios in certain
situations
um and then i think there is like
four channel adc analog to digital
and probably if they had a digital to
analog
they would also mention it there but
here but they don't and the usb 1 host
device so i i usually read this section
if i'm comparing a few chips and i want
to find which ship
is best for uh my needs but in this case
we already know
i mean you are in this uh pi pico curve
so uh there is no choice we are going
with this one um
[Music]
and then after this uh i usually start
in um i look for memory errors map so
this is where i like to start exploring
data sheets
and you can see like um there is
um uh
there are a few sections uh that uh
that uh in the memory space of the pip
code there is this rom there is
xap which is a weird name we'll explain
that in a moment
sram so that's the ram where your
variables are stored
and then a bunch of peripherals
registers and internal registers which
we will get
to but first of all where is our code
running from
so one way to answer that would be uh to
read the data sheet i mean
i would guess it might be from the rom
or
from flash but i don't see any reference
to flash here
but in this case we can also
use code to answer this question so
let's just print the value of setup
and i think printing it like that would
probably not work because of
uh yeah of type issues but we can
probably convert it
to unsigned longint
and then print it as hexadecimal
and uh yeah we can see that uh this is
the address the memory address of setup
so now we know where setup lives
and let's also see i mean we already
know like um
uh where was that in the data we already
know that the sram is mapped here but
let's just make sure let's just print
the address
of like let's say this value variable
um and then we should um yeah
we can see that in value leaves here
so yeah so um
now we know uh that this is i mean we
already knew that this is the
sram but now we can see it in our eyes
and we can see that setup
belongs to this xap and xap
actually when you click on it you don't
get a lot of details but when you click
twice
uh it says that this is the flash the
external flash
and um the uh there is a memory window
starting at
this address that uh whenever you read
from this is transfer
translated into a serial flash transfer
so
um that's basically a fancy way to say
that the
external flash is mapped in this address
which um
which we can see here so um
this is like where i like to start just
so
whenever i see an address a memory
address of something i know where it
belongs
to and then there is also this rom and
the rom um is just 60 kilobytes of
read-only memory
and they are like it's fixed it's
hard-coded in the chip you can't change
it and um
in in general it just uh let's
does take it takes care of booting the
chip and
uh letting you upload new code through
usb
um and there is like uh this link which
i really like this is the source code
of the uh the flash so for most chips
like the esp32 they also have
a built-in rom with some code but
you don't get to have the source code
and here you have the full source code
which
i think is really cool by the way let's
uh add this data sheet
oh somebody already did thank you uh
i mean yeah thank you patrick i already
added it now but uh thank you for
yes all right
um and
yeah the building you have to support is
awesome it means that you can just uh
plug in this spy pico
and drag a file into it and it will
program the pico you don't need to
install anything
just plug and play amazing and if you
are interested you can
uh what was that repo uh you can
find the source code for that bootloader
uh here in the bootrom
uh you see there is like this usb boot
device and
probably there is an external library
that takes care of the uf2
but anyway we'll take a look at the boot
rom uh in one of the next classes
i don't want to dive too deep right now
um
so we have this boot rom then we have
the flash then we have the sram
then we have this apb peripherals and if
we click here
we can see that there is like a bunch of
peripherals with
strange names and we'll go over there
some of them today
uh you can see that we have um
spi uart pwm analog to
digital i score c somebody is asking for
that link again so
yeah let's post it again um
i square c so basically these are like
um
all the peripherals and uh they are
mapped to this
uh address space starting with uh four
um for uh
40 million um and
next there is okay
next there is like ahb light peripherals
and you're probably asking yourself what
are those
apb and ahb lite these are just
uh types of bus that buses data buses
that are
part of the arm specification
and we don't really need to understand
the details in order to use them
and you can see that for the hp lite
we have dma and then also the usb
and the pio which is a cool feature of
the pi pico the programmable
programmable io we'll use it uh uh
in the last class and um
then we also have sao base and we are
going to talk a bit about sao today
sao is single cycle io block
and don't worry about that we'll explain
it in a moment
and we also have a bunch of uh internal
registers that
are part of the arm cortex zero
specification
and we are probably not going to talk
about them
um until the next class
all right so we have this address map
now if we see a memory address
we know uh how to look it up and see
uh where it belongs and um
another interesting thing to look at is
this bus fabric
and it's a bit complicated i guess
there is a lot going on here but
basically just showing the
connections between the various parts of
the systems
so you can see there are like two cores
to
processors that are connected to this
ahb light crossbar
and they can access use this uh fast
bus to access the rom the sram the flash
and also through this splitter this pio
[Music]
and usb and there is also an external
dma controller which
lets you uh transfer data between
the memory and some peripherals and it's
also connected to this
first ahb lite bus and then there is
also another bus which is the apb bus
and all the peripherals are connected
through this bus
so basically um as i understand this
this
it means that those ones get the
microcontroller the cpus get fast access
to those ones so the top
and those ones go through this splitter
so they get
slower access and we could go into the
details
but like it explains how it works
and how you can get uh um
like the bandwidth that you could get i
think up to
two gigahertz um but um
usually yeah up to uh uh
yeah up to two gigabit per second
but um for the most part
um just this is just to give you
a good idea or basic idea about
the connections inside the chip i don't
think it's super useful unless you need
to do
something that has a very precise timing
requirements
and if you do there is like a bunch of
registers that
uh help you figure out
the these registers uh
personal uh like let you
monitor the performance of accessing uh
peripherals through this buses but again
not interesting right now
um cool so um
[Music]
there is also like uh
i think there is like this diagram of
the chip which
shows uh another like block diagram of
all the parts in the chip
i don't know i don't find it very useful
but it's again if you just want to get a
quick overview of what peripherals you
have um
and like um
the connections inside the chip swd is
like a debugger interface
um all right so um i think that that's
what i usually try to when i get a new
data sheet a new chip i'm
looking at that's usually what um what
i'm starting to look at
like the memory addresses how the
peripherals are connected
and as we will soon see there are like
some very interesting details hidden
here
because what we see here is that what we
have seen so far is just like the high
level connections
but um there are like interesting things
like this
atomic register access and we'll get to
that in a moment
but uh before we get to that um
let's talk about gpio so
we have this setup where we link an led
and i created another setup here with uh
that's the same code other than the
led number and you have eight leds and
this is like uh a great example
of where arduino sort of um
kind of limits you because arduino
provides you an
api to write or read from a single pin
but what happens if you want to write to
multiple
pins at once for instance what happens
if you want to blink
all the leds so sure you could do some
kind of
for loop that would iterate over the
leds
but i mean
that that wouldn't be very efficient and
that's also a lot of code
right and this is where um
knowing the actual hardware interfaces
of the chip really starts to pay off
so let's see um how do we
access the gpio not through the arduino
library but rather
through the hardware the registers
and whenever we want to access the
hardware directly we have to look for
those
registers that control that specific
piece of hardware
and usually inside most of the chips
there is like a gpio
hardware peripheral and you can see
there is one here
that explains how to uh use the
registers how to write to specific
memory addresses to control
gpio um specifically in the pi
you can see that there are like a few
ways to control the gpio so
there is software control via sao single
cycle i o which we are going to
look at right now and then there's like
all those peripherals that can
also um access the gpio
and control it um
in addition to that there are like uh
two banks of
uh gpao there is like the uh user bank
which is like the standard of 30 gpios
and then there is
also like the qspi bank which is like
a bunch of um six uh
gpios uh it's probably written somewhere
uh six gpios that um
are connected to the uh flash chip on
the
uh pipe eco so um in our case
we are not interested in controlling
those those are like
used by the bootloader to see if you
press the boot cell button
um but other than that i guess they are
not very useful
for user code rather we are going to
focus on this user bank with
gpio029
and um
we are going to use the standard
interface the software control interface
via sao so let's take a look at
that and we can see that there are like
two identical set of registers
that control the gpio there is like gpio
x
for direct control of io bank fs 0
which is like those user gpios
and gpio high which is not interesting
because it controls these
gpios that are connected to the flash so
not interesting and this one is
interesting
um yeah somebody says that it helps the
clocks aren't as annoying as the sums
atmel a tendency to make very annoying
clocks here the clocks are
quite simple and we'll take a look at
them in a few
minutes um cool
so um if we want to control the gpio
and like the output there is like a gpio
art register that allows us to do it
uh and it sets the uh level of
gpio one zero high low so this sounds
like a good
candidate and if we check it we can see
this is the register
and we can see it has uh out of 32 bits
there are like uh
30 bits from 0 to 29 that are relevant
and then
we can read and write to them and we can
use them to set the level
high low of each gpio so basically this
is like a single register
gpio out that we can write to and
use it to set the values or
the levels of the gpio pins and this is
the offset of the register
and if we go to this it's
relative to the sao base so
let's define it for a moment in our code
uh gpio out
and then we can add those two
values uh constant signed
actually we can just uh add them like
that so that's
the sao bass offset plus the register
uh offset and then um actually it's a
pointer uh and then
uh we know that we can uh
by writing to this address it says that
we can control the output of the gpios
so hopefully hopefully if we
write their uh all bits once
like eight beats of once uh
it will set all those like gpio0 to
uh 7 to high and then if we write their
0
it will set all of them too low and it
doesn't build because
we need this type cast because it's a
pointer
okay and let's run it again and
oh it's not cons
oh yeah we need to write at the address
this is pointing to so this
this syntax means right at the address
that is stored in this variable
um all right and now
it's almost working only one led is
blinking and do you know what is the
reason for that
the reason for that is that we haven't
set our
leds to output so only one led if we set
another led we can see uh
or i think this one specifically doesn't
work right now in the simulation due to
a bug
um okay that's interesting
i promised you there will be some kinks
and here they are yeah for some reason
those two
don't like to work um but yeah
um other than interesting all the
uh even ones don't work
that's uh i will have to uh sometime
some fun debugging this tonight
anyway um this is like
one way to uh control the gpio
we can use it to uh set a bunch of pins
but uh just like we can control um
the um use this to control like the
values of the gbio there is another
register
which is a gpio i would enable
oe which allows us to uh control the
um the oh wait a moment
i think i may have some idea why it's
not working
so let's hey
like plus the funny thing is i tested
all the examples but then
i uploaded a few changes to the emulator
and now
in thai writing too much javascript
all right um
yeah okay so interesting all of them
works other than
zero maybe because zero is connected to
the
serial monitor it's not
working but if we cut this connection
still not working okay i will have to
debug it later but anyway
you can see that by writing to this
register uh we don't have to do this
loop
where we uh set each uh led each pin
individually even more uh instead of
like
um uh
having to do like writing once and then
zeros
there is another register in this uh
gpio sao gpio section
which you can see here uh so other than
the outer is like a register that allows
you to set
or clear a specific bin or a specific
pin so you can use it to control a
specific pin
and then there is like another one that
lets you um
[Music]
sort them so toggle one of the pins
and you can that's the offset of it and
you can write a value to it and writing
the value will just
toggle uh those pins so for instance
i can do something like this let's
change this to the
gpio out toggle or store
and then i can just write this value
and it will just toggle them for me so i
don't
have to um other than zero maybe that's
just a defective led and i have to
replace the led i don't know um
so uh that's another cool shortcut so
uh i could do something like if i wanted
to have a nice pattern i could do
something
like let's have this gpio
out again so we can set a bunch of
that was 10 right um gpa
out is that yep i can set a bunch of
registers
and then i can do something like that to
have this
fancy pattern so just
yeah oh i don't want to toggle those i
just want to set
those this better yeah
okay interesting um
yeah so mark is asking how to add
registers
and right now if you want to add them to
the simulation you can do it through
diagram.json
but you you can really skip them i mean
there is no um
yeah we'll link that sketch of course
eight leds sketch cool
um so yeah so um these leds are
simulated once they will work
fine without these resistors they are
just a decorative
thing there is no analog simulation so
they are just in the simulation they are
just functioning as a
wire they have no function um
all right so uh yeah we can see there is
probably some bug that i have to figure
out uh
in this gpio out mechanism simulation
but ideally that would just create uh
like
half of them would start on and then
they would uh
all blink um so i promise to fix that
bug for the next session and next
session
and then you can try this example again
um and just like the sao
allows you allows us direct access to
the
uh gpio pins to get output
uh the other direction is also possible
so um we have um
a bunch of input registers so
if we go back to the sao you can see we
have this
uh out uh and i would set clerk store
and then we have a bunch of those to uh
set a pin direction
whether it's output or input and then
the heist
aren't interesting but there is also
gpao in
which we can read from to read a bunch
of
gpios at once so let's try to do that
we have this demo with a bunch of
switches
and if we start this it just has the
setup uh it says those switches are
connected to these
uh um gpio pins 8 to 15.
uh the reason is that this pin is used
by the serial terminal
and we don't want any conflicts
and then we can you know just copy this
i think it will work with the const now
that i'm
using it as a pointer so we said the
offset is four
and that's uh let's call it the same
name
as in the datasheet gpao in
and then i can just you know print the
value of that as a binary
so um yeah maybe this
is already defined
yeah i guess it's already defined for
some other
purpose so let's call it red gpiowin so
we don't have any conflicts
oh yeah we need to read the this value
not past the pointer pointer but the
value
and yeah you can see it's zero but now
uh if i
change uh yeah ah let's add a
delay one delay so i can
change it and see changing so you can
see as soon as
i toggled interesting
oh yeah i know what's going on here i
need to enable the pull up resistors
on this pin so r8
i less than 16 i plus
plus pin mode so that's the arduino way
to
enable pull up resistors on this pin
and now yeah you can see like uh
whenever
i they actually go to zero
when i um when i change them
because
and yeah you can see like uh it's
arduino doesn't print the leading zero
so it's a bit confusing but then if i
just want you know to print those
uh only those values i can shift it by
eight so we don't get those uh lower
eight bits for those gpios that are not
connected
and um
yeah and then uh you can see like let's
stamp them
all let's disconnect them all so it will
be one one one one one
and then we can just uh you know play
around with them and see the result
so that's basically how we use registers
to
access the hardware and um
instead of like doing um
pin mode and all of that we there are
also registers that control that
so for that there is like a bunch of
other registers not a part of the uh
of the uh pao of the sao
there is like a gpio peripheral and
they're like um you can see here for
each gpio they're like uh
there is a control register for each
specific pin
that lets you set up uh what what this
pin is that is doing
and uh the important part here is that
you can select different functions for
each pin so for instance um
there is a table here
somewhere yeah here yeah
so you can see each pin has a bunch of
alternate functions um and you can set
that register that i just showed you
uh gpao01 etc control
to select which peripheral the pin is
connected to so that's how you choose
uh you associate pins with peripherals
so for instance uh if we
look at this gpioc0cdrl
we'll probably see it set to 2 because
uh the uart is enabled on that bin let's
try that
um where is the what's the offset of it
this is at offset zero
at offset four sorry from
this uh this is like the base of the i o
peripheral
so let's i have this register
uh gpio zero control
equals this plus four right
yep um so now uh if we read from this
we expect it to be two because this pin
is configured
with um this pin is configured with
the uh serial port so yeah we can see
let's remove those prints for now yeah
we can see that the
output is two and this is connected to
the serial port
and if we choose another pin for
instance uh
let's say pin eight let's
change this to eight and add another one
four pin eight
uh where it's been eight pin eight where
are you
pin eight so um
that's 44 44
yep it should be five and i will tell
you
why in a second so uh this spin has
function
is now set to function number five and
if we take a look at the table
we can see that function five is sao so
whenever you want to control the pins
through directly as gpios through
software
you just set the function to five
and then if you want to connect them to
a different peripheral then you can
set the function accordingly like the
uart in this case
um so that's one more way
or one more um memory
a set of registers that control the gpio
and to make things a bit more complex
there is even
more so other than those there is also
like
a set of ped registers and um
pet registers are how you enable
things like uh the pull-up or pull-down
resistor
and you can also set like uh the uh
how much current these pins can supply
between
two milliamperes and twelve milliamperes
and other like uh parameters like
disabling the output for the pin all
together
um and there is like uh
here is what those registers look like
so for instance
uh if we wanted to implement uh input
pull up
ourself we would need to set this pin in
uh gpio0 bank
control register and this bit and
uh let's do that but uh instead of like
having to uh usually if we want to set a
bit we need to read the value of the
register
and then set a bit and then write the
value of the register
but the pi pico has a nice feature that
allows you to
um write
like to set a specific bit in a specific
register of a peripheral without reading
the value first
and let's see how that works so um
if we want to set a pull down for
instance we want to set bit number two
so uh that's the pad bank
let's say we want to do it for
let's do it for uh pad
gpio what is that
uh pets banks zero gpao8
so that would be 24
24 that's the address of the pad control
for this register
and it's relative to this uh pedi
control peripheral
so yeah that's the address
and uh yeah
and then um we
we can like do this by you know uh using
there is an
arduino micro macro for that uh
to set uh bit number two i think
um and that's uh
why doesn't it like
uh
[Music]
the expansion assignment to free the
only location
oh probably because we have discussed
here i guess
yeah so that's one way to do it to uh
set this bit of the register but behind
the scenes
this means that we need to read the
register
set a bit and write it back um but there
is
another way which works across all the
peripherals and that's uh
one pretty nice feature of the pi pico i
told you about it a few moments ago
a few minutes ago and now we are getting
back to it
it's called um atomic register access
so for all the peripherals if we
a specific offset we can uh
instead of writing to a register we can
uh do something else so if we had
1000 we store those registers
2000 would set the bits that we assign
and 3 000 hexa would
clear those bits so in our case we can
just you know
add 2 000 hexa to the address
and then uh all we need to do is just
like
uh set it to a value with the second bit
set
and that would just uh do the same and
yeah actually um we don't really see it
but
it did the equivalent of setting pin
number eight to
pull up maybe we can enabling the pull
up on it
um not sure if this will still work
yeah you can see like now uh the pull up
for this pin
still works like this is the one
connected to
p number eight um
oh yeah of course it works we call it
pin mode
yeah okay great so now it doesn't work
and i think the reason it doesn't work
is
uh if you check out these um uh
pets what was that the pets
gpao and then we had that link to the
pads
somewhere here um yeah if you check out
the register
you will notice that by default uh the
pull-up is
not enabled but there is a pull-down
that is enabled
and uh oh and we actually enabled the
pull down as well
we set b2 and not b3 so first of all we
want to set bit number three
right um and then i think that wouldn't
work as well because we already have
like
the pull-up oh wow
this made the simulator go crazy setting
up
pull-up and pull-down at once probably
isn't a very
good idea but
let's see what happens if we just you
know uh
instead of setting this bit we use the
other
um register atomic register
shortcut to you know uh sort so
we we are going to uh switch beat number
two
off and turn bit number three on at once
uh no oh i know why this
probably doesn't work it probably
doesn't work because
uh let's see the print at the beginning
yeah you can see that we have now that
we haven't set the
pin mode on that pin on pin number eight
then um um
[Music]
yeah um it it doesn't have a function
the function is 31 that's
means it's unassigned so let's set a
function five
which we have seen above five is like
uh the s i o
function select yeah five is sao so
now i think this should be the
equivalent
and this is not constant anymore
gpo 8 control yep
okay and now we can see
i guess that ooh
yeah function is number five and
let's clear the terminal oh why did we
remove the delay
i think that wasn't a wise thing to do
um
okay and now well
still doesn't work interesting anyway
yeah you see i still got
uh some work to do in this uh yeah
on this uh simulation
but uh what i wanted to show you here is
that
uh we have a lot of a bunch of hardware
features like this
atomic register access or those uh this
ability to write
to multiple pins at once uh using the
sao
or read from all the io pins at once
using the
sao registers and these these aren't
available
if we are just using the high level
arduino libraries
and um the truth is you don't really
need to write all this code if you want
to
access this uh this has already been
done for you there is a
great sdk from the pi pico and it has
a bunch of functions like gpio
say direction gpio
set function so instead of like
doing this i can do something like this
gpio set function and set a function of
pin number eight to i don't remember how
it goes gaofunk
uh sao so yeah so that's
another way to um you know just set it
to five um and the nice thing about this
sdk is that it's
also open on github i will uh post the
link here
and let's also post the link to these
eight switches
let's call it
eight switches sketch
cool and then that's the pico sdk
but let me show you a cool trick if we
really want to explore this
sdk we don't really want to do it with a
github interface so you can add
1s to the link github1s.com
the rest of the url stays the same so
i'm adding one
is here and as soon as i do that i get
a visual studio code in my browser that
uh open that like opens this repository
with all the files let's zoom in so yeah
that's a very cool shortcut i use
all the time um i will just add a link
as well so you will have it later
one s
um and then i i can actually find the
source code like
gpio dot c or
i think this one is the right file gpio
oh here here we go gpio set function so
we can see it it actually uh calls this
uh it's writing to there is like a
pointer here and
uh it writes to one of these pad banks
offset gpio which is the same register
and then it um enables the
input bits and then uh it sets this
control
register to the function that we have
passed so
basically this is um doing writing to
the same register
so uh and if we open it with a
proper so this uh doesn't really support
c
code very well but if we open it with a
proper visual studio code that was gpa
let's see i think that was
this one uh set function
yeah oh i got it probably a bit older
version
anyway so if we click on here we can see
all those
structs that define those i o banks
the the registers and then all their uh
bits and that stuff um so it's really
cool that this is
also open source um
cool um and then uh one more link i want
to
share with you is uh this documentation
for the raspberry pi pico and walkway so
uh just if you want to uh
use different there are like two
different arduino course that you can
use there is like the official one which
is used by default
and a community maintained course so
there's instructions for that
and also this table which is right now
pretty red of the supported features
but uh over the course of the next few
weeks you'll see how
it gets more and more green so this lets
you know what is
already supported in the simulator so
let's
add this here in case you need it
not the arduino core just the main thing
all right so um
yeah apply
and by the way this has links to the uh
inside the documentation there is also
links to the source code of the
uh arduino core for uh the pi
uh the official one and the school
communicore
so as i said it's a super like living
thing work in progress
uh expect to see updates new features
breaking things
and i think uh it's uh time to
switch to the q a session but before we
do that
uh so we i'll have a q a session now but
if you want to ask questions i'm on this
discord server
waiting for you in the rp240js channel
uh we also have weekly likes live
streams on tuesday when we hack on the
simulator itself if you want to join
there is also the hackaday chat so you
can catch me there if you need
and um just before we switch to q a
let me stop my screen sharing for a
moment
so you can see which uh the cool shirt
that i got
uh in the mail this week that's the
hackaday new shirt so thanks the
hackadayu team for sending me that shirt
all right let me put on my headphones
and let's switch to the q a session
um
yeah um
[Music]
all right uh let me see if you have any
questions then you can either
write in the chat or you can um
or you can like just open your mic and
ask
and in the meanwhile while you do this
this
yeah plus for my o versus arduino 2.0
um so yeah so while you do this
um let's do one more fun thing uh
until the questions start to surface
so we had this example here where we
printed to the serial monitor
but you know we can do the same with uh
by writing to a specific register
so if we go here to uh
peripherals and
uart then we can just you know
go to list of registers there is this
first one uart
data register uh so if we take a look at
this uh
offset of uart zero add zero the data
register
uh then we have this uh
yeah or you might have to share the
screen
again oh good good call yeah let's share
let's share the screen again uh for this
small bonus
session so can you see the screen now
yes okay perfect so yeah so i just went
to the data sheet
and uh went to peripherals uart
list of registers and then the first one
is the data register
and basically whatever you write there
is written
to the uh uart and
um yeah data received transmit right i
got a character
so um you can see that uh
this uart zero starts at this address
plus
zero for the data register and then
um yeah uh i had this
started writing something okay yeah if
we take this
address uh let's call it uart
dr and just you know
uh write some value to it
like h then i expect it to
uh yeah it should be a
car pointer because i'm writing a
character there
oh yeah star
okay and then uh you can see that it
right ages
so uh once you spot the right register
um like you know you figure out which
register you want
you need to use to interact with
hardware it's pretty straightforward
like just
writing values to a specific location in
the memory
or reading from a specific location um
so uh that was just you know another
quick demo
of how to access the other registers
directly
by the information we have in the
datasheet