1
00:00:00,870 --> 00:00:01,260
Hello.

2
00:00:01,290 --> 00:00:02,040
Welcome back.

3
00:00:02,040 --> 00:00:04,590
So let's implement a what you call your driver.

4
00:00:05,310 --> 00:00:09,290
So I'm gonna start with the um the directives.

5
00:00:09,570 --> 00:00:15,510
Um for those of you who don't know there is a prerequisite for this course before you take this course

6
00:00:15,510 --> 00:00:24,280
I expect you to take the um the um arm assembly program it from ground up of course and in that course

7
00:00:24,280 --> 00:00:30,750
we went through the instructions step by step the directives step by step we'll explain everything.

8
00:00:30,880 --> 00:00:31,840
So over here.

9
00:00:32,550 --> 00:00:38,470
Yeah I'm not gonna be explaining the instructions under directives much I'm just going to I'll be demonstrating

10
00:00:38,500 --> 00:00:46,350
how we use those instructions and directives to write usable um drivers for our microcontroller board.

11
00:00:46,360 --> 00:00:52,750
So for those of you who haven't taken that course I would suggest you stop this course and then give

12
00:00:52,770 --> 00:00:54,960
you the first few lessons.

13
00:00:55,420 --> 00:01:01,630
Up to the point where you um you view the lessons on directives and instructions and then you can continue

14
00:01:01,630 --> 00:01:02,090
here.

15
00:01:02,260 --> 00:01:05,110
You can send me a message I'm gonna send you a coupon for that you need.

16
00:01:05,110 --> 00:01:08,300
No you know buy it at it's expensive price.

17
00:01:09,410 --> 00:01:13,300
Um so I'm gonna start off by using the area directive

18
00:01:18,800 --> 00:01:22,960
text and this the code area is read only

19
00:01:28,390 --> 00:01:29,890
gonna align to

20
00:01:32,930 --> 00:01:34,120
it firm over here.

21
00:01:34,150 --> 00:01:38,170
This the entry and then I'm gonna export

22
00:01:41,870 --> 00:01:53,510
on it's gonna escort me like this is gonna school me and I'm gonna start off by enabling I'm gonna start

23
00:01:53,510 --> 00:02:02,000
off by branch into a subroutine to enable our GPL you call this GPL you in it and then let's implement

24
00:02:02,030 --> 00:02:07,600
GPL your niche no GPL you underscore in it.

25
00:02:07,700 --> 00:02:12,580
So we start off by enabling the clock access for Port Pete.

26
00:02:12,980 --> 00:02:19,100
If we had to write this in bare metal embedded C using CRM says R2 says control like this

27
00:02:23,000 --> 00:02:32,120
and then our C GC GPL you and then I'll use this I'll put a vertical sign for all and then I'll take

28
00:02:32,390 --> 00:02:34,120
the symbolic name we create it.

29
00:02:35,210 --> 00:02:36,100
Right.

30
00:02:36,140 --> 00:02:41,640
And this would enable clock access to port C this is a comment right in assembly.

31
00:02:41,720 --> 00:02:44,280
So this is what we're going to implement.

32
00:02:44,630 --> 00:02:52,730
So to do that we need to load the address of this GPL u r c GC GPL you I'll say load

33
00:02:55,730 --> 00:03:00,320
our 1 equals we have the address here

34
00:03:04,970 --> 00:03:14,030
and then I'm going to load take basically to use this in plain language what this is I'm gonna see take

35
00:03:14,120 --> 00:03:17,850
our issue out to take um.

36
00:03:18,410 --> 00:03:26,090
So basically this means take take the content of it.

37
00:03:26,210 --> 00:03:28,100
How do I put this in plain language.

38
00:03:32,490 --> 00:03:38,990
Take the content of what is located at at any one input into our view.

39
00:03:39,870 --> 00:03:42,860
So something is located at r 1.

40
00:03:42,880 --> 00:03:44,780
All I want is pointing to something.

41
00:03:45,840 --> 00:03:49,230
Take the content of what our one is pointing to and put into our series.

42
00:03:49,260 --> 00:03:56,170
So in effect we take the content of the current content of system control RC GC GPL you register input

43
00:03:56,190 --> 00:03:59,900
into our 0 I'm gonna perform an operation of that.

44
00:04:00,960 --> 00:04:10,690
When I say Oh Iris you are 0 and then GPL you enable.

45
00:04:11,100 --> 00:04:19,160
So so after that after this line what is in this register is gonna be put in R2.

46
00:04:19,350 --> 00:04:21,310
So we're gonna take what is an Irish U.

47
00:04:21,330 --> 00:04:24,650
And then we perform an operation would you call you f enable.

48
00:04:24,690 --> 00:04:27,010
Which is the symbolic name we created here.

49
00:04:27,050 --> 00:04:28,490
I store it back into our Sera.

50
00:04:28,500 --> 00:04:31,670
We can use to operations if we use to operations.

51
00:04:31,770 --> 00:04:32,850
It means that resort.

52
00:04:32,850 --> 00:04:37,140
This is the source number two as well as the destination.

53
00:04:37,140 --> 00:04:40,060
So we can keep it like this and it's gonna be stored in our ship.

54
00:04:40,920 --> 00:04:41,220
Right.

55
00:04:41,220 --> 00:04:42,800
Once this is that is done.

56
00:04:43,200 --> 00:04:48,900
Meaning we've modified what is an Irish you don't know we can write the new contents of Irish you at

57
00:04:48,900 --> 00:04:58,480
the location of this register in effect at the location of this um um at the location of this address.

58
00:04:58,530 --> 00:05:05,040
The reason why when I see red is that I always freeze is that we've got registers Irish who are 1 are

59
00:05:05,040 --> 00:05:07,910
two or three and business are registered to.

60
00:05:08,010 --> 00:05:12,780
But when I say this reg is that are you thinking there's any cortex is it.

61
00:05:12,920 --> 00:05:16,910
Um is it the system going through our GC register.

62
00:05:16,920 --> 00:05:21,480
Or is it the register in the register bank such as Irish you are one.

63
00:05:21,520 --> 00:05:27,110
So what I do is oh endeavor to call these addresses or although the outrageous this or refer to them

64
00:05:27,110 --> 00:05:31,510
at as this address read them register that to limit confusion.

65
00:05:31,800 --> 00:05:37,560
Anyway if you if at any given point you you have a question just send me a message.

66
00:05:37,560 --> 00:05:39,820
I don't know how this is going thus far.

67
00:05:39,840 --> 00:05:45,010
Cos I keep explaining random stuff by should you find yourself confuse the boy a little thin.

68
00:05:45,030 --> 00:05:46,280
You can send me a message.

69
00:05:47,000 --> 00:05:48,020
Um.

70
00:05:48,510 --> 00:05:48,860
Right.

71
00:05:48,900 --> 00:05:50,850
So we going to use this for instruction.

72
00:05:50,850 --> 00:05:53,510
I'm gonna say you stole the source.

73
00:05:53,540 --> 00:05:54,750
I just ask you.

74
00:05:54,750 --> 00:05:55,980
And then I have one here.

75
00:05:56,040 --> 00:05:59,610
So after this we would have executed this.

76
00:06:00,240 --> 00:06:00,700
Right.

77
00:06:02,280 --> 00:06:12,180
And we can allow some time to finish activating by using the new operation A.P. A.P. A.P. this would

78
00:06:12,180 --> 00:06:16,360
just allow some time it's like Yeah wait a bit.

79
00:06:17,860 --> 00:06:18,200
Okay.

80
00:06:18,960 --> 00:06:31,510
So now the next thing to do would be to set up a whopping to output pin a red pin red over here.

81
00:06:31,510 --> 00:06:37,880
We need to set it as output and we do that by accessing the display of direction register.

82
00:06:37,960 --> 00:06:41,150
So in C language how do you spell you f desire.

83
00:06:42,990 --> 00:06:45,790
And then I'm going to say 0 x

84
00:06:48,610 --> 00:06:50,800
0 2.

85
00:06:51,460 --> 00:06:56,460
I'm gonna do this but we've already created a symbolic name for 0 extra 2.

86
00:06:56,620 --> 00:07:05,950
I should point out 0 0 2 is the same US is the same as um is the same as this.

87
00:07:05,950 --> 00:07:07,340
Why do I say that.

88
00:07:07,390 --> 00:07:14,880
Cos if I explain this you were X 0 2 to it s binary form 0 end up with 0 b 1 2 3 4.

89
00:07:15,100 --> 00:07:17,770
And then one two one zero.

90
00:07:17,890 --> 00:07:19,130
Right.

91
00:07:19,420 --> 00:07:24,260
So this 0 this hexadecimal 0 does.

92
00:07:24,660 --> 00:07:25,520
Sorry about that.

93
00:07:25,700 --> 00:07:29,940
This hexadecimal 0 corresponds to this for binary zeros.

94
00:07:30,250 --> 00:07:35,170
This 2 in binary form will give us this uh this 2.

95
00:07:35,560 --> 00:07:37,330
Yeah.

96
00:07:37,510 --> 00:07:41,170
If we convert it to binary 4 bits binary does what we get.

97
00:07:41,200 --> 00:07:46,730
So this is the same US shift uh shift in one at position number one to number one.

98
00:07:46,750 --> 00:07:49,340
So this is bits numbers zero a bit to number one.

99
00:07:49,360 --> 00:07:54,340
So if I do this I'm saying shift 1 2 bits.

100
00:07:54,340 --> 00:08:01,930
Number 1 which is the same as having this which is the same as having this in hexadecimal code right.

101
00:08:01,930 --> 00:08:04,260
And we gave a symbolic name to this.

102
00:08:04,480 --> 00:08:09,200
This shift one at the position number 1 we call that OLED red.

103
00:08:09,970 --> 00:08:12,520
So I'm gonna copy LCD red and put it here like this.

104
00:08:14,410 --> 00:08:14,960
Um

105
00:08:17,840 --> 00:08:23,060
I'm gonna see like this I'm just gonna over come into this okay.

106
00:08:23,060 --> 00:08:28,350
Right as the course goes on I'm gonna reduce the amount of comments I use.

107
00:08:28,880 --> 00:08:32,380
Okay so this is the C language estimate and assembly.

108
00:08:32,390 --> 00:08:47,480
I'm gonna say load R 1 GPL u f D.A. R register and then load r 0

109
00:08:50,640 --> 00:08:53,750
are 1 and then I'm gonna perform all

110
00:09:02,740 --> 00:09:14,640
o r as you are sure I can use a single upper hand over here I had to bring the number sine sorry I'll

111
00:09:14,970 --> 00:09:21,130
let you read then I can write a book by using the store operating.

112
00:09:21,270 --> 00:09:27,920
Oh operator store the store instruction I should say store like this.

113
00:09:28,280 --> 00:09:28,620
Okay.

114
00:09:28,640 --> 00:09:31,250
Now we have set this as output

115
00:09:36,820 --> 00:09:38,760
I'll put more comment here.

116
00:09:38,800 --> 00:09:44,350
Set p f 1 as output.

117
00:09:44,410 --> 00:09:45,750
What we just did.

118
00:09:52,770 --> 00:09:53,730
Enable clock

119
00:09:58,250 --> 00:10:01,850
access to port F right.

120
00:10:01,910 --> 00:10:02,810
That's what we did here.

121
00:10:02,810 --> 00:10:06,020
Now we're going to

122
00:10:11,070 --> 00:10:22,980
digitally enable Pier One so to do this and see language oh would do chippy i o f d end for digital

123
00:10:22,980 --> 00:10:24,160
and they would register.

124
00:10:24,720 --> 00:10:30,810
No I'm simply going to do this early do read again I'm right and the same thing but this time to the

125
00:10:30,810 --> 00:10:32,980
digital enabled register.

126
00:10:33,210 --> 00:10:33,640
Right.

127
00:10:33,660 --> 00:10:36,000
So in assembly language how well you cried.

128
00:10:36,000 --> 00:10:41,730
Could you post a video and try to enable this in assembly language you can look about what we did over

129
00:10:41,730 --> 00:10:43,530
here and over here.

130
00:10:45,570 --> 00:10:45,960
Right.

131
00:10:46,230 --> 00:10:49,710
So once you write down we can do it together.

132
00:10:49,890 --> 00:10:50,490
I'm gonna do.

133
00:10:50,490 --> 00:10:50,880
Load

134
00:10:53,540 --> 00:11:18,270
one course GPA F D E N R and then load are sure I run and then O R Syria a lady red and then store our

135
00:11:18,380 --> 00:11:20,690
0 R1.

136
00:11:21,250 --> 00:11:28,780
Once that is done we are done with this subroutine we can return from the subroutine by using the B

137
00:11:28,840 --> 00:11:33,530
X L are like this okay.

138
00:11:34,110 --> 00:11:35,320
Right.

139
00:11:35,910 --> 00:11:37,390
So now we are done.

140
00:11:37,390 --> 00:11:40,370
Next less write a subroutine to turn on the LCD.

141
00:11:40,390 --> 00:11:43,260
I'm going to call this early on.

142
00:11:43,300 --> 00:11:58,620
Come over here and have sorry for the lady on over here and then we start off by loading the data register.

143
00:11:58,630 --> 00:12:09,640
Remember to turn it on we need to write 1 2 the P F two P F one of the data register of port F and because

144
00:12:09,640 --> 00:12:16,780
the LCD connector there when we write one that the LCD in effect will be turned on so I'm going to show

145
00:12:16,780 --> 00:12:31,210
you how to do this C language GP I o f data and then um thus we can use friendly programming again is

146
00:12:31,230 --> 00:12:35,920
simply right in additive red I think.

147
00:12:35,950 --> 00:12:36,190
Yeah.

148
00:12:37,230 --> 00:12:38,860
Okay.

149
00:12:39,370 --> 00:12:41,270
So I'm gonna do load.

150
00:12:41,270 --> 00:12:48,330
I'm going to load the address.

151
00:12:50,720 --> 00:12:52,420
I have a typo here.

152
00:12:52,420 --> 00:12:53,260
There should be d I.

153
00:12:53,320 --> 00:12:55,510
Ah okay.

154
00:12:55,900 --> 00:13:02,860
So GPL you f data from the school are

155
00:13:05,630 --> 00:13:06,150
and then

156
00:13:09,900 --> 00:13:11,890
this is going to be a simple move.

157
00:13:13,200 --> 00:13:15,520
Oh do you move into register.

158
00:13:15,530 --> 00:13:21,930
Are you do you read and then store it

159
00:13:27,730 --> 00:13:37,630
and then be X a la and then a line and then end.

160
00:13:38,530 --> 00:13:39,050
Right.

161
00:13:42,300 --> 00:13:42,660
Okay.

162
00:13:44,010 --> 00:13:44,400
Okay.

163
00:13:44,400 --> 00:13:46,350
We look good.

164
00:13:46,350 --> 00:13:50,430
So what I'm gonna do is I'm going to call this subroutine as well.

165
00:13:52,350 --> 00:13:56,420
So we start off by enabling our what she you.

166
00:13:56,430 --> 00:14:03,360
Once we've done that we're going to branch to turn on the entity and then we're going to create a loop

167
00:14:03,420 --> 00:14:08,320
by branch in by branch into the top over here.

168
00:14:08,380 --> 00:14:16,350
Be such that after we turn on the LCD and we execute this next line it's going to take us back to the

169
00:14:16,350 --> 00:14:17,070
top.

170
00:14:17,190 --> 00:14:18,020
Back to the top.

171
00:14:18,030 --> 00:14:18,750
We come back.

172
00:14:18,750 --> 00:14:20,250
We turn on the LCD.

173
00:14:20,400 --> 00:14:22,050
This is going to take us back to the top.

174
00:14:22,050 --> 00:14:24,810
In effect this is our wall one loop.

175
00:14:24,810 --> 00:14:30,120
So now let's test well we have right.

176
00:14:30,140 --> 00:14:38,290
So I'm going to set up my debugger or come to target options over here under debug dropdown still areas

177
00:14:38,320 --> 00:14:44,870
ICD I CDI click on settings and then I'm going to click reset to run.

178
00:14:44,870 --> 00:14:45,550
Okay.

179
00:14:45,570 --> 00:14:52,160
And then okay and then I'm going to click here to build up here.

180
00:14:52,400 --> 00:14:53,690
It's built successfully.

181
00:14:53,690 --> 00:14:55,590
Click here to download onto my board.

182
00:14:55,600 --> 00:15:01,060
It's downloaded and my Elegy is not on let's see

183
00:15:04,610 --> 00:15:05,840
um.

184
00:15:06,100 --> 00:15:09,880
Let's let's check our code from the top.

185
00:15:11,660 --> 00:15:18,880
Um I think the reason this the reason the LCD or Blinken is from the source that base the system control

186
00:15:18,880 --> 00:15:22,170
base address here I'm skeptical about this address.

187
00:15:22,180 --> 00:15:26,770
Let's go to the data sheet and um see um.

188
00:15:27,160 --> 00:15:28,000
Come over here.

189
00:15:28,030 --> 00:15:30,810
I'm gonna search.

190
00:15:31,810 --> 00:15:37,500
I'm gonna search system control base address and then um it's a problem here.

191
00:15:37,540 --> 00:15:39,120
You can stuff from the top.

192
00:15:39,240 --> 00:15:44,440
I simply type system control base address and then is promo here.

193
00:15:44,440 --> 00:15:52,390
Register map as the offset listed as Exodus more increment to the registers relative to the system control

194
00:15:52,390 --> 00:15:53,720
base address.

195
00:15:53,860 --> 00:15:57,070
So it says this is the base address of the system control.

196
00:15:57,100 --> 00:16:04,000
So I'm gonna use this is that I'm gonna copy this and I'm gonna search more and see what this is that

197
00:16:04,000 --> 00:16:09,830
persistent piece that tries given to system control base address over here.

198
00:16:09,840 --> 00:16:15,250
It talks about system control registered description all addresses given their relative to system control

199
00:16:15,250 --> 00:16:20,620
base address and thus the system control base address and range that's provided for legacy software

200
00:16:20,620 --> 00:16:21,160
support.

201
00:16:21,280 --> 00:16:24,990
Okay so it's the same address we saw earlier.

202
00:16:25,440 --> 00:16:26,230
Right.

203
00:16:27,030 --> 00:16:27,690
Okay.

204
00:16:27,850 --> 00:16:29,680
It's the same thing right.

205
00:16:34,220 --> 00:16:34,660
Right.

206
00:16:34,670 --> 00:16:39,410
So this indeed the system control base address I'm gonna use that.

207
00:16:39,470 --> 00:16:40,100
So yeah.

208
00:16:40,100 --> 00:16:45,680
Taking the system control base upgrades from the RCC base address won't work.

209
00:16:45,710 --> 00:16:45,960
Yeah.

210
00:16:45,970 --> 00:16:51,230
Sometimes they are such nuances and with experience you would know what to look for.

211
00:16:51,910 --> 00:16:52,880
Okay.

212
00:16:53,210 --> 00:16:54,240
So now let's try.

213
00:16:54,450 --> 00:17:01,460
Um I'm going to click here to build Click here to download onto my board and it's download it right.

214
00:17:01,490 --> 00:17:04,230
If you have any questions just let me know and I'll see you in the next lesson.
