找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 33223|回复: 81

TP-LINK WR841N v7.1 成功添加 SD/MMC 接口

 火.. [复制链接]
发表于 2014-2-27 21:51 | 显示全部楼层 |阅读模式
本帖最后由 hackpascal 于 2014-4-3 12:52 编辑

参考 http://wiki.openwrt.org/ru/toh/tp-link/tl-mr3420/deep.mmc.hack (俄语),成功地在路由上添加了 SD/MMC 接口,使用的是 SPI 模式。

OpenWrt Wiki 上的接线图 (稍作修改):



简要说明:
SoC 是 AR7241,设备是 TP-LINK TL-WR841N v7.1。

根据接线图在 FLASH 焊盘上找到对应的 SCLK DI DO 针脚,并将其引出,接在 SD 的接口上(用卡套或插槽)
Vdd 需要 3.3V 电压,可选择 TTL 的 Vdd,也可直接使用 FLASH 的 Vdd。
GND 随便找个地方接

CS 针脚:
有两种选择,要么用 SoC 内部的 CS 针脚,要么使用普通的 GPIO 针脚。
这里建议使用普通的 GPIO,因为内部的 CS 一个被 SYS LED 占用了,一个被 QSS LED 占用了。

经网上查找和测试发现 WR841N v7.1 的 GPIO7 和 GPIO18 是可以用的。
GPIO7 对应的针脚为 82,对应的电阻为 R617。
GPIO18 对应的针脚为 85,对应的电阻为 R427。
图:


以 GPIO7 为例:
拆掉 R617 电阻,然后将 CS 接在靠近 SoC 的焊盘上。

以 GPIO18 为例:
拆掉 R427 电阻,然后将 CS 接在远离 SoC 的焊盘上。

CS 另需接一个 10K 的上拉电阻到 Vdd (3.3V) 上。

实际接线:


MicroSD 卡槽:


整体图:


背部:


编译代码:
直接安装驱动是不行的,必须要修改架构代码。

针对 OpenWrt Barrier Breaker:
  1. diff --git a/target/linux/ar71xx/files/arch/mips/ath79/dev-m25p80.c b/target/linux/ar71xx/files/arch/mips/ath79/dev-m25p80.c
  2. index 9323b31..50ea143 100644
  3. --- a/target/linux/ar71xx/files/arch/mips/ath79/dev-m25p80.c
  4. +++ b/target/linux/ar71xx/files/arch/mips/ath79/dev-m25p80.c
  5. @@ -7,14 +7,23 @@
  6.   */

  7. #include <linux/init.h>
  8. +#include <linux/mmc/host.h>
  9. #include <linux/spi/spi.h>
  10. #include <linux/spi/flash.h>
  11. +#include <linux/spi/mmc_spi.h>
  12. #include <linux/mtd/mtd.h>
  13. #include <linux/mtd/partitions.h>
  14. #include <linux/mtd/concat.h>

  15. #include "dev-spi.h"
  16. #include "dev-m25p80.h"
  17. +
  18. +static struct mmc_spi_platform_data ath79_mmc_data = {
  19. +        .get_ro = NULL,
  20. +        .get_cd = NULL,
  21. +        .detect_delay = 100, /* msecs */
  22. +        .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  23. +};

  24. static struct ath79_spi_controller_data ath79_spi0_cdata =
  25. {
  26. @@ -24,8 +33,8 @@ static struct ath79_spi_controller_data ath79_spi0_cdata =

  27. static struct ath79_spi_controller_data ath79_spi1_cdata =
  28. {
  29. -        .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
  30. -        .cs_line = 1,
  31. +        .cs_type = ATH79_SPI_CS_TYPE_GPIO,
  32. +        .cs_line = 7,     /* GPIO 号,7 或 18 */
  33. };

  34. static struct spi_board_info ath79_spi_info[] = {
  35. @@ -40,7 +49,8 @@ static struct spi_board_info ath79_spi_info[] = {
  36.                  .bus_num        = 0,
  37.                  .chip_select        = 1,
  38.                  .max_speed_hz   = 25000000,
  39. -                .modalias        = "m25p80",
  40. +                .modalias        = "mmc_spi",
  41. +                .platform_data        = &ath79_mmc_data,
  42.                  .controller_data = &ath79_spi1_cdata,
  43.          }
  44. };
  45. @@ -50,10 +60,10 @@ static struct ath79_spi_platform_data ath79_spi_data;
  46. void __init ath79_register_m25p80(struct flash_platform_data *pdata)
  47. {
  48.          ath79_spi_data.bus_num = 0;
  49. -        ath79_spi_data.num_chipselect = 1;
  50. +        ath79_spi_data.num_chipselect = 2;
  51.          ath79_spi0_cdata.is_flash = true;
  52.          ath79_spi_info[0].platform_data = pdata;
  53. -        ath79_register_spi(&ath79_spi_data, ath79_spi_info, 1);
  54. +        ath79_register_spi(&ath79_spi_data, ath79_spi_info, 2);
  55. }

  56. static struct flash_platform_data *multi_pdata;
复制代码

patch 格式,- 是删除行,+ 是添加行。
对照修改。

重新编译,并加上 kmod-mmc 和 kmod-mmc-spi 即可。

修改好之后:

内核日志:
[    3.010000] TCP: cubic registered
[    3.020000] NET: Registered protocol family 17
[    3.020000] 8021q: 802.1Q VLAN Support v1.8
[    3.030000] VFS: Mounted root (squashfs filesystem) readonly on device 31:2.
[    3.040000] Freeing unused kernel memory: 220K (80329000 - 80360000)
[    8.660000] mmc_spi spi0.1: SD/MMC host mmc0, no DMA, no WP, no poweroff
[    8.810000] mmc0: host does not support reading read-only switch. assuming write-enable.
[    8.810000] mmc0: new SDHC card on SPI
[    8.820000] mmcblk0: mmc0:0000 SS08G 7.40 GiB
[    8.830000]  mmcblk0: p1 p2
[    8.870000] SCSI subsystem initialized
[    9.150000] usbcore: registered new interface driver usbfs
[    9.160000] usbcore: registered new interface driver hub
[    9.160000] usbcore: registered new device driver usb
[    9.390000] Button Hotplug driver version 0.4.1

截图:







由于使用 SPI 接口,其时钟频率会受到 FLASH 的限制,及只能以低的时钟频率为准。由于 SPI FLASH 的时钟频率不能太高,一般在 UBoot 中都设在 25MHz 左右,传输速率远低于 SD 的最大传输速率。
因此在这种情况下对 SD 的读写效率不会太高。

使用测试:
SD卡: ADATA MicroSD 8G Class 4
网络:有线 LAN 100mbps
FTP上传:5~7Mbps (0.6MB/s ~ 0.9MB/s)
FTP 下载:8~9Mbps (大概 1MB/s)



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

评分

参与人数 7恩山币 +7 收起 理由
3ax31a + 1 楼主威武—我就想问问挖掘机技术哪家强?
Leap_ahead + 1 亲,你太牛逼了,走,我请你吃鳇鱼头去~~.
imsing + 1 楼主威武—我就想问问挖掘机技术哪家强?
bugmenot + 1 强大的恩山!(以下重复1万次)
四哥! + 1 土豪,我们做朋友吧!
pla132jw + 1 一看就是觉得高端、大气、上档次!
cypher + 1 神马都是浮云,淡定!

查看全部评分

我的恩山、我的无线 The best wifi forum is right here.
发表于 2014-2-27 21:59 | 显示全部楼层
牛人啊。
1G flash...
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2014-2-27 22:04 | 显示全部楼层
hzzsn520 发表于 2014-2-27 21:59
牛人啊。
1G flash...

1G Flash,很早以前的,而且都有损坏了。准备重新买一个。

点评

不都是说 spi flash有10W次 擦写寿命  发表于 2014-7-15 18:06
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-2-27 22:38 | 显示全部楼层
不佩服不行呀
技术牛人
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-2-28 00:19 | 显示全部楼层
玩个路由要不要这风骚
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-2-28 00:44 | 显示全部楼层
这个有意思啊。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-2-28 07:57 来自手机 | 显示全部楼层
速度有多少呢?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2014-2-28 15:44 | 显示全部楼层

实际测出来速度也不是太高。。
更新了1楼,测试结果在最后
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-2-28 16:57 | 显示全部楼层
牛人 膜拜!!! 啥也不说了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-2-28 19:20 来自手机 | 显示全部楼层
好犀利,ar7241可以刷ros 不知能否搞上去
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-3-1 07:27 来自手机 | 显示全部楼层
841确实经典啊
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-3-7 00:17 | 显示全部楼层
顶。就是内存大概最大64M,否则真可以上debian等等了。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-3-7 13:43 | 显示全部楼层
早就了解SD/MMC卡有SPI模式,可是没想到还可以这么玩,佩服原作者的钻研精神。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-3-11 21:41 | 显示全部楼层
AR7241
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2014-3-13 23:34 | 显示全部楼层
软硬兼修。的确牛人。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-19 07:03

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表