int zx_spi_flash_init(void) { zx_err_t ret = ZX_EOK; GPIO_InitType GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); /* Configure flash_vcc pin PowerOn */ RCC_APB2PeriphClockCmd(SPI_FLASH_VCC_CTR_GPIO_RCC, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP; GPIO_InitStructure.GPIO_Pins = SPI_FLASH_PIN_VCC_CTR; #if(ZC_HARDWARE_BOARD) GPIO_ResetBits(SPI_FLASH_VCC_CTR_GPIO, SPI_FLASH_PIN_VCC_CTR); #else GPIO_SetBits(SPI_FLASH_VCC_CTR_GPIO, SPI_FLASH_PIN_VCC_CTR); #endif /* Configure CS pin as Output Pullup */ RCC_APB2PeriphClockCmd(SPI_FLASH_NSS_GPIO_RCC, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP; GPIO_InitStructure.GPIO_Pins = SPI_FLASH_PIN_NSS; GPIO_Init(SPI_FLASH_NSS_GPIO, &GPIO_InitStructure); GPIO_SetBits(SPI_FLASH_NSS_GPIO, SPI_FLASH_PIN_NSS); ret = drv_spi_bus_register(SPI_FLASH, ZX_SPI_FLASH_BUS); spi_flash_cs.GPIOx = SPI_FLASH_NSS_GPIO; spi_flash_cs.GPIO_Pin = SPI_FLASH_PIN_NSS; zx_spi_bus_attach_device(&spi_flash_device_10, SPI_FLASH_DEVICE_NAME, ZX_SPI_FLASH_BUS, (void *)&spi_flash_cs); spi_flash_device = zx_device_find(SPI_FLASH_DEVICE_NAME); zx_device_open(spi_flash_device, ZX_DEVICE_FLAG_RDWR); spi_flash_d = (struct zx_spi_device *)spi_flash_device; { struct zx_spi_configuration cfg; cfg.data_width = 8; cfg.mode = ZX_SPI_MASTER | ZX_SPI_MODE_3 | ZX_SPI_MSB; cfg.max_hz = 30 * 1000 * 1000; zx_spi_configure(spi_flash_d, &cfg); } /* config spi */ return ret; }解释一下
时间: 2023-08-06 09:07:11 浏览: 99
ACE_OS::mktime函数源代码
3星 · 编辑精心推荐
这段代码是一个函数,用于初始化SPI闪存设备。在函数中,使用GPIO_InitStructure结构体来配置GPIO口的参数,包括模式、引脚等。通过RCC_APB2PeriphClockCmd函数,开启SPI_FLASH_VCC_CTR_GPIO_RCC和SPI_FLASH_NSS_GPIO_RCC的时钟。然后分别设置SPI_FLASH_PIN_VCC_CTR和SPI_FLASH_PIN_NSS引脚的输出模式,其中SPI_FLASH_PIN_VCC_CTR被设置为输出低电平,SPI_FLASH_PIN_NSS被设置为输出高电平。接着,调用drv_spi_bus_register函数来注册SPI_FLASH设备,并通过zx_spi_bus_attach_device函数将设备与总线连接。最后,通过zx_spi_configure函数配置SPI设备的参数,包括数据宽度、模式和频率等。函数返回值为ret。
阅读全文