0:07
hello everyone welcome to controllers
0:11
Tech in my previous video I covered how
0:15
to store data in the flash memory of
0:17
f103 microcontroller it have memory
0:21
distributed in pages today in this video
0:25
we will see how to store data in the
0:27
flash memory of those controller whose
0:30
memory is distributed in sectors
0:32
this would include cortex m4 & m7 series
0:36
controllers I am using stm32f4 for 6r II
0:48
here is the cube M X I am selecting
0:53
external crystal for the clock we don't
0:56
need to do any setup in the clock setup
1:02
crystal is 8 megahertz and I want the
1:05
system to run at 180 megahertz
1:16
click Save to generate the project
1:32
first we will include the library in the
1:35
project copy the head of file into the
1:39
include folder and C file into the
1:41
source folder let's refresh the project
1:55
and you can see the files here now
1:59
include the flash sector dot H in the
2:01
main file let's build it once to check
2:08
for any errors there are no errors let's
2:13
take a look at the flash sector dorsey
2:15
file get sector is used to get the
2:19
sector number where the memory address
2:21
is located this is the reference manual
2:24
for a four four six r e as you can see
2:28
here we have seven sectors
2:34
some of these are 16 kilobytes or 64
2:38
kilobyte and rest are 128 kilobytes this
2:46
is the manual for a 4:07 microcontroller
2:54
this one have 11 sectors your controller
2:58
may have fifteen or twenty three sectors
3:01
also you have to comment out the number
3:06
after sectors you have mine have seven
3:09
sectors so I have commented the rest if
3:13
you have 11 sectors include this portion
3:16
also if you have 23 then include
3:20
everything next flash right data will
3:23
write the respective data to the flash
3:25
memory it takes the memory address as
3:28
the parameter along with the address of
3:31
32-bit data variable that you want to
3:40
it will first calculate the number of
3:42
words based on the size of the data then
3:46
it will get the starts Teta number based
3:49
on the length of data it will calculate
3:52
the memory location of the end sector
3:54
and then the end sector number and
3:58
finally the number of sectors needed to
4:05
it will then erase the required sectors
4:08
and write the data into the NetID memory
4:24
flash read data reads the data from the
4:27
memory and save it in the entered
4:29
variable convert to STR converts the 32
4:33
bits data into the string let's start
4:42
now I am creating a 32 bit variable to
4:46
store the string our X data will store
4:53
the data that we will read from the
4:55
memory string is to store the converted
4:59
string flash write data will write the
5:05
data to the given memory location I will
5:08
use this memory address pass the address
5:12
to the data flash read data will read
5:15
the data from the same location and
5:18
store it in the RX data and finally
5:21
convert the received data to the string
5:24
let's build it I will connect my
5:28
controller now hit the debug button now
5:32
I will add the memory location to
5:50
this is data from my previous experience
5:58
but we are writing in this location so
6:01
that's where we need to focus I will add
6:04
a breakpoint here so we hit the
6:07
breakpoint let's step in
6:16
number of words r8 based on the address
6:26
it have determined that the start sector
6:28
is sector four which is exactly where we
6:32
chose the address and sector address
6:35
will be calculated based on the number
6:37
of words and the end sector number is
6:41
also the same as start sector number of
6:53
sectors needs to be deleted is one and
6:56
now we will exit this function
7:10
I will add rx data in the live
7:25
as you can see the data is written here
7:28
there were eight words so eight 32-bit
7:32
memory locations are used let's read the
7:39
data now the data is stored in the RX
7:43
data array I have defined array of six
7:46
words but I needed eight words anyway
7:50
let's finish this execution
8:00
so the converted data is stored in the
8:03
string and off course it's not the
8:05
entire data because of the size of our X
8:11
let me quickly correct this I am
8:16
increasing the size of the array and
8:18
string also let's debug now
8:28
okay you might also get this error if
8:31
you try to debug again go to debug
8:34
configuration debugger tab reset
8:38
behavior and choose none click apply and
8:55
data is already stored in the location
8:58
so you won't see any change here our X
9:02
data now have all the data
9:19
and the string now shows the entire
9:22
string this was the result of
9:25
programming flash memory from the start
9:27
of the sector let's see can we get the
9:30
same result if we program the from end
9:33
of the sector now I will start writing
9:36
from this address and eight words means
9:39
it will come up to this address here we
9:43
are covering two sectors to write the
9:44
data and that's exactly what we want to
9:47
test this is the memory location of
9:50
sector three and while writing data we
9:54
will come to sector four
9:56
let's see the address of this location
9:59
the address is zero cross eight zero
10:02
zero F F F four enter the memory
10:18
location in the flash write data and in
10:20
flash read data also
10:34
let's enter in the flash write data the
10:38
number of words are eight as the data is
10:41
same start sector is sector three as
10:50
that's where the address is located
11:04
this is the address of the memory
11:06
location where the data will be written
11:09
up to this location is in Sector four
11:25
the number of sectors needed to be
11:34
note that this pre-written data here
11:37
will be erased when the sectors are
11:39
erased now our data has been stored in
11:43
the desired memory location which covers
11:45
two different sectors the same data can
11:53
be read and converted to string also
12:13
keep one thing in mind that the entire
12:15
sector will be erased before writing
12:18
data we cannot erase some particular
12:21
memory location inside the sector not at
12:24
least with hull functions this is it for
12:27
the video guys I hope you understood it
12:31
you can download the code from the link
12:34
in the description have a nice day