rusEFI
The most advanced open source ECU
Functions
Collaboration diagram for FLASH Private Functions:

Functions

HAL_StatusTypeDef FLASH_WaitForLastOperation (uint32_t Timeout, uint32_t Bank)
 Wait for a FLASH operation to complete. More...
 
HAL_StatusTypeDef FLASH_OB_WaitForLastOperation (uint32_t Timeout)
 Wait for a FLASH Option Bytes change operation to complete. More...
 
HAL_StatusTypeDef FLASH_CRC_WaitForLastOperation (uint32_t Timeout, uint32_t Bank)
 Wait for a FLASH CRC computation to complete. More...
 

Detailed Description

Function Documentation

◆ FLASH_CRC_WaitForLastOperation()

HAL_StatusTypeDef FLASH_CRC_WaitForLastOperation ( uint32_t  Timeout,
uint32_t  Bank 
)

Wait for a FLASH CRC computation to complete.

Parameters
Timeoutmaximum flash operation timeout
Bankflash FLASH_BANK_1 or FLASH_BANK_2
Return values
HAL_StatusTypeDefHAL Status

Definition at line 1111 of file stm32h7xx_hal_flash.c.

1112 {
1113  uint32_t bsyflag;
1114  (void)Timeout;
1115  //uint32_t tickstart = HAL_GetTick();
1116 
1117  assert_param(IS_FLASH_BANK_EXCLUSIVE(Bank));
1118 
1119  /* Select bsyflag depending on Bank */
1120  if(Bank == FLASH_BANK_1)
1121  {
1122  bsyflag = FLASH_FLAG_CRC_BUSY_BANK1;
1123  }
1124  else
1125  {
1126  bsyflag = FLASH_FLAG_CRC_BUSY_BANK2;
1127  }
1128 
1129  /* Wait for the FLASH CRC computation to complete by polling on CRC_BUSY flag to be reset */
1130  while(__HAL_FLASH_GET_FLAG(bsyflag))
1131  {
1132  // TODO: rusefi own timeout
1133  // if(Timeout != HAL_MAX_DELAY)
1134  // {
1135  // if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1136  // {
1137  // return HAL_TIMEOUT;
1138  // }
1139  // }
1140  }
1141 
1142  /* Check FLASH CRC read error flag */
1143  if(Bank == FLASH_BANK_1)
1144  {
1145  if (__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_CRCRDERR_BANK1))
1146  {
1147  /* Save the error code */
1148  pFlash.ErrorCode |= HAL_FLASH_ERROR_CRCRD_BANK1;
1149 
1150  /* Clear FLASH CRC read error pending bit */
1151  __HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_CRCRDERR_BANK1);
1152 
1153  return HAL_ERROR;
1154  }
1155  }
1156 #if defined (DUAL_BANK)
1157  else
1158  {
1159  if (__HAL_FLASH_GET_FLAG_BANK2(FLASH_FLAG_CRCRDERR_BANK2))
1160  {
1161  /* Save the error code */
1162  pFlash.ErrorCode |= HAL_FLASH_ERROR_CRCRD_BANK2;
1163 
1164  /* Clear FLASH CRC read error pending bit */
1165  __HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_CRCRDERR_BANK2);
1166 
1167  return HAL_ERROR;
1168  }
1169  }
1170 #endif /* DUAL_BANK */
1171 
1172  /* If there is no error flag set */
1173  return HAL_OK;
1174 }
FLASH_ProcessTypeDef pFlash

Referenced by HAL_FLASHEx_ComputeCRC().

Here is the caller graph for this function:

◆ FLASH_OB_WaitForLastOperation()

HAL_StatusTypeDef FLASH_OB_WaitForLastOperation ( uint32_t  Timeout)

Wait for a FLASH Option Bytes change operation to complete.

Parameters
Timeoutmaximum flash operation timeout
Return values
HAL_StatusTypeDefHAL Status

Definition at line 1070 of file stm32h7xx_hal_flash.c.

1071 {
1072  (void)Timeout;
1073  /* Get timeout */
1074  //uint32_t tickstart = HAL_GetTick();
1075 
1076  /* Wait for the FLASH Option Bytes change operation to complete by polling on OPT_BUSY flag to be reset */
1077  while(READ_BIT(FLASH->OPTSR_CUR, FLASH_OPTSR_OPT_BUSY) != 0U)
1078  {
1079  // TODO: rusefi own timeout
1080  /*if(Timeout != HAL_MAX_DELAY)
1081  {
1082  if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1083  {
1084  return HAL_TIMEOUT;
1085  }
1086  }*/
1087  }
1088 
1089  /* Check option byte change error */
1090  if(READ_BIT(FLASH->OPTSR_CUR, FLASH_OPTSR_OPTCHANGEERR) != 0U)
1091  {
1092  /* Save the error code */
1093  pFlash.ErrorCode |= HAL_FLASH_ERROR_OB_CHANGE;
1094 
1095  /* Clear the OB error flag */
1096  FLASH->OPTCCR |= FLASH_OPTCCR_CLR_OPTCHANGEERR;
1097 
1098  return HAL_ERROR;
1099  }
1100 
1101  /* If there is no error flag set */
1102  return HAL_OK;
1103 }

Referenced by HAL_FLASHEx_ComputeCRC().

Here is the caller graph for this function:

◆ FLASH_WaitForLastOperation()

HAL_StatusTypeDef FLASH_WaitForLastOperation ( uint32_t  Timeout,
uint32_t  Bank 
)

Wait for a FLASH operation to complete.

Parameters
Timeoutmaximum flash operation timeout
Bankflash FLASH_BANK_1 or FLASH_BANK_2
Return values
HAL_StatusTypeDefHAL Status

Definition at line 993 of file stm32h7xx_hal_flash.c.

994 {
995  (void)Timeout;
996 
997  /* Wait for the FLASH operation to complete by polling on QW flag to be reset.
998  Even if the FLASH operation fails, the QW flag will be reset and an error
999  flag will be set */
1000 
1001  uint32_t bsyflag = FLASH_FLAG_QW_BANK1;
1002  uint32_t errorflag = FLASH->SR1 & FLASH_FLAG_ALL_ERRORS_BANK1;
1003  //uint32_t tickstart = HAL_GetTick();
1004 
1005  assert_param(IS_FLASH_BANK_EXCLUSIVE(Bank));
1006 
1007 #if defined (DUAL_BANK)
1008 
1009  if (Bank == FLASH_BANK_2)
1010  {
1011  /* Get Error Flags */
1012  errorflag = (FLASH->SR2 & FLASH_FLAG_ALL_ERRORS_BANK2) | 0x80000000U;
1013  /* Select bsyflag depending on Bank */
1014  bsyflag = FLASH_FLAG_QW_BANK2;
1015  }
1016 #endif /* DUAL_BANK */
1017 
1018  while(__HAL_FLASH_GET_FLAG(bsyflag))
1019  {
1020  if(Timeout != HAL_MAX_DELAY)
1021  {
1022  // todo: implement rusEfi own timeout
1023  // if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1024  // {
1025  // return HAL_TIMEOUT;
1026  // }
1027  }
1028  }
1029 
1030  /* In case of error reported in Flash SR1 or SR2 register */
1031  if((errorflag & 0x7FFFFFFFU) != 0U)
1032  {
1033  /*Save the error code*/
1034  pFlash.ErrorCode |= errorflag;
1035 
1036  /* Clear error programming flags */
1037  __HAL_FLASH_CLEAR_FLAG(errorflag);
1038 
1039  return HAL_ERROR;
1040  }
1041 
1042  /* Check FLASH End of Operation flag */
1043  if(Bank == FLASH_BANK_1)
1044  {
1045  if (__HAL_FLASH_GET_FLAG_BANK1(FLASH_FLAG_EOP_BANK1))
1046  {
1047  /* Clear FLASH End of Operation pending bit */
1048  __HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1);
1049  }
1050  }
1051 #if defined (DUAL_BANK)
1052  else
1053  {
1054  if (__HAL_FLASH_GET_FLAG_BANK2(FLASH_FLAG_EOP_BANK2))
1055  {
1056  /* Clear FLASH End of Operation pending bit */
1057  __HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2);
1058  }
1059  }
1060 #endif /* DUAL_BANK */
1061 
1062  return HAL_OK;
1063 }

Referenced by HAL_FLASH_Program(), and HAL_FLASH_Program_IT().

Here is the caller graph for this function: