Exemplo n.º 1
0
void w25q80bv_setup(void)
{
  const uint8_t serial_clock_rate = 2;
  const uint8_t clock_prescale_rate = 2;

  /* Reset SPIFI peripheral before to Erase/Write SPIFI memory through SPI */
  RESET_CTRL1 = RESET_CTRL1_SPIFI_RST;
  
  /* Init SPIFI GPIO to Normal GPIO */
  scu_pinmux(P3_3, (SCU_SSP_IO | SCU_CONF_FUNCTION2));    // P3_3 SPIFI_SCK => SSP0_SCK
  scu_pinmux(P3_4, (SCU_GPIO_FAST | SCU_CONF_FUNCTION0)); // P3_4 SPIFI SPIFI_SIO3 IO3 => GPIO1[14]
  scu_pinmux(P3_5, (SCU_GPIO_FAST | SCU_CONF_FUNCTION0)); // P3_5 SPIFI SPIFI_SIO2 IO2 => GPIO1[15]
  scu_pinmux(P3_6, (SCU_GPIO_FAST | SCU_CONF_FUNCTION0)); // P3_6 SPIFI SPIFI_MISO IO1 => GPIO0[6]
  scu_pinmux(P3_7, (SCU_GPIO_FAST | SCU_CONF_FUNCTION4)); // P3_7 SPIFI SPIFI_MOSI IO0 => GPIO5[10]
  scu_pinmux(P3_8, (SCU_GPIO_FAST | SCU_CONF_FUNCTION4)); // P3_8 SPIFI SPIFI_CS => GPIO5[11]
  
  /* configure SSP pins */
  scu_pinmux(SCU_SSP0_MISO, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
  scu_pinmux(SCU_SSP0_MOSI, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
  scu_pinmux(SCU_SSP0_SCK,  (SCU_SSP_IO | SCU_CONF_FUNCTION2));

  /* configure GPIO pins */
  scu_pinmux(SCU_FLASH_HOLD, SCU_GPIO_FAST);
  scu_pinmux(SCU_FLASH_WP, SCU_GPIO_FAST);
  scu_pinmux(SCU_SSP0_SSEL, (SCU_GPIO_FAST | SCU_CONF_FUNCTION4));

  /* drive SSEL, HOLD, and WP pins high */
  gpio_set(PORT_FLASH, (PIN_FLASH_HOLD | PIN_FLASH_WP));
  gpio_set(PORT_SSP0_SSEL, PIN_SSP0_SSEL);

  /* Set GPIO pins as outputs. */
  GPIO1_DIR |= (PIN_FLASH_HOLD | PIN_FLASH_WP);
  GPIO5_DIR |= PIN_SSP0_SSEL;
  
  /* initialize SSP0 */
  ssp_init(SSP0_NUM,
  SSP_DATA_8BITS,
  SSP_FRAME_SPI,
  SSP_CPOL_0_CPHA_0,
  serial_clock_rate,
  clock_prescale_rate,
  SSP_MODE_NORMAL,
  SSP_MASTER,
  SSP_SLAVE_OUT_ENABLE);

  device_id = 0;

  while(1)
  {
    if(device_id == W25Q80BV_DEVICE_ID_RES)
    break;

    if(device_id == S25FL032P_DEVICE_ID_RES)
    break;

    device_id = w25q80bv_get_device_id();
  }
}
Exemplo n.º 2
0
/*
 * Set up pins for GPIO and SPI control, configure SSP0 peripheral for SPI.
 * SSP0_SSEL is controlled by GPIO in order to handle various transfer lengths.
 */
void w25q80bv_setup(w25q80bv_driver_t* const drv)
{
	uint8_t device_id;

	drv->page_len = 256U;
	drv->num_pages = 4096U;
	drv->num_bytes = 1048576U;

	drv->target_init(drv);

	device_id = 0;
	while(device_id != W25Q80BV_DEVICE_ID_RES)
	{
		device_id = w25q80bv_get_device_id(drv);
	}
}
Exemplo n.º 3
0
void w25q80bv_chip_erase(w25q80bv_driver_t* const drv)
{
	uint8_t device_id;

	device_id = 0;
	while(device_id != W25Q80BV_DEVICE_ID_RES)
	{
		device_id = w25q80bv_get_device_id(drv);
	}

	w25q80bv_write_enable(drv);
	w25q80bv_wait_while_busy(drv);

	uint8_t data[] = { W25Q80BV_CHIP_ERASE };
	spi_bus_transfer(drv->bus, data, ARRAY_SIZE(data));
}
Exemplo n.º 4
0
/* write an arbitrary number of bytes */
void w25q80bv_program(w25q80bv_driver_t* const drv, uint32_t addr, uint32_t len, uint8_t* data)
{
	uint16_t first_block_len;
	uint8_t device_id;

	device_id = 0;
	while(device_id != W25Q80BV_DEVICE_ID_RES)
	{
		device_id = w25q80bv_get_device_id(drv);
	}	
	
	/* do nothing if we would overflow the flash */
	if ((len > drv->num_bytes) || (addr > drv->num_bytes)
			|| ((addr + len) > drv->num_bytes))
		return;

	/* handle start not at page boundary */
	first_block_len = drv->page_len - (addr % drv->page_len);
	if (len < first_block_len)
		first_block_len = len;
	if (first_block_len) {
		w25q80bv_page_program(drv, addr, first_block_len, data);
		addr += first_block_len;
		data += first_block_len;
		len -= first_block_len;
	}

	/* one page at a time on boundaries */
	while (len >= drv->page_len) {
		w25q80bv_page_program(drv, addr, drv->page_len, data);
		addr += drv->page_len;
		data += drv->page_len;
		len -= drv->page_len;
	}

	/* handle end not at page boundary */
	if (len) {
		w25q80bv_page_program(drv, addr, len, data);
	}
}