[bsp][hc32][spi]update rt_hw_spi_device_attach
This commit is contained in:
parent
60d7198da0
commit
0947a44658
@ -27,8 +27,7 @@
|
|||||||
#define SPI_BUS_NAME "spi1"
|
#define SPI_BUS_NAME "spi1"
|
||||||
#define SPI_FLASH_DEVICE_NAME "spi10"
|
#define SPI_FLASH_DEVICE_NAME "spi10"
|
||||||
#define SPI_FLASH_CHIP "w25q64"
|
#define SPI_FLASH_CHIP "w25q64"
|
||||||
#define SPI_FLASH_SS_PORT GPIO_PORT_C
|
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
|
||||||
#define SPI_FLASH_SS_PIN GPIO_PIN_07
|
|
||||||
/* Partition Name */
|
/* Partition Name */
|
||||||
#define FS_PARTITION_NAME "filesystem"
|
#define FS_PARTITION_NAME "filesystem"
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
|
|||||||
|
|
||||||
static int rt_hw_spi_flash_with_sfud_init(void)
|
static int rt_hw_spi_flash_with_sfud_init(void)
|
||||||
{
|
{
|
||||||
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
|
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
|
||||||
|
|
||||||
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
||||||
{
|
{
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
#define SPI_BUS_NAME "spi3"
|
#define SPI_BUS_NAME "spi3"
|
||||||
#define SPI_FLASH_DEVICE_NAME "spi30"
|
#define SPI_FLASH_DEVICE_NAME "spi30"
|
||||||
#define SPI_FLASH_CHIP "w25q64"
|
#define SPI_FLASH_CHIP "w25q64"
|
||||||
#define SPI_FLASH_SS_PORT GPIO_PORT_C
|
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
|
||||||
#define SPI_FLASH_SS_PIN GPIO_PIN_07
|
|
||||||
/* Partition Name */
|
/* Partition Name */
|
||||||
#define FS_PARTITION_NAME "filesystem"
|
#define FS_PARTITION_NAME "filesystem"
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
|
|||||||
|
|
||||||
static int rt_hw_spi_flash_with_sfud_init(void)
|
static int rt_hw_spi_flash_with_sfud_init(void)
|
||||||
{
|
{
|
||||||
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
|
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
|
||||||
|
|
||||||
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
||||||
{
|
{
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
#define SPI_BUS_NAME "spi1"
|
#define SPI_BUS_NAME "spi1"
|
||||||
#define SPI_FLASH_DEVICE_NAME "spi10"
|
#define SPI_FLASH_DEVICE_NAME "spi10"
|
||||||
#define SPI_FLASH_CHIP "w25q64"
|
#define SPI_FLASH_CHIP "w25q64"
|
||||||
#define SPI_FLASH_SS_PORT GPIO_PORT_C
|
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
|
||||||
#define SPI_FLASH_SS_PIN GPIO_PIN_07
|
|
||||||
/* Partition Name */
|
/* Partition Name */
|
||||||
#define FS_PARTITION_NAME "filesystem"
|
#define FS_PARTITION_NAME "filesystem"
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
|
|||||||
|
|
||||||
static int rt_hw_spi_flash_with_sfud_init(void)
|
static int rt_hw_spi_flash_with_sfud_init(void)
|
||||||
{
|
{
|
||||||
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
|
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
|
||||||
|
|
||||||
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
||||||
{
|
{
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
#define SPI_BUS_NAME "spi1"
|
#define SPI_BUS_NAME "spi1"
|
||||||
#define SPI_FLASH_DEVICE_NAME "spi10"
|
#define SPI_FLASH_DEVICE_NAME "spi10"
|
||||||
#define SPI_FLASH_CHIP "w25q64"
|
#define SPI_FLASH_CHIP "w25q64"
|
||||||
#define SPI_FLASH_SS_PORT GPIO_PORT_A
|
#define SPI_FLASH_SS_PIN GET_PIN(A, 4)
|
||||||
#define SPI_FLASH_SS_PIN GPIO_PIN_04
|
|
||||||
/* Partition Name */
|
/* Partition Name */
|
||||||
#define FS_PARTITION_NAME "filesystem"
|
#define FS_PARTITION_NAME "filesystem"
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
|
|||||||
|
|
||||||
static int rt_hw_spi_flash_with_sfud_init(void)
|
static int rt_hw_spi_flash_with_sfud_init(void)
|
||||||
{
|
{
|
||||||
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
|
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
|
||||||
|
|
||||||
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
||||||
{
|
{
|
||||||
|
@ -637,30 +637,19 @@ static const struct rt_spi_ops hc32_spi_ops =
|
|||||||
/**
|
/**
|
||||||
* Attach the spi device to SPI bus, this function must be used after initialization.
|
* Attach the spi device to SPI bus, this function must be used after initialization.
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, uint8_t cs_gpio_port, uint16_t cs_gpio_pin)
|
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin)
|
||||||
{
|
{
|
||||||
RT_ASSERT(bus_name != RT_NULL);
|
RT_ASSERT(bus_name != RT_NULL);
|
||||||
RT_ASSERT(device_name != RT_NULL);
|
RT_ASSERT(device_name != RT_NULL);
|
||||||
|
|
||||||
rt_err_t result;
|
rt_err_t result;
|
||||||
struct rt_spi_device *spi_device;
|
struct rt_spi_device *spi_device;
|
||||||
struct hc32_hw_spi_cs *cs_pin;
|
|
||||||
stc_gpio_init_t stcGpioInit;
|
|
||||||
|
|
||||||
GPIO_StructInit(&stcGpioInit);
|
|
||||||
stcGpioInit.u16PinState = PIN_STAT_SET;
|
|
||||||
stcGpioInit.u16PinDir = PIN_DIR_OUT;
|
|
||||||
stcGpioInit.u16PullUp = PIN_PU_ON;
|
|
||||||
GPIO_Init(cs_gpio_port, cs_gpio_pin, &stcGpioInit);
|
|
||||||
|
|
||||||
/* attach the device to spi bus*/
|
/* attach the device to spi bus*/
|
||||||
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
|
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
|
||||||
RT_ASSERT(spi_device != RT_NULL);
|
RT_ASSERT(spi_device != RT_NULL);
|
||||||
cs_pin = (struct hc32_hw_spi_cs *)rt_malloc(sizeof(struct hc32_hw_spi_cs));
|
|
||||||
RT_ASSERT(cs_pin != RT_NULL);
|
result = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);
|
||||||
cs_pin->port = cs_gpio_port;
|
|
||||||
cs_pin->pin = cs_gpio_pin;
|
|
||||||
result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
|
|
||||||
|
|
||||||
if (result != RT_EOK)
|
if (result != RT_EOK)
|
||||||
{
|
{
|
||||||
|
@ -24,13 +24,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct hc32_hw_spi_cs
|
|
||||||
{
|
|
||||||
rt_uint8_t port;
|
|
||||||
rt_uint16_t pin;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct hc32_spi_irq_config
|
struct hc32_spi_irq_config
|
||||||
{
|
{
|
||||||
struct hc32_irq_config irq_config;
|
struct hc32_irq_config irq_config;
|
||||||
@ -58,7 +51,7 @@ struct hc32_spi
|
|||||||
rt_uint16_t spi_dma_flag;
|
rt_uint16_t spi_dma_flag;
|
||||||
};
|
};
|
||||||
|
|
||||||
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, uint8_t cs_gpio_port, uint16_t cs_gpio_pin);
|
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -27,20 +27,17 @@
|
|||||||
#define SPI_BUS_NAME "spi1"
|
#define SPI_BUS_NAME "spi1"
|
||||||
#define SPI_FLASH_DEVICE_NAME "spi10"
|
#define SPI_FLASH_DEVICE_NAME "spi10"
|
||||||
#define SPI_FLASH_CHIP "w25q64"
|
#define SPI_FLASH_CHIP "w25q64"
|
||||||
#define SPI_FLASH_SS_PORT GPIO_PORT_C
|
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
|
||||||
#define SPI_FLASH_SS_PIN GPIO_PIN_07
|
|
||||||
#elif defined(HC32F460)
|
#elif defined(HC32F460)
|
||||||
#define SPI_BUS_NAME "spi3"
|
#define SPI_BUS_NAME "spi3"
|
||||||
#define SPI_FLASH_DEVICE_NAME "spi30"
|
#define SPI_FLASH_DEVICE_NAME "spi30"
|
||||||
#define SPI_FLASH_CHIP "w25q64"
|
#define SPI_FLASH_CHIP "w25q64"
|
||||||
#define SPI_FLASH_SS_PORT GPIO_PORT_C
|
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
|
||||||
#define SPI_FLASH_SS_PIN GPIO_PIN_07
|
|
||||||
#elif defined(HC32F472)
|
#elif defined(HC32F472)
|
||||||
#define SPI_BUS_NAME "spi1"
|
#define SPI_BUS_NAME "spi1"
|
||||||
#define SPI_FLASH_DEVICE_NAME "spi10"
|
#define SPI_FLASH_DEVICE_NAME "spi10"
|
||||||
#define SPI_FLASH_CHIP "w25q64"
|
#define SPI_FLASH_CHIP "w25q64"
|
||||||
#define SPI_FLASH_SS_PORT GPIO_PORT_B
|
#define SPI_FLASH_SS_PIN GET_PIN(B,12)
|
||||||
#define SPI_FLASH_SS_PIN GPIO_PIN_12
|
|
||||||
#endif
|
#endif
|
||||||
#define SPI_FLASH_CMD_ENABLE_RESET 0x66
|
#define SPI_FLASH_CMD_ENABLE_RESET 0x66
|
||||||
#define SPI_FLASH_CMD_RESET_DEVICE 0x99
|
#define SPI_FLASH_CMD_RESET_DEVICE 0x99
|
||||||
@ -72,7 +69,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
|
|||||||
|
|
||||||
static int rt_hw_spi_flash_with_sfud_init(void)
|
static int rt_hw_spi_flash_with_sfud_init(void)
|
||||||
{
|
{
|
||||||
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
|
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
|
||||||
|
|
||||||
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user