Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions bsp/stm32/libraries/HAL_Drivers/drv_flash/drv_flash_f4.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -373,9 +373,48 @@ static int fal_flash_erase_16k(long offset, size_t size);
static int fal_flash_erase_64k(long offset, size_t size);
static int fal_flash_erase_128k(long offset, size_t size);

const struct fal_flash_dev stm32_onchip_flash_16k = { "onchip_flash_16k", STM32_FLASH_START_ADRESS_16K, FLASH_SIZE_GRANULARITY_16K, (16 * 1024), {NULL, fal_flash_read_16k, fal_flash_write_16k, fal_flash_erase_16k} };
const struct fal_flash_dev stm32_onchip_flash_64k = { "onchip_flash_64k", STM32_FLASH_START_ADRESS_64K, FLASH_SIZE_GRANULARITY_64K, (64 * 1024), {NULL, fal_flash_read_64k, fal_flash_write_64k, fal_flash_erase_64k} };
const struct fal_flash_dev stm32_onchip_flash_128k = { "onchip_flash_128k", STM32_FLASH_START_ADRESS_128K, FLASH_SIZE_GRANULARITY_128K, (128 * 1024), {NULL, fal_flash_read_128k, fal_flash_write_128k, fal_flash_erase_128k} };
const struct fal_flash_dev stm32_onchip_flash_16k =
{
"onchip_flash_16k",
STM32_FLASH_START_ADRESS_16K,
FLASH_SIZE_GRANULARITY_16K,
(16 * 1024),
{
NULL,
fal_flash_read_16k,
fal_flash_write_16k,
fal_flash_erase_16k,
},
8,
};
const struct fal_flash_dev stm32_onchip_flash_64k =
{
"onchip_flash_64k",
STM32_FLASH_START_ADRESS_64K,
FLASH_SIZE_GRANULARITY_64K,
(64 * 1024),
{
NULL,
fal_flash_read_64k,
fal_flash_write_64k,
fal_flash_erase_64k,
},
8,
};
const struct fal_flash_dev stm32_onchip_flash_128k =
{
"onchip_flash_128k",
STM32_FLASH_START_ADRESS_128K,
FLASH_SIZE_GRANULARITY_128K,
(128 * 1024),
{
NULL,
fal_flash_read_128k,
fal_flash_write_128k,
fal_flash_erase_128k,
},
8,
};

static int fal_flash_read_16k(long offset, rt_uint8_t *buf, size_t size)
{
Expand Down
30 changes: 15 additions & 15 deletions bsp/stm32/libraries/HAL_Drivers/drv_gpio.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -159,7 +159,7 @@ static struct rt_pin_irq_hdr pin_irq_hdr_tab[] =
};
static uint32_t pin_irq_enable_mask = 0;

#define ITEM_NUM(items) sizeof(items) / sizeof(items[0])
#define ITEM_NUM(items) (sizeof(items) / sizeof((items)[0]))

/* e.g. PE.7 */
static rt_base_t stm32_pin_get(const char *name)
Expand Down Expand Up @@ -280,10 +280,10 @@ static void stm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)

rt_inline rt_int32_t bit2bitno(rt_uint32_t bit)
{
rt_uint8_t i;
rt_int32_t i;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i的取值范围只有 0 ~ 32 有必要 32 位吗?

for (i = 0; i < 32; i++)
{
if ((0x01 << i) == bit)
if (((rt_uint32_t)0x01 << i) == bit)
{
return i;
}
Expand All @@ -294,7 +294,7 @@ rt_inline rt_int32_t bit2bitno(rt_uint32_t bit)
rt_inline const struct pin_irq_map *get_pin_irq_map(uint32_t pinbit)
{
rt_int32_t mapindex = bit2bitno(pinbit);
if (mapindex < 0 || mapindex >= ITEM_NUM(pin_irq_map))
if (mapindex < 0 || mapindex >= (rt_int32_t)ITEM_NUM(pin_irq_map))
{
return RT_NULL;
}
Expand All @@ -313,9 +313,9 @@ static rt_err_t stm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
}

irqindex = bit2bitno(PIN_STPIN(pin));
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
if (irqindex < 0 || irqindex >= (rt_int32_t)ITEM_NUM(pin_irq_map))
{
return RT_ENOSYS;
return -RT_ENOSYS;
}

level = rt_hw_interrupt_disable();
Expand All @@ -330,7 +330,7 @@ static rt_err_t stm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
if (pin_irq_hdr_tab[irqindex].pin != -1)
{
rt_hw_interrupt_enable(level);
return RT_EBUSY;
return -RT_EBUSY;
}
pin_irq_hdr_tab[irqindex].pin = pin;
pin_irq_hdr_tab[irqindex].hdr = hdr;
Expand All @@ -352,9 +352,9 @@ static rt_err_t stm32_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
}

irqindex = bit2bitno(PIN_STPIN(pin));
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
if (irqindex < 0 || irqindex >= (rt_int32_t)ITEM_NUM(pin_irq_map))
{
return RT_ENOSYS;
return -RT_ENOSYS;
}

level = rt_hw_interrupt_disable();
Expand Down Expand Up @@ -388,17 +388,17 @@ static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
if (enabled == PIN_IRQ_ENABLE)
{
irqindex = bit2bitno(PIN_STPIN(pin));
if (irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
if (irqindex < 0 || irqindex >= (rt_int32_t)ITEM_NUM(pin_irq_map))
{
return RT_ENOSYS;
return -RT_ENOSYS;
}

level = rt_hw_interrupt_disable();

if (pin_irq_hdr_tab[irqindex].pin == -1)
{
rt_hw_interrupt_enable(level);
return RT_ENOSYS;
return -RT_ENOSYS;
}

irqmap = &pin_irq_map[irqindex];
Expand Down Expand Up @@ -434,7 +434,7 @@ static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
irqmap = get_pin_irq_map(PIN_STPIN(pin));
if (irqmap == RT_NULL)
{
return RT_ENOSYS;
return -RT_ENOSYS;
}

level = rt_hw_interrupt_disable();
Expand Down Expand Up @@ -498,7 +498,7 @@ static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,

return RT_EOK;
}
const static struct rt_pin_ops _stm32_pin_ops =
static const struct rt_pin_ops _stm32_pin_ops =
{
stm32_pin_mode,
stm32_pin_write,
Expand Down
5 changes: 2 additions & 3 deletions bsp/stm32/libraries/HAL_Drivers/drv_soft_i2c.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -195,10 +195,9 @@ static rt_err_t stm32_i2c_bus_unlock(const struct stm32_soft_i2c_config *cfg)
/* I2C initialization function */
int rt_hw_i2c_init(void)
{
rt_size_t obj_num = sizeof(i2c_obj) / sizeof(struct stm32_i2c);
rt_err_t result;

for (int i = 0; i < obj_num; i++)
for (rt_size_t i = 0; i < sizeof(i2c_obj) / sizeof(struct stm32_i2c); i++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥要合并起来呀,感觉可读性还不如之前

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

节省一个内部变量

{
i2c_obj[i].ops = stm32_bit_ops_default;
i2c_obj[i].ops.data = (void*)&soft_i2c_config[i];
Expand Down
5 changes: 3 additions & 2 deletions bsp/stm32/libraries/HAL_Drivers/drv_spi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -446,7 +446,8 @@ static const struct rt_spi_ops stm_spi_ops =
static int rt_hw_spi_bus_init(void)
{
rt_err_t result;
for (int i = 0; i < sizeof(spi_config) / sizeof(spi_config[0]); i++)

for (rt_size_t i = 0; i < sizeof(spi_config) / sizeof(spi_config[0]); i++)
{
spi_bus_obj[i].config = &spi_config[i];
spi_bus_obj[i].spi_bus.parent.user_data = &spi_config[i];
Expand Down
5 changes: 2 additions & 3 deletions bsp/stm32/libraries/HAL_Drivers/drv_usart.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -1156,13 +1156,12 @@ static const struct rt_uart_ops stm32_uart_ops =

int rt_hw_usart_init(void)
{
rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct stm32_uart);
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
rt_err_t result = 0;

stm32_uart_get_dma_config();

for (int i = 0; i < obj_num; i++)
for (rt_size_t i = 0; i < sizeof(uart_obj) / sizeof(struct stm32_uart); i++)
{
/* init UART object */
uart_obj[i].config = &uart_config[i];
Expand Down
7 changes: 4 additions & 3 deletions components/dfs/filesystems/romfs/dfs_romfs.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -40,7 +40,7 @@ int dfs_romfs_ioctl(struct dfs_fd *file, int cmd, void *args)
rt_inline int check_dirent(struct romfs_dirent *dirent)
{
if ((dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR)
|| dirent->size == ~0)
|| dirent->size == ~0U)
return -1;
return 0;
}
Expand Down Expand Up @@ -84,7 +84,7 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch
{
if (check_dirent(&dirent[index]) != 0)
return NULL;
if (rt_strlen(dirent[index].name) == (subpath_end - subpath) &&
if (rt_strlen(dirent[index].name) == (rt_size_t)(subpath_end - subpath) &&
rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0)
{
dirent_size = dirent[index].size;
Expand Down Expand Up @@ -295,6 +295,7 @@ static const struct dfs_file_ops _rom_fops =
NULL,
dfs_romfs_lseek,
dfs_romfs_getdents,
NULL,
};
static const struct dfs_filesystem_ops _romfs =
{
Expand Down
8 changes: 4 additions & 4 deletions components/dfs/filesystems/romfs/romfs.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -10,17 +10,17 @@
#include <rtthread.h>
#include <dfs_romfs.h>

const static unsigned char _dummy_dummy_txt[] =
static const unsigned char _dummy_dummy_txt[] =
{
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a,
};

const static struct romfs_dirent _dummy[] =
static const struct romfs_dirent _dummy[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分代码是脚本自动生成的,如果要修改,后面最好把tool目录下的脚本也修改了。要不然下次生成又被还原了。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这就是下一个pr了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块应该是要改一下脚本吧 脚本生成的有问题 确实应该是static关键字在前 const在后

Copy link
Member

@mysterywolf mysterywolf Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确认了 脚本没啥问题

{
{ROMFS_DIRENT_FILE, "dummy.txt", _dummy_dummy_txt, sizeof(_dummy_dummy_txt)},
};

const static unsigned char _dummy_txt[] =
static const unsigned char _dummy_txt[] =
{
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a,
};
Expand Down
8 changes: 4 additions & 4 deletions components/dfs/src/dfs.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -132,7 +132,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd)
}

/* allocate a larger FD container */
if (idx == fdt->maxfd && fdt->maxfd < DFS_FD_MAX)
if (idx == (int)fdt->maxfd && fdt->maxfd < DFS_FD_MAX)
{
int cnt, index;
struct dfs_fd **fds;
Expand All @@ -145,7 +145,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd)
if (fds == NULL) goto __exit; /* return fdt->maxfd */

/* clean the new allocated fds */
for (index = fdt->maxfd; index < cnt; index ++)
for (index = (int)fdt->maxfd; index < cnt; index ++)
{
fds[index] = NULL;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ int fd_new(void)
idx = fd_alloc(fdt, 0);

/* can't find an empty fd entry */
if (idx == fdt->maxfd)
if (idx == (int)fdt->maxfd)
{
idx = -(1 + DFS_FD_OFFSET);
LOG_E("DFS fd new is failed! Could not found an empty fd entry.");
Expand Down
6 changes: 5 additions & 1 deletion components/drivers/i2c/i2c-bit-ops.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -404,7 +404,9 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
{
ret = i2c_recv_bytes(bus, msg);
if (ret >= 1)
{
LOG_D("read %d byte%s", ret, ret == 1 ? "" : "s");
}
if (ret < msg->len)
{
if (ret >= 0)
Expand All @@ -416,7 +418,9 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
{
ret = i2c_send_bytes(bus, msg);
if (ret >= 1)
{
LOG_D("write %d byte%s", ret, ret == 1 ? "" : "s");
}
if (ret < msg->len)
{
if (ret >= 0)
Expand Down
6 changes: 3 additions & 3 deletions components/drivers/i2c/i2c_core.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -108,7 +108,7 @@ rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus,
const rt_uint8_t *buf,
rt_uint32_t count)
{
rt_err_t ret;
rt_size_t ret;
struct rt_i2c_msg msg;

msg.addr = addr;
Expand All @@ -127,7 +127,7 @@ rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
rt_uint8_t *buf,
rt_uint32_t count)
{
rt_err_t ret;
rt_size_t ret;
struct rt_i2c_msg msg;
RT_ASSERT(bus != RT_NULL);

Expand Down
Loading