Пример #1
0
void flash_erase_all_pages(void)
{
	flash_wait_for_last_operation();

	FLASH_CR |= FLASH_CR_MER;		/* Enable mass erase. */
	FLASH_CR |= FLASH_CR_STRT;		/* Trigger the erase. */

	flash_wait_for_last_operation();
	FLASH_CR &= ~FLASH_CR_MER;		/* Disable mass erase. */
}
Пример #2
0
void flash_erase_all_sectors(u32 program_size)
{
	flash_wait_for_last_operation();
	flash_set_program_size(program_size);

	FLASH_CR |= FLASH_MER;		/* Enable mass erase. */
	FLASH_CR |= FLASH_STRT;		/* Trigger the erase. */

	flash_wait_for_last_operation();
	FLASH_CR &= ~FLASH_MER;		/* Disable mass erase. */
}
Пример #3
0
void flash_program_option_bytes(u32 data)
{
	flash_wait_for_last_operation();

	if (FLASH_OPTCR & FLASH_OPTLOCK)
		flash_unlock_option_bytes();

	FLASH_OPTCR = data & ~0x3;
	FLASH_OPTCR |= FLASH_OPTSTRT;	/* Enable option byte programming. */
	flash_wait_for_last_operation();
}
Пример #4
0
void flash_erase_page(u32 page_address)
{
	flash_wait_for_last_operation();

	FLASH_CR |= FLASH_CR_PER;
	FLASH_AR = page_address;
	FLASH_CR |= FLASH_CR_STRT;

	flash_wait_for_last_operation();
	FLASH_CR &= ~FLASH_CR_PER;
}
Пример #5
0
void flash_program_half_word(u32 address, u16 data)
{
	flash_wait_for_last_operation();

	FLASH_CR |= FLASH_CR_PG;

	(*(volatile u16 *)address) = data;

	flash_wait_for_last_operation();

	FLASH_CR &= ~FLASH_CR_PG;		/* Disable the PG bit. */
}
Пример #6
0
void flash_writer_page_erase(void *page)
{
    flash_wait_for_last_operation();

    FLASH_CR |= FLASH_CR_PER;
    FLASH_AR = (uint32_t) page;
    FLASH_CR |= FLASH_CR_STRT;

    flash_wait_for_last_operation();

    FLASH_CR &= ~FLASH_CR_PER;
}
Пример #7
0
void flash_erase_option_bytes(void)
{
	flash_wait_for_last_operation();

	if ((FLASH_CR & FLASH_CR_OPTWRE) == 0)
		flash_unlock_option_bytes();

	FLASH_CR |= FLASH_CR_OPTER;	/* Enable option byte erase. */
	FLASH_CR |= FLASH_CR_STRT;
	flash_wait_for_last_operation();
	FLASH_CR &= ~FLASH_CR_OPTER;	/* Disable option byte erase. */
}
Пример #8
0
void flash_program_option_bytes(u32 address, u16 data)
{
	flash_wait_for_last_operation();

	if ((FLASH_CR & FLASH_CR_OPTWRE) == 0)
		flash_unlock_option_bytes();

	FLASH_CR |= FLASH_CR_OPTPG;	/* Enable option byte programming. */
	(*(volatile u16 *)address) = data;
	flash_wait_for_last_operation();
	FLASH_CR &= ~FLASH_CR_OPTPG;	/* Disable option byte programming. */
}
Пример #9
0
void flash_erase_sector(u32 sector, u32 program_size)
{
	flash_wait_for_last_operation();
	flash_set_program_size(program_size);

	FLASH_CR &= ~(((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)) << 3);
	FLASH_CR |= sector;
	FLASH_CR |= FLASH_STRT;

	flash_wait_for_last_operation();
	FLASH_CR &= ~FLASH_SER;
	FLASH_CR &= ~(((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)) << 3);
}
Пример #10
0
void flash_program_byte(uint32_t address, uint8_t data)
{
	flash_wait_for_last_operation();
	flash_set_program_size(FLASH_CR_PROGRAM_X8);

	FLASH_CR |= FLASH_CR_PG;

	MMIO8(address) = data;

	flash_wait_for_last_operation();

	FLASH_CR &= ~FLASH_CR_PG;		/* Disable the PG bit. */
}
Пример #11
0
void flash_program_half_word(uint32_t address, uint16_t data)
{
	flash_wait_for_last_operation();
	flash_set_program_size(FLASH_CR_PROGRAM_X16);

	FLASH_CR |= FLASH_CR_PG;

	MMIO16(address) = data;

	flash_wait_for_last_operation();

	FLASH_CR &= ~FLASH_CR_PG;		/* Disable the PG bit. */
}
Пример #12
0
void flash_program_half_word(u32 address, u16 data, u32 program_size)
{
	flash_wait_for_last_operation();
	flash_set_program_size(program_size);

	FLASH_CR |= FLASH_CR_PG;

	MMIO16(address) = data;

	flash_wait_for_last_operation();

	FLASH_CR &= ~FLASH_CR_PG;		/* Disable the PG bit. */
}
Пример #13
0
void flash_program_option_bytes(uint32_t address, uint16_t data)
{
	flash_wait_for_last_operation();

	if ((FLASH_CR & FLASH_CR_OPTWRE) == 0) {
		flash_unlock_option_bytes();
	}

	FLASH_CR |= FLASH_CR_OPTPG;	/* Enable option byte programming. */
	MMIO16(address) = data;
	flash_wait_for_last_operation();
	FLASH_CR &= ~FLASH_CR_OPTPG;	/* Disable option byte programming. */
}
Пример #14
0
void flash_program_byte(u32 address, u8 data, u32 program_size)
{
	flash_wait_for_last_operation();
	flash_set_program_size(program_size);

	FLASH_CR |= FLASH_PG;

	MMIO8(address) = data;

	flash_wait_for_last_operation();

	FLASH_CR &= ~FLASH_PG;		/* Disable the PG bit. */
}
Пример #15
0
void flash_erase_sector(uint8_t sector, uint32_t program_size)
{
	flash_wait_for_last_operation();
	flash_set_program_size(program_size);

	FLASH_CR &= ~(FLASH_CR_SNB_MASK << FLASH_CR_SNB_SHIFT);
	FLASH_CR |= (sector & FLASH_CR_SNB_MASK) << FLASH_CR_SNB_SHIFT;
	FLASH_CR |= FLASH_CR_SER;
	FLASH_CR |= FLASH_CR_STRT;

	flash_wait_for_last_operation();
	FLASH_CR &= ~FLASH_CR_SER;
	FLASH_CR &= ~(FLASH_CR_SNB_MASK << FLASH_CR_SNB_SHIFT);
}
Пример #16
0
void flash_erase_sector(uint8_t sector, uint32_t program_size)
{
	flash_wait_for_last_operation();
	flash_set_program_size(program_size);

	FLASH_CR &= ~(0xF << 3);
	FLASH_CR |= (sector << 3) & 0x78;
	FLASH_CR |= FLASH_CR_SER;
	FLASH_CR |= FLASH_CR_STRT;

	flash_wait_for_last_operation();
	FLASH_CR &= ~FLASH_CR_SER;
	FLASH_CR &= ~(0xF << 3);
}
Пример #17
0
/* page address is assumed to be half-word aligned */
void flash_writer_page_write(void *page, void *data, size_t len)
{
    uint8_t *bytes = (uint8_t *) data;
    uint16_t *flash = (uint16_t *) page;
    uint16_t half_word;

    flash_wait_for_last_operation();

    size_t count;
    for (count = len; count > 1; count -= 2) {

        half_word = *bytes++;
        half_word |= (uint16_t)*bytes++ << 8;

        flash_write_half_word(flash++, half_word);
    }

    if (count == 1) {
        half_word = *bytes;
        /* preserve value of adjacent byte */
        half_word |= (uint16_t)(*(uint8_t *)flash) << 8;

        flash_write_half_word(flash, half_word);
    }

    /* reset flags */
    FLASH_CR &= ~FLASH_CR_PG;
    FLASH_SR |= FLASH_SR_EOP;
}
Пример #18
0
void flash_program_half_word(uint32_t address, uint16_t data)
{
	flash_wait_for_last_operation();

	if ((MEMORY_SIZE_REG > 512) && (address >= FLASH_BASE+0x00080000))
		FLASH_CR2 |= FLASH_CR_PG;
	else FLASH_CR |= FLASH_CR_PG;

	MMIO16(address) = data;

	flash_wait_for_last_operation();

	if ((MEMORY_SIZE_REG > 512) && (address >= FLASH_BASE+0x00080000))
		FLASH_CR2 &= ~FLASH_CR_PG;
	else FLASH_CR &= ~FLASH_CR_PG;
}
Пример #19
0
void flash_program_double_word(uint32_t address, uint64_t data)
{
	/* Ensure that all flash operations are complete. */
	flash_wait_for_last_operation();
	flash_set_program_size(FLASH_CR_PROGRAM_X64);

	/* Enable writes to flash. */
	FLASH_CR |= FLASH_CR_PG;

	/* Program the first half of the word. */
	MMIO64(address) = data;

	/* Wait for the write to complete. */
	flash_wait_for_last_operation();

	/* Disable writes to flash. */
	FLASH_CR &= ~FLASH_CR_PG;
}
Пример #20
0
void flash_program_word(u32 address, u32 data, u32 program_size)
{
	/* Ensure that all flash operations are complete. */
	flash_wait_for_last_operation();
	flash_set_program_size(program_size);

	/* Enable writes to flash. */
	FLASH_CR |= FLASH_PG;

	/* Program the first half of the word. */
	MMIO32(address) = data;

	/* Wait for the write to complete. */
	flash_wait_for_last_operation();

	/* Disable writes to flash. */
	FLASH_CR &= ~FLASH_PG;
}
Пример #21
0
static uint32_t svhandler_flash_lock(void) {
  /* Wait for any write operation to complete. */
  flash_wait_for_last_operation();
  /* Disable writes to flash. */
  FLASH_CR &= ~FLASH_CR_PG;
  /* lock flash register */
  FLASH_CR |= FLASH_CR_LOCK;
  /* return flash status register */
  return FLASH_SR;
}
Пример #22
0
static void flash_write_half_word(uint16_t *flash, uint16_t half_word)
{
    /* select flash programming */
    FLASH_CR |= FLASH_CR_PG;

    /* perform half-word write */
    *flash = half_word;

    flash_wait_for_last_operation();
}
Пример #23
0
void flash_program_half_word(uint32_t address, uint16_t data)
{
	flash_wait_for_last_operation();

	if ((DESIG_FLASH_SIZE > 512) && (address >= FLASH_BASE+0x00080000)) {
		FLASH_CR2 |= FLASH_CR_PG;
	} else {
		FLASH_CR |= FLASH_CR_PG;
	}

	MMIO16(address) = data;

	flash_wait_for_last_operation();

	if ((DESIG_FLASH_SIZE > 512) && (address >= FLASH_BASE+0x00080000)) {
		FLASH_CR2 &= ~FLASH_CR_PG;
	} else {
		FLASH_CR &= ~FLASH_CR_PG;
	}
}
Пример #24
0
static void svhandler_flash_program(uint32_t psize) {
  /* Wait for any write operation to complete. */
  flash_wait_for_last_operation();
  /* check program size argument */
  if (psize != FLASH_CR_PROGRAM_X8 && psize != FLASH_CR_PROGRAM_X16 &&
      psize != FLASH_CR_PROGRAM_X32 && psize != FLASH_CR_PROGRAM_X64)
    return;
  FLASH_CR = (FLASH_CR & ~(FLASH_CR_PROGRAM_MASK << FLASH_CR_PROGRAM_SHIFT)) |
             (psize << FLASH_CR_PROGRAM_SHIFT);
  FLASH_CR |= FLASH_CR_PG;
}
Пример #25
0
void flash_erase_page(uint32_t page_address)
{
	flash_wait_for_last_operation();

	if ((MEMORY_SIZE_REG > 512) && (page_address >= FLASH_BASE+0x00080000)) {
		FLASH_CR2 |= FLASH_CR_PER;
		FLASH_AR2 = page_address;
		FLASH_CR2 |= FLASH_CR_STRT;
	} else  {
		FLASH_CR |= FLASH_CR_PER;
		FLASH_AR = page_address;
		FLASH_CR |= FLASH_CR_STRT;
	}

	flash_wait_for_last_operation();

	if ((MEMORY_SIZE_REG > 512) && (page_address >= FLASH_BASE+0x00080000))
		FLASH_CR2 &= ~FLASH_CR_PER;
	else
		FLASH_CR &= ~FLASH_CR_PER;
}
Пример #26
0
void flash_program_word(u32 address, u32 data)
{
	/* Ensure that all flash operations are complete. */
	flash_wait_for_last_operation();

	/* Enable writes to flash. */
	FLASH_CR |= FLASH_CR_PG;

	/* Program the first half of the word. */
	(*(volatile u16 *)address) = (u16)data;

	/* Wait for the write to complete. */
	flash_wait_for_last_operation();

	/* Program the second half of the word. */
	(*(volatile u16 *)(address + 2)) = data >> 16;

	/* Wait for the write to complete. */
	flash_wait_for_last_operation();

	/* Disable writes to flash. */
	FLASH_CR &= ~FLASH_CR_PG;
}
Пример #27
0
static void svhandler_flash_unlock(void) {
  flash_wait_for_last_operation();
  flash_clear_status_flags();
  flash_unlock();
}