Skip to content

Commit

Permalink
[bsp][hc32][spi]update rt_hw_spi_device_attach
Browse files Browse the repository at this point in the history
  • Loading branch information
yangpengya authored and Rbb666 committed Dec 4, 2024
1 parent 60d7198 commit 0947a44
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 42 deletions.
5 changes: 2 additions & 3 deletions bsp/hc32/ev_hc32f448_lqfp80/board/ports/drv_spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
#define SPI_BUS_NAME "spi1"
#define SPI_FLASH_DEVICE_NAME "spi10"
#define SPI_FLASH_CHIP "w25q64"
#define SPI_FLASH_SS_PORT GPIO_PORT_C
#define SPI_FLASH_SS_PIN GPIO_PIN_07
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
/* Partition Name */
#define FS_PARTITION_NAME "filesystem"

Expand All @@ -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)
{
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))
{
Expand Down
5 changes: 2 additions & 3 deletions bsp/hc32/ev_hc32f460_lqfp100_v2/board/ports/drv_spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#define SPI_BUS_NAME "spi3"
#define SPI_FLASH_DEVICE_NAME "spi30"
#define SPI_FLASH_CHIP "w25q64"
#define SPI_FLASH_SS_PORT GPIO_PORT_C
#define SPI_FLASH_SS_PIN GPIO_PIN_07
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
/* Partition Name */
#define FS_PARTITION_NAME "filesystem"

Expand All @@ -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)
{
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))
{
Expand Down
5 changes: 2 additions & 3 deletions bsp/hc32/ev_hc32f4a0_lqfp176/board/ports/drv_spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#define SPI_BUS_NAME "spi1"
#define SPI_FLASH_DEVICE_NAME "spi10"
#define SPI_FLASH_CHIP "w25q64"
#define SPI_FLASH_SS_PORT GPIO_PORT_C
#define SPI_FLASH_SS_PIN GPIO_PIN_07
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
/* Partition Name */
#define FS_PARTITION_NAME "filesystem"

Expand All @@ -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)
{
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))
{
Expand Down
5 changes: 2 additions & 3 deletions bsp/hc32/lckfb-hc32f4a0-lqfp100/board/ports/drv_spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#define SPI_BUS_NAME "spi1"
#define SPI_FLASH_DEVICE_NAME "spi10"
#define SPI_FLASH_CHIP "w25q64"
#define SPI_FLASH_SS_PORT GPIO_PORT_A
#define SPI_FLASH_SS_PIN GPIO_PIN_04
#define SPI_FLASH_SS_PIN GET_PIN(A, 4)
/* Partition Name */
#define FS_PARTITION_NAME "filesystem"

Expand All @@ -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)
{
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))
{
Expand Down
19 changes: 4 additions & 15 deletions bsp/hc32/libraries/hc32_drivers/drv_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess
else
rt_pin_write(device->cs_pin, PIN_LOW);
}

LOG_D("%s transfer prepare and start", spi_drv->config->bus_name);
LOG_D("%s sendbuf: %X, recvbuf: %X, length: %d", spi_drv->config->bus_name,
(uint32_t)message->send_buf, (uint32_t)message->recv_buf, message->length);
Expand Down Expand Up @@ -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.
*/
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(device_name != RT_NULL);

rt_err_t result;
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*/
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
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);
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);

result = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);

if (result != RT_EOK)
{
Expand Down
9 changes: 1 addition & 8 deletions bsp/hc32/libraries/hc32_drivers/drv_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
extern "C" {
#endif


struct hc32_hw_spi_cs
{
rt_uint8_t port;
rt_uint16_t pin;
};

struct hc32_spi_irq_config
{
struct hc32_irq_config irq_config;
Expand Down Expand Up @@ -58,7 +51,7 @@ struct hc32_spi
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
Expand Down
11 changes: 4 additions & 7 deletions bsp/hc32/platform/sfud/drv_spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@
#define SPI_BUS_NAME "spi1"
#define SPI_FLASH_DEVICE_NAME "spi10"
#define SPI_FLASH_CHIP "w25q64"
#define SPI_FLASH_SS_PORT GPIO_PORT_C
#define SPI_FLASH_SS_PIN GPIO_PIN_07
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
#elif defined(HC32F460)
#define SPI_BUS_NAME "spi3"
#define SPI_FLASH_DEVICE_NAME "spi30"
#define SPI_FLASH_CHIP "w25q64"
#define SPI_FLASH_SS_PORT GPIO_PORT_C
#define SPI_FLASH_SS_PIN GPIO_PIN_07
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
#elif defined(HC32F472)
#define SPI_BUS_NAME "spi1"
#define SPI_FLASH_DEVICE_NAME "spi10"
#define SPI_FLASH_CHIP "w25q64"
#define SPI_FLASH_SS_PORT GPIO_PORT_B
#define SPI_FLASH_SS_PIN GPIO_PIN_12
#define SPI_FLASH_SS_PIN GET_PIN(B,12)
#endif
#define SPI_FLASH_CMD_ENABLE_RESET 0x66
#define SPI_FLASH_CMD_RESET_DEVICE 0x99
Expand Down Expand Up @@ -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)
{
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))
{
Expand Down

0 comments on commit 0947a44

Please sign in to comment.