From 0667139d7eeb25a86572b69c6fd62686fd1b578f Mon Sep 17 00:00:00 2001 From: liangkangnan Date: Wed, 29 Sep 2021 09:26:57 +0800 Subject: [PATCH] sdk:examples: remove spi_master2 Signed-off-by: liangkangnan --- sdk/examples/spi_master2/.gitignore | 8 -- sdk/examples/spi_master2/Makefile | 21 ----- sdk/examples/spi_master2/README.md | 1 - sdk/examples/spi_master2/flash_w25q.c | 116 -------------------------- sdk/examples/spi_master2/flash_w25q.h | 24 ------ sdk/examples/spi_master2/main.c | 44 ---------- 6 files changed, 214 deletions(-) delete mode 100644 sdk/examples/spi_master2/.gitignore delete mode 100644 sdk/examples/spi_master2/Makefile delete mode 100644 sdk/examples/spi_master2/README.md delete mode 100644 sdk/examples/spi_master2/flash_w25q.c delete mode 100644 sdk/examples/spi_master2/flash_w25q.h delete mode 100644 sdk/examples/spi_master2/main.c diff --git a/sdk/examples/spi_master2/.gitignore b/sdk/examples/spi_master2/.gitignore deleted file mode 100644 index 80a4578..0000000 --- a/sdk/examples/spi_master2/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Object files -*.o -*.ko -*.obj -*.bin -*.dump -*.mem -spi_master diff --git a/sdk/examples/spi_master2/Makefile b/sdk/examples/spi_master2/Makefile deleted file mode 100644 index e5f03e7..0000000 --- a/sdk/examples/spi_master2/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -RISCV_ARCH := rv32im -RISCV_ABI := ilp32 -RISCV_MCMODEL := medlow - - -TARGET = spi_master - - -#CFLAGS += -DSIMULATION -#CFLAGS += -O2 -#ASM_SRCS += -#LDFLAGS += -#INCLUDES += -I. - -C_SRCS := \ - main.c \ - flash_w25q.c - - -BSP_DIR = ../../bsp -include ../../bsp/bsp.mk diff --git a/sdk/examples/spi_master2/README.md b/sdk/examples/spi_master2/README.md deleted file mode 100644 index 9f12e40..0000000 --- a/sdk/examples/spi_master2/README.md +++ /dev/null @@ -1 +0,0 @@ -spi_master例程。 \ No newline at end of file diff --git a/sdk/examples/spi_master2/flash_w25q.c b/sdk/examples/spi_master2/flash_w25q.c deleted file mode 100644 index 89a0358..0000000 --- a/sdk/examples/spi_master2/flash_w25q.c +++ /dev/null @@ -1,116 +0,0 @@ -#include - -#include "../../bsp/include/spi.h" -#include "../../bsp/include/rvic.h" -#include "../../bsp/include/utils.h" -#include "flash_w25q.h" - - -void flash_w25q_init(uint16_t clk_div) -{ - spi0_set_clk_div(clk_div); - spi0_set_role_mode(SPI_ROLE_MODE_MASTER); - spi0_set_spi_mode(SPI_MODE_STANDARD); - spi0_set_cp_mode(SPI_CPOL_0_CPHA_0); - spi0_set_msb_first(); - spi0_master_set_ss_delay(1); - spi0_set_ss_level(1); - spi0_set_ss_ctrl_by_sw(1); - spi0_set_enable(1); -} - -uint8_t flash_w25q_read_reg(uint8_t cmd) -{ - uint8_t data; - - spi0_set_ss_level(0); - spi0_master_write_bytes(&cmd, 1); - spi0_master_read_bytes(&data, 1); - spi0_set_ss_level(1); - - return data; -} - -uint8_t flash_w25q_write_reg(uint8_t cmd, uint8_t data) -{ - spi0_set_ss_level(0); - spi0_master_write_bytes(&cmd, 1); - spi0_master_write_bytes(&data, 1); - spi0_set_ss_level(1); -} - -uint8_t flash_w25q_send_cmd(uint8_t cmd) -{ - spi0_set_ss_level(0); - spi0_master_write_bytes(&cmd, 1); - spi0_set_ss_level(1); -} - -void flash_w25q_volatile_status_reg_write_enable() -{ - flash_w25q_send_cmd(CMD_WRITE_ENABLE_FOR_VOL_STATUS_REG); -} - -// 读flash ID -w25q_id_t flash_w25q_read_id() -{ - w25q_id_t id; - uint8_t cmd; - uint8_t data[2]; - uint8_t addr[3]; - - cmd = CMD_READ_ID; - addr[0] = 0x0; - addr[1] = 0x0; - addr[2] = 0x0; - - spi0_set_ss_level(0); - spi0_master_write_bytes(&cmd, 1); - spi0_master_write_bytes(addr, 3); - spi0_master_read_bytes(data, 2); - spi0_set_ss_level(1); - - id.manf_id = data[0]; - id.device_id = data[1]; - - return id; -} - -void flash_w25q_enable_qspi(uint8_t en) -{ - uint8_t data; - - flash_w25q_volatile_status_reg_write_enable(); - data = flash_w25q_read_reg(CMD_READ_STATUS_REG2); - if (en) - data |= 1 << 1; - else - data &= ~(1 << 1); - flash_w25q_write_reg(CMD_WRITE_STATUS_REG2, data); -} - -w25q_id_t flash_w25q_read_id_quad() -{ - w25q_id_t id; - uint8_t cmd; - uint8_t data[2]; - uint8_t addr[3]; - - cmd = CMD_READ_ID_QUAD; - addr[0] = 0x0; - addr[1] = 0x0; - addr[2] = 0x0; - - spi0_set_ss_level(0); - spi0_master_write_bytes(&cmd, 1); - spi0_set_spi_mode(SPI_MODE_QUAD); - spi0_master_write_bytes(addr, 3); - spi0_master_read_bytes(data, 2); - spi0_master_read_bytes(data, 2); - spi0_set_ss_level(1); - - id.manf_id = data[0]; - id.device_id = data[1]; - - return id; -} diff --git a/sdk/examples/spi_master2/flash_w25q.h b/sdk/examples/spi_master2/flash_w25q.h deleted file mode 100644 index 219811e..0000000 --- a/sdk/examples/spi_master2/flash_w25q.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _FLASH_W25Q_H_ -#define _FLASH_W25Q_H_ - - - -#define CMD_READ_ID (0x90) -#define CMD_READ_ID_QUAD (0x94) -#define CMD_READ_STATUS_REG2 (0x35) -#define CMD_WRITE_STATUS_REG2 (0x31) -#define CMD_WRITE_ENABLE_FOR_VOL_STATUS_REG (0x50) - - -typedef struct { - uint8_t manf_id; - uint8_t device_id; -} w25q_id_t; - -void flash_w25q_init(uint16_t clk_div); -w25q_id_t flash_w25q_read_id(); -void flash_w25q_enable_qspi(uint8_t en); -w25q_id_t flash_w25q_read_id_quad(); - - -#endif diff --git a/sdk/examples/spi_master2/main.c b/sdk/examples/spi_master2/main.c deleted file mode 100644 index 9087f3c..0000000 --- a/sdk/examples/spi_master2/main.c +++ /dev/null @@ -1,44 +0,0 @@ -#include - -#include "../../bsp/include/uart.h" -#include "../../bsp/include/spi.h" -#include "../../bsp/include/xprintf.h" -#include "../../bsp/include/utils.h" -#include "../../bsp/include/rvic.h" -#include "../../bsp/include/pinmux.h" -#include "../../bsp/include/sim_ctrl.h" -#include "flash_w25q.h" - - - -int main() -{ - w25q_id_t id; - - pinmux_set_io0_func(IO0_UART0_TX); - pinmux_set_io3_func(IO3_UART0_RX); - - pinmux_set_io6_func(IO6_SPI_CLK); - pinmux_set_io8_func(IO8_SPI_SS); - pinmux_set_io1_func(IO1_SPI_DQ0); - pinmux_set_io2_func(IO2_SPI_DQ1); - pinmux_set_io4_func(IO4_SPI_DQ2); - pinmux_set_io5_func(IO5_SPI_DQ3); - - uart0_init(uart0_putc); - flash_w25q_init(5); - - xprintf("read id:\n"); - id = flash_w25q_read_id(); - xprintf("manf id = 0x%2x\n", id.manf_id); - xprintf("device id = 0x%2x\n", id.device_id); - - flash_w25q_enable_qspi(1); - xprintf("quad read id:\n"); - id = flash_w25q_read_id_quad(); - xprintf("manf id = 0x%2x\n", id.manf_id); - xprintf("device id = 0x%2x\n", id.device_id); - flash_w25q_enable_qspi(0); - - while (1); -}