2025/07/20

[Raspberry] Misc

/boot/firmware/config.txt 是 Raspberry Pi 系統中用來設定硬體行為的設定檔,主要在啟動階段由 GPU bootloader 讀取。這個檔案允許你設定像是顯示輸出、音訊介面、I2C/I2S/SPI 啟用、裝置樹載入與參數等。

⚠️ 注意:/boot/firmware/config.txt 是 Raspberry Pi OS 使用 UEFI 或 Ubuntu 系統的名稱,傳統 Raspberry Pi OS 使用的是 /boot/config.txt

 

aplay -D hw:0,0 -r 16000 -f S16_LE -c 2 test.wav
 
arecord -D plughw:3,0 -d 5 -f S16_LE -r 16000 -c 2 test.wav 
-d 5 :錄音時長 5 秒
-f S16_LE :格式為 16-bit 小端(Little Endian)
-r 16000 :取樣率 16000 Hz
-c 2 :雙聲道
 
 
dtc -I fs /proc/device-tree | less
 

2025/04/20

[Linux] DTS

 

如何從執行中的檔案系統截取出 DTS

在已執行的系統中,其檔案系統格式的 DTS 位於:
/sys/firmware/devicetree/base/
而 /proc/device-tree 只是一個 soft link 連結到上述的位置。

另一個為 DTB 格式的 DTS 則是位於:
/sys/firmware/fdt

$ dtc -I dts -O dtb -o device-tree.dtb device_tree.dts

在 /sys/kernel/config/device-tree/overlays/ 目录下创建目录,创建完成后目录内自动会有三个文件 dtbo path status
直接复制 已经编译好的 *.dtbo 文件覆盖 dtbo 文件.

root@npi:/sys/kernel/config/device-tree/overlays# mkdir test
root@npi:/sys/kernel/config/device-tree/overlays# cd test
root@npi:/sys/kernel/config/device-tree/overlays/test# ls
root@npi:/sys/kernel/config/device-tree/overlays/test# dtbo path status
root@npi:/sys/kernel/config/device-tree/overlays/test# cat status
root@npi:/sys/kernel/config/device-tree/overlays/test# unapplied
root@npi:/sys/kernel/config/device-tree/overlays/test# cp /lib/firmware/test.dtbo dtbo
root@npi:/sys/kernel/config/device-tree/overlays/test# cat status
root@npi:/sys/kernel/config/device-tree/overlays/test# applied


 

2025/04/15

[Linux] Macro

#define DEVICE_ATTR_RW(_name) \
	struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
#define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) 
#define __ATTR(_name, _mode, _show, _store) {				\
	.attr = {.name = __stringify(_name),				\
		 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) },		\
	.show	= _show,						\
	.store	= _store,						\
}
  
#define ATTRIBUTE_GROUPS(_name)					\
static const struct attribute_group _name##_group = {		\
	.attrs = _name##_attrs,					\
}; 
struct attribute_group {
	const char		*name;
	umode_t			(*is_visible)(struct kobject *,
					      struct attribute *, int);
	umode_t			(*is_bin_visible)(struct kobject *,
						  const struct bin_attribute *, int);
	size_t			(*bin_size)(struct kobject *,
					    const struct bin_attribute *,
					    int);
	struct attribute	**attrs;
	union {
		struct bin_attribute		**bin_attrs;
		const struct bin_attribute	*const *bin_attrs_new;
	};
};
struct attribute {
	const char		*name;
	umode_t			mode;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
	bool			ignore_lockdep:1;
	struct lock_class_key	*key;
	struct lock_class_key	skey;
#endif
};
    
CLASS_ATTR_RW(xxx);  <<-- xxx代表你想要的节点名字,可以任意字符内容
||
||
\/
struct class_attribute class_attr_xxx = <<--xxx是宏定义的括号里的内容
{
.attr = {
.name = "xxx", <<--这里就是宏定义的括号里的内容,你想要的节点名字
.mode = VERIFY_OCTAL_PERMISSIONS((S_IWUSR | S_IRUGO))
},
.show = xxx_show, <<--xxx也是宏定义括号里的内容,根据你括号里的内容而变
.store = xxx_store <<--xxx也是宏定义括号里的内容,根据你括号里的内容而变
}; 

2025/04/12

[Linux] Commands

 [GPIO]
gpioinfo // 板子定義gpio
gpioget gpiochip* [pin]
gpioset gpiochip* [pin]=[1/0]
cat /sys/kernel/debug/gpio // 真實ic定義gpio 給 gpio_request()
 
[Network] 
nmcli r wifi [on/off]
 
[I2C]
i2cdetect -y 1
// i2cdetect:用於列出某個 I²C 匯流排上已連接的裝置。
// -y:跳過互動式確認(直接執行,不提示)。
// 1:代表第 1 號 I²C 匯流排(Raspberry Pi 上通常是 /dev/i2c-1)。

2025/04/05

[Linux] Simple Makefile

obj-m += "file_name".o


PWD := $(CURDIR)

all:
        $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean