Edit online

SPI 配置

16 Dec 2024
Read time: 2 minute(s)

内核配置

使能 SPI 相关的内核驱动,可在通过下列命令进行配置(在 SDK 顶层目录执行):

  1. 在 SDK 根目录下,执行下列命令,进入 kernel 的功能配置界面:
    make kernel-menuconfig

    或使用简写命令

    make km
  2. 在内核的配置界面中,进行下列的选择:
    Device Drivers  --->
        [*] SPI support  --->
            <*>   ArtInChip SPI controller
            ......
        [*] DMA Engine support  --->
            <*>   ArtInChip SoCs DMA support
    

    结果:内核 SPI 驱动使能,且 SPI 可使用 DMA 进行数据传输。

DTS 配置

芯片级的 DTS:

spi0: spi@10400000 {
    compatible = "artinchip,aic-spi-v1.0";
    reg = <0x0 0x10400000 0x0 0x1000>;
    interrupts-extended = <&plic0 44 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&cmu CLK_SPI0>;
    resets = <&rst RESET_SPI0>;
    dmas = <&dma DMA_SPI0>, <&dma DMA_SPI0>;
    dma-names = "rx", "tx";
    #address-cells = <1>;
    #size-cells = <0>;
    spi-max-frequency = <24000000>;
};

spi1: spi@10410000 {
    compatible = "artinchip,aic-spi-v1.0";
    reg = <0x0 0x10410000 0x0 0x1000>;
    interrupts-extended = <&plic0 45 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&cmu CLK_SPI1>;
    resets = <&rst RESET_SPI1>;
    dmas = <&dma DMA_SPI1>, <&dma DMA_SPI1>;
    dma-names = "rx", "tx";
    #address-cells = <1>;
    #size-cells = <0>;
    spi-max-frequency = <24000000>;
};

其中板级的配置 board.dts 中需要使能该模块,并且根据实际情况,配置最大工作频率:

&spi0 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins_a>;
    spi-max-frequency = <100000000>;
    status = "okay";
};

&spi1 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi1_pins_a>;
    spi-max-frequency = <100000000>;
    status = "okay";
};

board-u-boot.dtsi 需要设置 u-boot,dm-pre-reloc ,只有设置了该标记,SPL 中才可以使用 SPI:

&spi0 {
    u-boot,dm-pre-reloc;
};

&spi1 {
    u-boot,dm-pre-reloc;
};