Hello.
Welcome back.
In this lesson we shall see how to configure a y GPA port on the Texas Instrument team 4C 1 2 3 microcontroller
using bare metal code.
Come over here to create a new project new project and I'll keep it in a folder I've created quite a
folder here.
Create a new 4.0 Stories Project projects.
I'll call this Kiki Io
output
and I'll call the project to tell you outputs as well.
GPA or score output.
Like this approach I'm going to select my board.
It's the team for you.
1 2 3 zero.
Age 6 p.m..
Like this.
And then I select this then okay.
Then under CMC as I select call on the device I select start up and then okay over here and then I'll
change the target to the name of my MCU team for C 1 2 3 and then over here.
Source group Oh name it I rename it to APB for up and I'll come to target options right here.
I'll say this to my extort which is 16 megahertz debug by here I'll select distilleries ICD I this one
over here and then I'll click over here and I'll take this.
Yeah reset and run and then okay and then OK then I'm going to come over here right click that new item
and then I'll add to demand that c file name over here in the c file.
So right.
So over here in call you vision you can you perform so all you wish and provide just the complete solution
apart from keeping our project well structured and given us the debugger and other things like the compiler.
It also provides us with reference manuals and books when it comes to the books tab whichever microcontroller
they use in call you vision provides the required reference my no audio available reference material
for that particular hardware for instance we've got the TVC Tim 4C One two three data sheet here and
we've got cortex and for generic User Guide this is because the Tim 4C One two three microcontroller
is a cortex M4 and also we've got books here dealing with the compiler as well as cow empty K itself.
So let's click here and see
OK.
It says Page Not Found this shouldn't be what's happening right.
So Texas Instruments has to fix this.
Often when you open here it takes you directly to the link of the PDA off of the data sheet.
Right.
Since the link is broken for this particular M.S. you would have to find it.
So before we program the microcontroller in bare metal we first need to examine how its peripherals
are connected and how its clock is connected to the various components as well as how the registers
are arranged.
So to do that we need to take a look at the data sheet so that is what a microcontroller.
But we have the development board.
Right.
So the development board has the microcontroller on it and it provides us with certain eye or devices
we can experiment with.
We've got OLED here we've got push buttons here and we've got other things.
So let's first take a look at the user guide for the development board so that we know which pins our
LCD and push buttons are connected to.
So then when we go to the data sheet and see how the GPI use connected to the CPE you we know exactly
which PS to initialize in order to control whether LCD or push button.
So I'm going to go to Google over here and I'll see Tim for.
1 2 3 0 c
launch pad and then I'll just I'll just search
or search user guide.
Let's see you guys should give us this.
OK.
So there's a link it TVC series the unforeseen launch part of evaluation kit use a guide right click
this.
So over here the the purpose of this course is not just to give you a cookbook approach such that when
you're looking for this you do this and no the purpose is to make you a better embedded systems developer.
So this assumes this assumes you know you're not familiar with the overseas series at all.
You've just put this board.
And how do you go about to program it.
This is how you program it.
First you take a look at the user guide and you take a look at a data sheet.
Once you've done that you know exactly how to control the board.
And you can apply this to any microcontroller regardless of the vendor.
So that is why I'm taking this approach.
I can write all the code and just tell you do this do that.
So rather than telling you straightforward what needs to be done in this course I'm going to take you
to the data sheet and you and I shall find information together.
We would assume we just got this new microcontroller from Texas Instrument and we are embedded developers
and we want to know how to program this type of microcontroller.
So I'm going to be taking you through the steps that we often go through in order to figure out information
about a new development board or a new microcontroller from a different manufacturer.
Right.
So let's take a look at this user guide so the user guide for our TVC launch part evaluation board.
I'm going to scroll down here.
Over here we have an overview of the board.
It tells us what we've got it says we've got to use a switch over here.
This is quite a use switch too.
We've got one other one here and we've got we've got these bins here.
It's allows us to add something on us booster pack perhaps want to expand this like head pays for I
didn't more just like Bluetooth module Wi-Fi module et cetera.
And we've got our attribute OLED over here as well.
We've got a USB connector in this USP here is for our debugger and it provides post Well there's a post
which this is another microcontroller.
This one is for debugging and this the main microcontroller.
This is where our program is stored right over here.
It took us a bit about it.
You can take a look at it if you prefer.
But what we are truly interested in is the is the schematic diagram to see how the peripherals are connected
to DMC how yeah the for those like the LCD and other things.
OK.
We've got this information here.
User switches and Archie Chibi signals right.
Actually I'm just going to copy all of this controversy to copy and I'm going to bring it over here.
Let's see if it works.
OK.
Excellent.
It's arranged properly so we're going to keep this information here
so we know we've caught our switch one which is on the left.
That's f for window switch to it.
That's PFC you switch P if one has the red LCD and then the blue LCD is SPF 2 3 has the green LCD.
OK good.
So p f just means port F right.
So we've seen this actually.
We have what we need but if you have if you find a user guide and they use a guy doesn't give the table
showing this type of information you often find this in the schematic diagram and over here when you
check the schematic diagram you should see the LCD.
So let's start from the top.
So it is the maze.
This schematic diagram of the main MCU connections and this is the MCU over here from the microcontroller
diagram.
We still see OLED red blue and green here.
So when I assume over here I can see the red is connected to this one here P F one like this when I
trace the wire I realized red SPF 1 and P.F. 2 has blue P 3 has green.
And in fact P A 4 has used a switch one on PSU has used a switch to switch just by seeing this I know
and I can enable it it registers appropriately.
So now that we know where our entities are connected let's go and take a look at the data sheet of a
war with our microcontroller I'm going to come over here and I'm going to search Tim for C 1 2 3 this
time I'll say data sheets and the data sheet is about a chip that microcontroller chip is not about
it TVC development board this is about just the ICI the MCU itself right.
So I'll come over here.
Texas Instruments has a link to it.
I'll click this over here.
Let's see.
It's probably got over a thousand pages often long.
Right.
It's got 1400 pages.
Don't be worried.
You need not read all of it.
In fact you probably use like 20 percent of it.
Most of the time it's just a reference guide.
So this the data sheet is called.
It's table of contents over here and over here starts by saying OK.
Architectural overview the MCU overview etc..
Let's take a look at the MCU.
If you click this and it should have a diagram.
OK.
Excellent square diagram here.
So this did that when we're interested in the first diagram we're interested in this this one this one
tells us which bus are MCU.
Which bus a particular pair four is connected to.
So more than the microcontrollers use two types of buses.
We've got the advanced pair for bus this one here known as the APB assuming a bit and we've got the
advanced height the four months pass known as the HB de HB is extremely fast and with HB you can access
a pair for using a single processor cycle if you want to access a pair full with the APB you may require
at least three processor cycles in order to be able to do that so we have to find the bus our particular
airflow is connected to so that we can enable clock access to the pair flow through the bus so over
here let's see we've got GPA to GPA has an arrow starting from here and over here and it's got an arrow
from here and here as well.
So the GP is are connected both to the HB and the APB so we can control the GPA you or initialize the
GPA you put using the HB bus for the APB bus something like the DMV the DMV also has both HP bus and
APB bus so we can access using both HP and APB that you are is connected just to the APB.
The general purpose time is just to the APB as well in the ATC test to the APD.
Right.
So that's good.
So now we know the bus connection of our GPA.
Let's go to their GP section and see how to configure the GP you.
So I'm gonna scroll back to the table of contents and we're going to go to the GPO side of things which
jump straight to the GP you side going to come back to the top and I'll come down here should be GPA
somewhere down.
Yeah we go.
General Purpose input output so I click over here and this first starts by giving an overview of our
GPO you.
So it says the GPO module is composed of six physical GPO blocks each corresponding to an individual
UK port.
So we've got port a port B port sea port deportee and port f the GPO module supports up to 43 programmable
input output pins depending on the pair for was being use and it goes on to give us the features assess
up to 43 GPL use depending on the configuration.
Highly flexible pin marks in many Multiplex and allows us to use US GPL or several peripheral functions.
This means we can use the same GPL European can be used as a you at a DAC ADC etc..
We'll see how to do all of that and the penis.
Also five fold tolerant and the port are named A2 G and we can access them through the APB bus.
Yeah it's fair to mention the HB here.
Okay it's talking about that here and over here it goes on to tell us that we can access using HB as
well.
Right.
So you can spend some time to read if you're interested in it but we know that we've put a through F.
So that's the take away from here.
We know we've got a through F right to once that is done.
We can go ahead to see if the data sheet tells us how to initialize the GPA to some data sheets go ahead
to give you a step by step information on how to initialize a particular peripheral.
So let's see if this data sheet from Texas Instrument does the same.
OK.
It's called initialization and configuration over here.
And it says the GPA modules may be access to different memory pictures.
The legacy our is the advanced peripheral bus and is backwards compatible with previous devices.
The aperture is the advanced high performance bus and this is just like what we saw in the systems diagram
we saw earlier we saw that the GPA you module is connected both to the AP and the HB.
So we already know this and it's telling us how to decide which one to use here.
It says These are pictures are mutually exclusive.
The aperture the aperture enable for a given GPA port is controlled by the appropriate bits in GPA or
HPC t l register.
So if we want to enable a particular aperture whether APB or HP we would have to enable it using this
register here which we shall take a look at.
But by default we are connected to the APB so if we don't even access this register and we go ahead
to enable our GPA report we will be using the APB but by default unless we want to switch to HB and
over here it gives us steps it says to configure the GPA Europeans for a particular sport follow these
steps.
Right.
First it says we need to enable clock to the port by setting the appropriate bids in the RC GC Can you
register right to a bit of history here.
So in recent years in recent decades I would say microcontroller design has been moving towards low
power systems and previously systems had clog previously microcontroller had clock access to all parts
of it or part of the peripheral.
Regardless of whether you're using it or not.
So this made the the system or the microcontroller consume more power then clock gate in mechanism was
invented and what it clunky to mechanism means is you only enable clock to the part of the MCU that
you want to use.
So with a clock gating mechanism if I'm using just puts a I need to enable clock access just to get
to port a if I'm using just the ADC module I need to enable clock access for just the ADC module I don't
need to enable clock access to every module in the system to save power I just enable clock access to
the peripheral or the module that I'm using.
And over here we use the RC GC GPA you register to do the right thing that stands for propagate and
control register which will see its full name later on.
So that's the that's the reason why we first need to enable that clock by default the various modules
and peripherals do not have clock enabled.
We have to save power.
We cannot be providing clock to each and every corner of the microcontroller so we first need to enable
the clock.
It says over here in addition we've got the SC GC GPL you and DC GC GPL you.
And these are for sleep mode and deep sleep mode right.
So this our first point we need to enable clock.
And then it says set the direction of the GPL your port pin by using the QR code key I are registered.
This is the direction register and this is the register which we use to decide whether our pin is an
input being or an output pin.
After that if we want to use the GPL for alternate functions such as ADC you at DAC SBI A2 C etc..
We've got to configure that alternate function in the GPA to F E L.
This basically means keeping you alternate functions select.
So we've got to configure the automate function in the automate function select register write.
Once that is done if we wish to drive something high current we can use the GPA you drive register so
we've got GPA you d are two are and I think this provides to merely arms or so and this for here stands
for formulae arms and this eight year stands for each of the arms will verify this later but this register
is used to increase the current produce at that particular GPA your PIN and also we can decide to put
a GPA u up or pull it down by initialize and pull up resistor or put our resistor or an open drain resistor.
We can decide to initialize a pull up resistor or pull down or open drain and we've got registers to
allow us to make these elections so these are just optional selection is now first.
The only thing we need to do.
Actually the GPA or module on every microcontroller should have at least two registers the direction
register and the data register after that every other thing is just optional.
But now you can think of the clock gate and register as one of those three compulsory registers.
Because we need to enable clock access to the port.
So once you've got a clock to register and a direction register every other thing should be optional.
Right and we've caught this this at a register.
We leave the rest on we just use them when we required them.
Let's see right.
Right.
Looks good.
OK.
So the table goes on to give us example over here.
For instance if you are initializing a digital input you would want to set the alternate function so
late for that being to zero.
You will set the direction to zero.
You said you already are registered to zero and you set the end to 1 D.
And means digital enabled.
Is that digital enable register and be you are pull up register and put on register you would have to
decide which one you want.
This doesn't apply since it's an input.
So this is just an example.
So that data sheet is a really useful tool for the embedded developer and it's very important that you
get used to it.
You get used to go into the details you to solve your your problems.
It makes you a better programmer when it comes to embedded systems than just looking for you know something
that's already cooked.
And then you just copy and paste or import a library if you want to be good you've got to understand
how to find your way around a data sheet.
So now we have enough information actually to to stop writing code to blink our entity.
So let's go and see how we make use of the information we've got it over here.
I'm back here in Carl vision and this the main file so to include the header file of my microcontroller.
I simply need to right click include file and then I'll select this file is included.
Right so I'm gonna come down here into main to open the main function and open close and I'm going to
open the infinite loop here while one open close as well.
Right.
So let's start by.
So let's start by following the steps we read.
First we need to enable clock access.
Did I close this.
No I didn't.
So we need to enable clock access.
Do not worry we wouldn't be spending so much time in the data sheet.
Well when it's required we would have to find it in the data sheets.
I think it's much more useful this way than me telling you what to write.
So yeah just bear with the process.
Right.
So we would have to enable the clock access.
Let's go and see the RCC register.
Sure.
Come over here you can press control F and search RCC GPO just like we saw in the initialization sequence.
So when you search RCC there's a number of them.
So over here when you actually come down this registers list over here.
Page 18.
And when you come here and you search our CTC your approach is known as the general purpose input outputs
run more run mode clock gate in control.
Right.
And it's under system control over here system control and then there's RC RC GC.
Right.
So let's take a look up this register here.
I'll click on it and I'm brought over here.
This Register says the RC GC GPA register provides software capability to enable and disable GPA your
modules in run mode when enabled and module is provided a clock and accesses to the module register
allowed when disabled the clock is disabled to save power and accesses to the module registers generates
a boss fault.
OK.
So basically we use this to enable clock access for GPL you ports.
So let's take a look at what we've got here.
It's 32 bit.
Starting from Zero over here to 31 over here.
Let's see what 0 is for.
You can find that by coming over here.
So bid 0 over here.
It says it's zero GPA you put a run more clunky and register.
If we set it to zero GPA you put a is disabled.
If we set it to 1 GPA you put a enabled so enable and provide a clock to GPA you put a run mode.
So that's what we do.
We find it under our system control and the name of the register is RC GC GPA.
Right.
So we know how to look at this.
Now let's go and write our code.
Okay.
We are back here in call you vision so to enable clock access.
We simply say CIS control system control and then proceed GC GPA.
Just like we saw in the data sheet and we realised that bit serial corresponds to put a switch to enable
clock access for bit zero for port a we use pid 0 0 ball port f course our entity our entities are connected
to port f let's see Port f I know you can guess where Port F is if zero S is for port eight and you
can tell it up it's five will be four port F can you ever hear better number five is for QPR your port
f run mode clock 18 so it's number five or by here we shall use this to enable clock access to port
F so let's do that now come over here and then I'll do this I'll pass 0 x to zero over here and basically
this is hexadecimal notation I can explain this to binary for you this means 0 0 1 0 and 0 0 0 0 we
can have we can have other 0 0 0 0 0 0 0 but n is you in front of the 2 over here can be deleted cos
he has no effect has I've deleted all of those zeros and I've left this yet but we cannot delete the
zero after that no no.
This affects the bits position so if we check this we know that the euro is for port a the second one
is for Port B puts you port D This one is for Port e and this one about yes for Port f that is why it
is set to 1 and if you compress this into hexadecimal mode it becomes your X to 0 and I'm using this
operator here this is for friendly operation I can disable an equal sign here but when I if I put an
equal sign here what happens is then to our GC GPA you register is going to be written with this new
value so you can think of it this way if a different module lets say a different module using port a
initialized less a better number two or better number three and I come in I initialize use in this statement
I'm going to on initialize what was initialized before because I'm going to set bits number two and
three to zero by writing this to it.
So in order to enable just the bits that I want to be enabled I put the I this Fed school line operation
here operator here such that just this is added just this is added to the the the initial value of the
RC DC GPL you register.
So by doing this.
If the GC GPO register had a value before and it's five over here was it enabled five has just enabled
and all add up bits aren't affected this just makes sure the bit I'm interested in which is bits 5 is
the affected bit.
So this is known as friendly programming.
You put this here like this.
So once we've done this we can set the direction register.
So let's say we want to use the red LRT the red LCD connector to pick F1.
So I'm going to come over here GPA you a direction register SDI R and then I'm going to set its direction
because we want it as output.
We have to set a direction to one if we want it as input.
We have to keep its direction to zero.
So P F one over here I can pass 2 x 2 0 x 02 here and this essentially means it's number one.
I would explain this for you this is 1 2 3 4 0 and this is 0 x this is 0 0 1 0 here like this or bit
0 bit 1 and bit 1 is for P F 1 right.
Red LCD put a comment here
and this one here I'll put a comment here as well for your revision
so once we've set a direction register we have to enable it by accessing the digital enabled register.
So I'm gonna come over here and see GPL a DC and is that digital enable register and because I want
to enable P F one I'm going to pass your x 0 2 Yeah as well.
So come over here use the sign equals zero x it's here to like this so once this is done we are fine
we can write to the data register in order to turn on the LCD.
So I'll simply come over here hand to keep the are you a.
And then I'll access the data register by saying data and then I'll write 0 x or y here.
It's sure to like this right.
So now we're ready.
We've written this.
Basically what we've done is we've said set.
So that's been one high because if X expand this is what you get.
This is what you get.
And this corresponds to being one
that's been one
that's been one digital like this.
OK.
So let's build and see how this works.
I'll click over here to build and it's finished building successfully.
Now we have to download onto a board that's two days see how it works.
Oh sorry about that.
We're working with GPO port f not port a.
So everything here should be changed to f our LTE is connected to port F
right.
This is the red OLED.
It's connected to p F1.
So everything here should be about Port f.
Let's build again a click over here to build show.
I'm going to click here to download onto my board and I can see the red LDS on.
Right.
So let's create a pseudo delay here to help explain the LCD when we get to the time a section and we're
going to create more accurate delays.
But over here we're going to create a very simple delay which is actually a forced DeLay.
Our code is delayed M.S. And this is going to accept the millisecond amount as argument.
It's a mess and I'll come over here I use a nested loop.
Basically this this is an empirically derived value we're going to use here and this is based on the
16 megahertz clock frequency of our system.
So if your system is operating at a different frequency which isn't 16 megahertz this delay won't be
accurate.
And also this is tied to how long it takes for our call you efficient compiler to compile our stuff.
So this also takes into account that we usually call your vision compiler here but this a pseudo delay.
We don't care about accuracy much delay accuracy at this point when we get to the time of section we'll
see how to create more accurate delays but this would just help us do things like blinking LCD since
we've not studied about timers yet
so I say for int i equal zero ice less than the parameter passed by the user a plus plus in India I'm
going to have an inner loop I see for j equals zero G is less than J is less than three thousand one
hundred and eighty.
This is an empirically derived value it's derived experimentally and I said the computation is based
on our sixteen megahertz and the compiler that we're using.
So we just use the value as it is.
There is no explanation behind this value really.
So we're just open and close on empty brackets here like this.
So this is it.
This is going to provide millisecond delay based on the value we pass yes if we pass 10 here we're going
to get 10 millisecond delay.
This is not how you should be creating or delay functions.
I repeat when we get to that part on time as we learn how to create much more precise delays and do
things like measure event with time it's okay.
But for now we can use this when I copy a prototype of this function and put it over here and I'm going
to call it a delay function before I do that I'm going to cut this year.
This one that writes to the pin I'll cut it and bring it in the main loop and then I'm going to call
I delay M.S.
And then I'm going to say delay hundred m s by passing one hundred here and then once that's done I'm
going to set this low and bring this over here and then I'm going to change this to set this below.
I'm going to use the opposite of this.
Operator I remember this the friendly way.
Friendly way of setting the pin high.
This means you set only the pin you are dealing with high without affecting the other pins in the Indy
register to do the same for setting low to set only the pin we are interested in without affecting other
pins.
We put no son assigned here and then a two day like this.
Right.
And this will set only our pin 5 pin 1.
This was actually our pin 1 low right.
So this was set a pin low end.
Once we've set that I want to delay that at 100 milliseconds or pull our delay function here.
And once that is done or click over here to compile and click over here to download onto the board I
can see the LCD is blinking at the hundred millisecond rate.
So this order is for this lesson if you have any questions at all regarding annual 4 we've done.
Just send me a message.
You're leaving the questions area and I shall see you in the next lesson.
Have a good day.