SD card using SDIO in STM32 || Uart RIng buffer || 4-Bit Mode || CubeMx
0 views
Aug 3, 2019
Check the Updated video :::: https://youtu.be/KNuMM7NdgYw?si=EzJ7zfthDpUla8Ln
View Video Transcript
0:08
hello everyone welcome to controllers
0:11
tech a lot of you guys requested SDIO
0:15
interface for the SD card and so today
0:18
in this video we will interface the SD
0:21
card using SDIO 4-bit mode please keep
0:25
in mind that all stm32 series does not
0:29
support SDIO
0:30
especially those who were requesting it
0:33
for stm32 f-100 and three controller we
0:37
can't use SDIO in F 103 controller I am
0:42
using stm32f4 hundred and seven
0:45
controller and it have onboard SD card
0:48
reader with SDIO support so I will start
0:52
with cube MX first select the SDIO 4-bit
0:56
mode and leave everything as it is
1:07
I will be using UART to control the
1:10
entire process so select the UART
1:13
interrupts in the fat FS select the SD
1:21
card we are going to keep everything
1:23
same except increase the size here
1:27
[Music]
1:40
as you can see these are the pins for
1:44
the SDIO 4-bit mode and these are how
1:48
they are connected to the on-board SD
1:50
card reader you can pause the video and
1:52
take a better look
1:55
[Music]
2:06
let's set up the clock now I will keep
2:10
the clock at maximum possible frequency
2:13
here
2:14
[Music]
2:32
this finishes up the setup let's
2:35
generate the code now
2:37
[Music]
2:56
[Music]
3:19
[Music]
3:27
[Music]
3:33
[Music]
3:43
first of all copy the library files in
3:47
the project folder I will be using some
3:50
functions from UART ring buffer I
3:52
already made a video about it you can
3:55
watch it if you don't understand
3:57
something I will leave the link below
4:01
[Music]
4:20
[Music]
4:32
next we need to include these functions
4:35
in our project
4:47
let's build it once to check for any
4:49
errors okay so everything is good till
4:57
now let's proceed
5:14
open the file handling dot H and here
5:17
you can modify the buffer size and path
5:20
length these are the commands that you
5:23
can use for different operations on the
5:25
SD card
5:26
these include LS to list all files and
5:29
directories
5:30
mkdir to create a directory m'kay fill
5:35
to create a file read and write for the
5:39
data operation on the file RM removes
5:42
the file or directory update is for
5:46
updating the contents of a file check
5:49
file gives the information about the
5:51
file and check st gives the memory
5:54
details of SD card if you don't want to
5:58
use with the UART you can use the
6:00
functions directly they are as follows
6:03
send UART sends the string to the UART
6:07
you won't need CMD length and get path
6:11
functions then mount and unmount the SD
6:14
card scan file gives all the directories
6:18
and files from the input path write read
6:21
create and remove works as their name
6:24
suggests in this tutorial I will use the
6:28
UART to control the file handling in
6:31
sdcard first of all we need to
6:34
initialize the ring buffer
6:43
next mount the SD card using the
6:46
function mount SD now the rest of the
6:50
code will be written inside the while
6:52
loop till the data is available to be
6:54
read in the RX buffer we will get the
6:57
string sent by the user data from the RX
7:00
buffer will be written to this input
7:02
buffer only when the user press Enter or
7:05
send a terminating character at the end
7:08
of the string next we are going to
7:11
measure the length of the command within
7:12
the string this works on the fact that
7:15
there will be a space after the command
7:18
next we are going to get the path this
7:21
path will be copied in the path buffer
7:23
next we are going to compare the input
7:26
commands to the saved commands I forgot
7:30
to define this CMD variable based on the
7:33
comparison we are going to assign
7:35
different characters to this CMD
7:38
variable and finally use the switch and
7:41
case function to perform different
7:43
operations according to the command for
7:47
example if command is LS then CMD
7:50
variable will be assigned character L
7:52
and inside the case function we can scan
7:56
files for the entered path
8:05
just like this we can write the
8:08
appropriate functions for the other
8:09
commands also M for creating directory C
8:14
for creating file
8:16
ah for reading a file and other
8:18
characters as you wish
8:21
[Music]
8:42
[Music]
8:48
one last thing we need to do is we need
8:51
to change the default interrupt routine
8:53
to the one we have in the library file
8:56
so open the UART ring buffer dot C file
9:00
and copy the is our definition and paste
9:03
it in the stm32f4xx IT dot C file
9:11
[Music]
9:23
then locate the uart irq handler and
9:27
comment the default function in it and
9:29
add the function that we just defined
9:32
above
9:42
now let's spill this code and test it
9:47
[Music]
10:15
you
10:17
[Music]
10:21
I am getting an error about resetting
10:24
the target go to debug configuration or
10:31
run configuration under the debugger tab
10:35
select show generate a script and change
10:38
it to software system reset
10:42
[Music]
10:58
so the flashing part is success I am
11:01
using Hercules for the serial data
11:04
transmission in the computer on
11:12
resetting the controller I got the
11:14
following message on the terminal
11:18
let's try by listing all the directories
11:21
and files present in the SD card of this
11:24
moment as you can see there is a
11:32
directory and there is a file inside
11:35
this directory let's first try to remove
11:39
the directory and see what happens
11:42
so there is an error this is because the
11:45
directories can only be removed if they
11:48
are empty so I will remove the file
11:51
first this is successful now let's try
12:03
to remove the directory so now the
12:09
directory is removed and there are no
12:12
files present in the SD card right now
12:15
let's create a directory in the root you
12:23
can see this now let's create a file in
12:25
the root itself
12:37
[Music]
12:42
I made one more file inside the
12:46
directory as you can see here if we read
12:55
the file at this moment we won't get
12:57
anything
13:02
so let's first write the data into this
13:06
file I will write hello world into the
13:09
file and got the confirmation - now
13:13
let's read the same file
13:28
and yes we got the string that we wrote
13:31
into the file
13:38
we can also update the file but this
13:41
data will be written to the end of the
13:44
file
13:57
and on reading I got the updated file
14:07
check file gives the details about the
14:10
file
14:12
[Music]
14:29
if we check the another file that we
14:32
created you can see its details
14:43
check st gives the memory details of SD
14:46
card
14:51
you
14:56
[Music]
15:14
this is it guys I hope it would be
15:18
useful for you can modify it according
15:21
to the requirement to download the code
15:24
visit the link in the description
15:27
[Music]
15:35
you
#Computer Hardware
#Electronics & Electrical
#Programming