usb_request_status_t usb_vendor_request_write_spiflash(
	usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
	uint32_t addr = 0;
	uint16_t len = 0;

	if (stage == USB_TRANSFER_STAGE_SETUP) {
		addr = (endpoint->setup.value << 16) | endpoint->setup.index;
		len = endpoint->setup.length;
		if ((len > spi_flash.page_len) || (addr > spi_flash.num_bytes)
				|| ((addr + len) > spi_flash.num_bytes)) {
			return USB_REQUEST_STATUS_STALL;
		} else {
			usb_transfer_schedule_block(endpoint->out, &spiflash_buffer[0], len,
						    NULL, NULL);
			spi_bus_start(spi_flash.bus, &ssp_config_w25q80bv);
			w25q80bv_setup(&spi_flash);
			return USB_REQUEST_STATUS_OK;
		}
	} else if (stage == USB_TRANSFER_STAGE_DATA) {
		addr = (endpoint->setup.value << 16) | endpoint->setup.index;
		len = endpoint->setup.length;
		/* This check is redundant but makes me feel better. */
		if ((len > spi_flash.page_len) || (addr > spi_flash.num_bytes)
				|| ((addr + len) > spi_flash.num_bytes)) {
			return USB_REQUEST_STATUS_STALL;
		} else {
			w25q80bv_program(&spi_flash, addr, len, &spiflash_buffer[0]);
			usb_transfer_schedule_ack(endpoint->in);
			return USB_REQUEST_STATUS_OK;
		}
	} else {
		return USB_REQUEST_STATUS_OK;
	}
}
usb_request_status_t usb_vendor_request_erase_spiflash(
		usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
	if (stage == USB_TRANSFER_STAGE_SETUP) {
		spi_bus_start(spi_flash.bus, &ssp_config_w25q80bv);
		w25q80bv_setup(&spi_flash);
		/* only chip erase is implemented */
		w25q80bv_chip_erase(&spi_flash);
		usb_transfer_schedule_ack(endpoint->in);
	}
	return USB_REQUEST_STATUS_OK;
}
isp_iap_ret_code_t iap_cmd_call(iap_cmd_res_t* iap_cmd_res) 
{
	uint32_t* p_u32_data;
	
	if( iap_is_implemented() )
	{
		pROM_API->IAP( (uint32_t*)&iap_cmd_res->cmd_param, (uint32_t*)&iap_cmd_res->status_res);
	}else
	{
		/* 
		  Alternative way to retrieve Part Id on MCU with no IAP 
		  Read Serial No => Read Unique ID in SPIFI (only compatible with W25Q80BV
		*/
		spi_bus_start(spi_flash_drv.target, &ssp_config_spi);
		spiflash_setup(&spi_flash_drv);

		switch(iap_cmd_res->cmd_param.command_code)
		{
			case IAP_CMD_READ_PART_ID_NO:
				p_u32_data = (uint32_t*)ROM_OTP_PART_ID_ADDR;
				iap_cmd_res->status_res.iap_result[0] = p_u32_data[0];
				iap_cmd_res->status_res.iap_result[1] = p_u32_data[1];
				iap_cmd_res->status_res.status_ret = CMD_SUCCESS;
			break;
			
			case IAP_CMD_READ_SERIAL_NO:
			/* Only 64bits used */
			iap_cmd_res->status_res.iap_result[0] = 0;
			iap_cmd_res->status_res.iap_result[1] = 0;
			spiflash_get_unique_id(&spi_flash_drv, (spiflash_unique_id_t*)&iap_cmd_res->status_res.iap_result[2] );
				iap_cmd_res->status_res.status_ret = CMD_SUCCESS;
			break;
			
			default:
				iap_cmd_res->status_res.status_ret = ERROR_IAP_NOT_IMPLEMENTED;
			break;
		}
	}
	return iap_cmd_res->status_res.status_ret;
}
Exemple #4
0
void pin_setup(void) {
	/* Release CPLD JTAG pins */
	scu_pinmux(SCU_PINMUX_CPLD_TDO, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION4);
	scu_pinmux(SCU_PINMUX_CPLD_TCK, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
	scu_pinmux(SCU_PINMUX_CPLD_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
	scu_pinmux(SCU_PINMUX_CPLD_TDI, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
	
	gpio_input(&gpio_cpld_tdo);
	gpio_input(&gpio_cpld_tck);
	gpio_input(&gpio_cpld_tms);
	gpio_input(&gpio_cpld_tdi);
	
	/* Configure SCU Pin Mux as GPIO */
	scu_pinmux(SCU_PINMUX_LED1, SCU_GPIO_NOPULL);
	scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_NOPULL);
	scu_pinmux(SCU_PINMUX_LED3, SCU_GPIO_NOPULL);
#ifdef RAD1O
	scu_pinmux(SCU_PINMUX_LED4, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION4);
#endif

	scu_pinmux(SCU_PINMUX_EN1V8, SCU_GPIO_NOPULL);

	/* Configure USB indicators */
#ifdef JAWBREAKER
	scu_pinmux(SCU_PINMUX_USB_LED0, SCU_CONF_FUNCTION3);
	scu_pinmux(SCU_PINMUX_USB_LED1, SCU_CONF_FUNCTION3);
#endif

	/* Configure all GPIO as Input (safe state) */
	gpio_init();

	gpio_output(&gpio_led[0]);
	gpio_output(&gpio_led[1]);
	gpio_output(&gpio_led[2]);
#ifdef RAD1O
	gpio_output(&gpio_led[3]);
#endif

	gpio_output(&gpio_1v8_enable);

#ifdef HACKRF_ONE
	/* Configure RF power supply (VAA) switch control signal as output */
	gpio_output(&gpio_vaa_disable);

	/* Safe state: start with VAA turned off: */
	disable_rf_power();

	scu_pinmux(SCU_PINMUX_GPIO3_10, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
	scu_pinmux(SCU_PINMUX_GPIO3_11, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);

#endif

#ifdef RAD1O
	/* Configure RF power supply (VAA) switch control signal as output */
	gpio_output(&gpio_vaa_enable);

	/* Safe state: start with VAA turned off: */
	disable_rf_power();

	scu_pinmux(SCU_PINMUX_GPIO3_10, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
	scu_pinmux(SCU_PINMUX_GPIO3_11, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);

#endif

	/* enable input on SCL and SDA pins */
	SCU_SFSI2C0 = SCU_I2C0_NOMINAL;

	spi_bus_start(&spi_bus_ssp1, &ssp_config_max2837);

	mixer_bus_setup(&mixer);

	rf_path_pin_setup(&rf_path);
	
	/* Configure external clock in */
	scu_pinmux(SCU_PINMUX_GP_CLKIN, SCU_CLK_IN | SCU_CONF_FUNCTION1);

	sgpio_configure_pin_functions(&sgpio_config);
}
Exemple #5
0
void ssp1_set_mode_max5864(void)
{
	spi_bus_start(max5864.bus, &ssp_config_max5864);
}
Exemple #6
0
void ssp1_set_mode_max2837(void)
{
	spi_bus_start(max2837.bus, &ssp_config_max2837);
}