Fix some compilation warning
This commit is contained in:
parent
b8bb6a4a87
commit
be842606d2
|
@ -19,144 +19,145 @@
|
|||
#endif
|
||||
|
||||
//#define DRV_DEBUG
|
||||
#define LOG_TAG "drv.flash"
|
||||
#define LOG_TAG "drv.flash"
|
||||
#include <drv_log.h>
|
||||
|
||||
/* Base address of the Flash sectors Bank 1 */
|
||||
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */
|
||||
|
||||
/* Base address of the Flash sectors Bank 2 */
|
||||
#define ADDR_FLASH_SECTOR_12 ((uint32_t)0x08100000) /* Base @ of Sector 0, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_13 ((uint32_t)0x08104000) /* Base @ of Sector 1, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_14 ((uint32_t)0x08108000) /* Base @ of Sector 2, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_15 ((uint32_t)0x0810C000) /* Base @ of Sector 3, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_16 ((uint32_t)0x08110000) /* Base @ of Sector 4, 64 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_17 ((uint32_t)0x08120000) /* Base @ of Sector 5, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_18 ((uint32_t)0x08140000) /* Base @ of Sector 6, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_19 ((uint32_t)0x08160000) /* Base @ of Sector 7, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_20 ((uint32_t)0x08180000) /* Base @ of Sector 8, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_21 ((uint32_t)0x081A0000) /* Base @ of Sector 9, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_22 ((uint32_t)0x081C0000) /* Base @ of Sector 10, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_23 ((uint32_t)0x081E0000) /* Base @ of Sector 11, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_12 ((uint32_t)0x08100000) /* Base @ of Sector 0, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_13 ((uint32_t)0x08104000) /* Base @ of Sector 1, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_14 ((uint32_t)0x08108000) /* Base @ of Sector 2, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_15 ((uint32_t)0x0810C000) /* Base @ of Sector 3, 16 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_16 ((uint32_t)0x08110000) /* Base @ of Sector 4, 64 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_17 ((uint32_t)0x08120000) /* Base @ of Sector 5, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_18 ((uint32_t)0x08140000) /* Base @ of Sector 6, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_19 ((uint32_t)0x08160000) /* Base @ of Sector 7, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_20 ((uint32_t)0x08180000) /* Base @ of Sector 8, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_21 ((uint32_t)0x081A0000) /* Base @ of Sector 9, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_22 ((uint32_t)0x081C0000) /* Base @ of Sector 10, 128 Kbytes */
|
||||
#define ADDR_FLASH_SECTOR_23 ((uint32_t)0x081E0000) /* Base @ of Sector 11, 128 Kbytes */
|
||||
|
||||
/**
|
||||
* @brief Gets the sector of a given address
|
||||
* @param None
|
||||
* @retval The sector of a given address
|
||||
*/
|
||||
* @brief Gets the sector of a given address
|
||||
* @param None
|
||||
* @retval The sector of a given address
|
||||
*/
|
||||
static rt_uint32_t GetSector(rt_uint32_t Address)
|
||||
{
|
||||
rt_uint32_t sector = 0;
|
||||
|
||||
if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
|
||||
if ((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
|
||||
{
|
||||
sector = FLASH_SECTOR_0;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1))
|
||||
{
|
||||
sector = FLASH_SECTOR_1;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2))
|
||||
{
|
||||
sector = FLASH_SECTOR_2;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3))
|
||||
{
|
||||
sector = FLASH_SECTOR_3;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4))
|
||||
{
|
||||
sector = FLASH_SECTOR_4;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5))
|
||||
{
|
||||
sector = FLASH_SECTOR_5;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6))
|
||||
{
|
||||
sector = FLASH_SECTOR_6;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7))
|
||||
{
|
||||
sector = FLASH_SECTOR_7;
|
||||
}
|
||||
#if defined(FLASH_SECTOR_8)
|
||||
else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8))
|
||||
{
|
||||
sector = FLASH_SECTOR_8;
|
||||
}
|
||||
#endif
|
||||
#if defined(FLASH_SECTOR_9)
|
||||
else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9))
|
||||
{
|
||||
sector = FLASH_SECTOR_9;
|
||||
}
|
||||
#endif
|
||||
#if defined(FLASH_SECTOR_10)
|
||||
else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10))
|
||||
{
|
||||
sector = FLASH_SECTOR_10;
|
||||
}
|
||||
#endif
|
||||
#if defined(FLASH_SECTOR_11)
|
||||
else if((Address < ADDR_FLASH_SECTOR_12) && (Address >= ADDR_FLASH_SECTOR_11))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_12) && (Address >= ADDR_FLASH_SECTOR_11))
|
||||
{
|
||||
sector = FLASH_SECTOR_11;
|
||||
}
|
||||
#endif
|
||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx)
|
||||
else if((Address < ADDR_FLASH_SECTOR_13) && (Address >= ADDR_FLASH_SECTOR_12))
|
||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) \
|
||||
|| defined(STM32F469xx) || defined(STM32F479xx)
|
||||
else if ((Address < ADDR_FLASH_SECTOR_13) && (Address >= ADDR_FLASH_SECTOR_12))
|
||||
{
|
||||
sector = FLASH_SECTOR_12;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_14) && (Address >= ADDR_FLASH_SECTOR_13))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_14) && (Address >= ADDR_FLASH_SECTOR_13))
|
||||
{
|
||||
sector = FLASH_SECTOR_13;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_15) && (Address >= ADDR_FLASH_SECTOR_14))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_15) && (Address >= ADDR_FLASH_SECTOR_14))
|
||||
{
|
||||
sector = FLASH_SECTOR_14;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_16) && (Address >= ADDR_FLASH_SECTOR_15))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_16) && (Address >= ADDR_FLASH_SECTOR_15))
|
||||
{
|
||||
sector = FLASH_SECTOR_15;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_17) && (Address >= ADDR_FLASH_SECTOR_16))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_17) && (Address >= ADDR_FLASH_SECTOR_16))
|
||||
{
|
||||
sector = FLASH_SECTOR_16;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_18) && (Address >= ADDR_FLASH_SECTOR_17))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_18) && (Address >= ADDR_FLASH_SECTOR_17))
|
||||
{
|
||||
sector = FLASH_SECTOR_17;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_19) && (Address >= ADDR_FLASH_SECTOR_18))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_19) && (Address >= ADDR_FLASH_SECTOR_18))
|
||||
{
|
||||
sector = FLASH_SECTOR_18;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_20) && (Address >= ADDR_FLASH_SECTOR_19))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_20) && (Address >= ADDR_FLASH_SECTOR_19))
|
||||
{
|
||||
sector = FLASH_SECTOR_19;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_21) && (Address >= ADDR_FLASH_SECTOR_20))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_21) && (Address >= ADDR_FLASH_SECTOR_20))
|
||||
{
|
||||
sector = FLASH_SECTOR_20;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_22) && (Address >= ADDR_FLASH_SECTOR_21))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_22) && (Address >= ADDR_FLASH_SECTOR_21))
|
||||
{
|
||||
sector = FLASH_SECTOR_21;
|
||||
}
|
||||
else if((Address < ADDR_FLASH_SECTOR_23) && (Address >= ADDR_FLASH_SECTOR_22))
|
||||
else if ((Address < ADDR_FLASH_SECTOR_23) && (Address >= ADDR_FLASH_SECTOR_22))
|
||||
{
|
||||
sector = FLASH_SECTOR_22;
|
||||
}
|
||||
|
@ -184,13 +185,13 @@ int stm32_flash_read(rt_uint32_t addr, rt_uint8_t *buf, size_t size)
|
|||
|
||||
if ((addr + size) > STM32_FLASH_END_ADDRESS)
|
||||
{
|
||||
LOG_E("read outrange flash size! addr is (0x%p)", (void*)(addr + size));
|
||||
LOG_E("read outrange flash size! addr is (0x%p)", (void *)(addr + size));
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++, buf++, addr++)
|
||||
{
|
||||
*buf = *(rt_uint8_t *) addr;
|
||||
*buf = *(rt_uint8_t *)addr;
|
||||
}
|
||||
|
||||
return size;
|
||||
|
@ -209,14 +210,14 @@ int stm32_flash_read(rt_uint32_t addr, rt_uint8_t *buf, size_t size)
|
|||
*/
|
||||
int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
rt_err_t result = RT_EOK;
|
||||
rt_uint32_t end_addr = addr + size;
|
||||
rt_uint32_t written_size = 0;
|
||||
rt_uint32_t write_size = 0;
|
||||
|
||||
if ((end_addr) > STM32_FLASH_END_ADDRESS)
|
||||
{
|
||||
LOG_E("write outrange flash size! addr is (0x%p)", (void*)(addr + size));
|
||||
LOG_E("write outrange flash size! addr is (0x%p)", (void *)(addr + size));
|
||||
return -RT_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -227,13 +228,16 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
|
|||
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
|
||||
| FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
||||
|
||||
while (written_size < size)
|
||||
{
|
||||
if (((addr + written_size) % 4 == 0) && (size - written_size >= 4))
|
||||
{
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, addr + written_size, *((rt_uint32_t *)(buf + written_size))) == HAL_OK)
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, addr + written_size,
|
||||
*((rt_uint32_t *)(buf + written_size)))
|
||||
== HAL_OK)
|
||||
{
|
||||
if (*(rt_uint32_t *)(addr + written_size) != *(rt_uint32_t *)(buf + written_size))
|
||||
{
|
||||
|
@ -250,7 +254,9 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
|
|||
}
|
||||
else if (((addr + written_size) % 2 == 0) && (size - written_size >= 2))
|
||||
{
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, addr + written_size, *((rt_uint16_t *)(buf + written_size))) == HAL_OK)
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, addr + written_size,
|
||||
*((rt_uint16_t *)(buf + written_size)))
|
||||
== HAL_OK)
|
||||
{
|
||||
if (*(rt_uint16_t *)(addr + written_size) != *(rt_uint16_t *)(buf + written_size))
|
||||
{
|
||||
|
@ -267,7 +273,9 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, addr + written_size, *((rt_uint8_t *)(buf + written_size))) == HAL_OK)
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, addr + written_size,
|
||||
*((rt_uint8_t *)(buf + written_size)))
|
||||
== HAL_OK)
|
||||
{
|
||||
if (*(rt_uint8_t *)(addr + written_size) != *(rt_uint8_t *)(buf + written_size))
|
||||
{
|
||||
|
@ -308,13 +316,13 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
|
|||
*/
|
||||
int stm32_flash_erase(rt_uint32_t addr, size_t size)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
rt_err_t result = RT_EOK;
|
||||
rt_uint32_t FirstSector = 0, NbOfSectors = 0;
|
||||
rt_uint32_t SECTORError = 0;
|
||||
|
||||
if ((addr + size) > STM32_FLASH_END_ADDRESS)
|
||||
{
|
||||
LOG_E("ERROR: erase outrange flash size! addr is (0x%p)\n", (void*)(addr + size));
|
||||
LOG_E("ERROR: erase outrange flash size! addr is (0x%p)\n", (void *)(addr + size));
|
||||
return -RT_EINVAL;
|
||||
}
|
||||
|
||||
|
@ -329,17 +337,18 @@ int stm32_flash_erase(rt_uint32_t addr, size_t size)
|
|||
/* Unlock the Flash to enable the flash control register access */
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
|
||||
| FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
||||
|
||||
/* Get the 1st sector to erase */
|
||||
FirstSector = GetSector(addr);
|
||||
/* Get the number of sector to erase from 1st sector*/
|
||||
NbOfSectors = GetSector(addr + size - 1) - FirstSector + 1;
|
||||
/* Fill EraseInit structure*/
|
||||
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
|
||||
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
|
||||
EraseInitStruct.Sector = FirstSector;
|
||||
EraseInitStruct.NbSectors = NbOfSectors;
|
||||
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
|
||||
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
|
||||
EraseInitStruct.Sector = FirstSector;
|
||||
EraseInitStruct.NbSectors = NbOfSectors;
|
||||
|
||||
if (HAL_FLASHEx_Erase(&EraseInitStruct, (uint32_t *)&SECTORError) != HAL_OK)
|
||||
{
|
||||
|
@ -355,7 +364,7 @@ __exit:
|
|||
return result;
|
||||
}
|
||||
|
||||
LOG_D("erase done: addr (0x%p), size %d", (void*)addr, size);
|
||||
LOG_D("erase done: addr (0x%p), size %d", (void *)addr, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -373,9 +382,27 @@ 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)
|
||||
{
|
||||
|
|
|
@ -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]))
|
||||
|
||||
static rt_base_t stm32_pin_get(const char *name)
|
||||
{
|
||||
|
@ -279,10 +279,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;
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
if ((0x01 << i) == bit)
|
||||
if (((rt_uint32_t)0x01 << i) == bit)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
@ -293,7 +293,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;
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ 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;
|
||||
}
|
||||
|
@ -351,7 +351,7 @@ 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;
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ 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;
|
||||
}
|
||||
|
@ -497,7 +497,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,
|
||||
|
|
|
@ -198,7 +198,7 @@ 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_uint32_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
i2c_obj[i].ops = stm32_bit_ops_default;
|
||||
i2c_obj[i].ops.data = (void*)&soft_i2c_config[i];
|
||||
|
|
|
@ -420,7 +420,7 @@ 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_uint32_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];
|
||||
|
|
|
@ -1132,7 +1132,7 @@ int rt_hw_usart_init(void)
|
|||
|
||||
stm32_uart_get_dma_config();
|
||||
|
||||
for (int i = 0; i < obj_num; i++)
|
||||
for (rt_uint32_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
/* init UART object */
|
||||
uart_obj[i].config = &uart_config[i];
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -157,7 +157,7 @@ int dfs_romfs_read(struct dfs_fd *file, void *buf, size_t count)
|
|||
|
||||
int dfs_romfs_lseek(struct dfs_fd *file, off_t offset)
|
||||
{
|
||||
if (offset <= file->size)
|
||||
if (offset <= (off_t)file->size)
|
||||
{
|
||||
file->pos = offset;
|
||||
return file->pos;
|
||||
|
@ -261,7 +261,7 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
|
|||
return -EINVAL;
|
||||
|
||||
index = 0;
|
||||
for (index = 0; index < count && file->pos < file->size; index ++)
|
||||
for (index = 0; index < count && file->pos < (off_t)file->size; index ++)
|
||||
{
|
||||
d = dirp + index;
|
||||
|
||||
|
@ -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 =
|
||||
{
|
||||
|
|
|
@ -10,17 +10,16 @@
|
|||
#include <rtthread.h>
|
||||
#include <dfs_romfs.h>
|
||||
|
||||
const static unsigned char _dummy_dummy_txt[] =
|
||||
{
|
||||
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a,
|
||||
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[] = {
|
||||
{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,
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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.");
|
||||
|
|
|
@ -372,7 +372,8 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
|
|||
{
|
||||
struct rt_i2c_msg *msg;
|
||||
struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv;
|
||||
rt_int32_t i, ret;
|
||||
rt_uint32_t i;
|
||||
rt_int32_t ret;
|
||||
rt_uint16_t ignore_nack;
|
||||
|
||||
if (num == 0) return 0;
|
||||
|
@ -404,7 +405,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)
|
||||
|
@ -416,7 +419,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)
|
||||
|
|
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ static int serial_fops_poll(struct dfs_fd *fd, struct rt_pollreq *req)
|
|||
return mask;
|
||||
}
|
||||
|
||||
const static struct dfs_file_ops _serial_fops =
|
||||
static const struct dfs_file_ops _serial_fops =
|
||||
{
|
||||
serial_fops_open,
|
||||
serial_fops_close,
|
||||
|
@ -893,7 +893,7 @@ struct speed_baudrate_item
|
|||
int baudrate;
|
||||
};
|
||||
|
||||
const static struct speed_baudrate_item _tbl[] =
|
||||
static const struct speed_baudrate_item _tbl[] =
|
||||
{
|
||||
{B2400, BAUD_RATE_2400},
|
||||
{B4800, BAUD_RATE_4800},
|
||||
|
@ -911,7 +911,7 @@ const static struct speed_baudrate_item _tbl[] =
|
|||
|
||||
static speed_t _get_speed(int baudrate)
|
||||
{
|
||||
int index;
|
||||
rt_uint32_t index;
|
||||
|
||||
for (index = 0; index < sizeof(_tbl)/sizeof(_tbl[0]); index ++)
|
||||
{
|
||||
|
@ -924,7 +924,7 @@ static speed_t _get_speed(int baudrate)
|
|||
|
||||
static int _get_baudrate(speed_t speed)
|
||||
{
|
||||
int index;
|
||||
rt_uint32_t index;
|
||||
|
||||
for (index = 0; index < sizeof(_tbl)/sizeof(_tbl[0]); index ++)
|
||||
{
|
||||
|
|
|
@ -264,7 +264,7 @@ static rt_err_t mtd_nor_dev_erase(struct rt_mtd_nor_device* device, rt_off_t off
|
|||
|
||||
ret = fal_partition_erase(part->fal_part, offset, length);
|
||||
|
||||
if (ret != length)
|
||||
if ((rt_uint32_t)ret != length)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
@ -556,7 +556,7 @@ static void fal(uint8_t argc, char **argv) {
|
|||
#define CMD_ERASE_INDEX 3
|
||||
#define CMD_BENCH_INDEX 4
|
||||
|
||||
int result;
|
||||
int result = 0;
|
||||
static const struct fal_flash_dev *flash_dev = NULL;
|
||||
static const struct fal_partition *part_dev = NULL;
|
||||
size_t i = 0, j = 0;
|
||||
|
@ -875,7 +875,7 @@ static void fal(uint8_t argc, char **argv) {
|
|||
result = fal_partition_read(part_dev, i, read_data, cur_op_size);
|
||||
}
|
||||
/* data check */
|
||||
for (int index = 0; index < cur_op_size; index ++)
|
||||
for (rt_uint32_t index = 0; index < cur_op_size; index ++)
|
||||
{
|
||||
if (write_data[index] != read_data[index])
|
||||
{
|
||||
|
|
|
@ -154,7 +154,7 @@ static int poll_do(struct pollfd *fds, nfds_t nfds, struct rt_poll_table *pt, in
|
|||
{
|
||||
int num;
|
||||
int istimeout = 0;
|
||||
int n;
|
||||
rt_uint32_t n;
|
||||
struct pollfd *pf;
|
||||
int ret = 0;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
|
|||
{
|
||||
rt_base_t level;
|
||||
uint16_t flags_mask;
|
||||
int index;
|
||||
rt_uint32_t index;
|
||||
|
||||
RT_ASSERT(netdev);
|
||||
RT_ASSERT(name);
|
||||
|
@ -706,7 +706,7 @@ void netdev_low_level_set_gw(struct netdev *netdev, const ip_addr_t *gw)
|
|||
*/
|
||||
void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server)
|
||||
{
|
||||
int index;
|
||||
uint32_t index;
|
||||
|
||||
RT_ASSERT(dns_server);
|
||||
|
||||
|
@ -1066,7 +1066,8 @@ int netdev_cmd_ping(char* target_name, char *netdev_name, rt_uint32_t times, rt_
|
|||
|
||||
struct netdev *netdev = RT_NULL;
|
||||
struct netdev_ping_resp ping_resp;
|
||||
int index, ret = 0;
|
||||
uint32_t index;
|
||||
int ret = 0;
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
|
@ -1172,7 +1173,7 @@ MSH_CMD_EXPORT_ALIAS(netdev_ping, ping, ping network host);
|
|||
|
||||
static void netdev_list_dns(void)
|
||||
{
|
||||
int index = 0;
|
||||
rt_uint32_t index = 0;
|
||||
struct netdev *netdev = RT_NULL;
|
||||
rt_slist_t *node = RT_NULL;
|
||||
|
||||
|
|
|
@ -158,7 +158,8 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
|
|||
#define SAL_INTERNET_MONTH_LEN 4
|
||||
#define SAL_INTERNET_DATE_LEN 16
|
||||
|
||||
int index, sockfd = -1, result = 0;
|
||||
rt_uint32_t index;
|
||||
int sockfd = -1, result = 0;
|
||||
struct sockaddr_in server_addr;
|
||||
struct hostent *host;
|
||||
struct timeval timeout;
|
||||
|
@ -168,7 +169,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
|
|||
|
||||
const char month[][SAL_INTERNET_MONTH_LEN] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
char date[SAL_INTERNET_DATE_LEN];
|
||||
int moth_num = 0;
|
||||
rt_uint32_t moth_num = 0;
|
||||
|
||||
struct sal_proto_family *pf = (struct sal_proto_family *) netdev->sal_user_data;
|
||||
const struct sal_socket_ops *skt_ops;
|
||||
|
@ -376,7 +377,8 @@ static void sal_unlock(void)
|
|||
*/
|
||||
int sal_netdev_cleanup(struct netdev *netdev)
|
||||
{
|
||||
int idx = 0, find_dev;
|
||||
uint32_t idx = 0;
|
||||
int find_dev;
|
||||
|
||||
do
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
void rt_hw_show_memory(rt_uint32_t addr, rt_uint32_t size)
|
||||
{
|
||||
int i = 0, j =0;
|
||||
rt_uint32_t i = 0, j =0;
|
||||
|
||||
RT_ASSERT(addr);
|
||||
|
||||
|
|
|
@ -247,7 +247,7 @@ RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
|
|||
char *src_ptr = (char *)src;
|
||||
long *aligned_dst;
|
||||
long *aligned_src;
|
||||
int len = count;
|
||||
rt_ubase_t len = count;
|
||||
|
||||
/* If the size is small, or either SRC or DST is unaligned,
|
||||
then punt into the byte copy loop. This should be rare. */
|
||||
|
|
|
@ -290,10 +290,14 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size)
|
|||
RT_ASSERT(rt_object_is_systemobject(&m->parent));
|
||||
|
||||
if (size != RT_ALIGN(size, RT_ALIGN_SIZE))
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d, but align to %d\n",
|
||||
size, RT_ALIGN(size, RT_ALIGN_SIZE)));
|
||||
}
|
||||
else
|
||||
{
|
||||
RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d\n", size));
|
||||
}
|
||||
|
||||
small_mem = (struct rt_small_mem *)m;
|
||||
/* alignment size */
|
||||
|
|
|
@ -820,7 +820,7 @@ static void _timer_thread_entry(void *parameter)
|
|||
*/
|
||||
void rt_system_timer_init(void)
|
||||
{
|
||||
int i;
|
||||
rt_uint32_t i;
|
||||
|
||||
for (i = 0; i < sizeof(_timer_list) / sizeof(_timer_list[0]); i++)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue