Hello.
Welcome back.
In this lesson we're going to see how to develop a GP I O output drive up for a while Texas Instrument
Tim for C one two three microcontroller board will create a new project by coming over here.
Project New Vision project
and then um I'm going to navigate to the um so for that to start my project
I'm going to keep it over here.
I call this GPO and then I'll save it.
My board is t n for C team for C 1 2 3 0 8 6 p.m. and then okay.
So like this and then I'll click Okay.
And then on the Simpsons I select the core on a device I select the start up then I say okay.
Over here.
Right.
So then this my project target just him for C so renamed this to him for C and then I'll drop down over
here.
Source group are renamed is to up then I'll add new file but new item I see that dot s file.
I'll give it a name made right.
So before we went before we're able to develop our drivers we would have to take a look at the data
sheet and the um the reference module provided so that we can know the addresses of the various ports
and on the other pair forms that we need.
So if you're using common vision you can come to the book stop over here and then they provide us to
provide us um device data books we can click this and see if it works.
The last time I tried it it didn't work.
Um it brings us to the s t microelectronics website.
Windows Explorer has crashed.
Um anyway I suspect this doesn't work.
So what I'm gonna do is I'm going to go to Google and find the um they use a module as well as the data
sheet.
For those of you who office in the S M 32 version of this course you realize that we were able to get
access to those documents from this side here.
It's not the same for Texas Instruments if not updated.
So we have to find out from the Internet.
I'm going to open my my search and I'm going to start off by search and time for C 1 2 3 to 4 C use
a manual
and.
Okay.
This appeal.
Yeah.
No no S T C Series lunch but I'm gonna open this
and I'm going to save it.
This is the TVC use of my new
I call this.
You can say that on your computer at cost.
If you have the board you would need this document right.
Okay.
And went to fetch another documents.
This time I'm going to get the data sheet.
I'll just change this to words use a mind or here to a single word data sheet
and we have this other document to the SCC we still foresee key age 6 p.m. okay.
This is it open in another tab and it s got over 1000 pages.
This the data sheet.
I'll save this as well.
Team 4 C 1 2 3
data sheet.
Right.
So I'm going to close this no.
Right.
So let's open the documents.
We download it.
I've got them here.
So I've got to use a manual here and then I've got a data sheet.
Let's take a look at the um the user manual.
Um I'm going to take a look at this schematic diagram of the T4 seaport cause I want to know where our
edit LCD connected.
We are going to use our our GP LCD for our experiment right here on the page number on the page number
four.
We have an overview of the port showing the various components we have on the board.
We've got the power here.
We've got this microcontroller for debugging.
This is our main microcontroller.
We've got our Archie B LCD over here.
And then we've got to to use our switches that we're going to use for our experiment as well.
Then we've got USP here for those of you who want to develop USPTO devices right.
But we'll we're truly interested in is down here.
Page number 40
I just go to 40 by searching over here.
It's gonna 40 says it's gonna page number 40 sorry.
I think it's page number 20.
Skip.
Okay.
Yeah.
Here we go.
Okay.
I'm going to zoom in
and over here we have our LCD.
We have we have our GP so we have Red Queen blue LCD and they are connected.
Let's see if we can find the connection we want to see which pins they are connected to the microcontroller.
Okay.
This is the bit that talks about.
Okay.
So it seems our user buttons and melodies are all connected to port f f you is connected to this switch.
Number two if one is connected to the red LCD P F two is connected to the blue LCD P if three is connected
to the green LG P F four is connected to the switch number one.
So we find this information at page number 20 of the user my new winner take note I'm gonna just put
some notes here I'm just taking a step by step.
So I just put this board and I hope I know nothing about it this is how I'll go about to write my first
assembly driver or first go to the user manual to see how the power flows out connect to see how the
arm to see how things like the LCD and other test test component are connected and then I'll take note
and I will just take note by writing a comment this is what I do in my professional life I see um LCD
red as we saw this is Pier 1
we saw the switch one off switch to SPF 0 0 just call this Toby 2 This was PFC row
and then little green SPF 2
reality blue SPF 3.
And then we had to switch one
which was Pier 4.
Okay.
So these are the components we have we can test both GPL you input and output with the LCD and the switches
right.
And we know where to find them.
They're all input F right.
So we know to write what you tell your driver.
Um to to sort of use our Elegy for our GPL you experiment.
We need to access GPL you put F and couldn't figure out the registers that relates to the particular
entity we want to talk.
We want to Tokyo.
So we need to find those registers before we do that.
I have to give you a quick overview of how how modern day microcontrollers are designed and so modern
day microcontrollers um are different in what in many ways from auto microcontrollers.
One of these ways is in the mix and what is known as the implementation of the club gating mechanism
and what this means is the clock access to various parts or you can call its various modules or you
can still call its various peripherals so if the board block access to these various parts are blocked
by default.
So if I take my microcontroller proc access to GPL you.
It doesn't exist.
It is closed clock access to you can you be this close clock access to ATC clearance clock access to
you are disclosed et cetera.
This is known as clock gate.
And what this does is this this sort of makes the Metro controller consume less power.
And this is done because because the um the clock access is close by default you only enable or allow
clock access to the parts that you want to use so that you don't just allow clock access to the entire
board.
Yes.
Enable clock access to the parts that you want to use.
So in this lesson we are going to use Port F because our output is connected to port F to port f we
need to enable clock access to port F right.
So um yeah we need to enable clock access to port F and then once we enable clock access to port f we
can uh we can Togo the um their respective um port f registers.
We can talk out the right registers in now that to configure port f us be the input output.
Right.
Now to enable clock access to a particular module and also I should mention in this course when I use
the word module part and peripheral they mean the same thing I'm going to be using them interchangeably
um paraphrase is much more specific as you would know about when I say module or parts.
I'm just trying to see a particular unit.
Right.
Yeah.
So to see how to enable clock access for a particular module um we have to decide on which bus to use
generally in um quote X M architecture idea two types of buses.
We have the AP bus and the HP bus the AP bus stands for Advanced peripheral bus and the HP bus stands
for iPhone's high performance bus.
The difference between the two is that the high performance one the HP allows for faster access to pay
for those
so as I was saying the um the HP I'm sorry that I had to replace my my headphones it got broken so as
all saying we've got HP and AP bus and HP allows for a faster access to peripherals.
So for instance if you use an HP bus to access a GPL you peripheral it might take let's say just two
clock cycles to access it but if you want to access the same profile through APB you might need four.
So HP could give you two and then APB would require four cycles to do the this is just an example.
It's not specific anyway let's go to the data sheet to see a block diagram of our board and see how
the HP an APB bus connects to the various peripherals of the board.
I'm gonna go to the data sheets that we downloaded over here.
There should be a block diagram somewhere.
All of the data sheets have them.
See.
Sorry about that
so um getting familiar with the data sheet is um so requirement for anyone who wants to take embedded
development seriously you would have to get used to the data sheet and try.
Um begin to like it essentially.
Um once you understand the data sheets you can sort of rewrite the entire library of a particular board
and get the most out of the port if you may.
Right.
Mr. block diagram we're looking for you can find this on page number 48.
It's a 48.
Yes it is 48 of the data sheet.
Okay.
So this is the um uh microcontroller high level block diagram.
We have the E P B bus here and then we have the HP bus when you see this arrow.
It means the particle profile connects to this bus.
For instance the ATC connects to the APB bus to kill you.
It also connects to the AP bus.
So to use this you need to enable clock access of the eight through the APB bus.
Right.
General Purpose time it connects to the AP bus.
Watchdog time is connect to the APB bus as well.
Okay but what brought us here is the GPA you we have that you pay you for the GPL you they connect to
both the HP and the APB.
That is why we have two areas here.
One for HP.
Another one for APB so we can we can um we can use any bus we want for the GPL.
But in our experiment we're going to use the default which is the APB connection.
Right.
So that's what we gonna do.
Okay.
Now on that we know the um the bus is available for access and the pair.
We have to take a look at the registers of the peripheral.
We are working with and then um also over here I have to give a short um short explanation.
So um microcontrollers regardless of silicon manufacturer and regardless of architecture what eight
sixteen bits 32 bits a microcontrollers all microcontrollers when you are dealing with the GPL you should
have at least two registers and I know if you've seen the theoretical lesson I may have mentioned this
already.
They should have at least two registers.
One is called the direction register and one is the data register.
We use a direction register to set the GPL you as are inputs or outputs the data register is where the
data is stored if it's output we write the data to the data register if it's input we read the data
from the data register.
Right.
Apart from these two registers you would have optional registers that are useful things like decide
into whether the pin should serve as an alternate function pane and then digitally enable in the pen
or on the locally and enabling the pin cetera but a two man registers are the data in the direction
register.
Right.
So far here in um in the architecture registers of the peripheral are often arranged as offsets from
a base address.
So in order to sort of find the register of a particular pair for let's say GPL you a GPL you a must.
It's like the Register saying GPL you e are of the same type of state register as in GPL you'll be in
the of the same type as registered some GPL you see of the same type as registers and GPL your D etc..
And because of this it's designed such that there is just a single address for GPL you e and then the
GPL you register as such as GPL you a direction register is an offset from that single base address
of GPL you e and GPL you a data register is another offset from the base address of GPA a such that
the offset of the various types of registers the offsets are the same so wherever you are looking for
direction register you can have the offset to be zero x2 1 and then when you are using looking for data
register you can have the offset to be 0 x 3 2 but how we know that this data register belongs to GPL
you e not GPL you see is that to get a complete address of lessee GPL you a data register you've got
to take the bass address of GPL you e and you add the offset and because the various peripherals GPL
a b c d etc. Do they have different base address they have their own base addresses so even if the offset
of the various registers are the same because they have different base addresses we can be able to identify
that this particular data register belongs to GPL you e this particular direction register it belongs
to GPL you e etc. so without talking much less writes this less continue clued in you understand what
I mean.
So I'm gonna go back to the data sheet and I'm going to go to a page.
I'm gonna go to Page 92 to find what is known as the memory model and this would give me the base address
of my peripherals.
So let's go to the data sheet.
I'm gonna search 92 over here.
It says memory module here and this keeps the base address so GPL you a base addresses this.
It starts from here.
It ends here.
So the base address that that's what we need.
So I'm gonna copy this.
Sorry
Grinch.
Copy this and then I'll keep.
I'll take note the call this GPL your APIs
or delete the dot here right.
So we have the base address.
Another thing we need is the um system control base address system control is what we going to we're
going to go through the system control to enable clock access for the entire GPL you um peripheral.
So I'm going to fetch the system control piece address as well.
Let's see.
We should have this somewhere.
Y is
okay so if we want to o just point this out if we want to access GPL you e through the E HP bus we would
have to use this other base address but because we accessing it through the default which is the APB.
That is why I took the first address to this I know the address but it says HB here right.
Right.
If we cannot find the um the address on the table is fine that s another way.
So when we go to the page that talks about the um the particular module it s right.
The um what we call it it s gives us the address of the module.
So let's go to the clock Kate and register and see the address written that the clock gate and um it
s code the RC GC RC GC So just go to the top of the data sheet and search RC gc um RC DC.
Okay.
So this is a RC GC GP I O O click this and then let's see
okay so that's the base address.
It keeps us the base address too.
And this is good.
In other um in other documentations such as the um that of s t microelectronics when you go to the page
that talks about a particular peripheral.
It talks only about the.
It gives you just the offset.
It's expected to go to the um the table we're going to to fetch the uh the base address.
But over here it keeps the base address as well.
So we're going to use this to exit uh to a neighbor clock access and we can read more about it before
I copy this.
Oh sure you can.
So it is called the general purpose input output run mode.
Clock age in control.
So this is this sort of closes.
This is the gate clock gate to the GPL you and we can readable bits number five over here and you can
simply come over here and read about the Spitzer number five.
It says GPL puts f run mode locating control value description.
Def zero GPL you put F is disabled if one enable and provide cloak to GPL you put F in run mode.
So we would have to write we would have to write 1 2 bits 5 of this register here.
So I'm going to copy the register
right.
And then um oh take note this is the base address actually belongs.
It is for something um is for a structure known us says control so I'm going to call this this control
base cos this uh the other the other members of the CIS control.
So um perhaps perhaps I should just show you this.
So this is how it is written.
If if if we're going to write um let's say the um the complete Dreyfus from ground up professionally
if we're going to write it to look like the CMC s um the CMC is written drivers we're going to write
it in a structure form.
So it's C language it would look like something like it would look something like this struct and then
instruct I might probably have I I probably have um
I may probably have GPL you RCC our GC right and then I probably have g p t m RCC and then I might probably
have component 3 comp 3 and then comp for something like this
and then I'll come here and give it a name
something like Cisco control
like this
sorry for the look at the kind of spill control.
So so that's the base.
The reason why we keep talking about base address and offset is to get a complete address of this member
here and these members.
Yeah just yeah just registers.
So let's say I want to get a complete address of this has to be the address of the base which is the
structure the address of the structure plus the address of the member.
Right.
So this address that would just fetch our C GC belongs to a structure in no system control.
That is why I've given it the name system control base here and all of it GPL you.
This can be GPL you GPL you a it's the same way and we're going to have direction right yes the data
so enable register data register etc. This is how it looks if you want to view it in the form of a data
structure.
So to get the address or direction register we've got to take the base address plus the offset here
to get the address uh the address of digital enabled register we've got to take the base address plus
the offset.
Right.
Anyway so we've got system control base and then there's the IP address of the base.
Right.
So let's see the offset for the RCC it gives us the offset here.
That's the offset of RCC um offset of I Richie I see GC.
I keep saying RCC because in SDM microelectronics it is called the RCC.
So I'm going to take this sort of what the goodness to copy is you.
X 6 0 8
0 x 6 0 8.
Okay.
So now let's construct the RCC register to construct the RCC register.
What I'm gonna do is to improve readability I'm going to do this step by step I'm going to first create
a symbolic name for the base address or two Ss control and it's called base and I use the Q you directive
and then I just assign this hexadecimal number here and then next I'll say I will C G C G P I 0 offset
and we know it already this the offset the offset for our GC GPA you.
So if we take the base and then we add the offset we get the complete address for this register.
So this
this I'll say it to you and then I'll pass the base that we got so x 6 0 8.
Let's confirm it's the same as your x 6 or 8.
So now to get the address I'm simply going to say since I'm going to use this naming convention and
I'll explain why that is later I'll say says control
R C G C G P I O underscore r e q u
and this is simply a course system control base plus the offset.
Simple as this.
The reason I've decided to call this this registered this I could have used a shorter name.
I could afford it.
I could have called it Rick 1 or rec 2.
All my.
I could have given it any name in a symbolic name but the reason I'm using this as a figure to write
this code in bare metal embedded to see you're going to use this same um the same naming convention
if you use only Texas Instruments library you would see that there's a register that is called this.
If you use this naming convention if I use under CMC this library provided by um you see that the naming
convention is like this.
I'm showing what I mean.
I remember when I told you it's a structure in a member relationship with a base address and the offset.
If I'm to get access to this register in my bare metal programming for those of you who have taken them
met the bare metal um version of this course you would understand what I mean.
But if you haven't this explanation should suffice.
If I'm too if I want to access this register in C language or simply say SAS control and it's written
seize control of put an R here.
Yeah I think it's gonna hurt.
We're gonna eliminate the.
Ah yeah.
It's written says control.
That's the name they use.
And then they use the arrow operator to access the RC GC GP.
I remember and then I can assign my number here.
So say I want to enable clock for Port f I would write this.
This is what I want to in C language to enable clock access for Port f this bit here gives me this register
that we've just created.
So that is why I'm using the operator.
So anyway you see the arrow if you just think way you see the underscore.
If you had to convey this to C language it becomes an arrow.
And for those of you who know you know basic data structures of C C in this you know that are C GC GPL
you is a member of this CIS controls which is a structure like I explained earlier.
Right.
Moving on.
So if you do understand any of what I just said.
Just send me a message.
So we have our RC GC GPL you register.
We're going to do the same for GPL U A and it s registers so we can create GPL you a piece.
I'm going to see the GPL you f sorry I keep saying eh.
We have a way.
Oh uh LDA switches on GPL you f do play F base but I ended up fetching GPL you a bass.
This is ridiculous.
Let's go and get GPL you f g p you f do we have it
just bear with me.
Um.
I'm just gonna do d e end to get one registered D to um the digital will register.
Okay.
This is the key player U.S.
Denholm
register descriptions.
Let's see what we have.
Okay.
So over here it gives us the complete addresses of the GPL you registers.
Okay I'm on page number.
Let's see.
I'm on Page.
Page Number Six hundred and sixty two.
So um I'm looking for the GPL.
You f register um the GPL you f register bass address and I'm using APB which is the default.
I'm not using HP.
What do I mean by default.
I'm deciding which address to use.
There's no default here.
I'm using the APB right to copy this.
Yeah.
Um.
Yeah.
So GPL you f APB bass address.
I'm gonna copy this then you can use this as I just cleaned a dot in there.
Now we are going to look for the various GPA registers to do that.
One thing we we can do is just to behave naive if I didn't know how to program this board the Texas
Instrument.
Um the guys at the guys at Texas Instruments and the ladies who wrote the um the reference my door in
the data sheet they provide the steps steps for sort of working with the GPA.
Let's see if given a step by step.
Okay.
This is it initialization and configuration.
Who goes over here.
Did you apply with more jokes maybe access to different memory just like we mentioned like uh previously
the legacy a picture I.D. APB advanced peripheral but is backwards compatible with previous devices.
The other aperture the advanced high performance bus HP offers the same register map but provides better
back to back access before most than APB.
These approaches are mutually exclusive meaning we can have just one.
The aperture enabled for a given GPL your port is controlled by the appropriate port in the GPL you
each keep playing HPC register.
Okay.
Note that GPL you can only access.
Note that GPL you can only be accessed through the HB aperture.
Note that the you play you can only be access to the HB aperture.
This is strange.
Mm hmm.
Yeah yeah.
Okay.
You need not worry about this because I have tried this you can access it both through the HP and APB
a picture.
So I wonder why does it not.
That's creepy.
I can only be accessed through the HB.
Okay.
Anyway so these are the steps to figure out a GPL Europeans.
We face enable clock access and then we set a direction using that direction register sets the direction
of the GPL your port use in that direction register and to set a direction means to decide whether it
should be input or output and then configure the alternate function select if we want to configure it
will alternate function and then if we want it to drive something like a DC motor we can set the.
We can get we can set to decry for strength.
This basically means to set the current.
We have to our for our eight hour and then after that we can set some pull up registers pull down registers
or output drain program each part in the port to have it up pull up pull it out or open drain.
Right.
And then we can said this but when are we going to do decompose we start to do is to set a direction
register and then to set the ditch to enable to digitally enable the pin.
There should be a d e n register.
Okay to digitally enabled a pin over here and then to read and write the data into the data register
so you can read more about this if you want to get a complete picture.
Right.
So let's go find a direction register it should be found here.
Cause we are in the GPL u um section okay.
You give us a list of.
Yeah.
Give us a summary of the register and the various various offsets.
But I want us to go to what it registers.
Okay.
Um.
This that direction registered the GPL you direction register is that data direction register sets in
a bit and a desire register.
Can't forget that corresponded to be an output while clearing the pin meaning setting a bit I mean and
setting it to zero config as their corresponding pin to be an input.
So if we want to set a P F to as output we've got a right to want to bet number two in a way.
Yeah.
He has the offset of this register is 0 x for sure sure.
Okay so I'm gonna create this register.
I'll come here and see your GP.
I f said GPL you f d I are for direction
offset and you.
Q You said this is your ex force your issue let's confirm that it's your ex force your issue right.
So once we've done that we can create the other and we can create the register itself GPL you F D I
R and R you are here for register and this is equal to the GPA f page address plus the GPL you f offset
right.
So the next register will deal with is the um the GPL you f data register so I'm gonna say since we
have the offset.
Since we have the base I simply need to drop the offset and create the register.
I'm gonna write over here GPL you f data offset
and then I'm gonna say a Q you we don't have it yet so I'll leave it blank and then GPL f data are mean
in the register itself.
This a course the GPL you f base
plus t offset.
Okay.
Once this is done we need to sort out the key you output.
Um the digital enabled register which is that the end source GPA f DG n offset.
And then we say to you we fetch later.
So GPL you f the N R over here the real register
and we know this to be the base
plus to offset
right.
So let's go locate the offset of these two registers.
How many miles is this a bit.
Right.
So um let's find the um the offset of the data register.
Gonna come back to the data sheet.
So I've got to tell your data register.
You can read about it from here.
If you want the offset is sure X Sure.
So good a place that over here
rather strange
to see the data register as a tricky one.
This is not the offset data right.
Yes that is it's different from other registers.
We talk about that later.
So I'm gonna keep that open.
The GPL UDP and the digital mini will register the um.
We scroll down here for the n
it should be down here somewhere.
Um research
d e n here it is.
So the offsets for this is your x5 one c.
Okay.
Right.
Okay.
So back to the data register.
Um in the data sheet we saw the offset of the data register to be sure extra issue.
Um but if we use your x years for it it wouldn't work.
The actual offset is 0 x 3 FC and um the reason why this is I think uh would have to create a separate
lesson to explain how the GPL your data register is configured or it arranged a bit different from the
other registers.
So for now this is still a way to accept this offsets for the GPL data register.
Yeah I want you to accept this at face value.
I'm going to add it up an article or if you do less and explain why this is the offset.
Right.
Moving on.
So we um we saw that in the GPL you in the um in the RC GC GPL you register would need to set bits number
5 to 1 in order to allow clock access for Port f.
I'm gonna create a symbolic name for that.
I'm gonna say GPL you f enable and enable I'm gonna see you can you and I'm gonna shift one two bits
number five shift one to position number five and then I'm gonna create another symbolic name to turn
on the red LCD.
We already know what a red is connected to P.F. 1.
So I'm gonna shift 1 to position number 1 shift 1 2 bits Number 1 like this and then I'm going to do
for the green LCD LCD screen
Oh which is which
blue SPF two green SPF 3.
I think this is blue and this is green.
Right.
So a lady blue
Q You
two and then a lady green.
Q You were right.
So we've got all of this.
Um I'm going to clean our notes
right.
So we've been able to locate and create symbolic names for all the relevant registers we require.
So let's continue in the next lesson and let's implement a.
Driver in the next lesson I'll see you in the.