0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

FRDM RW612 - zephyr rtosでspiを利用してsdcardを使用してみる。

0
Last updated at Posted at 2026-08-10
FRDM RW612 - zephyr rtosでspiを利用してmicro sdcardを使用してみる。
build
west build -b frdm_rw612 samples/hello_world -p always
書き込み
sudo env "PATH=/usr/local/LinkServer_26.3.123:$PATH" $(which west) flash -r linkserver
  • 機器の接続
    FRDM-RW612はポート電圧3.3Vで利用できるためレベルシフタは用いない

FRDM-RW612

microSDスロットDIP化キット

接続先

SPI FRDM RW612 microSD
MOSI J1-2 DAT0
MISO J1-4 CMD
CS J2-6 CD/DAT3
SCK J2-12 CLK
GND J2-14 VSS
3.3V J2-16 VDD
  • prj.confの変更
samples/hello_world/prj.conf
#nothing here
+CONFIG_MAIN_STACK_SIZE=4096

+CONFIG_LOG=y
+CONFIG_LOG_MODE_IMMEDIATE=y

+CONFIG_SPI=y

+CONFIG_DISK_ACCESS=y
+CONFIG_SDHC=y

+CONFIG_FILE_SYSTEM=y
+CONFIG_FAT_FILESYSTEM_ELM=y
  • dtsの追加
samples/boards/frdm_rw612.overlay
&flexcomm1 {
    cs-gpios = <&hsgpio0 6 GPIO_ACTIVE_LOW>;
	sdhc0: sdhc@0 {
		compatible = "zephyr,sdhc-spi-slot";
		reg = <0>;
		status = "okay";

		spi-max-frequency = <25000000>;

		mmc0: mmc {
			compatible = "zephyr,sdmmc-disk";
			disk-name = "SD";
			status = "okay";
		};
	};
};
  • main.cの変更
samples/hello_world/src/main.c
#include <stdio.h>
+#include <zephyr/kernel.h>
+#include <zephyr/device.h>
+#include <zephyr/storage/disk_access.h>
+#include <zephyr/fs/fs.h>
+#include <ff.h>

+static FATFS fat_fs;

+static struct fs_mount_t mp = {
+    .type = FS_FATFS,
+    .fs_data = &fat_fs,
+    .mnt_point = "/SD:",
+};

int main(void)
{
+    struct fs_file_t file;
+    int rc;
        
	printf("Hello World! %s\n", CONFIG_BOARD_TARGET);
+	printk("\n*** SD Card SPI Test on FRDM-RW612 ***\n");
+	
+	rc = fs_mount(&mp);
+	if (rc < 0) {
+	    printk("Error: Failed to mount SD card (%d)\n", rc);
+	    printk("Please check wiring and ensure SD card is formatted as FAT32.\n");
+	    return rc;
+	}
+	
+	fs_file_t_init(&file);
+	rc = fs_open(&file, "/SD:/hello.txt", FS_O_CREATE | FS_O_WRITE);
+	if(rc < 0) {
+	    printk("Error: Failed to open/create file (%d\n)", rc);
+	    return rc;
+	}
+	
+	const char *text = "Hello from Zephyr RTOS on FRDM-RW612!\n";
+	rc = fs_write(&file, text, strlen(text));
+	if(rc < 0) {
+	    printk("Error: Failed to write to file (%d)", rc);
+	} else {
+	    printk("Success: Wrote %d byte to /SD:hello.txt\n", rc);
+	}
+	
+	fs_close(&file);
+	printk("Test completed.\n");

  • アプリケーション実行時のメッセージ出力
    microSDカードには、
    hello.txtというファイルにHello from Zephyr RTOS on FRDM-RW612!が書き込まれる。
*** Booting Zephyr OS build v4.4.0-8011-gb01be6b7b16e ***
Hello World! frdm_rw612/rw612

*** SD Card SPI Test on FRDM-RW612 ***
Success: Wrote 38 byte to /SD:hello.txt
Test completed.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?