diff --git a/doc/hal/reports/misra.txt b/doc/hal/reports/misra.txt index 8fc03efec..c381f9c26 100644 --- a/doc/hal/reports/misra.txt +++ b/doc/hal/reports/misra.txt @@ -1,19 +1,25 @@ --- Module: ..\..\..\os\hal\src\hal.c (C) +--- Module: ..\..\..\os\hal\src\hal_st.c (C) + --- Module: ..\..\..\os\hal\src\hal_buffers.c (C) --- Module: ..\..\..\os\hal\src\hal_queues.c (C) +--- Module: ..\..\..\os\hal\src\hal_flash.c (C) + --- Module: ..\..\..\os\hal\src\hal_mmcsd.c (C) --- Module: ..\..\..\os\hal\src\hal_adc.c (C) --- Module: ..\..\..\os\hal\src\hal_can.c (C) +--- Module: ..\..\..\os\hal\src\hal_crypto.c (C) + --- Module: ..\..\..\os\hal\src\hal_dac.c (C) ---- Module: ..\..\..\os\hal\src\hal_ext.c (C) +--- Module: ..\..\..\os\hal\src\hal_efl.c (C) --- Module: ..\..\..\os\hal\src\hal_gpt.c (C) @@ -31,8 +37,6 @@ --- Module: ..\..\..\os\hal\src\hal_pwm.c (C) ---- Module: ..\..\..\os\hal\src\hal_qspi.c (C) - --- Module: ..\..\..\os\hal\src\hal_rtc.c (C) --- Module: ..\..\..\os\hal\src\hal_sdc.c (C) @@ -41,9 +45,11 @@ --- Module: ..\..\..\os\hal\src\hal_serial_usb.c (C) +--- Module: ..\..\..\os\hal\src\hal_sio.c (C) + --- Module: ..\..\..\os\hal\src\hal_spi.c (C) ---- Module: ..\..\..\os\hal\src\hal_st.c (C) +--- Module: ..\..\..\os\hal\src\hal_trng.c (C) --- Module: ..\..\..\os\hal\src\hal_uart.c (C) @@ -51,6 +57,8 @@ --- Module: ..\..\..\os\hal\src\hal_wdg.c (C) +--- Module: ..\..\..\os\hal\src\hal_wspi.c (C) + --- Module: ..\..\..\os\hal\templates\osal\osal.c (C) --- Module: ..\..\..\os\hal\templates\hal_lld.c (C) @@ -59,9 +67,11 @@ --- Module: ..\..\..\os\hal\templates\hal_can_lld.c (C) +--- Module: ..\..\..\os\hal\templates\hal_crypto_lld.c (C) + --- Module: ..\..\..\os\hal\templates\hal_dac_lld.c (C) ---- Module: ..\..\..\os\hal\templates\hal_ext_lld.c (C) +--- Module: ..\..\..\os\hal\templates\hal_efl_lld.c (C) --- Module: ..\..\..\os\hal\templates\hal_gpt_lld.c (C) @@ -77,20 +87,24 @@ --- Module: ..\..\..\os\hal\templates\hal_pwm_lld.c (C) ---- Module: ..\..\..\os\hal\templates\hal_qspi_lld.c (C) - --- Module: ..\..\..\os\hal\templates\hal_rtc_lld.c (C) --- Module: ..\..\..\os\hal\templates\hal_sdc_lld.c (C) --- Module: ..\..\..\os\hal\templates\hal_serial_lld.c (C) +--- Module: ..\..\..\os\hal\templates\hal_sio_lld.c (C) + --- Module: ..\..\..\os\hal\templates\hal_spi_lld.c (C) --- Module: ..\..\..\os\hal\templates\hal_st_lld.c (C) +--- Module: ..\..\..\os\hal\templates\hal_trng_lld.c (C) + --- Module: ..\..\..\os\hal\templates\hal_uart_lld.c (C) --- Module: ..\..\..\os\hal\templates\hal_usb_lld.c (C) --- Module: ..\..\..\os\hal\templates\hal_wdg_lld.c (C) + +--- Module: ..\..\..\os\hal\templates\hal_wspi_lld.c (C) diff --git a/os/hal/ports/STM32/STM32F4xx/hal_efl_lld.h b/os/hal/ports/STM32/STM32F4xx/hal_efl_lld.h index 73e1cee37..d13876496 100644 --- a/os/hal/ports/STM32/STM32F4xx/hal_efl_lld.h +++ b/os/hal/ports/STM32/STM32F4xx/hal_efl_lld.h @@ -120,7 +120,7 @@ extern "C" { flash_error_t efl_lld_start_erase_all(void *instance); flash_error_t efl_lld_start_erase_sector(void *instance, flash_sector_t sector); - flash_error_t efl_lld_query_erase(void *instance, uint32_t *wait_time); + flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec); flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector); #ifdef __cplusplus } diff --git a/os/hal/ports/STM32/STM32G0xx/hal_efl_lld.h b/os/hal/ports/STM32/STM32G0xx/hal_efl_lld.h index 3b4bbdf0a..d8119ee12 100644 --- a/os/hal/ports/STM32/STM32G0xx/hal_efl_lld.h +++ b/os/hal/ports/STM32/STM32G0xx/hal_efl_lld.h @@ -131,7 +131,7 @@ extern "C" { flash_error_t efl_lld_start_erase_all(void *instance); flash_error_t efl_lld_start_erase_sector(void *instance, flash_sector_t sector); - flash_error_t efl_lld_query_erase(void *instance, uint32_t *wait_time); + flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec); flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector); #ifdef __cplusplus } diff --git a/os/hal/ports/STM32/STM32L4xx+/hal_efl_lld.h b/os/hal/ports/STM32/STM32L4xx+/hal_efl_lld.h index e6babb952..b4350c32e 100644 --- a/os/hal/ports/STM32/STM32L4xx+/hal_efl_lld.h +++ b/os/hal/ports/STM32/STM32L4xx+/hal_efl_lld.h @@ -146,7 +146,7 @@ extern "C" { flash_error_t efl_lld_start_erase_all(void *instance); flash_error_t efl_lld_start_erase_sector(void *instance, flash_sector_t sector); - flash_error_t efl_lld_query_erase(void *instance, uint32_t *wait_time); + flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec); flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector); #ifdef __cplusplus } diff --git a/os/hal/ports/STM32/STM32L4xx/hal_efl_lld.h b/os/hal/ports/STM32/STM32L4xx/hal_efl_lld.h index be58fb7cc..774e8ae45 100644 --- a/os/hal/ports/STM32/STM32L4xx/hal_efl_lld.h +++ b/os/hal/ports/STM32/STM32L4xx/hal_efl_lld.h @@ -103,7 +103,7 @@ extern "C" { flash_error_t efl_lld_start_erase_all(void *instance); flash_error_t efl_lld_start_erase_sector(void *instance, flash_sector_t sector); - flash_error_t efl_lld_query_erase(void *instance, uint32_t *wait_time); + flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec); flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector); #ifdef __cplusplus } diff --git a/os/hal/src/hal_rtc.c b/os/hal/src/hal_rtc.c index 49facf310..840e2ec79 100644 --- a/os/hal/src/hal_rtc.c +++ b/os/hal/src/hal_rtc.c @@ -222,7 +222,7 @@ void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec, uint32_t *tv_msec) { int sec; - timp->tm_year = (int)timespec->year + (RTC_BASE_YEAR - 1900); + timp->tm_year = (int)timespec->year + (int)(RTC_BASE_YEAR - 1900U); timp->tm_mon = (int)timespec->month - 1; timp->tm_mday = (int)timespec->day; timp->tm_isdst = (int)timespec->dstflag; diff --git a/os/hal/src/hal_sdc.c b/os/hal/src/hal_sdc.c index 53c772ad7..17995e415 100644 --- a/os/hal/src/hal_sdc.c +++ b/os/hal/src/hal_sdc.c @@ -684,11 +684,6 @@ bool sdcConnect(SDCDriver *sdcp) { if (_mmcsd_get_slice(sdcp->csd, MMCSD_CSD_MMC_CSD_STRUCTURE_SLICE) > 1U) { uint8_t *ext_csd = sdcp->buf; - /* Size detection requires the buffer.*/ - if (NULL == ext_csd) { - goto failed; - } - if (sdc_lld_read_special(sdcp, ext_csd, 512, MMCSD_CMD_SEND_EXT_CSD, 0)) { goto failed; } diff --git a/os/hal/templates/hal_efl_lld.c b/os/hal/templates/hal_efl_lld.c index 6fdf98a83..a573c8b0d 100644 --- a/os/hal/templates/hal_efl_lld.c +++ b/os/hal/templates/hal_efl_lld.c @@ -45,6 +45,19 @@ EFlashDriver EFLD1; /* Driver local variables and types. */ /*===========================================================================*/ +static const flash_descriptor_t efl_lld_descriptor = { + .attributes = FLASH_ATTR_ERASED_IS_ONE | + FLASH_ATTR_MEMORY_MAPPED | + FLASH_ATTR_ECC_CAPABLE | + FLASH_ATTR_ECC_ZERO_LINE_CAPABLE, + .page_size = 0, + .sectors_count = 0, + .sectors = NULL, + .sectors_size = 0, + .address = (uint8_t *)0, + .size = 0 +}; + /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ @@ -112,6 +125,241 @@ void efl_lld_stop(EFlashDriver *eflp) { } } +/** + * @brief Gets the flash descriptor structure. + * + * @param[in] ip pointer to a @p EFlashDriver instance + * @return A flash device descriptor. + * + * @notapi + */ +const flash_descriptor_t *efl_lld_get_descriptor(void *instance) { + + (void)instance; + + return &efl_lld_descriptor; +} + +/** + * @brief Read operation. + * + * @param[in] ip pointer to a @p EFlashDriver instance + * @param[in] offset flash offset + * @param[in] n number of bytes to be read + * @param[out] rp pointer to the data buffer + * @return An error code. + * @retval FLASH_NO_ERROR if there is no erase operation in progress. + * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. + * @retval FLASH_ERROR_READ if the read operation failed. + * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. + * + * @notapi + */ +flash_error_t efl_lld_read(void *instance, flash_offset_t offset, + size_t n, uint8_t *rp) { + EFlashDriver *devp = (EFlashDriver *)instance; + flash_error_t err = FLASH_NO_ERROR; + + osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U)); + osalDbgCheck(((size_t)offset + n) <= (size_t)efl_lld_descriptor.size); + osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), + "invalid state"); + + /* No reading while erasing.*/ + if (devp->state == FLASH_ERASE) { + return FLASH_BUSY_ERASING; + } + + /* FLASH_READY state while the operation is performed.*/ + devp->state = FLASH_READ; + + /* IMPLEMENT */ + + /* Ready state again.*/ + devp->state = FLASH_READY; + + return err; + +} + +/** + * @brief Program operation. + * @note The device supports ECC, it is only possible to write erased + * pages once except when writing all zeroes. + * + * @param[in] ip pointer to a @p EFlashDriver instance + * @param[in] offset flash offset + * @param[in] n number of bytes to be programmed + * @param[in] pp pointer to the data buffer + * @return An error code. + * @retval FLASH_NO_ERROR if there is no erase operation in progress. + * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. + * @retval FLASH_ERROR_PROGRAM if the program operation failed. + * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. + * + * @notapi + */ +flash_error_t efl_lld_program(void *instance, flash_offset_t offset, + size_t n, const uint8_t *pp) { + EFlashDriver *devp = (EFlashDriver *)instance; + flash_error_t err = FLASH_NO_ERROR; + + osalDbgCheck((instance != NULL) && (pp != NULL) && (n > 0U)); + osalDbgCheck(((size_t)offset + n) <= (size_t)efl_lld_descriptor.size); + + osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), + "invalid state"); + + /* No programming while erasing.*/ + if (devp->state == FLASH_ERASE) { + return FLASH_BUSY_ERASING; + } + + /* FLASH_PGM state while the operation is performed.*/ + devp->state = FLASH_PGM; + + /* IMPLEMENT */ + + /* Ready state again.*/ + devp->state = FLASH_READY; + + return err; +} + +/** + * @brief Starts a whole-device erase operation. + * @note This function only erases bank 2 if it is present. Bank 1 is not + * touched because it is where the program is running on. + * Pages on bank 1 can be individually erased. + * + * @param[in] ip pointer to a @p EFlashDriver instance + * @return An error code. + * @retval FLASH_NO_ERROR if there is no erase operation in progress. + * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. + * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. + * + * @notapi + */ +flash_error_t efl_lld_start_erase_all(void *instance) { + EFlashDriver *devp = (EFlashDriver *)instance; + + osalDbgCheck(instance != NULL); + osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), + "invalid state"); + + /* No erasing while erasing.*/ + if (devp->state == FLASH_ERASE) { + return FLASH_BUSY_ERASING; + } + + /* FLASH_PGM state while the operation is performed.*/ + devp->state = FLASH_ERASE; + + /* IMPLEMENT */ + + return FLASH_NO_ERROR; +} + +/** + * @brief Starts an sector erase operation. + * + * @param[in] ip pointer to a @p EFlashDriver instance + * @param[in] sector sector to be erased + * @return An error code. + * @retval FLASH_NO_ERROR if there is no erase operation in progress. + * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. + * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. + * + * @notapi + */ +flash_error_t efl_lld_start_erase_sector(void *instance, + flash_sector_t sector) { + EFlashDriver *devp = (EFlashDriver *)instance; + + osalDbgCheck(instance != NULL); + osalDbgCheck(sector < efl_lld_descriptor.sectors_count); + osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), + "invalid state"); + + /* No erasing while erasing.*/ + if (devp->state == FLASH_ERASE) { + return FLASH_BUSY_ERASING; + } + + /* FLASH_PGM state while the operation is performed.*/ + devp->state = FLASH_ERASE; + + /* IMPLEMENT */ + + return FLASH_NO_ERROR; +} + +/** + * @brief Queries the driver for erase operation progress. + * + * @param[in] ip pointer to a @p EFlashDriver instance + * @param[out] msec recommended time, in milliseconds, that + * should be spent before calling this + * function again, can be @p NULL + * @return An error code. + * @retval FLASH_NO_ERROR if there is no erase operation in progress. + * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. + * @retval FLASH_ERROR_ERASE if the erase operation failed. + * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. + * + * @api + */ +flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec) { + EFlashDriver *devp = (EFlashDriver *)instance; + flash_error_t err = FLASH_NO_ERROR; + + (void)msec; + + /* If there is an erase in progress then the device must be checked.*/ + if (devp->state == FLASH_ERASE) { + + /* IMPLEMENT */ + + } + + return err; +} + +/** + * @brief Returns the erase state of a sector. + * + * @param[in] ip pointer to a @p EFlashDriver instance + * @param[in] sector sector to be verified + * @return An error code. + * @retval FLASH_NO_ERROR if the sector is erased. + * @retval FLASH_BUSY_ERASING if there is an erase operation in progress. + * @retval FLASH_ERROR_VERIFY if the verify operation failed. + * @retval FLASH_ERROR_HW_FAILURE if access to the memory failed. + * + * @notapi + */ +flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector) { + EFlashDriver *devp = (EFlashDriver *)instance; + flash_error_t err = FLASH_NO_ERROR; + + osalDbgCheck(instance != NULL); + osalDbgCheck(sector < efl_lld_descriptor.sectors_count); + osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE), + "invalid state"); + + /* No verifying while erasing.*/ + if (devp->state == FLASH_ERASE) { + return FLASH_BUSY_ERASING; + } + + /* IMPLEMENT */ + + /* Ready state again.*/ + devp->state = FLASH_READY; + + return err; +} + #endif /* HAL_USE_EFL == TRUE */ /** @} */ diff --git a/os/hal/templates/hal_efl_lld.h b/os/hal/templates/hal_efl_lld.h index c855009fb..a65ee3b31 100644 --- a/os/hal/templates/hal_efl_lld.h +++ b/os/hal/templates/hal_efl_lld.h @@ -89,6 +89,16 @@ extern "C" { void efl_lld_init(void); void efl_lld_start(EFlashDriver *eflp); void efl_lld_stop(EFlashDriver *eflp); + const flash_descriptor_t *efl_lld_get_descriptor(void *instance); + flash_error_t efl_lld_read(void *instance, flash_offset_t offset, + size_t n, uint8_t *rp); + flash_error_t efl_lld_program(void *instance, flash_offset_t offset, + size_t n, const uint8_t *pp); + flash_error_t efl_lld_start_erase_all(void *instance); + flash_error_t efl_lld_start_erase_sector(void *instance, + flash_sector_t sector); + flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec); + flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector); #ifdef __cplusplus } #endif diff --git a/os/hal/templates/hal_sdc_lld.h b/os/hal/templates/hal_sdc_lld.h index 97c7d40bc..61ee84b61 100644 --- a/os/hal/templates/hal_sdc_lld.h +++ b/os/hal/templates/hal_sdc_lld.h @@ -77,14 +77,6 @@ typedef struct SDCDriver SDCDriver; * @note It could be empty on some architectures. */ typedef struct { - /** - * @brief Working area for memory consuming operations. - * @note It is mandatory for detecting MMC cards bigger than 2GB else it - * can be @p NULL. - * @note Memory pointed by this buffer is only used by @p sdcConnect(), - * afterward it can be reused for other purposes. - */ - uint8_t *scratchpad; /** * @brief Bus width. */ @@ -132,6 +124,10 @@ struct SDCDriver { * @brief Card RCA. */ uint32_t rca; + /** + * @brief Buffer for internal operations. + */ + uint8_t buf[MMCSD_BLOCK_SIZE]; /* End of the mandatory fields.*/ };