F1C
(→最小系统) |
(→最小系统) |
||
第123行: | 第123行: | ||
* KEY INPUT | * KEY INPUT | ||
* LRADC0 | * LRADC0 | ||
+ | **6bit resolution; 0 - 2V, 250Hz; 3.0/2^6 = 0.047 | ||
<br> | <br> |
2022年11月8日 (二) 16:58的版本
目录 |
1 F1C100s Overview
- ARM926-EJS, up to 900MHz
- 32KB I-Cache, 16KB D-Cache, 5-stage pipeline
- 32MB SiP DDR1 (F1C200s is 64MB SiP DDR1)
- RGB LCD interface
- USB 2.0 OTG
- SDIO
- SPI x2
- TWI x3
- UART x3
- TV out x 1, TV in x 2
- PWM x2
- LRADC x1
- Speaker x2 + Mic x1
2 Roadmap
3 Pinmap
3.1 荔枝派 Pin Map
- UART
- UART0_RX --- PE0
- UART0_TX --- PE1
- dtb 中默认系统启动的串口 serial0:115200n8
- UART1_RX --- PD3 --- D5
- UART1_TX --- PD4 --- D6
- UART2_RX --- PD14 --- D20
- UART2_TX --- PD13 --- D19
- SPI1
- PA0 - SPI1_CS
- PA1 - SPI1_MOSI
- PA2 - SPI1_SCK
- PA3 - SPI1_MISO
- PE3 -- Reset -- D0
- PE4 -- Interrupt -- D1
- USB
- 右上角,PCLK 右边为 USB_DM (D-)
- 右上角,PCLK 左边为 USB_DP (D+)
- USB_ID,拉低为主机模式,拉高为设备模式。Nano 开发板将 USB_ID 47K 上拉到 3V3,同时 USB_ID 和 PE2 相连。dts 设置使用 PE2 作为检测管脚(默认 active high,即:高电平):
&usb_otg { dr_mode = "otg"; status = "okay"; }; &usbphy { usb0_id_det-gpio = <&pio 4 2 GPIO_ACTIVE_HIGH>; /* PE2 */ status = "okay"; };
进入系统后,可通过改变 PE2 的高低电平来控制 USB 的模式。比如默认 dtb 设置 PE2 为 active high,则进系统后,设置 PE2 为低电平,则 USB 会切换为主机模式
- I2C0
- PE11 --- SCL
- PE12 --- SDA
- GPIO
- PE3 --- D0
- PE4 --- D1
https://fdvad021asfd8q.oss-cn-hangzhou.aliyuncs.com/migrate/Lichee_nano.pdf
4 最小系统
- Power
- VCC-CORE: 1.0 - 1.2V
- VCC-DRAM: 2.3 - 2.7V
- AVCC: 2.5 - 3.1V
- VCC-IO: 3.0 - 3.6V
- VCC-HP: 3.0 - 3.5V
- VCC-TV: 3.0 - 3.5V
- VCC-USB: 3.0 - 3.5V
- SIP DDR1
- SVREF (P33)
- 音频
- HPL, HPR 左右声道;HPCOM, HPCOMFP 接耳机插座
- LINEIN:可用于连接电吉他、电子琴、合成器等外界设备的音频信号,由于这些设备本身输出功率就比较大,因此需要连接到 Line in 端口录音,当然使用它们录音从某种程度上也可以被称为外部设备的“内录”。一般您使用的声卡越好,Line in里的噪音就会越低,录制效果也会比较好。
- MICIN:用于连接麦克风,和 Line in 的区别在于它有前置放大器,麦克风本身输出功率小,因此必须要有一个放大设备来放大音频信号
- VRA1, VRA2, FMINL, FMINR
- TV
- TV_OUT
- TV_VRN, TV_VRP, TVIN1, TVIN0
- KEY INPUT
- LRADC0
- 6bit resolution; 0 - 2V, 250Hz; 3.0/2^6 = 0.047
5 Linux Kernel
$ git clone https://github.com/Icenowy/linux.git $ sudo vim /etc/hosts # 添加下面两行 192.30.253.112 github.com 151.101.73.194 github.global.ssl.fastly.net # 可自行通过dns检测网站检测github.global.ssl.fastly.net,更换为更快的ip地址 # 完整拉取linux极大,建议只拉取单层分支,减少等待时间: $ git clone --depth=1 -b f1c100s-480272lcd-test https://github.com/Icenowy/linux.git
.config: http://dl.sipeed.com/LICHEE/Nano/SDK/config http://nano.lichee.pro/_static/step_by_step/lichee_nano_linux.config
$ make ARCH=arm menuconfig $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j8 #请自行修改编译线程数 $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- dtbs
5.1 Notes
SPI:
# CONFIG_SPI_SUN4I is not set CONFIG_SPI_SUN6I=y
GPIO:
leds { compatible = "gpio-leds"; blue_led { label = "licheepi:blue:usr"; gpios = <&pio 4 4 GPIO_ACTIVE_LOW>; /* PE4 */ }; green_led { label = "licheepi:green:usr"; gpios = <&pio 4 5 GPIO_ACTIVE_LOW>; /* PE5 */ default-state = "on"; }; red_led { label = "licheepi:red:usr"; gpios = <&pio 5 6 GPIO_ACTIVE_LOW>; /* PE6 */ }; };
I2C:
i2c0: i2c@1C27000 { compatible = "allwinner,sun6i-a31-i2c"; reg = <0x01C27000 0x400>; interrupts = <7>; clocks = <&ccu CLK_BUS_I2C0>; resets = <&ccu RST_BUS_I2C0>; pinctrl-names = "default"; pinctrl-0 = <&i2c0_pins>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; }; /* 在 pio 节点下,添加 i2c 引脚定义 */ i2c0_pins: i2c0 { pins = "PE11", "PE12"; function = "i2c0"; };
5.2 电容触摸屏的支持
电容触摸屏的控制芯片为 GT911 使用 I2C 接口,我们要在 suniv-f1c100s-*.dts 文件中添加节点:
#include <dt-bindings/input/input.h> #include <dt-bindings/interrupt-controller/irq.h> /* 添加引用 */ &i2c0 { pinctrl-0 = <&i2c0_pins>; pinctrl-names = "default"; status = "okay"; gt911: touchscreen@14 { compatible = "goodix,gt911"; reg = <0x14>; interrupt-parent = <&pio>; interrupts = <4 10 IRQ_TYPE_EDGE_FALLING>; /* (PE10) */ pinctrl-names = "default"; pinctrl-0 = <&ts_reset_pin>; irq-gpios = <&pio 4 10 GPIO_ACTIVE_HIGH>; /* (PE10) */ reset-gpios = <&pio 4 9 GPIO_ACTIVE_HIGH>; /* RST (PE9) */ /* touchscreen-swapped-x-y */ }; }; &pio { ts_reset_pin: ts_reset_pin@0 { pins = "PE9"; function = "gpio_out"; }; };
若测试的触摸屏的 xy 方向颠倒,请添加或去掉 gt911 节点下的 touchscreen-swapped-x-y 属性。
5.3 ESP8089
- https://github.com/notabucketofspam/ESP8089-SPI
- https://whycan.com/t_5870.html
- https://github.com/al177/esp8089
dts:
&spi1 { status = "okay"; esp8089@0 { status = "okay"; compatible = "boss,esp8089"; spi-cpol; spi-cpha; reg = <0>; spi-max-frequency = <30000000>; reset= <104>; interrupt= <103>; debug= <0>; }; };
5.4 USB OTG
驱动通过读取 USB_ID 的电平,来判断是 host 模式还是 device 模式。
micro-USB 口: pin1 - vcc,pin4 - usb_id, pin5 - gnd
- USB Host: USB_ID 拉高
- USB Dev: USB_ID 拉低
- USB_ID 在 dts 设的是 PE2,active high (高电平进 device mode)
- nano 板默认把 PE2 拉高,因此默认进 device mode
&usb_otg { dr_mode = "otg"; status = "okay"; }; &usbphy { usb0_id_det-gpio = <&pio 4 2 GPIO_ACTIVE_HIGH>; /* PE2 */ status = "okay"; };
USB Hub chip: gl850/gl850g
5.4.1 Device Mode
F1C 作为 USB 设备,连接到主机。如果是 Linux 主机需要:
$ sudo modprobe rndis_host $ ifconfig usb0 192.168.3.1 up
作为客户端的 F1C 则:
$
- https://blog.csdn.net/lan120576664/article/details/101081608
- 荔枝派nano的spi-flash系统编译创建全过程
- 使用 Linux Gadget 复合设备共享网络与虚拟串口
- LicheePi Nano Usb复合设备RNDIS功能问题
- USB 裸机驱动
5.5 4G
5.6 USB 条码枪
https://whycan.com/t_3963.html
5.7 USB Serial
CONFIG_USB_SERIAL=y CONFIG_USB_SERIAL_CH341=m CONFIG_USB_SERIAL_CP210X=m
- CH341 lsusb: 0x1a86:7523 (drivers/usb/serial/ch341.c)
- CP210x lsusb: (drivers/usb/serial/cp210x.c)
6 Quick Start
6.1 Toolchain
$ wget http://releases.linaro.org/components/toolchain/binaries/7.2-2017.11/arm-linux-gnueabi/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz $ tar -vxJf gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz $ git clone -b f1c100s-spiflash https://github.com/Icenowy/sunxi-tools.git $ cd sunxi-tools $ make && sudo make install
如果出现:fel_lib.c:26:20: fatal error: libusb.h: No such file or directory,那需要安装libusb:
sudo apt-get install libusb-1.0-0-dev
sunxi-tools:
新到的一片 Nano ,基本上是上电无反应的,LCD亮但无内容,此时 Nano 自动进入fel下载模式,可以通过命令 sudo sunxi-fel ver 来确认有无成功进入fel模式。
此时有两种方式进行程序下载:
# 1.以 uboot file-with-spl形式进行(单次运行,测试时个人推荐) $ sunxi-fel uboot /your/path/to/u-boot-sunxi-with-spl.bin # 请自行修改到本机地址 # 2.烧进 spi-flash (开机自启) $ sunxi-fel -p spiflash-write 0 /your/path/to/u-boot-sunxi-with-spl.bin # note: 重新烧录或重进fel模式时,请在上电时拉低SPI flash 的 CS引脚 # 查看芯片信息 $ sudo sunxi-fel ver AWUSBFEX soc=00001663(F1C100s) 00000001 ver=0001 44 08 scratchpad=00007e00 00000000 00000000 # 列出所有芯片的信息 $ sudo sunxi-fel -l # 加载并执行 uboot 的 spl $ sudo sunxi-fel spl [文件名] # 把文件内容写入内存指定地址(-p 是显示写入进度) $ sudo sunxi-fel -p write [地址] [文件名] # 调用指定地址的函数 $ sudo sunxi-fel exec [地址] # 显示spiflash的信息 $ sudo sunxi-fel spiflash-info # 读取spiflash指定地址的数据并写入到文件 $ sudo sunxi-fel spiflash-read [地址] [长度] [存放数据的文件路径] # 写入指定文件的指定长度的内容到spiflash的指定地址 $ sudo sunxi-fel spiflash-write [地址] [长度] [存放数据的文件路径]
6.2 U-Boot
$ git clone https://github.com/Lichee-Pi/u-boot.git $ cd u-boot # 切换到 Nano 分支 $ git checkout nano-v2018.01 # 此处告知make采用arm-linux-gnueabi下的所有交叉编译工具,目标架构为Arm,设定各项默认配置为 nano 的spiflash支持版 # 若不带spi-flash的板子,请换成 licheepi_nano_defconfig $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- licheepi_nano_spiflash_defconfig
sudo apt-get install python-setuptools
6.3 ROOTFS
6.3.1 Buildroot
$ wget https://buildroot.org/downloads/buildroot-2020.11.2.tar.gz $ tar xvf buildroot-2020.11.2.tar.gz $ cd buildroot-2017.08/ $ make menuconfig
.config files: https://fdvad021asfd8q.oss-cn-hangzhou.aliyuncs.com/migrate/buildroot.config
快速添加一个 helloworld 包:http://www.chip-community.org/index.php/Startup_Program_with_Buildroot
重 build 某个包:
$ make <pkg>-rebuild $ make <pkg>-dirclean $ make <pkg>-reinstall $ make <pkg>-source $ make <pkg>-show-depends $ make <pkg>-extract $ make <pkg>-install-staging $ make <pkg>-install-target $ make <pkg>-patch
6.3.2 OpenWRT
$ git clone -b licheepi-nano https://github.com/qinfengling/openwrt cat > .config << EOL CONFIG_TARGET_sunxi=y CONFIG_TARGET_sunxi_arm9=y CONFIG_TARGET_sunxi_arm9_DEVICE_suniv-f1c100s-licheepi-nano=y CONFIG_DEVEL=y CONFIG_BRCMFMAC_SDIO=y CONFIG_BRCMFMAC_USB=y CONFIG_DRIVER_11AC_SUPPORT=y CONFIG_DRIVER_11N_SUPPORT=y CONFIG_PACKAGE_MAC80211_DEBUGFS=y CONFIG_PACKAGE_MAC80211_MESH=y CONFIG_PACKAGE_brcmfmac-firmware-usb=y CONFIG_PACKAGE_hostapd-common=y CONFIG_PACKAGE_iw=y CONFIG_PACKAGE_iwinfo=y CONFIG_PACKAGE_kmod-ata-ahci-platform=y CONFIG_PACKAGE_kmod-ata-core=y CONFIG_PACKAGE_kmod-ata-sunxi=y CONFIG_PACKAGE_kmod-brcmfmac=y CONFIG_PACKAGE_kmod-brcmutil=y CONFIG_PACKAGE_kmod-cfg80211=y CONFIG_PACKAGE_kmod-libphy=y CONFIG_PACKAGE_kmod-mac80211=y CONFIG_PACKAGE_kmod-mmc=y CONFIG_PACKAGE_kmod-nls-base=y CONFIG_PACKAGE_kmod-of-mdio=y CONFIG_PACKAGE_kmod-rtc-sunxi=y CONFIG_PACKAGE_kmod-scsi-core=y CONFIG_PACKAGE_kmod-sun4i-emac=y CONFIG_PACKAGE_kmod-usb-core=y CONFIG_PACKAGE_libiwinfo=y CONFIG_PACKAGE_swconfig=y CONFIG_PACKAGE_wireless-regdb=y CONFIG_PACKAGE_wpad-mini=y CONFIG_SOFT_FLOAT=y CONFIG_TARGET_OPTIONS=y EOL $ ./scripts/feeds update -a && ./scripts/feeds install -a $ make defconfig $ make world
Reference:
- https://qinfengling.pro/build_openwrt_image_for_licheepi_nano.html
- 尝试给f1c100s编译openwrt
- 荔枝派nano的SPI-Flash系统编译创建全过程2
- OpenWRT_Tips
6.4 Deploy TF
$ sudo fdisk -l # 首先查看电脑上已插入的TF卡的设备号 $ sudo umount /dev/sdXx # 若自动挂载了TF设备,请先卸载 $ sudo fdisk /dev/sdX # 进行分区操作 # 若已存分区即按 d 删除各个分区 # 通过 n 新建分区,第一分区暂且申请为32M(足够大了...),剩下的空间都给第二分区 # w 保存写入并退出 $ sudo mkfs.vfat /dev/sdX1 # 将第一分区格式化成FAT $ sudo mkfs.ext4 /dev/sdX2 # 将第一分区格式化成EXT4
第一分区:
- boot.scr # u-boot 使用
- zImage
- suniv-f1c100s-licheepi-nano.dtb
第二分区:
- 根文件系统内容
boot.scr 之生成:
$ cat boot.cmd setenv bootargs console=tty0 console=ttyS0,115200 panic=5 rootwait root=/dev/mmcblk0p2 rw load mmc 0:1 0x80C00000 suniv-f1c100s-ltegw.dtb load mmc 0:1 0x80008000 zImage bootz 0x80008000 - 0x80C00000 $ sudo apt install u-boot-tools $ mkimage -C none -A arm -T script -d boot.cmd boot.scr
7 Boot
After power-up, the F1C100s starts to fetch instructions from address 0xFFFF_0000 which is where the BROM is located at. It's an internal integrated 32 KB ROM Chip (Boot ROM or BROM).
The BROM split up into two parts: The first part (at 0xFFFF_0000) is the FEL mode and the second is the eGON.BRM (located at 0xFFFF_4000).
The reset vector is located at the very begining of FEL mode: at address 0xFFFF_0000. On reset, it jumps to 0xFFFF_0028 where it loads 0xFFFF_4000 (eGON.BRM) into the program counter to be executed next.
7.1 eGON Boot
The eGON Boot ROM performs a few tasks:
- do some co-processor setup (c15, (virtual) System Control Coprocessor).
- disables the WatchDog Timer
- setups CPU, AXI, AHB and APB0 clocks
- enables AHB Gating
- enables APB0 Gating
- sets the Stack Pointer to 32K
- then it jumps to 'boot' which immediately jumps to check_uboot
- check_uboot setups up some registers, then checks the status pin (often called FEL pin, BSP pin or uboot)
- if the pin is low (connected to GND) executes FEL mode at 0xFFFF_0020.
- If the pin is high it continues trying to boot from the following media and on failure continues to the next in order.
- SD Card0 also known as MMC0
- Internal NAND flash also known as NAND
- SD Card2 also known as MMC2
- SPI connected NOR flash also known as SPI
- If all fails, FEL/USB Boot mode is executed from 0xFFFF_0020
As can be seen, the SoC has several ways to boot and a lot would need to go wrong or 'fail' before entering FEL mode. This is especially important if there is a valid header in the NAND flash. Obviously this can be abused, by corrupting the header and thus forcing failure. If no other boot options are available, then FEL mode should be the final result. As a bypass mechanism, the A10 has the so called Boot Select Pin (BSP). This pin is normally internally pulled up by a 50KΩ resistor. If the pin is pulled low to GND, the A10 will try to boot into FEL mode. Otherwise the above boot-order will be tried.
boot-> check fel key pressed (yes)--> FEL mode (boot from USB OTG) \ (no) \ \-------> 1) try to boot from SMHC0 (SD card) 2) try to boot from SMHC2 (eMMC) 3) try to boot from SPI0 (SPI NOR Flash) 4) FEL mode (boot from USB OTG)
7.2 FEL mode
- 短接 flash 的 1、4 两脚,重新上电,上电后松开短接,即可重新进入 fel 模式
- 在启动到内核前,回车进入 uboot,执行 sf probe 0;sf erase 0 0x100000;reset 即可重新进入 fel 模式
7.3 Reference
- http://linux-sunxi.org/FEL
- http://linux-sunxi.org/FEL/USBBoot
- http://linux-sunxi.org/BROM
- http://linux-sunxi.org/Sunxi-tools
- http://nano.lichee.pro/get_started/first_eat.html#id6
- F1C100s入坑记录
- 尝试从零构建F1C100s开发环境
- https://whycan.com/t_2179.html spi-flash & wifi & usb-gad
- [https://whycan.com/t_6402.html
8 Reference
- V3S
- F1C100s Datasheet 2015
- F1C100 Datasheet 2011
- F1C600 User Manual
- Card Linux SCH
- H3 Datasheet
- V3S datasheet V3s datasheet