working psram
This commit is contained in:
parent
3a773d13c2
commit
648adb8d87
3
stm32/mk4-bootloader/.gitignore
vendored
3
stm32/mk4-bootloader/.gitignore
vendored
@ -8,4 +8,5 @@ version-full.txt
|
||||
version.txt
|
||||
|
||||
# dev shortcut
|
||||
hal
|
||||
H
|
||||
I
|
||||
|
||||
@ -27,11 +27,14 @@ TARGET_NAME = bootloader
|
||||
OBJS += startup.o assets/screens.o
|
||||
OBJS += enable.o dispatch.o verify.o oled.o clocks.o storage.o constant_time.o rng.o ae.o
|
||||
OBJS += delay.o gpio.o pins.o version.o sflash.o console.o psram.o
|
||||
OBJS += faster_sha256.o micro-ecc/uECC.o hal_glue.o
|
||||
|
||||
# Have to have copies of these because the DMA and interrupt stuff
|
||||
# needs to be commented-out.
|
||||
OBJS += stm32l4xx_hal_firewall.o stm32l4xx_hal_gpio.o stm32l4xx_hal_spi.o
|
||||
OBJS += stm32l4xx_hal_rcc.o stm32l4xx_hal_rcc_ex.o
|
||||
OBJS += faster_sha256.o micro-ecc/uECC.o
|
||||
OBJS += stm32l4xx_hal_hash.o stm32l4xx_hal_hash_ex.o stm32l4xx_hal_usart.o
|
||||
OBJS += stm32l4xx_hal_qspi.o
|
||||
OBJS += stm32l4xx_hal_hash.o # stm32l4xx_hal_usart.o
|
||||
OBJS += stm32l4xx_hal_ospi.o
|
||||
|
||||
#OBJS = $(addsuffix .o, $(basename $(C_SRCS) $(ASM_SRCS)))
|
||||
|
||||
@ -39,7 +42,7 @@ OBJS += stm32l4xx_hal_qspi.o
|
||||
micro-ecc/uECC.o: c_flags += -Wno-undef -Wno-redundant-decls
|
||||
|
||||
# Headers for chip stuff (assumes STM32L476 chip)
|
||||
STM32LIB_PATH = ../../external/micropython/lib
|
||||
#STM32LIB_PATH = ../../external/micropython/lib
|
||||
|
||||
# Where we will end up in the memory map (at start of flash)
|
||||
# - reserve last 8k flash page for other purposes
|
||||
@ -62,7 +65,7 @@ BL_SRAM_SIZE = 0x00001c00
|
||||
CFLAGS = -I. -Wall --std=gnu99 -Os -g3 \
|
||||
-mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mtune=cortex-m4 \
|
||||
-ffunction-sections -fdata-sections \
|
||||
-mcpu=cortex-m4 -DMCU_SERIES_L4 -DSTM32L4A6xx
|
||||
-mcpu=cortex-m4 -DMCU_SERIES_L4 -DSTM32L4S5xx
|
||||
|
||||
# -flto -fdata-sections -ffunction-sections -funsigned-char -funsigned-bitfields
|
||||
|
||||
@ -72,9 +75,12 @@ CFLAGS += -D BL_NVROM_BASE=$(BL_NVROM_BASE) -D BL_NVROM_SIZE=$(BL_NVROM_SIZE)
|
||||
CFLAGS += -D BL_SRAM_BASE=$(BL_SRAM_BASE) -D BL_SRAM_SIZE=$(BL_SRAM_SIZE)
|
||||
|
||||
# Header file search path
|
||||
INC_PATHS = $(STM32LIB_PATH)/stm32lib/CMSIS/STM32L4xx/Include \
|
||||
$(STM32LIB_PATH)/stm32lib/STM32L4xx_HAL_Driver/Inc \
|
||||
$(STM32LIB_PATH)/cmsis/inc
|
||||
#INC_PATHS = $(STM32LIB_PATH)/stm32lib/CMSIS/STM32L4xx/Include \
|
||||
# $(STM32LIB_PATH)/stm32lib/STM32L4xx_HAL_Driver/Inc \
|
||||
# $(STM32LIB_PATH)/cmsis/inc
|
||||
INC_PATHS = hal/Drivers/CMSIS/Device/ST/STM32L4xx/Include \
|
||||
hal/Drivers/STM32L4xx_HAL_Driver/Inc \
|
||||
hal/Drivers/CMSIS/Include
|
||||
|
||||
CFLAGS += $(foreach INC,$(INC_PATHS),-I$(INC))
|
||||
|
||||
@ -218,5 +224,10 @@ xxx:
|
||||
@echo OBJS = $(OBJS)
|
||||
|
||||
tags:
|
||||
ctags -f .tags *.[ch] -R $(INC_PATHS) $(STM32LIB_PATH)/stm32lib/STM32L4xx_HAL_Driver/*/*.h
|
||||
ctags -f .tags *.[ch] -R $(INC_PATHS) \
|
||||
hal/Drivers/STM32L4xx_HAL_Driver/Src/*.c
|
||||
|
||||
|
||||
#$(STM32LIB_PATH)/stm32lib/STM32L4xx_HAL_Driver/*/*.h
|
||||
|
||||
# EOF
|
||||
|
||||
@ -353,9 +353,13 @@ ae_setup(void)
|
||||
MY_UART->CR1 = 0;
|
||||
MY_UART->CR1 = 0x1000002d & ~(0
|
||||
| USART_CR1_PEIE
|
||||
#ifdef USART_CR1_TXEIE
|
||||
| USART_CR1_TXEIE
|
||||
#endif
|
||||
| USART_CR1_TCIE
|
||||
#ifdef USART_CR1_RXNEIE
|
||||
| USART_CR1_RXNEIE
|
||||
#endif
|
||||
| USART_CR1_IDLEIE
|
||||
| USART_CR1_OVER8
|
||||
| USART_CR1_UE);
|
||||
|
||||
@ -179,4 +179,499 @@ hex_dump(const void *d, int len)
|
||||
}
|
||||
}
|
||||
|
||||
// Copied parts of stm32l4xx_hal_usart.c
|
||||
|
||||
#if defined(USART_CR1_FIFOEN)
|
||||
#define USART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \
|
||||
USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8 | \
|
||||
USART_CR1_FIFOEN )) /*!< USART CR1 fields of parameters set by USART_SetConfig API */
|
||||
|
||||
#define USART_CR2_FIELDS ((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_CLKEN | \
|
||||
USART_CR2_LBCL | USART_CR2_STOP | USART_CR2_SLVEN | \
|
||||
USART_CR2_DIS_NSS)) /*!< USART CR2 fields of parameters set by USART_SetConfig API */
|
||||
|
||||
#define USART_CR3_FIELDS ((uint32_t)(USART_CR3_TXFTCFG | USART_CR3_RXFTCFG )) /*!< USART or USART CR3 fields of parameters set by USART_SetConfig API */
|
||||
#else
|
||||
#define USART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \
|
||||
USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8)) /*!< USART CR1 fields of parameters set by USART_SetConfig API */
|
||||
#define USART_CR2_FIELDS ((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | \
|
||||
USART_CR2_CLKEN | USART_CR2_LBCL | USART_CR2_STOP)) /*!< USART CR2 fields of parameters set by USART_SetConfig API */
|
||||
#endif /* USART_CR1_FIFOEN */
|
||||
|
||||
#define USART_BRR_MIN 0x10U /* USART BRR minimum authorized value */
|
||||
#define USART_BRR_MAX 0xFFFFU /* USART BRR maximum authorized value */
|
||||
#define USART_TEACK_REACK_TIMEOUT 1000U /*!< USART TX or RX enable acknowledge time-out value */
|
||||
#define USART_DUMMY_DATA ((uint16_t) 0xFFFF) /*!< USART transmitted dummy data */
|
||||
|
||||
/**
|
||||
* @brief Handle USART Communication Timeout.
|
||||
* @param husart USART handle.
|
||||
* @param Flag Specifies the USART flag to check.
|
||||
* @param Status the Flag status (SET or RESET).
|
||||
* @param Tickstart Tick start value
|
||||
* @param Timeout timeout duration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status,
|
||||
uint32_t Tickstart, uint32_t Timeout)
|
||||
{
|
||||
/* Wait until flag is set */
|
||||
while ((__HAL_USART_GET_FLAG(husart, Flag) ? SET : RESET) == Status)
|
||||
{
|
||||
/* Check for the Timeout */
|
||||
if (Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
|
||||
{
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the USART peripheral.
|
||||
* @param husart USART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef USART_SetConfig(USART_HandleTypeDef *husart)
|
||||
{
|
||||
uint32_t tmpreg;
|
||||
USART_ClockSourceTypeDef clocksource;
|
||||
HAL_StatusTypeDef ret = HAL_OK;
|
||||
uint16_t brrtemp;
|
||||
uint32_t usartdiv = 0x00000000;
|
||||
uint32_t pclk;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_POLARITY(husart->Init.CLKPolarity));
|
||||
assert_param(IS_USART_PHASE(husart->Init.CLKPhase));
|
||||
assert_param(IS_USART_LASTBIT(husart->Init.CLKLastBit));
|
||||
assert_param(IS_USART_BAUDRATE(husart->Init.BaudRate));
|
||||
assert_param(IS_USART_WORD_LENGTH(husart->Init.WordLength));
|
||||
assert_param(IS_USART_STOPBITS(husart->Init.StopBits));
|
||||
assert_param(IS_USART_PARITY(husart->Init.Parity));
|
||||
assert_param(IS_USART_MODE(husart->Init.Mode));
|
||||
#if defined(USART_PRESC_PRESCALER)
|
||||
assert_param(IS_USART_PRESCALER(husart->Init.ClockPrescaler));
|
||||
#endif /* USART_PRESC_PRESCALER */
|
||||
|
||||
/*-------------------------- USART CR1 Configuration -----------------------*/
|
||||
/* Clear M, PCE, PS, TE and RE bits and configure
|
||||
* the USART Word Length, Parity and Mode:
|
||||
* set the M bits according to husart->Init.WordLength value
|
||||
* set PCE and PS bits according to husart->Init.Parity value
|
||||
* set TE and RE bits according to husart->Init.Mode value
|
||||
* force OVER8 to 1 to allow to reach the maximum speed (Fclock/8) */
|
||||
tmpreg = (uint32_t)husart->Init.WordLength | husart->Init.Parity | husart->Init.Mode | USART_CR1_OVER8;
|
||||
MODIFY_REG(husart->Instance->CR1, USART_CR1_FIELDS, tmpreg);
|
||||
|
||||
/*---------------------------- USART CR2 Configuration ---------------------*/
|
||||
/* Clear and configure the USART Clock, CPOL, CPHA, LBCL STOP and SLVEN bits:
|
||||
* set CPOL bit according to husart->Init.CLKPolarity value
|
||||
* set CPHA bit according to husart->Init.CLKPhase value
|
||||
* set LBCL bit according to husart->Init.CLKLastBit value (used in SPI master mode only)
|
||||
* set STOP[13:12] bits according to husart->Init.StopBits value */
|
||||
tmpreg = (uint32_t)(USART_CLOCK_ENABLE);
|
||||
tmpreg |= (uint32_t)husart->Init.CLKLastBit;
|
||||
tmpreg |= ((uint32_t)husart->Init.CLKPolarity | (uint32_t)husart->Init.CLKPhase);
|
||||
tmpreg |= (uint32_t)husart->Init.StopBits;
|
||||
MODIFY_REG(husart->Instance->CR2, USART_CR2_FIELDS, tmpreg);
|
||||
|
||||
#if defined(USART_PRESC_PRESCALER)
|
||||
/*-------------------------- USART PRESC Configuration -----------------------*/
|
||||
/* Configure
|
||||
* - USART Clock Prescaler : set PRESCALER according to husart->Init.ClockPrescaler value */
|
||||
MODIFY_REG(husart->Instance->PRESC, USART_PRESC_PRESCALER, husart->Init.ClockPrescaler);
|
||||
#endif /* USART_PRESC_PRESCALER */
|
||||
|
||||
/*-------------------------- USART BRR Configuration -----------------------*/
|
||||
/* BRR is filled-up according to OVER8 bit setting which is forced to 1 */
|
||||
USART_GETCLOCKSOURCE(husart, clocksource);
|
||||
|
||||
switch (clocksource)
|
||||
{
|
||||
case USART_CLOCKSOURCE_PCLK1:
|
||||
pclk = HAL_RCC_GetPCLK1Freq();
|
||||
#if defined(USART_PRESC_PRESCALER)
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(pclk, husart->Init.BaudRate, husart->Init.ClockPrescaler));
|
||||
#else
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(pclk, husart->Init.BaudRate));
|
||||
#endif /* USART_PRESC_PRESCALER */
|
||||
break;
|
||||
case USART_CLOCKSOURCE_PCLK2:
|
||||
pclk = HAL_RCC_GetPCLK2Freq();
|
||||
#if defined(USART_PRESC_PRESCALER)
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(pclk, husart->Init.BaudRate, husart->Init.ClockPrescaler));
|
||||
#else
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(pclk, husart->Init.BaudRate));
|
||||
#endif /* USART_PRESC_PRESCALER */
|
||||
break;
|
||||
case USART_CLOCKSOURCE_HSI:
|
||||
#if defined(USART_PRESC_PRESCALER)
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(HSI_VALUE, husart->Init.BaudRate, husart->Init.ClockPrescaler));
|
||||
#else
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(HSI_VALUE, husart->Init.BaudRate));
|
||||
#endif /* USART_PRESC_PRESCALER */
|
||||
break;
|
||||
case USART_CLOCKSOURCE_SYSCLK:
|
||||
pclk = HAL_RCC_GetSysClockFreq();
|
||||
#if defined(USART_PRESC_PRESCALER)
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(pclk, husart->Init.BaudRate, husart->Init.ClockPrescaler));
|
||||
#else
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(pclk, husart->Init.BaudRate));
|
||||
#endif /* USART_PRESC_PRESCALER */
|
||||
break;
|
||||
case USART_CLOCKSOURCE_LSE:
|
||||
#if defined(USART_PRESC_PRESCALER)
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(LSE_VALUE, husart->Init.BaudRate, husart->Init.ClockPrescaler));
|
||||
#else
|
||||
usartdiv = (uint32_t)(USART_DIV_SAMPLING8(LSE_VALUE, husart->Init.BaudRate));
|
||||
#endif /* USART_PRESC_PRESCALER */
|
||||
break;
|
||||
default:
|
||||
ret = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* USARTDIV must be greater than or equal to 0d16 and smaller than or equal to ffff */
|
||||
if ((usartdiv >= USART_BRR_MIN) && (usartdiv <= USART_BRR_MAX))
|
||||
{
|
||||
brrtemp = (uint16_t)(usartdiv & 0xFFF0U);
|
||||
brrtemp |= (uint16_t)((usartdiv & (uint16_t)0x000FU) >> 1U);
|
||||
husart->Instance->BRR = brrtemp;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = HAL_ERROR;
|
||||
}
|
||||
|
||||
#if defined(USART_CR1_FIFOEN)
|
||||
/* Initialize the number of data to process during RX/TX ISR execution */
|
||||
husart->NbTxDataToProcess = 1U;
|
||||
husart->NbRxDataToProcess = 1U;
|
||||
#endif /* USART_CR1_FIFOEN */
|
||||
|
||||
/* Clear ISR function pointers */
|
||||
husart->RxISR = NULL;
|
||||
husart->TxISR = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check the USART Idle State.
|
||||
* @param husart USART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef USART_CheckIdleState(USART_HandleTypeDef *husart)
|
||||
{
|
||||
uint32_t tickstart;
|
||||
|
||||
/* Initialize the USART ErrorCode */
|
||||
husart->ErrorCode = HAL_USART_ERROR_NONE;
|
||||
|
||||
/* Init tickstart for timeout management */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Check if the Transmitter is enabled */
|
||||
if ((husart->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
|
||||
{
|
||||
/* Wait until TEACK flag is set */
|
||||
if (USART_WaitOnFlagUntilTimeout(husart, USART_ISR_TEACK, RESET, tickstart, USART_TEACK_REACK_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
/* Timeout occurred */
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
/* Check if the Receiver is enabled */
|
||||
if ((husart->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
|
||||
{
|
||||
/* Wait until REACK flag is set */
|
||||
if (USART_WaitOnFlagUntilTimeout(husart, USART_ISR_REACK, RESET, tickstart, USART_TEACK_REACK_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
/* Timeout occurred */
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize the USART state*/
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the USART mode according to the specified
|
||||
* parameters in the USART_InitTypeDef and initialize the associated handle.
|
||||
* @param husart USART handle.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart)
|
||||
{
|
||||
/* Check the USART handle allocation */
|
||||
if (husart == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_USART_INSTANCE(husart->Instance));
|
||||
|
||||
if (husart->State == HAL_USART_STATE_RESET)
|
||||
{
|
||||
/* Allocate lock resource and initialize it */
|
||||
husart->Lock = HAL_UNLOCKED;
|
||||
}
|
||||
|
||||
husart->State = HAL_USART_STATE_BUSY;
|
||||
|
||||
/* Disable the Peripheral */
|
||||
__HAL_USART_DISABLE(husart);
|
||||
|
||||
/* Set the Usart Communication parameters */
|
||||
if (USART_SetConfig(husart) == HAL_ERROR)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* In Synchronous mode, the following bits must be kept cleared:
|
||||
- LINEN bit in the USART_CR2 register
|
||||
- HDSEL, SCEN and IREN bits in the USART_CR3 register.*/
|
||||
husart->Instance->CR2 &= ~USART_CR2_LINEN;
|
||||
husart->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN);
|
||||
|
||||
/* Enable the Peripheral */
|
||||
__HAL_USART_ENABLE(husart);
|
||||
|
||||
/* TEACK and/or REACK to check before moving husart->State to Ready */
|
||||
return (USART_CheckIdleState(husart));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Simplex send an amount of data in blocking mode.
|
||||
* @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
|
||||
* the sent data is handled as a set of u16. In this case, Size must indicate the number
|
||||
* of u16 provided through pTxData.
|
||||
* @param husart USART handle.
|
||||
* @param pTxData Pointer to data buffer (u8 or u16 data elements).
|
||||
* @param Size Amount of data elements (u8 or u16) to be sent.
|
||||
* @param Timeout Timeout duration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout)
|
||||
{
|
||||
uint8_t *ptxdata8bits;
|
||||
uint16_t *ptxdata16bits;
|
||||
uint32_t tickstart;
|
||||
|
||||
if (husart->State == HAL_USART_STATE_READY)
|
||||
{
|
||||
if ((pTxData == NULL) || (Size == 0U))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(husart);
|
||||
|
||||
husart->ErrorCode = HAL_USART_ERROR_NONE;
|
||||
husart->State = HAL_USART_STATE_BUSY_TX;
|
||||
|
||||
/* Init tickstart for timeout management */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
husart->TxXferSize = Size;
|
||||
husart->TxXferCount = Size;
|
||||
|
||||
/* In case of 9bits/No Parity transfer, pTxData needs to be handled as a uint16_t pointer */
|
||||
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
|
||||
{
|
||||
ptxdata8bits = NULL;
|
||||
ptxdata16bits = (uint16_t *) pTxData;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptxdata8bits = pTxData;
|
||||
ptxdata16bits = NULL;
|
||||
}
|
||||
|
||||
/* Check the remaining data to be sent */
|
||||
while (husart->TxXferCount > 0U)
|
||||
{
|
||||
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
if (ptxdata8bits == NULL)
|
||||
{
|
||||
husart->Instance->TDR = (uint16_t)(*ptxdata16bits & 0x01FFU);
|
||||
ptxdata16bits++;
|
||||
}
|
||||
else
|
||||
{
|
||||
husart->Instance->TDR = (uint8_t)(*ptxdata8bits & 0xFFU);
|
||||
ptxdata8bits++;
|
||||
}
|
||||
|
||||
husart->TxXferCount--;
|
||||
}
|
||||
|
||||
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
|
||||
/* Clear Transmission Complete Flag */
|
||||
__HAL_USART_CLEAR_FLAG(husart, USART_CLEAR_TCF);
|
||||
|
||||
/* Clear overrun flag and discard the received data */
|
||||
__HAL_USART_CLEAR_OREFLAG(husart);
|
||||
__HAL_USART_SEND_REQ(husart, USART_RXDATA_FLUSH_REQUEST);
|
||||
__HAL_USART_SEND_REQ(husart, USART_TXDATA_FLUSH_REQUEST);
|
||||
|
||||
/* At end of Tx process, restore husart->State to Ready */
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Receive an amount of data in blocking mode.
|
||||
* @note To receive synchronous data, dummy data are simultaneously transmitted.
|
||||
* @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
|
||||
* the received data is handled as a set of u16. In this case, Size must indicate the number
|
||||
* of u16 available through pRxData.
|
||||
* @param husart USART handle.
|
||||
* @param pRxData Pointer to data buffer (u8 or u16 data elements).
|
||||
* @param Size Amount of data elements (u8 or u16) to be received.
|
||||
* @param Timeout Timeout duration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
|
||||
{
|
||||
uint8_t *prxdata8bits;
|
||||
uint16_t *prxdata16bits;
|
||||
uint16_t uhMask;
|
||||
uint32_t tickstart;
|
||||
|
||||
if (husart->State == HAL_USART_STATE_READY)
|
||||
{
|
||||
if ((pRxData == NULL) || (Size == 0U))
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(husart);
|
||||
|
||||
husart->ErrorCode = HAL_USART_ERROR_NONE;
|
||||
husart->State = HAL_USART_STATE_BUSY_RX;
|
||||
|
||||
/* Init tickstart for timeout management */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
husart->RxXferSize = Size;
|
||||
husart->RxXferCount = Size;
|
||||
|
||||
/* Computation of USART mask to apply to RDR register */
|
||||
USART_MASK_COMPUTATION(husart);
|
||||
uhMask = husart->Mask;
|
||||
|
||||
/* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */
|
||||
if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
|
||||
{
|
||||
prxdata8bits = NULL;
|
||||
prxdata16bits = (uint16_t *) pRxData;
|
||||
}
|
||||
else
|
||||
{
|
||||
prxdata8bits = pRxData;
|
||||
prxdata16bits = NULL;
|
||||
}
|
||||
|
||||
/* as long as data have to be received */
|
||||
while (husart->RxXferCount > 0U)
|
||||
{
|
||||
#if defined(USART_CR2_SLVEN)
|
||||
if (husart->SlaveMode == USART_SLAVEMODE_DISABLE)
|
||||
#endif /* USART_CR2_SLVEN */
|
||||
{
|
||||
/* Wait until TXE flag is set to send dummy byte in order to generate the
|
||||
* clock for the slave to send data.
|
||||
* Whatever the frame length (7, 8 or 9-bit long), the same dummy value
|
||||
* can be written for all the cases. */
|
||||
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
husart->Instance->TDR = (USART_DUMMY_DATA & (uint16_t)0x0FF);
|
||||
}
|
||||
|
||||
/* Wait for RXNE Flag */
|
||||
if (USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
|
||||
if (prxdata8bits == NULL)
|
||||
{
|
||||
*prxdata16bits = (uint16_t)(husart->Instance->RDR & uhMask);
|
||||
prxdata16bits++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*prxdata8bits = (uint8_t)(husart->Instance->RDR & (uint8_t)(uhMask & 0xFFU));
|
||||
prxdata8bits++;
|
||||
}
|
||||
|
||||
husart->RxXferCount--;
|
||||
|
||||
}
|
||||
|
||||
#if defined(USART_CR2_SLVEN)
|
||||
/* Clear SPI slave underrun flag and discard transmit data */
|
||||
if (husart->SlaveMode == USART_SLAVEMODE_ENABLE)
|
||||
{
|
||||
__HAL_USART_CLEAR_UDRFLAG(husart);
|
||||
__HAL_USART_SEND_REQ(husart, USART_TXDATA_FLUSH_REQUEST);
|
||||
}
|
||||
#endif /* USART_CR2_SLVEN */
|
||||
|
||||
/* At end of Rx process, restore husart->State to Ready */
|
||||
husart->State = HAL_USART_STATE_READY;
|
||||
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(husart);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// EOF
|
||||
|
||||
@ -102,10 +102,6 @@ wipe_all_sram(void)
|
||||
{
|
||||
const uint32_t noise = 0xdeadbeef;
|
||||
|
||||
// strange omission from HAL headers
|
||||
#define SRAM3_BASE ((uint32_t)0x20040000U)
|
||||
#define SRAM3_SIZE ((uint32_t)0x00060000U)
|
||||
|
||||
// wipe all of SRAM (except our own memory, which was already wiped)
|
||||
memset4((void *)(SRAM1_BASE+BL_SRAM_SIZE), noise, SRAM1_SIZE_MAX - BL_SRAM_SIZE);
|
||||
memset4((void *)SRAM2_BASE, noise, SRAM2_SIZE);
|
||||
@ -802,14 +798,4 @@ fail:
|
||||
return rv;
|
||||
}
|
||||
|
||||
// HAL support garbage
|
||||
const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
const uint32_t MSIRangeTable[12] = {100000, 200000, 400000, 800000, 1000000, 2000000, \
|
||||
4000000, 8000000, 16000000, 24000000, 32000000, 48000000};
|
||||
uint32_t SystemCoreClock;
|
||||
|
||||
// TODO: cleanup HAL stuff to not use this
|
||||
uint32_t HAL_GetTick(void) { return 53; }
|
||||
|
||||
// EOF
|
||||
|
||||
@ -7,6 +7,16 @@
|
||||
#include "stm32l4xx_hal.h"
|
||||
#include <string.h>
|
||||
|
||||
// so we don't need stm32l4xx_hal_hash_ex.c
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HASH_Accumulate(hhash, pInBuffer, Size,HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
void sha256_init(SHA256_CTX *ctx)
|
||||
{
|
||||
memset(ctx, 0, sizeof(SHA256_CTX));
|
||||
@ -88,14 +98,13 @@ sha256_single(const uint8_t data[], uint32_t len, uint8_t digest[32])
|
||||
//#pragma GCC push_options
|
||||
//#pragma GCC optimize ("O0")
|
||||
|
||||
|
||||
void
|
||||
sha256_selftest(void)
|
||||
{
|
||||
SHA256_CTX ctx;
|
||||
uint8_t md[32], md2[32];
|
||||
|
||||
puts("sha256 selftest start");
|
||||
puts2("sha256 selftest: ");
|
||||
|
||||
sha256_single((uint8_t *)"a", 1, md);
|
||||
ASSERT(md[0] == 0xca);
|
||||
@ -129,9 +138,8 @@ sha256_selftest(void)
|
||||
}
|
||||
}
|
||||
|
||||
puts("sha256 selftest PASS");
|
||||
puts("PASS");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// EOF
|
||||
|
||||
1
stm32/mk4-bootloader/hal
Submodule
1
stm32/mk4-bootloader/hal
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 5e1553e07706491bd11f4edd304e093b6e4b83a4
|
||||
45
stm32/mk4-bootloader/hal_glue.c
Normal file
45
stm32/mk4-bootloader/hal_glue.c
Normal file
@ -0,0 +1,45 @@
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
// HAL support garbage
|
||||
const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
const uint32_t MSIRangeTable[12] = {100000, 200000, 400000, 800000, 1000000, 2000000, \
|
||||
4000000, 8000000, 16000000, 24000000, 32000000, 48000000};
|
||||
uint32_t SystemCoreClock;
|
||||
|
||||
// TODO: cleanup HAL stuff to not use this
|
||||
uint32_t HAL_GetTick(void) { return 53; }
|
||||
uint32_t uwTickPrio = 0; /* (1UL << __NVIC_PRIO_BITS); * Invalid priority */
|
||||
|
||||
// unwanted junk from stm32l4xx_hal_rcc.c
|
||||
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority) { return 0; }
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return Voltage Scaling Range.
|
||||
* @retval VOS bit field (PWR_REGULATOR_VOLTAGE_SCALE1 or PWR_REGULATOR_VOLTAGE_SCALE2
|
||||
* or PWR_REGULATOR_VOLTAGE_SCALE1_BOOST when applicable)
|
||||
*/
|
||||
uint32_t HAL_PWREx_GetVoltageRange(void)
|
||||
{
|
||||
#if defined(PWR_CR5_R1MODE)
|
||||
if (READ_BIT(PWR->CR1, PWR_CR1_VOS) == PWR_REGULATOR_VOLTAGE_SCALE2)
|
||||
{
|
||||
return PWR_REGULATOR_VOLTAGE_SCALE2;
|
||||
}
|
||||
else if (READ_BIT(PWR->CR5, PWR_CR5_R1MODE) == PWR_CR5_R1MODE)
|
||||
{
|
||||
/* PWR_CR5_R1MODE bit set means that Range 1 Boost is disabled */
|
||||
return PWR_REGULATOR_VOLTAGE_SCALE1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PWR_REGULATOR_VOLTAGE_SCALE1_BOOST;
|
||||
}
|
||||
#else
|
||||
return (PWR->CR1 & PWR_CR1_VOS);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,23 +6,29 @@
|
||||
*
|
||||
*/
|
||||
#include "psram.h"
|
||||
#include "oled.h"
|
||||
#include "assets/screens.h"
|
||||
#include <string.h>
|
||||
#include "delay.h"
|
||||
#include "stm32l4xx_hal.h"
|
||||
#include "console.h"
|
||||
|
||||
static QSPI_HandleTypeDef qh;
|
||||
uint8_t psram_chip_eid[8];
|
||||
|
||||
static OSPI_HandleTypeDef qh;
|
||||
|
||||
void
|
||||
psram_setup(void)
|
||||
{
|
||||
// Using OSPI1 block
|
||||
|
||||
// enable clocks
|
||||
__HAL_RCC_QSPI_CLK_ENABLE();
|
||||
__HAL_RCC_OSPI1_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
|
||||
// reset module
|
||||
__HAL_RCC_QSPI_FORCE_RESET();
|
||||
__HAL_RCC_QSPI_RELEASE_RESET();
|
||||
__HAL_RCC_OSPI1_FORCE_RESET();
|
||||
__HAL_RCC_OSPI1_RELEASE_RESET();
|
||||
|
||||
// configure pins: Port E PE10-PE15
|
||||
GPIO_InitTypeDef setup = {
|
||||
@ -30,74 +36,124 @@ psram_setup(void)
|
||||
.Mode = GPIO_MODE_AF_PP, // not sure
|
||||
.Pull = GPIO_NOPULL, // not sure
|
||||
.Speed = GPIO_SPEED_FREQ_VERY_HIGH,
|
||||
.Alternate = GPIO_AF10_QUADSPI,
|
||||
.Alternate = GPIO_AF10_OCTOSPIM_P1,
|
||||
};
|
||||
HAL_GPIO_Init(GPIOE, &setup);
|
||||
|
||||
#if 0
|
||||
QUADSPI_TypeDef *Instance; /* QSPI registers base address */
|
||||
QSPI_InitTypeDef Init; /* QSPI communication parameters */
|
||||
uint8_t *pTxBuffPtr; /* Pointer to QSPI Tx transfer Buffer */
|
||||
__IO uint32_t TxXferSize; /* QSPI Tx Transfer size */
|
||||
__IO uint32_t TxXferCount; /* QSPI Tx Transfer Counter */
|
||||
uint8_t *pRxBuffPtr; /* Pointer to QSPI Rx transfer Buffer */
|
||||
__IO uint32_t RxXferSize; /* QSPI Rx Transfer size */
|
||||
__IO uint32_t RxXferCount; /* QSPI Rx Transfer Counter */
|
||||
DMA_HandleTypeDef *hdma; /* QSPI Rx/Tx DMA Handle parameters */
|
||||
__IO HAL_LockTypeDef Lock; /* Locking object */
|
||||
__IO HAL_QSPI_StateTypeDef State; /* QSPI communication state */
|
||||
__IO uint32_t ErrorCode; /* QSPI Error code */
|
||||
uint32_t Timeout; /* Timeout for the QSPI memory access */
|
||||
uint32_t FifoThreshold; /*!< This is the threshold used by the Peripheral to generate the interrupt
|
||||
indicating that data are available in reception or free place
|
||||
is available in transmission.
|
||||
This parameter can be a value between 1 and 32 */
|
||||
uint32_t DualQuad; /*!< It enables or not the dual-quad mode which allow to access up to
|
||||
quad mode on two different devices to increase the throughput.
|
||||
This parameter can be a value of @ref OSPI_DualQuad */
|
||||
uint32_t MemoryType; /*!< It indicates the external device type connected to the OSPI.
|
||||
This parameter can be a value of @ref OSPI_MemoryType */
|
||||
uint32_t DeviceSize; /*!< It defines the size of the external device connected to the OSPI,
|
||||
it corresponds to the number of address bits required to access
|
||||
the external device.
|
||||
This parameter can be a value between 1 and 32 */
|
||||
uint32_t ChipSelectHighTime; /*!< It defines the minimun number of clocks which the chip select
|
||||
must remain high between commands.
|
||||
This parameter can be a value between 1 and 8 */
|
||||
uint32_t FreeRunningClock; /*!< It enables or not the free running clock.
|
||||
This parameter can be a value of @ref OSPI_FreeRunningClock */
|
||||
uint32_t ClockMode; /*!< It indicates the level of clock when the chip select is released.
|
||||
This parameter can be a value of @ref OSPI_ClockMode */
|
||||
uint32_t ClockPrescaler; /*!< It specifies the prescaler factor used for generating
|
||||
the external clock based on the AHB clock.
|
||||
This parameter can be a value between 1 and 256 */
|
||||
uint32_t SampleShifting; /*!< It allows to delay to 1/2 cycle the data sampling in order
|
||||
to take in account external signal delays.
|
||||
This parameter can be a value of @ref OSPI_SampleShifting */
|
||||
uint32_t DelayHoldQuarterCycle; /*!< It allows to hold to 1/4 cycle the data.
|
||||
This parameter can be a value of @ref OSPI_DelayHoldQuarterCycle */
|
||||
uint32_t ChipSelectBoundary; /*!< It enables the transaction boundary feature and
|
||||
defines the boundary of bytes to release the chip select.
|
||||
This parameter can be a value between 0 and 31 */
|
||||
uint32_t DelayBlockBypass; /*!< It enables the delay block bypass, so the sampling is not affected
|
||||
by the delay block.
|
||||
This parameter can be a value of @ref OSPI_DelayBlockBypass */
|
||||
#if defined (OCTOSPI_DCR3_MAXTRAN)
|
||||
uint32_t MaxTran; /*!< It enables the communication regulation feature. The chip select is
|
||||
released every MaxTran+1 bytes when the other OctoSPI request the access
|
||||
to the bus.
|
||||
This parameter can be a value between 0 and 255 */
|
||||
#endif
|
||||
#if defined (OCTOSPI_DCR4_REFRESH)
|
||||
uint32_t Refresh; /*!< It enables the refresh rate feature. The chip select is released every
|
||||
Refresh+1 clock cycles.
|
||||
This parameter can be a value between 0 and 0xFFFFFFFF */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
memset(&qh, 0, sizeof(qh));
|
||||
|
||||
qh.Instance = QUADSPI;
|
||||
qh.Init.ClockPrescaler = 64; // conservative starting value
|
||||
qh.Init.FifoThreshold = 4; // indirect mode only
|
||||
qh.Init.FlashSize = 23;
|
||||
qh.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_8_CYCLE; // maxed for now
|
||||
qh.Init.ClockMode = QSPI_CLOCK_MODE_0; // low clock between ops
|
||||
qh.Init.FlashID = QSPI_FLASH_ID_1;
|
||||
qh.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
|
||||
qh.Instance = OCTOSPI1;
|
||||
qh.Init.FifoThreshold = 4; // ??
|
||||
qh.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
|
||||
qh.Init.MemoryType = HAL_OSPI_MEMTYPE_MICRON; // seems like 8-bit mode stuff?
|
||||
qh.Init.DeviceSize = 23;
|
||||
qh.Init.ChipSelectHighTime = 8; // maxed out to start
|
||||
qh.Init.FreeRunningClock = HAL_OSPI_FREERUNCLK_DISABLE;
|
||||
qh.Init.ClockMode = HAL_OSPI_CLOCK_MODE_0; // low clock between ops
|
||||
qh.Init.ClockPrescaler = 16; // prescaller, decrease me
|
||||
|
||||
qh.Init.ChipSelectBoundary = 0; // set for 1024-byte block size?
|
||||
|
||||
|
||||
// module init
|
||||
HAL_StatusTypeDef rv = HAL_QSPI_Init(&qh);
|
||||
HAL_StatusTypeDef rv = HAL_OSPI_Init(&qh);
|
||||
ASSERT(rv == HAL_OK);
|
||||
|
||||
// do some SPI commands first
|
||||
|
||||
QSPI_CommandTypeDef cmd = {
|
||||
// Read Electronic ID
|
||||
// - length not clear from datasheet, but bits repeat after 8 bytes
|
||||
|
||||
OSPI_RegularCmdTypeDef cmd = {
|
||||
.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG,
|
||||
.Instruction = 0x9f, // "read ID" command
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE,
|
||||
.Address = 0, // dont care
|
||||
.AddressSize = QSPI_ADDRESS_24_BITS,
|
||||
.AddressMode = QSPI_ADDRESS_1_LINE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.AddressSize = HAL_OSPI_ADDRESS_24_BITS,
|
||||
.AddressMode = HAL_OSPI_ADDRESS_1_LINE,
|
||||
.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DataMode = QSPI_DATA_1_LINE,
|
||||
.NbData = 8, // how much to read in bytes
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE, // normal
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD, // normal
|
||||
.DataMode = HAL_OSPI_DATA_1_LINE,
|
||||
.NbData = sizeof(psram_chip_eid), // how much to read in bytes
|
||||
};
|
||||
|
||||
// Start "Indirection functional mode"
|
||||
uint8_t buf[8];
|
||||
rv = HAL_QSPI_Command(&qh, &cmd, HAL_MAX_DELAY);
|
||||
ASSERT(rv == HAL_OK);
|
||||
rv = HAL_OSPI_Command(&qh, &cmd, HAL_MAX_DELAY);
|
||||
if(rv != HAL_OK) goto fail;
|
||||
|
||||
rv = HAL_QSPI_Receive(&qh, buf, HAL_MAX_DELAY);
|
||||
rv = HAL_OSPI_Receive(&qh, psram_chip_eid, HAL_MAX_DELAY);
|
||||
if(rv != HAL_OK) goto fail;
|
||||
|
||||
puts2("HAL_QSPI_Receive "); puthex2(rv); putchar('\n');
|
||||
hex_dump(buf, sizeof(buf));
|
||||
puts2("PSRAM EID: ");
|
||||
hex_dump(psram_chip_eid, sizeof(psram_chip_eid));
|
||||
ASSERT(psram_chip_eid[0] == 0x0d);
|
||||
ASSERT(psram_chip_eid[1] == 0x5d);
|
||||
|
||||
#if 0
|
||||
QSPI_MemoryMappedTypeDef mmap = {
|
||||
OSPI_MemoryMappedTypeDef mmap = {
|
||||
};
|
||||
|
||||
rv = HAL_QSPI_MemoryMapped(&qh, &cmd, &mmap);
|
||||
rv = HAL_OSPI_MemoryMapped(&qh, &cmd, &mmap);
|
||||
ASSERT(rv == HAL_OK);
|
||||
#endif
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
puts("PSRAM fail");
|
||||
|
||||
oled_setup();
|
||||
oled_show(screen_fatal);
|
||||
|
||||
LOCKUP_FOREVER();
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
||||
@ -4,6 +4,9 @@
|
||||
#pragma once
|
||||
#include "basics.h"
|
||||
|
||||
// 8 bytes of unique data from chip
|
||||
extern uint8_t psram_chip_eid[8];
|
||||
|
||||
extern void psram_setup(void);
|
||||
|
||||
// EOF
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
*
|
||||
*/
|
||||
#include "sflash.h"
|
||||
#include "console.h"
|
||||
#include <string.h>
|
||||
#include "delay.h"
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
@ -2,50 +2,31 @@
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_hal_conf.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 25-November-2015
|
||||
* @brief HAL configuration template file.
|
||||
* This file should be copied to the application folder and renamed
|
||||
* to stm32l4xx_hal_conf.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32L4xx_HAL_CONF_H
|
||||
#define __STM32L4xx_HAL_CONF_H
|
||||
#ifndef STM32L4xx_HAL_CONF_H
|
||||
#define STM32L4xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define USE_USB_FS
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
@ -56,59 +37,69 @@
|
||||
#define HAL_MODULE_ENABLED
|
||||
//#define HAL_ADC_MODULE_ENABLED
|
||||
//#define HAL_CAN_MODULE_ENABLED
|
||||
/* #define HAL_COMP_MODULE_ENABLED */
|
||||
//#define HAL_CAN_LEGACY_MODULE_ENABLED
|
||||
//#define HAL_COMP_MODULE_ENABLED
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
/* #define HAL_CRC_MODULE_ENABLED */
|
||||
/* #define HAL_CRYP_MODULE_ENABLED */
|
||||
//#define HAL_CRC_MODULE_ENABLED
|
||||
//#define HAL_CRYP_MODULE_ENABLED
|
||||
//#define HAL_DAC_MODULE_ENABLED
|
||||
/* #define HAL_DFSDM_MODULE_ENABLED */
|
||||
//#define HAL_DCMI_MODULE_ENABLED
|
||||
//#define HAL_DFSDM_MODULE_ENABLED
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
//#define HAL_DMA2D_MODULE_ENABLED
|
||||
//#define HAL_DSI_MODULE_ENABLED
|
||||
//#define HAL_EXTI_MODULE_ENABLED
|
||||
#define HAL_FIREWALL_MODULE_ENABLED
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
/* #define HAL_HCD_MODULE_ENABLED */
|
||||
/* #define HAL_NAND_MODULE_ENABLED */
|
||||
/* #define HAL_NOR_MODULE_ENABLED */
|
||||
/* #define HAL_SRAM_MODULE_ENABLED */
|
||||
//#define HAL_GFXMMU_MODULE_ENABLED
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
#define HAL_HASH_MODULE_ENABLED
|
||||
//#define HAL_HCD_MODULE_ENABLED
|
||||
//#define HAL_I2C_MODULE_ENABLED
|
||||
/* #define HAL_IRDA_MODULE_ENABLED */
|
||||
/* #define HAL_IWDG_MODULE_ENABLED */
|
||||
/* #define HAL_LCD_MODULE_ENABLED */
|
||||
/* #define HAL_LPTIM_MODULE_ENABLED */
|
||||
/* #define HAL_OPAMP_MODULE_ENABLED */
|
||||
//#define HAL_IRDA_MODULE_ENABLED
|
||||
//#define HAL_IWDG_MODULE_ENABLED
|
||||
//#define HAL_LCD_MODULE_ENABLED
|
||||
//#define HAL_LPTIM_MODULE_ENABLED
|
||||
//#define HAL_LTDC_MODULE_ENABLED
|
||||
//#define HAL_MMC_MODULE_ENABLED
|
||||
//#define HAL_NAND_MODULE_ENABLED
|
||||
//#define HAL_NOR_MODULE_ENABLED
|
||||
//#define HAL_OPAMP_MODULE_ENABLED
|
||||
#define HAL_OSPI_MODULE_ENABLED
|
||||
//#define HAL_PCD_MODULE_ENABLED
|
||||
//#define HAL_PKA_MODULE_ENABLED
|
||||
//#define HAL_PSSI_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
//#define HAL_QSPI_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
#define HAL_RNG_MODULE_ENABLED
|
||||
//#define HAL_RTC_MODULE_ENABLED
|
||||
/* #define HAL_SAI_MODULE_ENABLED */
|
||||
//#define HAL_SAI_MODULE_ENABLED
|
||||
//#define HAL_SD_MODULE_ENABLED
|
||||
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/* #define HAL_SMBUS_MODULE_ENABLED */
|
||||
//#define HAL_SMARTCARD_MODULE_ENABLED
|
||||
//#define HAL_SMBUS_MODULE_ENABLED
|
||||
#define HAL_SPI_MODULE_ENABLED
|
||||
/* #define HAL_SWPMI_MODULE_ENABLED */
|
||||
//#define HAL_SRAM_MODULE_ENABLED
|
||||
//#define HAL_SWPMI_MODULE_ENABLED
|
||||
//#define HAL_TIM_MODULE_ENABLED
|
||||
//#define HAL_TSC_MODULE_ENABLED
|
||||
#define HAL_UART_MODULE_ENABLED
|
||||
#define HAL_USART_MODULE_ENABLED
|
||||
/* #define HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#define HAL_HASH_MODULE_ENABLED
|
||||
//#define HAL_WWDG_MODULE_ENABLED
|
||||
|
||||
|
||||
/* ########################## Oscillator Values adaptation ####################*/
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */
|
||||
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
@ -116,54 +107,66 @@
|
||||
* This value is the default MSI range value after Reset.
|
||||
*/
|
||||
#if !defined (MSI_VALUE)
|
||||
#define MSI_VALUE ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/
|
||||
#define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* MSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
|
||||
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC and RNG.
|
||||
* This internal oscillator is mainly dedicated to provide a high precision clock to
|
||||
* the USB peripheral by means of a special Clock Recovery System (CRS) circuitry.
|
||||
* When the CRS is not used, the HSI48 RC oscillator runs on it default frequency
|
||||
* which is subject to manufacturing process variations.
|
||||
*/
|
||||
#if !defined (HSI48_VALUE)
|
||||
#define HSI48_VALUE 48000000U /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
|
||||
The real value my vary depending on manufacturing process variations.*/
|
||||
#endif /* HSI48_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE ((uint32_t)32000) /*!< LSI Typical Value in Hz*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature. */
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature.*/
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
* This value is used by the UART, RTC HAL module to compute the system frequency
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/
|
||||
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */
|
||||
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief External clock source for SAI1 peripheral
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* frequency.
|
||||
*/
|
||||
#if !defined (EXTERNAL_SAI1_CLOCK_VALUE)
|
||||
#define EXTERNAL_SAI1_CLOCK_VALUE ((uint32_t)48000) /*!< Value of the SAI1 External clock source in Hz*/
|
||||
#define EXTERNAL_SAI1_CLOCK_VALUE 48000U /*!< Value of the SAI1 External clock source in Hz*/
|
||||
#endif /* EXTERNAL_SAI1_CLOCK_VALUE */
|
||||
|
||||
/**
|
||||
* @brief External clock source for SAI2 peripheral
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* frequency.
|
||||
*/
|
||||
#if !defined (EXTERNAL_SAI2_CLOCK_VALUE)
|
||||
#define EXTERNAL_SAI2_CLOCK_VALUE ((uint32_t)48000) /*!< Value of the SAI2 External clock source in Hz*/
|
||||
#define EXTERNAL_SAI2_CLOCK_VALUE 48000U /*!< Value of the SAI2 External clock source in Hz*/
|
||||
#endif /* EXTERNAL_SAI2_CLOCK_VALUE */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
@ -173,19 +176,73 @@
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY ((uint32_t)0x00) /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0
|
||||
#define PREFETCH_ENABLE 1
|
||||
#define INSTRUCTION_CACHE_ENABLE 1
|
||||
#define DATA_CACHE_ENABLE 1
|
||||
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY 0x0FU /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 0U
|
||||
#define INSTRUCTION_CACHE_ENABLE 1U
|
||||
#define DATA_CACHE_ENABLE 1U
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1 */
|
||||
/* #define USE_FULL_ASSERT 1U */
|
||||
|
||||
/* ################## Register callback feature configuration ############### */
|
||||
/**
|
||||
* @brief Set below the peripheral configuration to "1U" to add the support
|
||||
* of HAL callback registration/deregistration feature for the HAL
|
||||
* driver(s). This allows user application to provide specific callback
|
||||
* functions thanks to HAL_PPP_RegisterCallback() rather than overwriting
|
||||
* the default weak callback functions (see each stm32l4xx_hal_ppp.h file
|
||||
* for possible callback identifiers defined in HAL_PPP_CallbackIDTypeDef
|
||||
* for each PPP peripheral).
|
||||
*/
|
||||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_GFXMMU_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_OSPI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_TSC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_UART_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_USART_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 1U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
@ -220,6 +277,10 @@
|
||||
#include "stm32l4xx_hal_can.h"
|
||||
#endif /* HAL_CAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
|
||||
#include "Legacy/stm32l4xx_hal_can_legacy.h"
|
||||
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_COMP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_comp.h"
|
||||
#endif /* HAL_COMP_MODULE_ENABLED */
|
||||
@ -236,6 +297,26 @@
|
||||
#include "stm32l4xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DCMI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dcmi.h"
|
||||
#endif /* HAL_DCMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA2D_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dma2d.h"
|
||||
#endif /* HAL_DMA2D_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DSI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dsi.h"
|
||||
#endif /* HAL_DSI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_exti.h"
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GFXMMU_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_gfxmmu.h"
|
||||
#endif /* HAL_GFXMMU_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FIREWALL_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_firewall.h"
|
||||
#endif /* HAL_FIREWALL_MODULE_ENABLED */
|
||||
@ -244,136 +325,156 @@
|
||||
#include "stm32l4xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
#ifdef HAL_HASH_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_hash.h"
|
||||
#endif /* HAL_HASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lcd.h"
|
||||
#endif /* HAL_LCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LPTIM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lptim.h"
|
||||
#endif /* HAL_LPTIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LTDC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_ltdc.h"
|
||||
#endif /* HAL_LTDC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_MMC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_mmc.h"
|
||||
#endif /* HAL_MMC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NAND_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_nand.h"
|
||||
#endif /* HAL_NAND_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lcd.h"
|
||||
#endif /* HAL_LCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LPTIM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lptim.h"
|
||||
#endif /* HAL_LPTIM_MODULE_ENABLED */
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OPAMP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_opamp.h"
|
||||
#include "stm32l4xx_hal_opamp.h"
|
||||
#endif /* HAL_OPAMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OSPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_ospi.h"
|
||||
#endif /* HAL_OSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PKA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pka.h"
|
||||
#endif /* HAL_PKA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PSSI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pssi.h"
|
||||
#endif /* HAL_PSSI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pwr.h"
|
||||
#include "stm32l4xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_QSPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_qspi.h"
|
||||
#include "stm32l4xx_hal_qspi.h"
|
||||
#endif /* HAL_QSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rng.h"
|
||||
#include "stm32l4xx_hal_rng.h"
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rtc.h"
|
||||
#include "stm32l4xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SAI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sai.h"
|
||||
#include "stm32l4xx_hal_sai.h"
|
||||
#endif /* HAL_SAI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sd.h"
|
||||
#include "stm32l4xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMBUS_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_smbus.h"
|
||||
#include "stm32l4xx_hal_smbus.h"
|
||||
#endif /* HAL_SMBUS_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_spi.h"
|
||||
#include "stm32l4xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SWPMI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_swpmi.h"
|
||||
#include "stm32l4xx_hal_swpmi.h"
|
||||
#endif /* HAL_SWPMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_tim.h"
|
||||
#include "stm32l4xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TSC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_tsc.h"
|
||||
#include "stm32l4xx_hal_tsc.h"
|
||||
#endif /* HAL_TSC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_uart.h"
|
||||
#include "stm32l4xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_usart.h"
|
||||
#include "stm32l4xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_wwdg.h"
|
||||
#include "stm32l4xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HASH_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_hash.h"
|
||||
#endif /* HAL_HASH_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* @param expr If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
void assert_failed(uint8_t *file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0)
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32L4xx_HAL_CONF_H */
|
||||
#endif /* STM32L4xx_HAL_CONF_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,939 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_hal_hash_ex.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.7.2
|
||||
* @date 16-June-2017
|
||||
* @brief Extended HASH HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the HASH peripheral for SHA-224 and SHA-256
|
||||
* alogrithms:
|
||||
* + HASH or HMAC processing in polling mode
|
||||
* + HASH or HMAC processing in interrupt mode
|
||||
* + HASH or HMAC processing in DMA mode
|
||||
* Additionally, this file provides functions to manage HMAC
|
||||
* multi-buffer DMA-based processing for MD-5, SHA-1, SHA-224
|
||||
* and SHA-256.
|
||||
*
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### HASH peripheral extended features #####
|
||||
===============================================================================
|
||||
[..]
|
||||
The SHA-224 and SHA-256 HASH and HMAC processing can be carried out exactly
|
||||
the same way as for SHA-1 or MD-5 algorithms.
|
||||
(#) Three modes are available.
|
||||
(##) Polling mode: processing APIs are blocking functions
|
||||
i.e. they process the data and wait till the digest computation is finished,
|
||||
e.g. HAL_HASHEx_xxx_Start()
|
||||
(##) Interrupt mode: processing APIs are not blocking functions
|
||||
i.e. they process the data under interrupt,
|
||||
e.g. HAL_HASHEx_xxx_Start_IT()
|
||||
(##) DMA mode: processing APIs are not blocking functions and the CPU is
|
||||
not used for data transfer i.e. the data transfer is ensured by DMA,
|
||||
e.g. HAL_HASHEx_xxx_Start_DMA(). Note that in DMA mode, a call to
|
||||
HAL_HASHEx_xxx_Finish() is then required to retrieve the digest.
|
||||
|
||||
(#)Multi-buffer processing is possible in polling and DMA mode.
|
||||
(##) In polling mode, only multi-buffer HASH processing is possible.
|
||||
API HAL_HASHEx_xxx_Accumulate() must be called for each input buffer, except for the last one.
|
||||
User must resort to HAL_HASHEx_xxx_Start() to enter the last one and retrieve as
|
||||
well the computed digest.
|
||||
|
||||
(##) In DMA mode, multi-buffer HASH and HMAC processing are possible.
|
||||
|
||||
(+++) HASH processing: once initialization is done, MDMAT bit must be set thru __HAL_HASH_SET_MDMAT() macro.
|
||||
From that point, each buffer can be fed to the IP thru HAL_HASHEx_xxx_Start_DMA() API.
|
||||
Before entering the last buffer, reset the MDMAT bit with __HAL_HASH_RESET_MDMAT()
|
||||
macro then wrap-up the HASH processing in feeding the last input buffer thru the
|
||||
same API HAL_HASHEx_xxx_Start_DMA(). The digest can then be retrieved with a call to
|
||||
API HAL_HASHEx_xxx_Finish().
|
||||
|
||||
(+++) HMAC processing (MD-5, SHA-1, SHA-224 and SHA-256 must all resort to
|
||||
extended functions): after initialization, the key and the first input buffer are entered
|
||||
in the IP with the API HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and
|
||||
starts step 2.
|
||||
The following buffers are next entered with the API HAL_HMACEx_xxx_Step2_DMA(). At this
|
||||
point, the HMAC processing is still carrying out step 2.
|
||||
Then, step 2 for the last input buffer and step 3 are carried out by a single call
|
||||
to HAL_HMACEx_xxx_Step2_3_DMA().
|
||||
|
||||
The digest can finally be retrieved with a call to API HAL_HASH_xxx_Finish() for
|
||||
MD-5 and SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 and SHA-256.
|
||||
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#ifdef HAL_HASH_MODULE_ENABLED
|
||||
|
||||
#if defined (STM32L4A6xx)
|
||||
|
||||
/** @addtogroup STM32L4xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HASHEx HASHEx
|
||||
* @brief HASH HAL extended module driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions HASH Extended Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group1 HASH extended processing functions in polling mode
|
||||
* @brief HASH extended processing functions using polling mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Polling mode HASH extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in polling mode
|
||||
the hash value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HASHEx_SHA224_Start()
|
||||
(++) HAL_HASHEx_SHA224_Accumulate()
|
||||
(+) SHA256
|
||||
(++) HAL_HASHEx_SHA256_Start()
|
||||
(++) HAL_HASHEx_SHA256_Accumulate()
|
||||
|
||||
[..] For a single buffer to be hashed, user can resort to HAL_HASH_xxx_Start().
|
||||
|
||||
[..] In case of multi-buffer HASH processing (a single digest is computed while
|
||||
several buffers are fed to the IP), the user can resort to successive calls
|
||||
to HAL_HASHEx_xxx_Accumulate() and wrap-up the digest computation by a call
|
||||
to HAL_HASHEx_xxx_Start().
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then
|
||||
* read the computed digest.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @param Timeout: Timeout value
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief If not already done, initialize the HASH peripheral in SHA224 mode then
|
||||
* processes pInBuffer.
|
||||
* @note Consecutive calls to HAL_HASHEx_SHA224_Accumulate() can be used to feed
|
||||
* several input buffers back-to-back to the IP that will yield a single
|
||||
* HASH signature once all buffers have been entered. Wrap-up of input
|
||||
* buffers feeding and retrieval of digest is done by a call to
|
||||
* HAL_HASHEx_SHA224_Start().
|
||||
* @note Field hhash->Phase of HASH handle is tested to check whether or not
|
||||
* the IP has already been initialized.
|
||||
* @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA224_Start()
|
||||
* to read it, feeding at the same time the last input buffer to the IP.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted. Only HAL_HASHEx_SHA224_Start() is able
|
||||
* to manage the ending buffer with a length in bytes not a multiple of 4.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes, must be a multiple of 4.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HASH_Accumulate(hhash, pInBuffer, Size,HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then
|
||||
* read the computed digest.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @param Timeout: Timeout value
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief If not already done, initialize the HASH peripheral in SHA256 mode then
|
||||
* processes pInBuffer.
|
||||
* @note Consecutive calls to HAL_HASHEx_SHA256_Accumulate() can be used to feed
|
||||
* several input buffers back-to-back to the IP that will yield a single
|
||||
* HASH signature once all buffers have been entered. Wrap-up of input
|
||||
* buffers feeding and retrieval of digest is done by a call to
|
||||
* HAL_HASHEx_SHA256_Start().
|
||||
* @note Field hhash->Phase of HASH handle is tested to check whether or not
|
||||
* the IP has already been initialized.
|
||||
* @note Digest is not retrieved by this API, user must resort to HAL_HASHEx_SHA256_Start()
|
||||
* to read it, feeding at the same time the last input buffer to the IP.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted. Only HAL_HASHEx_SHA256_Start() is able
|
||||
* to manage the ending buffer with a length in bytes not a multiple of 4.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes, must be a multiple of 4.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HASH_Accumulate(hhash, pInBuffer, Size,HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group2 HASH extended processing functions in interrupt mode
|
||||
* @brief HASH extended processing functions using interrupt mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Interruption mode HASH extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in interrupt mode
|
||||
the hash value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HASHEx_SHA224_Start_IT()
|
||||
(+) SHA256
|
||||
(++) HAL_HASHEx_SHA256_Start_IT()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA224 mode, next process pInBuffer then
|
||||
* read the computed digest in interruption mode.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer)
|
||||
{
|
||||
return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer,HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA256 mode, next process pInBuffer then
|
||||
* read the computed digest in interruption mode.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer)
|
||||
{
|
||||
return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer,HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if 0
|
||||
/** @defgroup HASHEx_Exported_Functions_Group3 HASH extended processing functions in DMA mode
|
||||
* @brief HASH extended processing functions using DMA mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### DMA mode HASH extended processing functionss #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in DMA mode
|
||||
the hash value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HASHEx_SHA224_Start_DMA()
|
||||
(++) HAL_HASHEx_SHA224_Finish()
|
||||
(+) SHA256
|
||||
(++) HAL_HASHEx_SHA256_Start_DMA()
|
||||
(++) HAL_HASHEx_SHA256_Finish()
|
||||
|
||||
[..] When resorting to DMA mode to enter the data in the IP, user must resort
|
||||
to HAL_HASHEx_xxx_Start_DMA() then read the resulting digest with
|
||||
HAL_HASHEx_xxx_Finish().
|
||||
|
||||
[..] In case of multi-buffer HASH processing, MDMAT bit must first be set before
|
||||
the successive calls to HAL_HASHEx_xxx_Start_DMA(). Then, MDMAT bit needs to be
|
||||
reset before the last call to HAL_HASHEx_xxx_Start_DMA(). Digest is finally
|
||||
retrieved thanks to HAL_HASHEx_xxx_Finish().
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA224 mode then initiate a DMA transfer
|
||||
* to feed the input buffer to the IP.
|
||||
* @note Once the DMA transfer is finished, HAL_HASHEx_SHA224_Finish() API must
|
||||
* be called to retrieve the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Return the computed digest in SHA224 mode.
|
||||
* @note The API waits for DCIS to be set then reads the computed digest.
|
||||
* @note HAL_HASHEx_SHA224_Finish() can be used as well to retrieve the digest in
|
||||
* HMAC SHA224 mode.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @param Timeout: Timeout value.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HASH_Finish(hhash, pOutBuffer, Timeout);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in SHA256 mode then initiate a DMA transfer
|
||||
* to feed the input buffer to the IP.
|
||||
* @note Once the DMA transfer is finished, HAL_HASHEx_SHA256_Finish() API must
|
||||
* be called to retrieve the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Return the computed digest in SHA256 mode.
|
||||
* @note The API waits for DCIS to be set then reads the computed digest.
|
||||
* @note HAL_HASHEx_SHA256_Finish() can be used as well to retrieve the digest in
|
||||
* HMAC SHA256 mode.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @param Timeout: Timeout value.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HASH_Finish(hhash, pOutBuffer, Timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group4 HMAC extended processing functions in polling mode
|
||||
* @brief HMAC extended processing functions using polling mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Polling mode HMAC extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in polling mode
|
||||
the HMAC value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HMACEx_SHA224_Start()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA256_Start()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then
|
||||
* read the computed digest.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @param Timeout: Timeout value.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then
|
||||
* read the computed digest.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @param Timeout: Timeout value.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout)
|
||||
{
|
||||
return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group5 HMAC extended processing functions in interrupt mode
|
||||
* @brief HMAC extended processing functions using interruption mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Interrupt mode HMAC extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in interrupt mode
|
||||
the HMAC value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HMACEx_SHA224_Start_IT()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA256_Start_IT()
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA224 mode, next process pInBuffer then
|
||||
* read the computed digest in interrupt mode.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 28 bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer)
|
||||
{
|
||||
return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA256 mode, next process pInBuffer then
|
||||
* read the computed digest in interrupt mode.
|
||||
* @note Digest is available in pOutBuffer.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @param pOutBuffer: pointer to the computed digest. Digest size is 32 bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer)
|
||||
{
|
||||
return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group6 HMAC extended processing functions in DMA mode
|
||||
* @brief HMAC extended processing functions using DMA mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### DMA mode HMAC extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to calculate in DMA mode
|
||||
the HMAC value using one of the following algorithms:
|
||||
(+) SHA224
|
||||
(++) HAL_HMACEx_SHA224_Start_DMA()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA256_Start_DMA()
|
||||
|
||||
[..] When resorting to DMA mode to enter the data in the IP for HMAC processing,
|
||||
user must resort to HAL_HMACEx_xxx_Start_DMA() then read the resulting digest
|
||||
with HAL_HASHEx_xxx_Finish().
|
||||
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required
|
||||
* DMA transfers to feed the key and the input buffer to the IP.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA224_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note If MDMAT bit is set before calling this function (multi-buffer
|
||||
* HASH processing case), the input buffer size (in bytes) must be
|
||||
* a multiple of 4 otherwise, the HASH digest computation is corrupted.
|
||||
* For the processing of the last buffer of the thread, MDMAT bit must
|
||||
* be reset and the buffer length (in bytes) doesn't have to be a
|
||||
* multiple of 4.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the HASH peripheral in HMAC SHA224 mode then initiate the required
|
||||
* DMA transfers to feed the key and the input buffer to the IP.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note If MDMAT bit is set before calling this function (multi-buffer
|
||||
* HASH processing case), the input buffer size (in bytes) must be
|
||||
* a multiple of 4 otherwise, the HASH digest computation is corrupted.
|
||||
* For the processing of the last buffer of the thread, MDMAT bit must
|
||||
* be reset and the buffer length (in bytes) doesn't have to be a
|
||||
* multiple of 4.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (buffer to be hashed).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup HASHEx_Exported_Functions_Group7 Multi-buffer HMAC extended processing functions in DMA mode
|
||||
* @brief HMAC extended processing functions in multi-buffer DMA mode.
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Multi-buffer DMA mode HMAC extended processing functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions to manage HMAC multi-buffer
|
||||
DMA-based processing for MD5, SHA1, SHA224 and SHA256 algorithms.
|
||||
(+) MD5
|
||||
(++) HAL_HMACEx_MD5_Step1_2_DMA()
|
||||
(++) HAL_HMACEx_MD5_Step2_DMA()
|
||||
(++) HAL_HMACEx_MD5_Step2_3_DMA()
|
||||
(+) SHA1
|
||||
(++) HAL_HMACEx_SHA1_Step1_2_DMA()
|
||||
(++) HAL_HMACEx_SHA1_Step2_DMA()
|
||||
(++) HAL_HMACEx_SHA1_Step2_3_DMA()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA224_Step1_2_DMA()
|
||||
(++) HAL_HMACEx_SHA224_Step2_DMA()
|
||||
(++) HAL_HMACEx_SHA224_Step2_3_DMA()
|
||||
(+) SHA256
|
||||
(++) HAL_HMACEx_SHA256_Step1_2_DMA()
|
||||
(++) HAL_HMACEx_SHA256_Step2_DMA()
|
||||
(++) HAL_HMACEx_SHA256_Step2_3_DMA()
|
||||
|
||||
[..] User must first start-up the multi-buffer DMA-based HMAC computation in
|
||||
calling HAL_HMACEx_xxx_Step1_2_DMA(). This carries out HMAC step 1 and
|
||||
intiates step 2 with the first input buffer.
|
||||
|
||||
[..] The following buffers are next fed to the IP with a call to the API
|
||||
HAL_HMACEx_xxx_Step2_DMA(). There may be several consecutive calls
|
||||
to this API.
|
||||
|
||||
[..] Multi-buffer DMA-based HMAC computation is wrapped up by a call to
|
||||
HAL_HMACEx_xxx_Step2_3_DMA(). This finishes step 2 in feeding the last input
|
||||
buffer to the IP then carries out step 3.
|
||||
|
||||
[..] Digest is retrieved by a call to HAL_HASH_xxx_Finish() for MD-5 or
|
||||
SHA-1, to HAL_HASHEx_xxx_Finish() for SHA-224 or SHA-256.
|
||||
|
||||
[..] If only two buffers need to be consecutively processed, a call to
|
||||
HAL_HMACEx_xxx_Step1_2_DMA() followed by a call to HAL_HMACEx_xxx_Step2_3_DMA()
|
||||
is sufficient.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief MD5 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
|
||||
* @note Step 1 consists in writing the inner hash function key in the IP,
|
||||
* step 2 consists in writing the message text.
|
||||
* @note The API carries out the HMAC step 1 then starts step 2 with
|
||||
* the first buffer entered to the IP. DCAL bit is not automatically set after
|
||||
* the message buffer feeding, allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_MD5_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = SET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MD5 HMAC step 2 in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP.
|
||||
* @note The API carries on the HMAC step 2, applied to the buffer entered as input
|
||||
* parameter. DCAL bit is not automatically set after the message buffer feeding,
|
||||
* allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
if (hhash->DigestCalculationDisable != SET)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MD5 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP,
|
||||
* step 3 consists in writing the outer hash function key.
|
||||
* @note The API wraps up the HMAC step 2 in processing the buffer entered as input
|
||||
* parameter (the input buffer must be the last one of the multi-buffer thread)
|
||||
* then carries out HMAC step 3.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_MD5_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = RESET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief SHA1 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
|
||||
* @note Step 1 consists in writing the inner hash function key in the IP,
|
||||
* step 2 consists in writing the message text.
|
||||
* @note The API carries out the HMAC step 1 then starts step 2 with
|
||||
* the first buffer entered to the IP. DCAL bit is not automatically set after
|
||||
* the message buffer feeding, allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA1_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = SET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA1 HMAC step 2 in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP.
|
||||
* @note The API carries on the HMAC step 2, applied to the buffer entered as input
|
||||
* parameter. DCAL bit is not automatically set after the message buffer feeding,
|
||||
* allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
if (hhash->DigestCalculationDisable != SET)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA1 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP,
|
||||
* step 3 consists in writing the outer hash function key.
|
||||
* @note The API wraps up the HMAC step 2 in processing the buffer entered as input
|
||||
* parameter (the input buffer must be the last one of the multi-buffer thread)
|
||||
* then carries out HMAC step 3.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA1_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = RESET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA224 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
|
||||
* @note Step 1 consists in writing the inner hash function key in the IP,
|
||||
* step 2 consists in writing the message text.
|
||||
* @note The API carries out the HMAC step 1 then starts step 2 with
|
||||
* the first buffer entered to the IP. DCAL bit is not automatically set after
|
||||
* the message buffer feeding, allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = SET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA224 HMAC step 2 in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP.
|
||||
* @note The API carries on the HMAC step 2, applied to the buffer entered as input
|
||||
* parameter. DCAL bit is not automatically set after the message buffer feeding,
|
||||
* allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
if (hhash->DigestCalculationDisable != SET)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA224 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP,
|
||||
* step 3 consists in writing the outer hash function key.
|
||||
* @note The API wraps up the HMAC step 2 in processing the buffer entered as input
|
||||
* parameter (the input buffer must be the last one of the multi-buffer thread)
|
||||
* then carries out HMAC step 3.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA224_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = RESET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA224);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA256 HMAC step 1 completion and step 2 start in multi-buffer DMA mode.
|
||||
* @note Step 1 consists in writing the inner hash function key in the IP,
|
||||
* step 2 consists in writing the message text.
|
||||
* @note The API carries out the HMAC step 1 then starts step 2 with
|
||||
* the first buffer entered to the IP. DCAL bit is not automatically set after
|
||||
* the message buffer feeding, allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Step1_2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = SET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA256 HMAC step 2 in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP.
|
||||
* @note The API carries on the HMAC step 2, applied to the buffer entered as input
|
||||
* parameter. DCAL bit is not automatically set after the message buffer feeding,
|
||||
* allowing other messages DMA transfers to occur.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note The input buffer size (in bytes) must be a multiple of 4 otherwise, the
|
||||
* HASH digest computation is corrupted.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
if (hhash->DigestCalculationDisable != SET)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHA256 HMAC step 2 wrap-up and step 3 completion in multi-buffer DMA mode.
|
||||
* @note Step 2 consists in writing the message text in the IP,
|
||||
* step 3 consists in writing the outer hash function key.
|
||||
* @note The API wraps up the HMAC step 2 in processing the buffer entered as input
|
||||
* parameter (the input buffer must be the last one of the multi-buffer thread)
|
||||
* then carries out HMAC step 3.
|
||||
* @note Same key is used for the inner and the outer hash functions; pointer to key and
|
||||
* key size are respectively stored in hhash->Init.pKey and hhash->Init.KeySize.
|
||||
* @note Once the DMA transfers are finished (indicated by hhash->State set back
|
||||
* to HAL_HASH_STATE_READY), HAL_HASHEx_SHA256_Finish() API must be called to retrieve
|
||||
* the computed digest.
|
||||
* @param hhash: HASH handle.
|
||||
* @param pInBuffer: pointer to the input buffer (message buffer).
|
||||
* @param Size: length of the input buffer in bytes.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_HMACEx_SHA256_Step2_3_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
|
||||
{
|
||||
hhash->DigestCalculationDisable = RESET;
|
||||
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA256);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* defined (STM32L4A6xx) */
|
||||
|
||||
#endif /* HAL_HASH_MODULE_ENABLED */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
3213
stm32/mk4-bootloader/stm32l4xx_hal_ospi.c
Normal file
3213
stm32/mk4-bootloader/stm32l4xx_hal_ospi.c
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -54,20 +54,10 @@ _flash_wait_done(void)
|
||||
// busy wait
|
||||
}
|
||||
|
||||
if((__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PROGERR)) ||
|
||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR)) ||
|
||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_SIZERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGSERR)) ||
|
||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_MISERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_FASTERR)) ||
|
||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR)) ||
|
||||
#if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
|
||||
defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
|
||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_ECCD)) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_PEMPTY))
|
||||
#else
|
||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_ECCD))
|
||||
#endif
|
||||
) {
|
||||
// Save an error code; somewhat random
|
||||
return FLASH->SR;
|
||||
uint32_t error = (FLASH->SR & FLASH_FLAG_SR_ERRORS);
|
||||
if(error) {
|
||||
// Save an error code; somewhat random, depends on chip details
|
||||
return error;
|
||||
}
|
||||
|
||||
// Check FLASH End of Operation flag
|
||||
|
||||
Loading…
Reference in New Issue
Block a user