From b05a5a6f3d676eb1e328db53894d829505cf3adf Mon Sep 17 00:00:00 2001 From: zhuangwei123 Date: Sat, 9 Jun 2018 21:09:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[bsp/ls1cdev]SPI0=E6=B7=BB=E5=8A=A0CS0?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8C=E7=A7=BB=E9=99=A4drv=5Fspi.c?= =?UTF-8?q?=E4=B8=AD=E7=9A=84msd=5Finit=E3=80=82SPI00=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=B3=A8=E5=86=8CNORFLASH=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/ls1cdev/drivers/drv_spi.c | 21 ++++++++++++++------- bsp/ls1cdev/libraries/ls1c_spi.c | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/bsp/ls1cdev/drivers/drv_spi.c b/bsp/ls1cdev/drivers/drv_spi.c index 900f7e4aa..4e7012dc7 100644 --- a/bsp/ls1cdev/drivers/drv_spi.c +++ b/bsp/ls1cdev/drivers/drv_spi.c @@ -20,6 +20,7 @@ * Change Logs: * Date Author Notes * 2017-11-02 Ϊ first version + * 2018-06-09 zhuangwei add spi0 cs0 support,remove msd_init */ #include @@ -235,13 +236,15 @@ int ls1c_hw_spi_init(void) pin_set_purpose(79, PIN_PURPOSE_OTHER); pin_set_purpose(80, PIN_PURPOSE_OTHER); pin_set_purpose(83, PIN_PURPOSE_OTHER);//cs2 - SD card - pin_set_purpose(82, PIN_PURPOSE_OTHER);//cs1 + pin_set_purpose(82, PIN_PURPOSE_OTHER);//cs1 + pin_set_purpose(81, PIN_PURPOSE_OTHER);//cs0 - pin_set_remap(78, PIN_REMAP_FOURTH); - pin_set_remap(79, PIN_REMAP_FOURTH); - pin_set_remap(80, PIN_REMAP_FOURTH); - pin_set_remap(83, PIN_REMAP_FOURTH);//cs2 - SD card - pin_set_remap(82, PIN_REMAP_FOURTH);//cs1 + pin_set_remap(78, PIN_REMAP_DEFAULT); + pin_set_remap(79, PIN_REMAP_DEFAULT); + pin_set_remap(80, PIN_REMAP_DEFAULT); + pin_set_remap(83, PIN_REMAP_DEFAULT);//cs2 - SD card + pin_set_remap(82, PIN_REMAP_DEFAULT);//CS1 + pin_set_remap(81, PIN_REMAP_DEFAULT);//cs0 ls1c_spi_bus_register(LS1C_SPI_0,"spi0"); #endif @@ -262,8 +265,10 @@ int ls1c_hw_spi_init(void) #ifdef RT_USING_SPI0 /* attach cs */ { + static struct rt_spi_device spi_device0; static struct rt_spi_device spi_device1; static struct rt_spi_device spi_device2; + static struct ls1c_spi_cs spi_cs0; static struct ls1c_spi_cs spi_cs1; static struct ls1c_spi_cs spi_cs2; @@ -272,7 +277,8 @@ int ls1c_hw_spi_init(void) rt_spi_bus_attach_device(&spi_device2, "spi02", "spi0", (void*)&spi_cs2); spi_cs1.cs = LS1C_SPI_CS_1; rt_spi_bus_attach_device(&spi_device1, "spi01", "spi0", (void*)&spi_cs1); - msd_init("sd0", "spi02"); + spi_cs0.cs = LS1C_SPI_CS_0; + rt_spi_bus_attach_device(&spi_device0, "spi00", "spi0", (void*)&spi_cs0); } #endif #ifdef RT_USING_SPI1 @@ -287,6 +293,7 @@ int ls1c_hw_spi_init(void) #endif } + INIT_BOARD_EXPORT(ls1c_hw_spi_init); #endif diff --git a/bsp/ls1cdev/libraries/ls1c_spi.c b/bsp/ls1cdev/libraries/ls1c_spi.c index e3df72906..eff1deb74 100644 --- a/bsp/ls1cdev/libraries/ls1c_spi.c +++ b/bsp/ls1cdev/libraries/ls1c_spi.c @@ -260,7 +260,7 @@ inline void ls1c_spi_clear(void *spi_base) val = reg_read_8(spi_base + LS1C_SPI_SPSR_OFFSET); if (LS1C_SPI_SPSR_WCOL_MASK & val) { - rt_kprintf("[%s] clear register SPSR's wcol!\r\n"); // 手册和linux源码中不一样,加个打印看看 + rt_kprintf("[%s] clear register SPSR's wcol!\r\n",__FUNCTION__); // 手册和linux源码中不一样,加个打印看看 reg_write_8(val & ~LS1C_SPI_SPSR_WCOL_MASK, spi_base + LS1C_SPI_SPSR_OFFSET); // 写0,linux源码中是写0 // reg_write_8(val | LS1C_SPI_SPSR_WCOL_MASK, spi_base + LS1C_SPI_SPSR_OFFSET); // 写1,按照1c手册,应该写1 } From e7f78855bd09a798c247c3eec9409261584bb93f Mon Sep 17 00:00:00 2001 From: zhuangwei123 Date: Sun, 10 Jun 2018 10:52:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[bsp/ls1cdev]drv=5Fspi.c=20astyle=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/ls1cdev/drivers/drv_spi.c | 60 +++++++++++++++++------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/bsp/ls1cdev/drivers/drv_spi.c b/bsp/ls1cdev/drivers/drv_spi.c index 4e7012dc7..4b81d55d7 100644 --- a/bsp/ls1cdev/drivers/drv_spi.c +++ b/bsp/ls1cdev/drivers/drv_spi.c @@ -19,7 +19,7 @@ * * Change Logs: * Date Author Notes - * 2017-11-02 Ϊ first version + * 2017-11-02 勤为本 first version * 2018-06-09 zhuangwei add spi0 cs0 support,remove msd_init */ @@ -43,14 +43,14 @@ static rt_err_t configure(struct rt_spi_device *device, struct rt_spi_configurat static rt_uint32_t xfer(struct rt_spi_device *device, struct rt_spi_message *message); -static struct rt_spi_ops ls1c_spi_ops = +static struct rt_spi_ops ls1c_spi_ops = { .configure = configure, .xfer = xfer }; -static rt_err_t configure(struct rt_spi_device *device, +static rt_err_t configure(struct rt_spi_device *device, struct rt_spi_configuration *configuration) { struct rt_spi_bus *spi_bus = NULL; @@ -70,28 +70,28 @@ static rt_err_t configure(struct rt_spi_device *device, spi_base = ls1c_spi_get_base(SPIx); { - // ʹSPImasterģʽرж + // 使能SPI控制器,master模式,关闭中断 reg_write_8(0x53, spi_base + LS1C_SPI_SPCR_OFFSET); - // ״̬Ĵ + // 清空状态寄存器 reg_write_8(0xc0, spi_base + LS1C_SPI_SPSR_OFFSET); - // 1ֽڲжϣ()뷢(д)ʱͬʱ + // 1字节产生中断,采样(读)与发送(写)时机同时 reg_write_8(0x03, spi_base + LS1C_SPI_SPER_OFFSET); - // رSPI flash + // 关闭SPI flash val = reg_read_8(spi_base + LS1C_SPI_SFC_PARAM_OFFSET); val &= 0xfe; reg_write_8(val, spi_base + LS1C_SPI_SFC_PARAM_OFFSET); - // spi flashʱƼĴ + // spi flash时序控制寄存器 reg_write_8(0x05, spi_base + LS1C_SPI_SFC_TIMING_OFFSET); } - + // baudrate ls1c_spi_set_clock(spi_base, configuration->max_hz); - // ͨģʽ(ʱӼԺλ) + // 设置通信模式(时钟极性和相位) if (configuration->mode & RT_SPI_CPOL) // cpol { cpol = SPI_CPOL_1; @@ -116,7 +116,7 @@ static rt_err_t configure(struct rt_spi_device *device, } -static rt_uint32_t xfer(struct rt_spi_device *device, +static rt_uint32_t xfer(struct rt_spi_device *device, struct rt_spi_message *message) { struct rt_spi_bus *spi_bus = NULL; @@ -149,7 +149,7 @@ static rt_uint32_t xfer(struct rt_spi_device *device, ls1c_spi_set_cs(spi_base, cs, 0); } - // շ + // 收发数据 send_ptr = message->send_buf; recv_ptr = message->recv_buf; while (size--) @@ -181,7 +181,7 @@ static rt_uint32_t xfer(struct rt_spi_device *device, #ifdef RT_USING_SPI0 -struct ls1c_spi ls1c_spi0 = +struct ls1c_spi ls1c_spi0 = { .SPIx = LS1C_SPI_0, }; @@ -191,7 +191,7 @@ static struct rt_spi_bus spi0_bus; #ifdef RT_USING_SPI1 -struct ls1c_spi ls1c_spi1 = +struct ls1c_spi ls1c_spi1 = { .SPIx = LS1C_SPI_1, }; @@ -201,10 +201,10 @@ static struct rt_spi_bus spi1_bus; /* - * ʼעо1cspi - * @SPI SPIߣLS1C_SPI_0 LS1C_SPI_1 - * @spi_bus_name - * @ret + * 初始化并注册龙芯1c的spi总线 + * @SPI SPI总线,比如LS1C_SPI_0, LS1C_SPI_1 + * @spi_bus_name 总线名字 + * @ret */ rt_err_t ls1c_spi_bus_register(rt_uint8_t SPI, const char *spi_bus_name) { @@ -237,15 +237,15 @@ int ls1c_hw_spi_init(void) pin_set_purpose(80, PIN_PURPOSE_OTHER); pin_set_purpose(83, PIN_PURPOSE_OTHER);//cs2 - SD card pin_set_purpose(82, PIN_PURPOSE_OTHER);//cs1 - pin_set_purpose(81, PIN_PURPOSE_OTHER);//cs0 - + pin_set_purpose(81, PIN_PURPOSE_OTHER);//cs0 + pin_set_remap(78, PIN_REMAP_DEFAULT); pin_set_remap(79, PIN_REMAP_DEFAULT); pin_set_remap(80, PIN_REMAP_DEFAULT); pin_set_remap(83, PIN_REMAP_DEFAULT);//cs2 - SD card pin_set_remap(82, PIN_REMAP_DEFAULT);//CS1 pin_set_remap(81, PIN_REMAP_DEFAULT);//cs0 - ls1c_spi_bus_register(LS1C_SPI_0,"spi0"); + ls1c_spi_bus_register(LS1C_SPI_0, "spi0"); #endif #ifdef RT_USING_SPI1 @@ -257,7 +257,7 @@ int ls1c_hw_spi_init(void) pin_set_remap(47, PIN_REMAP_THIRD); pin_set_remap(48, PIN_REMAP_THIRD); pin_set_remap(49, PIN_REMAP_THIRD);//CS0 - touch screen - ls1c_spi_bus_register(LS1C_SPI_1,"spi1"); + ls1c_spi_bus_register(LS1C_SPI_1, "spi1"); #endif @@ -265,30 +265,30 @@ int ls1c_hw_spi_init(void) #ifdef RT_USING_SPI0 /* attach cs */ { - static struct rt_spi_device spi_device0; + static struct rt_spi_device spi_device0; static struct rt_spi_device spi_device1; static struct rt_spi_device spi_device2; - static struct ls1c_spi_cs spi_cs0; + static struct ls1c_spi_cs spi_cs0; static struct ls1c_spi_cs spi_cs1; static struct ls1c_spi_cs spi_cs2; /* spi02: CS2 SD Card*/ spi_cs2.cs = LS1C_SPI_CS_2; - rt_spi_bus_attach_device(&spi_device2, "spi02", "spi0", (void*)&spi_cs2); + rt_spi_bus_attach_device(&spi_device2, "spi02", "spi0", (void *)&spi_cs2); spi_cs1.cs = LS1C_SPI_CS_1; - rt_spi_bus_attach_device(&spi_device1, "spi01", "spi0", (void*)&spi_cs1); - spi_cs0.cs = LS1C_SPI_CS_0; - rt_spi_bus_attach_device(&spi_device0, "spi00", "spi0", (void*)&spi_cs0); + rt_spi_bus_attach_device(&spi_device1, "spi01", "spi0", (void *)&spi_cs1); + spi_cs0.cs = LS1C_SPI_CS_0; + rt_spi_bus_attach_device(&spi_device0, "spi00", "spi0", (void *)&spi_cs0); } #endif -#ifdef RT_USING_SPI1 +#ifdef RT_USING_SPI1 { static struct rt_spi_device spi_device; static struct ls1c_spi_cs spi_cs; /* spi10: CS0 Touch*/ spi_cs.cs = LS1C_SPI_CS_0; - rt_spi_bus_attach_device(&spi_device, "spi10", "spi1", (void*)&spi_cs); + rt_spi_bus_attach_device(&spi_device, "spi10", "spi1", (void *)&spi_cs); } #endif }