{"id":121,"date":"2023-10-26T15:10:18","date_gmt":"2023-10-26T07:10:18","guid":{"rendered":"http:\/\/152.136.53.188\/?p=121"},"modified":"2025-05-03T09:54:11","modified_gmt":"2025-05-03T01:54:11","slug":"spi-gpio-customspi","status":"publish","type":"post","link":"https:\/\/www.xuzhe.tj.cn\/index.php\/2023\/10\/26\/spi-gpio-customspi\/","title":{"rendered":"spi-gpio-custom\uff1a\u7075\u6d3b\u63a7\u5236SPI\u603b\u7ebf"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"> 1. \u5f15\u8a00<\/h2>\n\n\n<p>SPI\uff08Serial Peripheral Interface\uff09\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u4e32\u884c\u901a\u4fe1\u534f\u8bae\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5fae\u63a7\u5236\u5668\u4e0e\u5916\u90e8\u8bbe\u5907\u7684\u8fde\u63a5\u3002<\/p>\n\n\n<p>Linux\u5185\u6838\u4e2d\u7684spi-gpio\u4e0espi-bitbang\u6a21\u5757\u53ef\u4f7f\u7528GPIO\u5f15\u811a\u8fdb\u884cSPI\u7684\u4f4d\u64cd\u4f5c\uff0cspidev\u6a21\u5757\u53ef\u5c06SPI\u66b4\u9732\u7ed9\u7528\u6237\u7a7a\u95f4\u3002\u4f46\u662f\uff0c\u8fd9\u4e9b\u6a21\u5757\u5e76\u4e0d\u80fd\u201c\u76f4\u63a5\u201d\u4f7f\u7528\uff1a\u5b83\u4eec\u88ab\u5176\u4ed6\u5185\u6838\u9a71\u52a8\u7a0b\u5e8f\u4f7f\u7528\u3002\u6ca1\u6709\u529e\u6cd5\u52a8\u6001\u5730\u8bf4\u201c\u6211\u60f3\u5728\u8fd9\u4e9b\u5f15\u811a\u4e0a\u4f7f\u7528\u4e00\u4e2aSPI\u201d\u3002\u76f8\u53cd\uff0c\u6211\u4eec\u9700\u8981\u91cd\u65b0\u914d\u7f6e\u3001\u7f16\u8bd1\u5185\u6838\u3002<\/p>\n\n<!--more-->\n\n<p>spi-gpio-custom\u6a21\u5757\u5141\u8bb8\u52a8\u6001\u914d\u7f6eSPI\u603b\u7ebf\u53ca\u5176\u8282\u70b9\uff0c\u65e0\u9700\u91cd\u65b0\u7f16\u8bd1\u5185\u6838\u3002\u5bf9\u4e8e\u6d4b\u8bd5\u3001\u6982\u5ff5\u9a8c\u8bc1\u975e\u5e38\u65b9\u4fbf\u3002\u6b64\u5916\uff0cspi-gpio-custom\u6a21\u5757\u7684\u901f\u5ea6\u4e5f\u76f8\u5f53\u4e0d\u9519\uff0c\u6d4b\u8bd5\u663e\u793a\u5b83\u53ef\u4ee5\u8fbe\u52301 MHz\u4ee5\u4e0a\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">2. \u5b89\u88c5spi-gpio-custom<\/h2>\n\n\n<p>\u4ee5openwrt\u7cfb\u7edf\u4e3a\u4f8b\uff0c\u5b89\u88c5\u6a21\u5757\u5305\u662f\u6700\u65b9\u4fbf\u7684\u3002\u5982\u679c\u8fd8\u8981\u4fee\u6539\u5176\u5b83\u7684openwrt\u6784\u5efa\u8bbe\u7f6e\uff0c\u53ef\u5728<code>make menuconfig<\/code>\u4e2d\u9009\u4e0a\u6b64\u6a21\u5757\uff0c\u7136\u540e\u91cd\u65b0\u7f16\u8bd1openwrt\u3002<\/p>\n\n\n<h3 class=\"wp-block-heading\">2.1 \u79bb\u7ebf\u5b89\u88c5\u6a21\u5757\u5305<\/h3>\n\n\n<p>\u5728\u7ebf\u5b89\u88c5\u6700\u4fbf\u6377\uff0c\u4f1a\u81ea\u52a8\u5b89\u88c5\u4f9d\u8d56\u5305\uff0c\u4f46\u9700\u8981\u7f51\u7edc\u6761\u4ef6\u3002\u79bb\u7ebf\u5b89\u88c5\u9700\u8981\u5148\u4e0b\u8f7d\u597d\u6240\u9700\u8981\u7684\u5305\uff0c\u4e4b\u540e\u624b\u52a8\u5b89\u88c5\u3002<\/p>\n\n\n<p>\u53ef\u4f7f\u7528LuCI\u7f51\u9875\u754c\u9762\u5b89\u88c5\uff0c\u64cd\u4f5c\u7b80\u5355\u3002\u7b80\u5355\u76f4\u89c2\uff0c\u672c\u6587\u4e0d\u518d\u4ecb\u7ecd\u3002<\/p>\n\n\n<p>\u4e0b\u9762\u4ecb\u7ecd\u547d\u4ee4\u884c\u5b89\u88c5\u65b9\u6cd5\uff0c\u53ef\u5728\u6ca1\u6709\u914d\u7f6eLuCI\u529f\u80fd\uff0c\u6216LuCI\u9875\u9762\u51fa\u9519\u6253\u4e0d\u5f00\u65f6\u4f7f\u7528\u3002<\/p>\n\n\n<p>\u4e0b\u8f7d\u5305\uff1akernel\u3001kmod-spi-bitbang\u3001kmod-spi-dev\u3001kmod-spi-gpio\u3001kmod-spi-gpio-custom\u3002\u5176\u4e2d\u53eakmod-spi-gpio-custom\u662f\u9700\u8981\u7684spi-gpio-custom\u5305\uff0c\u5176\u5b83\u5747\u4e3a\u4f9d\u8d56\u5305\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1226\" height=\"220\" src=\"http:\/\/152.136.53.188\/wp-content\/uploads\/2023\/10\/CleanShot-2023-10-26-at-11.59.10@2x.png\" class=\"wp-image-120\" srcset=\"https:\/\/www.xuzhe.tj.cn\/wp-content\/uploads\/2023\/10\/CleanShot-2023-10-26-at-11.59.10@2x.png 1226w, https:\/\/www.xuzhe.tj.cn\/wp-content\/uploads\/2023\/10\/CleanShot-2023-10-26-at-11.59.10@2x-300x54.png 300w, https:\/\/www.xuzhe.tj.cn\/wp-content\/uploads\/2023\/10\/CleanShot-2023-10-26-at-11.59.10@2x-1024x184.png 1024w, https:\/\/www.xuzhe.tj.cn\/wp-content\/uploads\/2023\/10\/CleanShot-2023-10-26-at-11.59.10@2x-768x138.png 768w, https:\/\/www.xuzhe.tj.cn\/wp-content\/uploads\/2023\/10\/CleanShot-2023-10-26-at-11.59.10@2x-624x112.png 624w\" sizes=\"auto, (max-width: 1226px) 100vw, 1226px\" \/><\/figure><\/div>\n\n\n<p>\u5305\u8981\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u53ca\u786c\u4ef6\u4e3b\u63a7\u5bf9\u4e0a\u3002\u6bd4\u5982\u5305\u540d\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>kmod-spi-gpio-custom_3.18.29-1-8876e460a901ba0991338a5b1846e893_ramips_24kec.ipk \n<\/code><\/pre>\n\n\n<p>\u5176\u4e2d\uff0c\u5404\u90e8\u5206\u7684\u542b\u4e49\u4e3a\uff1a<\/p>\n\n\n<ul class=\"wp-block-list\">\n    <li>kmod-: \u5185\u6838\u6a21\u5757\uff08Kernel Module\uff09\u3002<\/li>\n    <li>spi-gpio-custom: \u5185\u6838\u6a21\u5757\u7684\u5177\u4f53\u540d\u79f0\u3002<\/li>\n    <li>3.18.29: \u8fd9\u662f\u8be5\u5185\u6838\u6a21\u5757\u6240\u4f9d\u8d56\u7684 Linux \u5185\u6838\u7248\u672c\u3002<\/li>\n    <li>-1: \u8fd9\u662f\u8be5\u8f6f\u4ef6\u5305\u7248\u672c\u7684\u4fee\u8ba2\u53f7\uff0c\u901a\u5e38\u7528\u4e8e\u8ffd\u8e2a\u5c0f\u7684\u66f4\u65b0\u6216\u4fee\u8865\u3002<\/li>\n    <li>8876e460a901ba0991338a5b1846e893: \u8fd9\u662f\u4e00\u4e2a\u6821\u9a8c\u548c\u6216\u552f\u4e00\u6807\u8bc6\u7b26\uff0c\u7528\u4e8e\u786e\u4fdd\u8f6f\u4ef6\u5305\u7684\u5b8c\u6574\u6027\u548c\u552f\u4e00\u6027\u3002<\/li>\n    <li>ramips: \u8fd9\u8868\u793a\u8be5\u6a21\u5757\u662f\u4e3a\u57fa\u4e8e Ralink\/MediaTek MIPS \u67b6\u6784\uff08ramips\uff09\u7684\u8bbe\u5907\u7f16\u8bd1\u7684\u3002<\/li>\n    <li>24kec: \u8fd9\u662f\u8be5 MIPS \u67b6\u6784\u4e0b\u7684\u4e00\u4e2a\u7279\u5b9a\u578b\u53f7\u6216\u5b50\u67b6\u6784\u3002<\/li>\n    <li>.ipk: \u8fd9\u662f\u8f6f\u4ef6\u5305\u7684\u6587\u4ef6\u6269\u5c55\u540d\uff0c\u8868\u660e\u5b83\u662f\u4e00\u4e2a\u7528\u4e8e OpenWRT \u7684\u5b89\u88c5\u5305\u3002<br><\/li>\n<\/ul>\n\n\n<p>\u6a21\u5757\u5305\u7684\u5b89\u88c5\u547d\u4ee4<code>opkg install<\/code>\u3002\u5982\u5b89\u88c5kmod-spi-gpio-custom\u5305\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>opkg install kmod-spi-gpio-custom*.ipk\n<\/code><\/pre>\n\n\n<p>\u5728\u547d\u4ee4\u4e2d\uff0c\u53ef\u7528<code>*<\/code>\u53f7\u7528\u66ff\u4ee3\u540e\u7eed\u5b57\u7b26\u3002<\/p>\n\n\n<p>\u6309\u7167\u8fd9\u4e2a\u987a\u5e8f\u4f9d\u6b21\u5b89\u88c5\uff1akernel\u3001kmod-spi-bitbang\u3001kmod-spi-dev\u3001kmod-spi-gpio\u3001kmod-spi-gpio-custom\u3002<\/p>\n\n\n<p>\u68c0\u9a8c\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>opkg list-installed | grep spi-gpio\n<\/code><\/pre>\n\n\n<p>\u770b\u5230<code>kmod-spi-gpio-custom<\/code>\uff0c\u8bf4\u660e\u5df2\u5b89\u88c5\u597d\u3002<\/p>\n\n\n<p>\u5b89\u88c5\u65f6\uff0c\u5982\u8fd8\u9047\u5230\u7f3a\u5c11\u4f9d\u8d56\u5305\u95ee\u9898\uff0c\u9700\u6839\u636e\u63d0\u793a\uff0c\u4f9d\u6b21\u5b89\u88c5\u3002<\/p>\n\n\n<h3 class=\"wp-block-heading\">2.2 \u7f16\u8bd1\u5b89\u88c5<\/h3>\n\n\n<p>\u5728\u7cfb\u7edf\u6e90\u4ee3\u7801\u6839\u76ee\u5f55\uff0c\u8f93\u5165\u914d\u7f6e\u6307\u4ee4\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>make menuconfig\n<\/code><\/pre>\n\n\n<p>\u5728kernel model -&gt; spi support\uff0c\u9009\u4e2d\u201dkmod-spi-gpio-custom\u201d\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u9009\u4e2d\u4e09\u4e2a\u4f9d\u8d56\u5305\uff1a\u201ckmod-spi-bitbang\u201d\u3001\u201ckmod-spi-dev\u201d\u3001\u201ckmod-spi-gpio\u201d\u3002<\/p>\n\n\n<p>\u4fdd\u5b58\u9000\u51fa\u540e\uff0c\u91cd\u65b0\u7f16\u8bd1openwrt\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>make j=2 \/\/\u53cc\u7ebf\u7a0b\u7f16\u8bd1\n<\/code><\/pre>\n\n\n<h2 class=\"wp-block-heading\">3 \u4f7f\u7528spi-gpio-custom\u6a21\u5757\u914d\u7f6eSPI\u603b\u7ebf<\/h2>\n\n\n<p>spi-gpio-custom \u7684\u4fbf\u5229\u5c31\u5728\u4e8e\u53ef\u52a8\u6001\u914d\u7f6eSPI\u603b\u7ebf\uff0c\u4e0d\u9700\u201c\u4fee\u6539dts\u6587\u4ef6\u3001\u7f16\u8bd1\u7cfb\u7edf\u201d\u7684\u7e41\u7410\u64cd\u4f5c\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u901a\u8fc7spi-gpio-custom\u4f7f\u7528spi\u65f6\uff0cdts\u6587\u4ef6\u4e2d\u53ef\u4ee5\u6ca1\u6709\u4efb\u4f55spi\u529f\u80fd\u7684\u5b9a\u4e49\u3002<\/p>\n\n\n<h3 class=\"wp-block-heading\">\u914d\u7f6e\u4e3e\u4f8b<\/h3>\n\n\n<p>\u914d\u7f6e\u4e00\u4e2aID\u4e3a1\u7684\u603b\u7ebf\uff0c\u4f7f\u7528GPIO3\u4f5c\u4e3aCLK\uff0cGPIO4\u4f5c\u4e3aMOSI\uff0cGPIO5\u4f5c\u4e3aMISO\uff0c\u5728SPI\u6a21\u5f0f0\u4e0b\u5de5\u4f5c\u3001\u6700\u5927\u9891\u7387\u4e3a20KHz\u3001GPIO2\u4f5c\u4e3aCS\u7684\u8bbe\u5907\u3002<\/p>\n\n\n<p>\u8fd0\u884c\u547d\u4ee4\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>insmod spi-gpio-custom bus0=1,3,4,5,0,20000,2\n<\/code><\/pre>\n\n\n<p>\u8bf7\u6ce8\u610fGPIOx\u4e2d\u7684x\uff0c\u4e0d\u662f\u5f15\u811a\u7f16\u53f7(pin)\uff0c\u800c\u662f\u5f15\u811a\u540d\u79f0\u3002<\/p>\n\n\n<p>\u5982\u9700\u4fee\u6539spi\u603b\u7ebf\u7684\u914d\u7f6e\uff0c\u9700\u5148\u5378\u8f7d\u540e\u518d\u52a0\u8f7d\uff1a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>rmmod spi-gpio-custom \ninsmod spi-gpio-custom &lt;new parameters&gt;\n<\/code><\/pre>\n\n\n<p>\u66f4\u590d\u6742\u7684\u914d\u7f6e\uff0c\u53c2\u8003<a href=\"https:\/\/randomcoderdude.wordpress.com\/2013\/08\/15\/spi-over-gpio-in-openwrt\/\">\u539f\u59cb\u6587\u6863: SPI over GPIO in OpenWrt <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u5f15\u8a00 SPI\uff08Serial Peripheral In&#8230;<\/p>\n","protected":false},"author":1,"featured_media":534,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[7,13,9,12],"class_list":["post-121","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-10","tag-gpio","tag-linux","tag-openwrt","tag-spi"],"_links":{"self":[{"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":2,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":147,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/posts\/121\/revisions\/147"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/media\/534"}],"wp:attachment":[{"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}