sdk:examples: remove spi_master2

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/4/head
liangkangnan 2021-09-29 09:26:57 +08:00
parent 2d9aab4ecb
commit 0667139d7e
6 changed files with 0 additions and 214 deletions

View File

@ -1,8 +0,0 @@
# Object files
*.o
*.ko
*.obj
*.bin
*.dump
*.mem
spi_master

View File

@ -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

View File

@ -1 +0,0 @@
spi_master例程。

View File

@ -1,116 +0,0 @@
#include <stdint.h>
#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;
}

View File

@ -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

View File

@ -1,44 +0,0 @@
#include <stdint.h>
#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);
}