Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
IAS0360
/
IAS0360_lab_excercises_2025
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e91eab80
authored
Sep 29, 2025
by
tatsukiishikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updating sd_card_example
parent
f407a506
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
lab_0/sd_card_example/CMakeLists.txt
lab_0/sd_card_example/main.cpp
lab_0/sd_card_example/CMakeLists.txt
View file @
e91eab80
...
@@ -15,7 +15,7 @@ endif()
...
@@ -15,7 +15,7 @@ endif()
cmake_minimum_required
(
VERSION 3.13
)
cmake_minimum_required
(
VERSION 3.13
)
set
(
PICO_BOARD pico_w CACHE STRING
"Board type"
)
set
(
PICO_BOARD pico_w CACHE STRING
"Board type"
)
set
(
PROGRAM_NAME
imu_data_logger
)
set
(
PROGRAM_NAME
sd_card_example
)
include
(
pico_sdk_import.cmake
)
include
(
pico_sdk_import.cmake
)
...
@@ -59,17 +59,30 @@ set_property(TARGET ${PROGRAM_NAME} APPEND_STRING PROPERTY LINK_FLAGS
...
@@ -59,17 +59,30 @@ set_property(TARGET ${PROGRAM_NAME} APPEND_STRING PROPERTY LINK_FLAGS
)
)
pico_set_program_name
(
${
PROGRAM_NAME
}
"
${
PROGRAM_NAME
}
"
)
pico_set_program_name
(
${
PROGRAM_NAME
}
"
${
PROGRAM_NAME
}
"
)
pico_set_program_version
(
${
PROGRAM_NAME
}
"
3.3
.1"
)
pico_set_program_version
(
${
PROGRAM_NAME
}
"
0
.1"
)
pico_enable_stdio_uart
(
${
PROGRAM_NAME
}
0
)
pico_enable_stdio_usb
(
${
PROGRAM_NAME
}
1
)
pico_enable_stdio_usb
(
${
PROGRAM_NAME
}
1
)
target_include_directories
(
${
PROGRAM_NAME
}
PUBLIC
target_include_directories
(
${
PROGRAM_NAME
}
PUBLIC
include/
include/
)
)
target_link_libraries
(
${
PROGRAM_NAME
}
target_link_libraries
(
${
PROGRAM_NAME
}
pico_stdlib
hardware_i2c
pico_multicore
pico_util
sd_custom_driver
sd_custom_driver
hardware_clocks
hardware_clocks
hardware_adc
hardware_adc
hardware_pio
)
# Add the standard include files to the build
target_include_directories
(
${
PROGRAM_NAME
}
PRIVATE
${
CMAKE_CURRENT_LIST_DIR
}
)
)
pico_add_extra_outputs
(
${
PROGRAM_NAME
}
)
pico_add_extra_outputs
(
${
PROGRAM_NAME
}
)
lab_0/sd_card_example/main.cpp
View file @
e91eab80
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include "pico/stdlib.h"
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "ff.h"
#include "ff.h"
#include "sd_card.h"
#include "sd_card.h"
#include "f_util.h"
#include "f_util.h"
...
@@ -167,9 +169,8 @@ static FRESULT check_and_list_files(const char *root_drive) {
...
@@ -167,9 +169,8 @@ static FRESULT check_and_list_files(const char *root_drive) {
}
}
// ------------------------------ Main -------------------------------------
// ------------------------------ Main -------------------------------------
int
main
(
void
)
{
stdio_init_all
();
void
core1_entry
()
{
sleep_ms
(
1500
);
// 1) Init + mount
// 1) Init + mount
if
(
!
sd_init_and_mount
())
{
if
(
!
sd_init_and_mount
())
{
...
@@ -178,7 +179,7 @@ int main(void) {
...
@@ -178,7 +179,7 @@ int main(void) {
// Build absolute file path: <drive>/test.txt
// Build absolute file path: <drive>/test.txt
char
path
[
PATH_MAX_LEN
];
char
path
[
PATH_MAX_LEN
];
join_path
(
path
,
sizeof
path
,
g_drive
,
"test
1
.txt"
);
join_path
(
path
,
sizeof
path
,
g_drive
,
"test
3
.txt"
);
// 2) Create the file
// 2) Create the file
FIL
f
;
FIL
f
;
...
@@ -186,7 +187,7 @@ int main(void) {
...
@@ -186,7 +187,7 @@ int main(void) {
if
(
fr
!=
FR_OK
)
die
(
fr
,
"f_open(create)"
);
if
(
fr
!=
FR_OK
)
die
(
fr
,
"f_open(create)"
);
// 3) Write data
// 3) Write data
const
char
*
msg
=
"data
writing
test!
\n
"
;
const
char
*
msg
=
"data
blahblah
test!
\n
"
;
UINT
bw
=
0
;
UINT
bw
=
0
;
fr
=
write_to_file
(
&
f
,
msg
,
(
UINT
)
strlen
(
msg
),
&
bw
);
fr
=
write_to_file
(
&
f
,
msg
,
(
UINT
)
strlen
(
msg
),
&
bw
);
if
(
fr
!=
FR_OK
||
bw
!=
strlen
(
msg
))
die
(
fr
,
"f_write/f_sync"
);
if
(
fr
!=
FR_OK
||
bw
!=
strlen
(
msg
))
die
(
fr
,
"f_write/f_sync"
);
...
@@ -203,5 +204,15 @@ int main(void) {
...
@@ -203,5 +204,15 @@ int main(void) {
fr
=
f_unmount
(
g_drive
);
fr
=
f_unmount
(
g_drive
);
printf
(
"f_unmount -> %s (%d)
\n
"
,
FRESULT_str
(
fr
),
fr
);
printf
(
"f_unmount -> %s (%d)
\n
"
,
FRESULT_str
(
fr
),
fr
);
while
(
1
)
{
tight_loop_contents
();
}
}
int
main
(
void
)
{
stdio_init_all
();
sleep_ms
(
3000
);
multicore_launch_core1
(
core1_entry
);
while
(
1
)
{
sleep_ms
(
1000
);
}
while
(
1
)
{
sleep_ms
(
1000
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment