Hello, welcome back.
In this lesson, we go into crisis.
We're going to create a simple you out driver to help us to be able to send information from our microcontroller
to our computer so that we can view the properties of our neural network as we develop it.
So I'm going to create a new project by coming to project new project.
And I have a folder here I'm going to call this.
I call this simple, you watch.
And my board, my and my board is the SDM fetch to EFORE won one seat.
I have the new clipboard of this.
I'll click OK over here and the Simms's also like to call on the device.
Isolette, start up.
I'll say OK here and target here.
I'm going to give the name of my board SDM 32 F4.
I'll drop down here, so this group here, I'm going to call this Eppy.
Right, and I'm going to create two files or you [REMOVED] three files here at item iSelect, see, I call
this mean this is going to be our main file.
Oh, I don't know the file.
Right.
Click right.
Click on up over here at item C again.
I'm going to call this you out and then I'm going to add the interface file, which is the far right
click add item over here.
I call it you got like this.
Why do we have this memory for you, interest in Iraq?
Right, so, um, we would have to create the other driver, a very simple one.
Those of you who have seen other causes of mine, like the the bare metal programming courses for developing
drivers, you already know how to do this before the rest of you who are new to my courses.
I'm going to take you through the steps of initialise in the.
So the U.
R stands for Universal Asynchronous Receiver transmitter and we can use it to transfer messages or data
between two devices and the two devices can be a microcontroller and a computer.
So in order to find out how to initialize any petrol at all of the microcontroller, we need to visit
the datasheet or the reference manual of the microcontroller.
And if you are using cardioversion, you can find it over here on the books or just come over here books
and I'll select the the reference manual by double click.
And this.
And there's the reference manual of the microcontroller, and what I'm looking for is the block diagram
showing me the Depass connection of my microcontroller.
Let's see.
OK, we find a block diagram in the data sheet so we can come back here and double click on datasheet
and this is datasheet.
OK, so this is what we're looking for.
And we're looking for this because we want to know how to initialize the clock to the Ewart's module.
So in the in the past, I'll see in about 20 years ago, microcontrollers had block access enabled on
all peripherals by default and by all peripherals.
I mean the pedobear module that you are module the let's say ATC all had clock access enabled by default.
And if we have block access enabled by default, it makes the microcontroller consume more power.
So although we might not be using a particular Peiffer or module because clock is enabled to the module,
some power is consumed because of this, something known as the clock gating mechanism was invented.
And what a clock counting mechanism does is that it allows us to just shut the clock off for every peripheral
and we enable clock access only to the peripherals that we want to use only to the peripherals that
we need.
So in this case, the only peripheral we need is the peripheral or the other module.
So we going to enable clock access to the UAT.
So we have to find the bus that it is connected to.
So I'm over here in this block diagram and I'm going to zoom in a bit.
Right, so let's see, so GPI is connected to this bus, you can use this area to see GPS is connected
to AHP one bus, right.
And you'll be connected here.
So if we want to enable the port, we would have to enable them through this bus.
So what we're looking for is you are we going to use you at two as you can see it over here?
It's called you sat here because we can use this module known as use that for both Synchronoss and asynchronous,
uh, receiver transmitter transfer.
So Usategui stands for Universal Synchronoss, asynchronous receiver transmitter.
But we are looking for just that.
You add without the S and it's the same in the same module can be configured for both Synchronoss and
asynchronous.
So you need not worry.
So that's what we're looking for.
And as we can see over here, it is connected to the APB, one bus app, one bus.
Right.
So we need to enable clock access to app one.
We need to go through the app one register set and then enable use that clock.
That is one.
One other thing is our you start or you add is connected to a standard Jhpiego pin.
And this also requires explanation.
So for those of you who are new to microcontrollers, often we have copies.
Those are the to see the basic peripherals that you need.
The Galopin allows for input and output.
In fact, the word GPA stands for general purpose input output.
Right.
We have copies and S.P.I opens and Spyro stands for.
Special purpose, input output.
So we've got general-purpose input output and special purpose input output, the GPU, PIN and spin
are physically the same.
And what I mean by this is that we would have to configure through software to decide whether a particular
PIN should act as a standard GPU, which is.
Yeah, general purpose, input output, or we want it to be SPU special purpose, input output.
So for instance, if you want to configure an ADC module, you would have to select the pin that your
sensor is connected to.
You've got to set that up in a special purpose being the special purpose setting.
We often call this as alternate function mode.
So if you check the datasheet or the reference manual of any microcontroller, you would see that there's
a part that talks about how to configure the pin as an alternate function pin.
This means configuring it for special purpose.
So our you at our receiver line and transmitter line are internally connected to some Gilpin's and we've
got to configure these KPIs for special purpose.
And these are the P, A two and a three.
So put it over here, put a pin to import a PIN three.
We would need to configure them as well.
And like I said, those of you who are already familiar with working with a UAT and initialize in peripherals,
you probably know all of this already.
So you can skip this lesson if you want and just download the resources and continue from there.
So.
Right.
We would need to we need to configure Jhpiego A because our our experience connected to a three and
then our T experience connected to you.
And we need to configure you Satya as well.
And this is because you said it's a special purpose function, so.
Yeah.
So that's some of the information we need.
We can get started with this, going to minimize this and we can start off in a way where we can start
off over here in our use of.
I don't know why I have this, we can start off in the USA Today HFA.
And I can start off by saying, if not defined, defined.
I've always called you out on a school age.
And then we end if here like this and if.
Right, and we we're going to have a number of functions, we going to create a function to initialize
the user to module.
So I'm just going to say void use to underscore in it over here like this.
And this void, void function, and we're going to have another function to help us, actually, we're
not going to expose the other functions.
We're going to have just this function and we're going to use print F from the C standard library to
send our information to.
Let's keep just this.
We can go to the USOC file and include the rage.
Right, so we can include our interface file here in our Dossey file or just say, include
you out today like this.
So once that is done, we can implement this function that we have written the head for
open and close, we said we've got to enable clock for you at.
And it is connected from our reference manual, we said it's connected to APB, one bus, so we need
to go to the datasheet and see what an APB one.
Can we locate our.
You ought to.
So I'm going to go back.
I kept the files here.
I'm going to go back to our reference, my no document and I'm going to search APB one.
Can press control F and then you can simply type one, APB one, and we're looking for the APB one and
they will register.
So I'll click this and let's see, we have our RACC, HP.
Let's see, so for those of you who already know how to do this, like I said, you can skip this.
But for those of you who want to see how such a driver can be initialised, you can just stick with
me here.
So this is the app one here.
And we are dealing with the app One Enabler Register.
And as you can see, this is a 32 bit register.
It starts from zero.
It ends up 31 and bits zero belongs to time.
A two bit.
One belongs to time, a three bits two blocks to time before and so on and so forth.
Um, let's see what we have and you can find this out by actually reading more.
So over here, what it means is if this bit is set to one, then we want to enable time or two.
If it's set to zero, then we want to disable time or two.
And the information is provided here.
So let's see over here.
It says it's given the bit numbers here.
I'm looking for pit number zero.
So it says over here, but number zero, set and cleared by software zero means time to clock disabled.
One means time or two clock enabled.
And our you at two is connected to pit number 17.
As you can see, zero means you start to clock disabled.
One means you start to clock enabled.
So we want to pass the number one at bit seventeen here to this register.
This is what would allow us to enable clock access to our users to.
So that's what we're going to do now.
So come over here and I'll see RACC app one enable register, the one we just saw.
And I'm going to pass hexadecimal code here also is your X two and then four zeros, one, two, three,
four.
And this corresponds to certain bit number bit number 17 to set in each one.
Remember, we start counting from zero, right?
And the reason we have in this is because we've not included the header file for our microcontroller,
so I'll come over here and I'll do right click include ASTM.
That's two for storage.
When I come here, you should disappear.
Right.
And then I'll comment here.
There's also a enable clock.
For you sought to, right?
So once we've done this, we need to enable the clock for port because our T, X and our X lines are
connected to two and three, respectively.
So I'm going to come back to RACC.
And in the block diagram, we realize that port, it was connected to the HP, Busse, HP one back.
So I'm going to see HP, one enabler register and I'm going to I'm going to pass one here, zero x one
like this, because the first bit in the register corresponds to Port A and a better way of doing it
is put in this vertical line here.
And this is what is known as friendly programming.
When we put a vertical line, it only changes the bits that we want to change.
So when we include this only bit 17 is changed and when we include it includes only bits, one is changed,
meaning if the register had a different value, everything else is going to remain the same in the register.
Apart from the bits that we want to change, this is known as friendly programming as opposed to this.
When we do this, meaning we clean everything in the register and we write a new value and this new
value is going to be zero zero zero zero zero zero zero zero zero zero zero one.
It's going to be thirty one zeros and then one.
Yeah, something of that nature.
Right.
But because we want everything else to remain the same, apart from just bits, one, we put this vertical
line here like this.
If you do not understand this, you can send me a message.
So once we've done this, we've got to set GPL.
You put a pin to PIN three as alternate function.
PS and we do this by accessing a register known as the AFAS and you can find this in the data sheet
to run the course quicker.
I'm not going to go back to the data sheet.
I'm just going to bring this here and this over here configures two and three of you 246 and IREX Ordinaire
function seven.
Once we've done this, we've got to set the mood.
We've got to set the mood of the pin to alter the function.
And we do this by accessing the most register and the mode register is written us mode are, as you
can see over here.
So these two lines would configure the mode.
And once that is done, we can start configuring the U.S. We can't forget about rate and then we enable
it and then we will be done with it.
So we start off by accessing the board register and we set about eight to nine thousand six hundred.
And all of that is included in this hexadecimal value here.
We're not going to go through how that is computed.
And once that is done, we're going to enable T, X and our X and set it for eight bits data.
And all of that also is encapsulated in this hexadecimal.
You can simply go to the data sheet and search for this register.
P are the same where we went and search for this and we're able to derive that this is the number we
need to store here.
Everything you see here, if you want to learn more about it, you can go to the data sheet and find
their respective registers.
So this register control register one we set in about an hour and eight put data in it.
And once that's done, we're going to go to control register two and set one.
Stop it by just keeping it in its default state, which is zero zero.
Researcher Was this down?
We go to a controlled register three and say we want no flow control by also keeping it in its default
state.
So we could have actually skipped this, but it's better programming to set it.
Even if the default state is zero.
It's it's good to sort of explicitly state set it back to zero zero zero.
Once we've done all of this, we can enable the the USA module by going back to control register one
like this.
Right.
So once we've done this, we can write a function to help us write a character to the user.
So I'm going to come over here.
I'm going to say int.
You said, too, and then you say, right, and then this function is going to take.
And S.H. as a parameter, and this is going to be what we want to send.
And what we have to do is we have to wait for the transfer buffer to be empty before we can send it,
and we do this by using a while loop.
So we say, well, not.
Used to over here like this and we go to status status register, which is Asare, and then we do end
through X zero zero eight zero while this wait for the transfer buffa to be empty, wants to transfer
barflies empty, then we can send what is currently in the D.R., which is the data register by saying
use it to.
D-R equals
S.H. and zero X.
Like this, right?
OK, so we can, in fact, return S.H. here
just to indicate success.
Once that's done, we can have another function here to help us read what is in the queue at the end
user to underscore read.
And this takes no argument.
And we we want to read what is in the want to read what is in the data register.
But before we do that, we have to make sure there is something in this.
We have to wait until the character arrives and we can use a similar while loop.
I'll copy this while loop, bring it over here.
This time I'm going to pass excerpts or two over here and then we're simply going to return what we
get from the data register by saying return user to D-R like this.
Right.
So they should help us.
Yeah, they should help us read and write.
The next thing we're going to do is we're going to interface the the C library.
I'm going to add DTD.
I ordered H I'll come to our USA dot h file and I'm going to include SDD over here so that we can use
print F.
Standard input output like this, and I'm going to bring a piece of a piece of code that would help
us, that would help us to interface to the standard CIA library, and we're not going to get into this.
So this over here would help us to interface to the library and other function is going to be called
by the sea library.
This last one here.
Right.
So by including this bit here, we should be able to use our normal print F and scanned scan functions
that we use in C language.
And like I said, I'm not going to get into the details of this.
We've already diverted too much from deep lowness, little deep learning as it is.
Um, yeah.
So we can put a bit of test code here.
I'm going to come down here and put a bit of test code that would allow us to test what our what you
what configuration is work.
And we're going to come over here and see FOID test set up.
Open and close, and we can simply see Pranav, as you can see, if in print is appearing now, so we
say, please, perhaps enter a number.
And we come over here and we can use Cunniff to grab the number.
Percentage day, and I'm going to create a variable to hold it.
We've got to come come up here and have intend to hold it, and I'm going to create another buffer here,
which I'll simply call SDR a size 80 like this.
And let's see, let's see, OK, how about we go back to number entered, we can say Pranav.
No, you entered is percentage did you line like this?
Whichever way, right?
And I'm going to pass it over here.
And how about we try a string by saying, please enter a string print of.
Please.
Enter a character string.
And we can grab this drink by using get as.
And we can store it in our character store that we created up up here, and then we can print out the
drink.
The string.
You it this and we can use put string to print out.
Want to print out the content of SDR and we can put a bit of a new line over here.
Right, let's expose this as well so that we can use this in our main function.
And we can still use the printf function in our main F test that I want to put it all together so that
we can test it at once.
That's why I've created a function for it.
Right.
So once this is done, we can go to Maine and test this up when I come to Maine and I'm going to include
the USA Today that we just created.
Include you at this or are you at fault?
And I'm going to come here and it made this void open, close, and we want to initialize the use that
you start to in it.
That's just the name of a function.
It's over here.
You've been close.
And let's see, we don't need a while loop.
Just put it here, over here regardless, OK?
And we can call our function, which is set up test.
Scored the test sets up, right, and have this.
OK, so let's build and see if it's all fine of click to build.
We've got no arrows and no we've got four.
One is I'm going to come here to set up the debugger.
I'm using the stealing debugger.
Select Citilink over here when I click settings over here says no stealing detected.
So I'm going to connect my microcontroller.
I've just connected my microcontroller.
I'm going to come back here again, debug as the debugger searches and a flash download, I'm going
to click over here to run hook and OK, I'm going to click here to download onto the board and to download
it successfully.
I'm going to open our terror term now and see what we have.
This is my territory, I'm going to click on Syria and I'm going to select from three as microelectronics
link and then OK, and I'm going to press the reset button on my microcontroller.
And as you can see, it says, please enter a number just like we wrote when it reset again, please
enter.
No, I'm going to enter 56, the number you entered.
Fifty six, please enter character shrink will come to DL destroying you into this world, come to DL
so it's fine and we can actually test out the print from here.
This is a message from Main Say, right, and I'm going to click here to build.
Or is it?
Click here to build and I'll click here to download onto the board and we can take a look at terrorism
again.
OK, I'm going to select my serial port here and I'm going to press reset on the board.
This is a message from me, right?
So this brings us to the end of this very lesson, and I shall see you in the next lesson.
If you have any questions, just let me know.
Send me your questions in the Q&A section or the Q&A area, I should say.
I'll see you later.