0:07
hello everyone welcome to controllers
0:11
tech today in this video we will see how
0:16
to use USB mass-storage class with or
0:18
without using SD card let's start by
0:22
creating the project in cube ide i am
0:26
using stm32f4 0 7 z ii give some name to
0:31
the project and click finish here is our
0:34
cube MX first of all i am enabling the
0:39
external crystal for the clock now go to
0:42
USB OTG FS and select device only in the
0:51
USB device select the Mass Storage class
0:55
you can change the device descriptor
0:58
here in this first half I am going to
1:02
show how to use mass storage without SD
1:04
card and that's why I am not selecting
1:07
SDIO go to the clock configuration now I
1:12
have 8 megahertz crystal and I want the
1:15
system to run at full 168 megahertz
1:23
note that this 48 megahertz clock is
1:26
also selected this is basically the
1:29
clock for USB click Save to generate the
1:33
project open USB D storage if dot C file
1:38
this is the file where we are going to
1:43
let me first build this project
1:49
as you can see here the device of 123
1:55
kilobytes of free RAM and I am going to
1:59
use this RAM as the storage let's start
2:03
then change the storage block number to
2:06
twice the amount of RAM that you are
2:08
going to use I want to use 100 kilobytes
2:12
of this Ram now create a buffer which
2:19
can hold this 100 kilobytes of data
2:27
storage block size is 512 and that's
2:31
make this buffer 100 kilobytes in size
2:49
next in the storage reach function we
2:53
will copy the data from our assigned
3:11
same thing in the storage right function
3:14
but this time copying will be the other
3:18
let's build and debug this code let's
3:27
run this as you can see there is no
3:31
external drive here now I will connect
3:38
the USB to the SDM 32 it's asking to
3:42
format the disk so let's do that
3:45
you can see here the size is 100
3:55
this is our mass storage disk of 100
4:07
we can create a file write data and save
4:34
now I will remove the USB and connect it
4:40
back and you can see the file is still
4:43
available but this is not always true
4:47
sometimes it asked me to format the disk
4:49
again I am still working on how to solve
4:53
this issue also see here that the RAM is
4:57
almost full as we are using it as mass
4:59
storage now I will show you how to use
5:03
SD card as a mass storage let's go back
5:07
to the cube M X leave USB configuration
5:17
and select SD i/o 4-bit mode as you can
5:22
see here these are the pins used for SD
5:32
this is how the pins are connected to
5:45
this is the time a diagram for stm32f4
5:49
as you can see the SDIO is connected to
6:07
and the APB two is running at eighty
6:10
four megahertz now if you remembered the
6:14
USB full-speed clock is twelve megahertz
6:17
so we need to bring SDIO to the same
6:32
as mentioned here SDIO CK is equal to
6:38
the SDIO clock divided by divided factor
6:42
plus 2 a PD clock is 84 megahertz so we
6:48
need to divide it by 7 for the SDIO to
6:51
become 12 therefore the divide factor
6:55
will be 5 that's all for the setup now
6:59
save to generate the project
7:28
delete the USB D storage if dot C file
7:33
and copy this USB storage file at the
7:39
same position this file contains the
7:42
functions needed for SD card to work
7:45
I am commenting out the ramp related
7:52
functions this function will get the
8:27
this will be used to read the SD card
8:37
and this one will be used to write the
8:57
let's build this note that the RAM is
9:14
again you can see there is no external
9:17
storage right now when I connect the USB
9:25
the SD card is detected as the mass
9:28
storage device the card is one gigabyte
9:32
in size these are some contents
9:38
I was testing with initially I will copy
9:50
this folder now let's see how much time
10:27
you can see this is only two point three
10:30
megabytes folder I have removed the USB
10:53
when connected back you can see the
10:55
files are still present this sums up
10:59
everything for this video you can use
11:02
the mass storage with or without sdcard
11:06
speed is slow right now but I will work
11:09
on it maybe DMA can make it a bit faster
11:13
I will update you guys if there are any
11:17
changes made in the code in future you
11:20
can download the code from the link in
11:22
the description stay safe and good bye