mirror of https://github.com/ARMmbed/mbed-os.git
HAL CRC: Basic implementation for STM32F0
parent
5e98eea1a0
commit
acbf41e673
|
@ -0,0 +1,69 @@
|
|||
#include "crc_api.h"
|
||||
|
||||
#include "platform/mbed_assert.h"
|
||||
|
||||
#ifdef DEVICE_CRC
|
||||
|
||||
#include "stm32f0xx_hal.h"
|
||||
|
||||
static CRC_HandleTypeDef current_state;
|
||||
static uint32_t final_xor;
|
||||
|
||||
bool hal_crc_is_supported(const crc_mbed_config_t* config)
|
||||
{
|
||||
if (config == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config->polynomial != DEFAULT_CRC32_POLY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config->width != 32) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((config->final_xor != 0xFFFFFFFFU) && (config->final_xor != 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void hal_crc_compute_partial_start(const crc_mbed_config_t* config)
|
||||
{
|
||||
MBED_ASSERT(hal_crc_is_supported(config));
|
||||
|
||||
__HAL_RCC_CRC_CLK_ENABLE();
|
||||
|
||||
final_xor = config->final_xor;
|
||||
|
||||
current_state.Instance = CRC;
|
||||
current_state.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
|
||||
current_state.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
|
||||
current_state.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_DISABLE;
|
||||
current_state.Init.InitValue = config->initial_xor;
|
||||
current_state.Init.CRCLength = CRC_POLYLENGTH_32B;
|
||||
current_state.Init.InputDataInversionMode =
|
||||
config->reflect_in ? CRC_INPUTDATA_INVERSION_BYTE
|
||||
: CRC_INPUTDATA_INVERSION_NONE;
|
||||
current_state.Init.OutputDataInversionMode =
|
||||
config->reflect_out ? CRC_OUTPUTDATA_INVERSION_ENABLE
|
||||
: CRC_OUTPUTDATA_INVERSION_DISABLE;
|
||||
|
||||
HAL_CRC_Init(¤t_state);
|
||||
}
|
||||
|
||||
void hal_crc_compute_partial(const uint8_t *data, const size_t size)
|
||||
{
|
||||
HAL_CRC_Accumulate(¤t_state, (uint32_t *)data, size);
|
||||
}
|
||||
|
||||
uint32_t hal_crc_get_result(void)
|
||||
{
|
||||
const uint32_t result = current_state.Instance->DR;
|
||||
|
||||
return (final_xor == 0xFFFFFFFFU) ? ~result : result;
|
||||
}
|
||||
|
||||
#endif // DEVICE_CRC
|
|
@ -872,7 +872,7 @@
|
|||
},
|
||||
"detect_code": ["0755"],
|
||||
"macros_add": ["CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\""],
|
||||
"device_has_add": ["LOWPOWERTIMER", "SERIAL_FC", "SERIAL_ASYNCH", "FLASH"],
|
||||
"device_has_add": ["CRC", "LOWPOWERTIMER", "SERIAL_FC", "SERIAL_ASYNCH", "FLASH"],
|
||||
"release_versions": ["2", "5"],
|
||||
"device_name": "STM32F070RB"
|
||||
},
|
||||
|
@ -1064,7 +1064,7 @@
|
|||
},
|
||||
"detect_code": ["0720"],
|
||||
"macros_add": ["USB_STM_HAL", "USBHOST_OTHER"],
|
||||
"device_has_add": ["SERIAL_ASYNCH", "SERIAL_FC", "FLASH", "LOWPOWERTIMER"],
|
||||
"device_has_add": ["CRC", "SERIAL_ASYNCH", "SERIAL_FC", "FLASH", "LOWPOWERTIMER"],
|
||||
"release_versions": ["2", "5"],
|
||||
"device_name": "STM32F401RE"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue