• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ HAL_FLASH_Unlock函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中HAL_FLASH_Unlock函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_FLASH_Unlock函数的具体用法?C++ HAL_FLASH_Unlock怎么用?C++ HAL_FLASH_Unlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了HAL_FLASH_Unlock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: flash_erase

void flash_erase(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32) {
    // check there is something to write
    if (num_word32 == 0) {
        return;
    }

    // unlock
    HAL_FLASH_Unlock();

    // Clear pending flags (if any)
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
                           FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);

    // erase the sector(s)
    FLASH_EraseInitTypeDef EraseInitStruct;
    EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
    EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V
    EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL);
    EraseInitStruct.NbSectors = flash_get_sector_info(flash_dest + 4 * num_word32 - 1, NULL, NULL) - EraseInitStruct.Sector + 1;
    uint32_t SectorError = 0;
    if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
        // error occurred during sector erase
        HAL_FLASH_Lock(); // lock the flash
        return;
    }
}
开发者ID:ashtons,项目名称:micropython,代码行数:26,代码来源:flash.c


示例2: FLASH_If_WriteProtectionConfig

/**
  * @brief  Configure the write protection status of user flash area.
  * @param  modifier DISABLE or ENABLE the protection
  * @retval HAL_StatusTypeDef HAL_OK if change is applied.
  */
HAL_StatusTypeDef FLASH_If_WriteProtectionConfig(uint32_t modifier)
{
  uint32_t ProtectedSECTOR = 0xFFF;
  FLASH_OBProgramInitTypeDef config_new, config_old;
  HAL_StatusTypeDef result = HAL_OK;
  
  /* Get pages write protection status ****************************************/
  HAL_FLASHEx_OBGetConfig(&config_old);

  /* The parameter says whether we turn the protection on or off */
  config_new.WRPState = modifier;

  /* We want to modify only the Write protection */
  config_new.OptionType = OPTIONBYTE_WRP;
  
  /* No read protection, keep BOR and reset settings */
  config_new.RDPLevel = OB_RDP_LEVEL_0;
  config_new.USERConfig = config_old.USERConfig;  
  /* Get pages already write protected ****************************************/
  ProtectedSECTOR = config_old.WRPSector | FLASH_SECTOR_TO_BE_PROTECTED;

  /* Unlock the Flash to enable the flash control register access *************/ 
  HAL_FLASH_Unlock();

  /* Unlock the Options Bytes *************************************************/
  HAL_FLASH_OB_Unlock();
  
  config_new.WRPSector    = ProtectedSECTOR;
  result = HAL_FLASHEx_OBProgram(&config_new);
  
  return result;
}
开发者ID:MrZANE42,项目名称:verisure1512,代码行数:37,代码来源:flash_if.c


示例3: writeEEPROM

// FIXME: HAL for now this will only work for F4/F7 as flash layout is different
void writeEEPROM(void)
{
    // Generate compile time error if the config does not fit in the reserved area of flash.
    BUILD_BUG_ON(sizeof(master_t) > FLASH_TO_RESERVE_FOR_CONFIG);

    HAL_StatusTypeDef status;
    uint32_t wordOffset;
    int8_t attemptsRemaining = 3;

    suspendRxSignal();

    // prepare checksum/version constants
    masterConfig.version = EEPROM_CONF_VERSION;
    masterConfig.size = sizeof(master_t);
    masterConfig.magic_be = 0xBE;
    masterConfig.magic_ef = 0xEF;
    masterConfig.chk = 0; // erase checksum before recalculating
    masterConfig.chk = calculateChecksum((const uint8_t *) &masterConfig, sizeof(master_t));

    // write it
    /* Unlock the Flash to enable the flash control register access *************/
    HAL_FLASH_Unlock();
    while (attemptsRemaining--)
    {
        /* Fill EraseInit structure*/
        FLASH_EraseInitTypeDef EraseInitStruct = {0};
        EraseInitStruct.TypeErase     = FLASH_TYPEERASE_SECTORS;
        EraseInitStruct.VoltageRange  = FLASH_VOLTAGE_RANGE_3; // 2.7-3.6V
        EraseInitStruct.Sector        = (FLASH_SECTOR_TOTAL-1);
        EraseInitStruct.NbSectors     = 1;
        uint32_t SECTORError;
        status = HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError);
        if (status != HAL_OK)
        {
            continue;
        }
        else
        {
            for (wordOffset = 0; wordOffset < sizeof(master_t); wordOffset += 4)
            {
                status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, CONFIG_START_FLASH_ADDRESS + wordOffset, *(uint32_t *) ((char *) &masterConfig + wordOffset));
                if(status != HAL_OK)
                {
                    break;
                }
            }
        }
        if (status == HAL_OK) {
            break;
        }
    }
    HAL_FLASH_Lock();

    // Flash write failed - just die now
    if (status != HAL_OK || !isEEPROMContentValid()) {
        failureMode(FAILURE_FLASH_WRITE_FAILED);
    }

    resumeRxSignal();
}
开发者ID:tianbin4279,项目名称:betaflight,代码行数:61,代码来源:config_eeprom.c


示例4: FLASH_If_Erase

/**
  * @brief  This function does an erase of all user flash area
  * @param  start: start of user flash area
  * @retval FLASHIF_OK : user flash area successfully erased
  *         FLASHIF_ERASEKO : error occurred
  */
uint32_t FLASH_If_Erase(uint32_t start)
{
  uint32_t NbrOfPages = 0;
  uint32_t PageError = 0;
  FLASH_EraseInitTypeDef pEraseInit;
  HAL_StatusTypeDef status = HAL_OK;

  /* Unlock the Flash to enable the flash control register access *************/ 
  HAL_FLASH_Unlock();

  /* Get the sector where start the user flash area */
  NbrOfPages = (USER_FLASH_END_ADDRESS - start)/FLASH_PAGE_SIZE;

  pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
  pEraseInit.PageAddress = start;
  pEraseInit.NbPages = NbrOfPages;
  status = HAL_FLASHEx_Erase(&pEraseInit, &PageError);

  /* Lock the Flash to disable the flash control register access (recommended
     to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();

  if (status != HAL_OK)
  {
    /* Error occurred while page erase */
    return FLASHIF_ERASEKO;
  }

  return FLASHIF_OK;
}
开发者ID:NjordCZ,项目名称:stm32cubef0,代码行数:36,代码来源:flash_if.c


示例5: stm32f3_flash_erase_block

/**
 * @brief Erase flash block
 * @note Block is the same thing as page in terms of stm32 lib:
 * it's minimal erasable chunk of flash memory
 *
 * @param dev
 * @param block
 *
 * @return Error code
 */
static int stm32f3_flash_erase_block(struct flash_dev *dev, uint32_t block) {
	int err;
	uint32_t page_err;
	FLASH_EraseInitTypeDef erase_struct;

	if (!stm32f3_flash_check_block(dev, block)) {
		return -EINVAL;
	}

	HAL_FLASH_Unlock();

	erase_struct = (FLASH_EraseInitTypeDef) {
		.TypeErase = TYPEERASE_PAGES,
		.PageAddress = dev->start + block * STM32F3_FLASH_PAGE_SIZE,
		.NbPages = 1,
	};

	err = HAL_FLASHEx_Erase(&erase_struct, &page_err);
	/* TODO check errcode */
	/* Lock to prevent unwanted operations with flash memory */
	HAL_FLASH_Lock();

	return err;
}


static int stm32f3_flash_read(struct flash_dev *dev, uint32_t base, void* data, size_t len) {
	size_t rlen = min(len, dev->end - dev->start + base);

	/* read can be unaligned */

	memcpy(data, (void *) dev->start + base, rlen);

	return rlen;
}
开发者ID:AleksandraButrova,项目名称:embox,代码行数:45,代码来源:stm32f3_flash.c


示例6: ResetSSIDPasswordInMemory

/**
  * @brief  Erase Access Point parameters from FLASH
  * @param  None
  * @retval System_Status_t (MODULE_SUCCESS/MODULE_ERROR)
  */
System_Status_t ResetSSIDPasswordInMemory(void)
{
  /* Reset Calibration Values in FLASH */
  System_Status_t status = MODULE_ERROR;

  /* Erase First Flash sector */
  FLASH_EraseInitTypeDef EraseInitStruct;
  uint32_t SectorError = 0;

  EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
  EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3;
  EraseInitStruct.Sector = BLUEMSYS_FLASH_SECTOR;
  EraseInitStruct.NbSectors = 1;

  /* Unlock the Flash to enable the flash control register access *************/
  HAL_FLASH_Unlock();

  if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK){
    /* Error occurred while sector erase.
      User can add here some code to deal with this error.
      SectorError will contain the faulty sector and then to know the code error on this sector,
      user can call function 'HAL_FLASH_GetError()'
      FLASH_ErrorTypeDef errorcode = HAL_FLASH_GetError(); */
      printf("\n\rError while erasing FLASH memory");
  } else {
      status = MODULE_SUCCESS;
  }
  /* Lock the Flash to disable the flash control register access (recommended
  to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();

  return status;
}
开发者ID:nguyendinhthi,项目名称:nguyendinh,代码行数:38,代码来源:wifi_support.c


示例7: ErasePage

void ErasePage(uint32_t pageAddress)
{
  FLASH_EraseInitTypeDef EraseInitStruct;
  uint32_t FirstPage = 0, NbOfPages = 0, BankNumber = 0, PAGEError = 0;

  /* Unlock the Flash to enable the flash control register access */
  HAL_FLASH_Unlock();

  /* Clear OPTVERR bit set on virgin samples */
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);

  /* Get the 1st page to erase */
  FirstPage = GetPage(pageAddress);
  /* Get the number of pages to erase from 1st page */
  NbOfPages = 1;
  /* Get the bank */
  BankNumber = GetBank(pageAddress);
  /* Fill EraseInit structure*/
  EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
  EraseInitStruct.Banks       = BankNumber;
  EraseInitStruct.Page        = FirstPage;
  EraseInitStruct.NbPages     = NbOfPages;

  HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError);

  HAL_FLASH_Lock();
}
开发者ID:meisteg,项目名称:muc-loader,代码行数:27,代码来源:stm32l4xx_flash.c


示例8: stm32f3_flash_program

/**
 * @brief Write data to flash memory
 *
 * @param dev
 * @param base
 * @param data
 * @param len
 *
 * @return Negative error code
 */
static int stm32f3_flash_program(struct flash_dev *dev, uint32_t base, const void* data, size_t len) {
	int err = 0;
	int offset;

	if (!stm32f3_flash_check_align(base, len)
			|| ((uintptr_t) data & 0x1) != 0) {
		return -EINVAL;
	}

	if (!stm32f3_flash_check_range(dev, base, len)) {
		return -EFBIG;
	}

	HAL_FLASH_Unlock();

	/* Write data halfword by halfword */
	for (offset = 0; offset < len; offset += 2) {
		if (HAL_OK != HAL_FLASH_Program(TYPEPROGRAM_HALFWORD,
					dev->start + base + offset,
					*((uint32_t*) data + offset)))
			return -1; /* TODO: set appropriate code */
	}

	/* Lock to prevent unwanted operations with flash memory */
	HAL_FLASH_Lock();

	return err;
}
开发者ID:AleksandraButrova,项目名称:embox,代码行数:38,代码来源:stm32f3_flash.c


示例9: flash_write

void flash_write(const uint32_t *src, uint32_t dst, uint32_t size)
{
    // Unlock flash
    HAL_FLASH_Unlock();

    #if defined(MCU_SERIES_H7)
    // Program the flash 32 bytes at a time.
    for (int i=0; i<size/32; i++) {
        if (HAL_FLASH_Program(TYPEPROGRAM_WORD, dst, (uint64_t)(uint32_t) src) != HAL_OK) {
            // error occurred during flash write
            HAL_FLASH_Lock(); // lock the flash
            __fatal_error();
        }
        src += 8;
        dst += 32;
    }
    #else
    // Program the flash 4 bytes at a time.
    for (int i=0; i<size/4; i++) {
        if (HAL_FLASH_Program(TYPEPROGRAM_WORD, dst, *src) != HAL_OK) {
            // error occurred during flash write
            HAL_FLASH_Lock(); // lock the flash
            __fatal_error();
        }
        src += 1;
        dst += 4;
    }
    #endif

    // lock the flash
    HAL_FLASH_Lock();
}
开发者ID:openmv,项目名称:openmv,代码行数:32,代码来源:flash.c


示例10: main

/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xB HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 64 MHz */
  SystemClock_Config();

  /* Unlock the Flash Program Erase controller */
  HAL_FLASH_Unlock();

  /* EEPROM Init */
  EE_Init();

/* --- Store successively many values of the three variables in the EEPROM ---*/
  /* Store 0x1000 values of Variable1 in EEPROM */
  for (VarValue = 1; VarValue <= 0x1000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[0], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);


  /* Store 0x2000 values of Variable2 in EEPROM */
  for (VarValue = 1; VarValue <= 0x2000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[1], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);


  /* Store 0x3000 values of Variable3 in EEPROM */
  for (VarValue = 1; VarValue <= 0x3000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[2], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);
  EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]);

  while (1)
  {
  };
}
开发者ID:NjordCZ,项目名称:STM32Cube_FW_F1,代码行数:65,代码来源:main.c


示例11: flash_erase

void flash_erase(uint32_t sector)
{
    uint32_t SectorError = 0;

    // unlock
    HAL_FLASH_Unlock();

    // Clear pending flags (if any)
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
                           FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);

    // erase the sector(s)
    FLASH_EraseInitTypeDef EraseInitStruct;
    EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
    EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V
    EraseInitStruct.Sector = sector;
    EraseInitStruct.NbSectors = 1;

    if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
        // error occurred during sector erase
        HAL_FLASH_Lock(); // lock the flash
        __fatal_error();
    }

    HAL_FLASH_Lock(); // lock the flash
}
开发者ID:michaelchi08,项目名称:openmv,代码行数:26,代码来源:flash.c


示例12: FLASH_If_GetWriteProtectionStatus

/**
  * @brief  Returns the write protection status of application flash area.
  * @param  None
  * @retval If a sector in application area is write-protected returned value is a combinaison
            of the possible values : FLASHIF_PROTECTION_WRPENABLED, FLASHIF_PROTECTION_PCROPENABLED, ...
  *         If no sector is write-protected FLASHIF_PROTECTION_NONE is returned.
  */
uint32_t FLASH_If_GetWriteProtectionStatus(void)
{
  uint32_t ProtectedPAGE = FLASHIF_PROTECTION_NONE;
  FLASH_OBProgramInitTypeDef OptionsBytesStruct;

  /* Unlock the Flash to enable the flash control register access *************/
  HAL_FLASH_Unlock();

  /* Check if there are write protected sectors inside the user flash area ****/
  HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);

  /* Lock the Flash to disable the flash control register access (recommended
     to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();

  /* Get pages already write protected ****************************************/
  ProtectedPAGE = ~(OptionsBytesStruct.WRPPage) & FLASH_PAGE_TO_BE_PROTECTED;

  /* Check if desired pages are already write protected ***********************/
  if(ProtectedPAGE != 0)
  {
    /* Some sectors inside the user flash area are write protected */
    return FLASHIF_PROTECTION_WRPENABLED;
  }
  else
  { 
    /* No write protected sectors inside the user flash area */
    return FLASHIF_PROTECTION_NONE;
  }
}
开发者ID:NjordCZ,项目名称:stm32cubef0,代码行数:37,代码来源:flash_if.c


示例13: FLASH_If_Write

/**
  * @brief  This function writes a data buffer in flash (data are 32-bit aligned).
  * @note   After writing data buffer, the flash content is checked.
  * @param  destination: start address for target location
  * @param  p_source: pointer on buffer with data to write
  * @param  length: length of data buffer (unit is 32-bit word)
  * @retval uint32_t 0: Data successfully written to Flash memory
  *         1: Error occurred while writing data in Flash memory
  *         2: Written Data in flash memory is different from expected one
  */
uint32_t FLASH_If_Write(uint32_t destination, uint32_t *p_source, uint32_t length)
{
  uint32_t i = 0;

  /* Unlock the Flash to enable the flash control register access *************/
  HAL_FLASH_Unlock();

  for (i = 0; (i < length) && (destination <= (USER_FLASH_END_ADDRESS-4)); i++)
  {
    /* Device voltage range supposed to be [2.7V to 3.6V], the operation will
       be done by word */ 
    if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, destination, *(uint32_t*)(p_source+i)) == HAL_OK)      
    {
     /* Check the written value */
      if (*(uint32_t*)destination != *(uint32_t*)(p_source+i))
      {
        /* Flash content doesn't match SRAM content */
        return(FLASHIF_WRITINGCTRL_ERROR);
      }
      /* Increment FLASH destination address */
      destination += 4;
    }
    else
    {
      /* Error occurred while writing data in Flash memory */
      return (FLASHIF_WRITING_ERROR);
    }
  }

  /* Lock the Flash to disable the flash control register access (recommended
     to protect the FLASH memory against possible unwanted operation) *********/
  HAL_FLASH_Lock();

  return (FLASHIF_OK);
}
开发者ID:NjordCZ,项目名称:stm32cubef0,代码行数:45,代码来源:flash_if.c


示例14: FLASH_If_Init

/**
  * @brief  Unlocks Flash for write access
  * @param  None
  * @retval None
  */
void FLASH_If_Init(void)
{
  HAL_FLASH_Unlock(); 

  /* Clear pending flags (if any) */  
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | 
                         FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_ERSERR);
}
开发者ID:MrZANE42,项目名称:verisure1512,代码行数:13,代码来源:flash_if.c


示例15: program_tftf_header

/**
 * @brief Writes the contents fo the TFTF header to the TFTF_PARTITION
 */
int program_tftf_header(uint8_t *data, uint32_t size)
{
  HAL_FLASH_Unlock();
  program_flash_data((uint32_t)(PARTITION_TFTF_START), size, data);
  HAL_FLASH_Lock();

  return 0;
}
开发者ID:meisteg,项目名称:muc-loader,代码行数:11,代码来源:stm32l4xx_flash.c


示例16: hacs_pstore_set

int hacs_pstore_set(hacs_pstore_type_t ent, uint8_t *wbuf, uint32_t byte_len)
{
  uint32_t ent_addr = hacs_pstore_ent_rel_addr[ent];
  hacs_pstore_entry_t *ent_header;
  hacs_pstore_header_t *bank_header;
  uint8_t *buf_ptr;
  uint32_t counter;
  uint32_t temp;
  uint32_t sector;
  int retval;

  // Read in the entire current bank
  memcpy(ram_buf, (uint8_t*)current_bank_addr, HACS_PSTORE_BANK_SIZE);

  // Check entry size. Make sure we are not writing something too big.
  retval = -HACS_INVALID_ARGS;
  HACS_REQUIRES(byte_len <= hacs_pstore_ent_size[ent], done);

  // Update entry content
  buf_ptr = (uint8_t*)(ram_buf + ent_addr + sizeof(hacs_pstore_entry_t));
  memcpy(buf_ptr, wbuf, byte_len);

  // Update entry header
  ent_header = (hacs_pstore_entry_t*)(ram_buf + ent_addr);
  ent_header->byte_len = byte_len;
  ent_header->crc = hacs_crc32_calc(wbuf, byte_len); // each entry has its own CRC

  // Update bank header
  bank_header = (hacs_pstore_header_t *)ram_buf;
  bank_header->bank_version++;
  bank_header->layout_version = HACS_PSTORE_LAYOUT_VERSION;

  // Write the ram buffer to the alternate bank
  HAL_FLASH_Unlock();
  sector = (alternate_bank_addr == HACS_PSTORE_0_ADDR) ? HACS_PSTORE_0_SECTOR : HACS_PSTORE_1_SECTOR;
  FLASH_Erase_Sector(sector, VOLTAGE_RANGE_3);
  // Write the ram buffer word by word.
  counter = 0;
  while(counter < sizeof(ram_buf)) {
    HAL_FLASH_Program(TYPEPROGRAM_WORD, alternate_bank_addr+counter,
                      *(uint32_t*)(ram_buf+counter)); // unaligned access supported
    counter += 4;
  }
  // Note that I exploit the fact that the ram buffer is word-aligned 
  // (its length is multiple of 4).
  assert(counter == sizeof(ram_buf));
  HAL_FLASH_Lock();

  // Switch current bank and alternate bank
  temp = alternate_bank_addr;
  alternate_bank_addr = current_bank_addr;
  current_bank_addr = temp;

  retval = HACS_NO_ERROR;
done:
  return retval;
}
开发者ID:gzwsc2007,项目名称:Hobby_Airplane_Control_System,代码行数:57,代码来源:hacs_pstore.c


示例17: flash_unlock

static int32_t flash_unlock(void)
{
    /* Allow Access to Flash control registers and user Falsh */
    if (HAL_FLASH_Unlock()) {
        return -1;
    } else {
        return 0;
    }
}
开发者ID:Archcady,项目名称:mbed-os,代码行数:9,代码来源:flash_api.c


示例18: stm32_flash_bdev_erase

static ssize_t stm32_flash_bdev_erase(struct bdev *bdev, off_t offset, size_t len)
{
    LTRACEF("dev %p, offset 0x%llx, len 0x%zx\n", bdev, offset, len);

    ssize_t total_erased = 0;

    HAL_FLASH_Unlock();

    while (len > 0) {
        uint32_t sector = 0;
        off_t sector_offset = 0;
        off_t next_offset = 0;

        if (offset_to_sector(offset, &sector, &sector_offset, &next_offset) < 0)
            return ERR_INVALID_ARGS;

        FLASH_EraseInitTypeDef erase;
        erase.TypeErase = FLASH_TYPEERASE_SECTORS;
        erase.Sector = sector;
        erase.NbSectors = 1;
        erase.VoltageRange = FLASH_VOLTAGE_RANGE_3; // XXX

        LTRACEF("erase params: sector %u, num_sectors %u, next_offset 0x%llx\n", erase.Sector, erase.NbSectors, next_offset);

        if (1) {
            uint32_t sector_error;
            HAL_StatusTypeDef err = HAL_FLASHEx_Erase(&erase, &sector_error);
            if (err != HAL_OK) {
                TRACEF("error starting erase operation, sector error %u\n", sector_error);
                total_erased = ERR_IO;
                break;
            }

            err = FLASH_WaitForLastOperation(HAL_MAX_DELAY);
            if (err != HAL_OK) {
                TRACEF("error waiting for erase operation to end, hal error %u\n", HAL_FLASH_GetError());
                total_erased = ERR_IO;
                break;
            }

            // invalidate the cache on this region
            arch_invalidate_cache_range(FLASHAXI_BASE + sector_offset, next_offset - sector_offset);
        }

        // move to the next erase boundary
        total_erased += next_offset - sector_offset;
        off_t erased_bytes = next_offset - offset;
        if (erased_bytes >= len)
            break;
        len -= erased_bytes;
        offset = next_offset;
    }

    HAL_FLASH_Lock();

    return total_erased;
}
开发者ID:ajithat,项目名称:lk,代码行数:57,代码来源:flash.c


示例19: main

int main(void)
{
	HAL_StatusTypeDef status;
	FLASH_EraseInitTypeDef eraseInit;
	uint32_t sectorError;
	uint32_t *ptr=ADDRESS_SECTOR_18;
	uint32_t checkCR;
	int guard=0;
	while(1){
		status=HAL_FLASH_Unlock();
		//this guard function is to program the Flash
		if(guard){
			while(status==HAL_BUSY);
			status=HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, ADDRESS_SECTOR_18, DATA_PROGRAM);
			while(status==HAL_BUSY);
			guard=0;
		}
		//this guard function is to sector erase the Flash
		if(guard){
			flashEraseInit(&eraseInit,
							FLASH_TYPEERASE_SECTORS,
							0,
							FLASH_SECTOR_18,
							1,
							FLASH_VOLTAGE_RANGE_3);

			while(status==HAL_BUSY);
			HAL_FLASHEx_Erase(&eraseInit,&sectorError);
			while(status==HAL_BUSY);
			guard=0;
		}
		//this guard function is to Mass erase the Flash
		if(guard){
			flashEraseInit(&eraseInit,
							FLASH_TYPEERASE_MASSERASE,
							0,
							0,
							1,
							FLASH_VOLTAGE_RANGE_3);

			while(status==HAL_BUSY);
			HAL_FLASHEx_Erase(&eraseInit,&sectorError);
			while(status==HAL_BUSY);
			guard=0;
		}



		status=HAL_FLASH_Lock();

	}




}
开发者ID:JangSing,项目名称:stm32f429_Flash_Hal,代码行数:56,代码来源:main.c


示例20: FLASH_If_Init

/**
  * @brief  Unlocks Flash for write access
  * @param  None
  * @retval None
  */
void FLASH_If_Init(void)
{
  /* Unlock the Program memory */
  HAL_FLASH_Unlock();

  /* Clear all FLASH flags */
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPERR);
  /* Unlock the Program memory */
  HAL_FLASH_Lock();
}
开发者ID:NjordCZ,项目名称:stm32cubef0,代码行数:15,代码来源:flash_if.c



注:本文中的HAL_FLASH_Unlock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ HAL_GPIO_EXTI_IRQHandler函数代码示例发布时间:2022-05-30
下一篇:
C++ HAL_FLASH_Program函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap