银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 0379-69926675-801 | ||
技术支持邮件 | Gingko@vip.163.com | ||
版本 | 日期 | 作者 | 修改内容 |
---|---|---|---|
V1.0 | 2020-07-29 | gingko | 初次建立 |
1.在主界面选择File–>New Project 或者直接点击ACCEE TO MCU SELECTOR 2.出现芯片型号选择,搜索自己芯片的型号,双击型号,或者点击Start Project进入配置 在搜索栏的下面,提供的各 种查找方式,可以选择芯片内核,型号,等等,可以帮助你查找芯片。本实验选取的芯片型号为:STM32H750IBKx。 3.配置RCC,使用外部时钟源 4.时基源选择SysTick 5.将PA10,PB7,PB8设置为GPIO_Output 6.引脚模式配置 7.配置串口 在NVIC Settings一栏使能接收中断 引脚配置 8.配置ADC 9.配置QUADSPI 10.配置SDMMC 11.配置FATFS 12.配置SPI 13.配置FMC 14.时钟源设置,选择外部高速时钟源,配置为最大主频 15.工程文件的设置, 这里就是工程的各种配置 我们只用到有限几个,其他的默认即可 IDE我们使用的是 MDK V5.27 16.点击Code Generator,进行进一步配置
引导模型 | 存储器 |
XiP | QSPI Flash memory |
NOR Flash memory(on FMC) | |
BootROM | SPI-NOR(emulated with QSPI 1 line) |
SDCARD | |
Volatile memory | Internal SRAM |
External SRAM | |
External SDRAM | |
External PSRAM |
int main(void) { int flash_id; CPU_CACHE_Enable(); HAL_Init(); i2c.initialize(); axp152.initialize(); axp152.set_dcdc1(3500);//[ARM & FPGA] axp152.set_dcdc2(1200);//[FPGA INT] axp152.set_dcdc3(3300);//[DCOUT3] axp152.set_dcdc4(3300);//[DCOUT4] axp152.set_aldo1(3300);//[BK3] axp152.set_aldo2(3300);//[ALDOOUT2] axp152.set_dldo1(3300);//[BK0] axp152.set_dldo2(3300);//[BK1] HAL_Delay(200); SystemClock_Config(); MX_GPIO_Init(); MX_DMA_Init(); MX_FMC_Init(); MX_USART2_UART_Init(); MX_QUADSPI_Init(); MX_ADC1_Init(); MX_ADC3_Init(); MX_SDMMC1_SD_Init(); MX_FATFS_Init(); MX_SPI4_Init(); BSP_QSPI_Init(); usart2.initialize(115200); usart2.printf("iCore4TX Bootloader(W25Q64) V%s\r\n",VER); /* 初始化 w25q64 */ W25QXX_ExitQPIMode(); W25QXX_Reset(); flash_id = BSP_QSPI_FLASH_ReadID(); W25QXX_EnterQPIMode(); if(flash_id == 0xEF4017){ usart2.printf("FLASH(W25Q64) init success!\r\n"); usart2.printf("Jump to Flash!\r\n"); }else{ usart2.printf("FLASH(W25Q64) init fail!\r\n"); while(1){ HAL_Delay(50); LED_ON; HAL_Delay(50); LED_OFF; } } LED_ON; QSPI_EnableMemoryMappedMode(&hqspi); CPU_CACHE_Disable(); SysTick->CTRL = 0; /* 初始化用户应用程序的堆栈指针并跳转到用户应用程序*/ JumpToApplication = (pFunction) (*(__IO uint32_t*) (APPLICATION_ADDRESS + 4)); __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); JumpToApplication(); while (1) { } }
void W25QXX_ExitQPIMode(void) { QSPI_CommandTypeDef cmd; cmd.InstructionMode = QSPI_INSTRUCTION_4_LINES; cmd.Instruction = W25X_ExitQPIMode; cmd.AddressMode = QSPI_ADDRESS_NONE; cmd.AddressSize = QSPI_ADDRESS_24_BITS; cmd.Address = 0x00; cmd.DataMode = QSPI_DATA_NONE; cmd.NbData = 0; cmd.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE; cmd.AlternateBytesSize = 0; cmd.AlternateBytes = 0x00; cmd.DummyCycles = 0; cmd.DdrMode = QSPI_DDR_MODE_DISABLE; cmd.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY; cmd.SIOOMode = QSPI_SIOO_INST_EVERY_CMD; HAL_QSPI_Command(&hqspi, &cmd, 100); w25qxx_mode = W25QXX_MODE_SPI; }
void W25QXX_EnterQPIMode(void) { uint8_t dat; QSPI_CommandTypeDef cmd; dat = W25QXX_ReadSR(2); //先读出状态寄存器2的原始值 if ((dat & QE_MASK) == 0x00) //QE位未使能 { W25QXX_WriteEnable(1); //写使能 dat |= QE_MASK; //使能QE位 W25QXX_WriteSR(2, dat); //写状态寄存器2 } cmd.InstructionMode = QSPI_INSTRUCTION_1_LINE; cmd.Instruction = W25X_EnterQPIMode; cmd.AddressMode = QSPI_ADDRESS_NONE; cmd.AddressSize = QSPI_ADDRESS_24_BITS; cmd.Address = 0x00; cmd.DataMode = QSPI_DATA_NONE; cmd.NbData = 0; cmd.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE; cmd.AlternateBytesSize = 0; cmd.AlternateBytes = 0x00; cmd.DummyCycles = 0; cmd.DdrMode = QSPI_DDR_MODE_DISABLE; cmd.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY; cmd.SIOOMode = QSPI_SIOO_INST_EVERY_CMD; HAL_QSPI_Command(&hqspi, &cmd, 100); w25qxx_mode = W25QXX_MODE_QPI; cmd.InstructionMode = QSPI_INSTRUCTION_4_LINES; cmd.Instruction = W25X_SetReadParameters; cmd.DataMode = QSPI_DATA_4_LINES; cmd.NbData = 1; dat = 0x03 << 4; //设置P4&P5=11,8个dummy clocks,104MHz W25QXX_WriteEnable(1); if (HAL_QSPI_Command(&hqspi, &cmd, 100) == HAL_OK) { HAL_QSPI_Transmit(&hqspi, &dat, 100); } }
void W25QXX_Reset(void) { QSPI_CommandTypeDef cmd; if (w25qxx_mode) { cmd.InstructionMode = QSPI_INSTRUCTION_4_LINES; } else { cmd.InstructionMode = QSPI_INSTRUCTION_1_LINE; } cmd.Instruction = W25X_EnableReset; cmd.AddressMode = QSPI_ADDRESS_NONE; cmd.AddressSize = QSPI_ADDRESS_24_BITS; cmd.Address = 0; cmd.DataMode = QSPI_DATA_NONE; cmd.NbData = 0; cmd.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE; cmd.AlternateBytesSize = 0; cmd.AlternateBytes = 0x00; cmd.DummyCycles = 0; cmd.DdrMode = QSPI_DDR_MODE_DISABLE; cmd.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY; cmd.SIOOMode = QSPI_SIOO_INST_EVERY_CMD; W25QXX_WaitBusy(); if (HAL_QSPI_Command(&hqspi, &cmd, 100) == HAL_OK) { cmd.Instruction = W25X_ResetDevice; HAL_QSPI_Command(&hqspi, &cmd, 100); } }
//写SPI FLASH void W25QXX_Write(uint8_t *pbuf, uint32_t addr, uint16_t size) { uint32_t sec_pos; uint32_t sec_off; uint32_t sec_rem; uint32_t i; uint8_t *W25QXX_BUF; W25QXX_BUF = w25qxx_buf; sec_pos = addr / 4096; //扇区地址 sec_off = addr % 4096; //在扇区内的偏移 sec_rem = 4096 - sec_off; //扇区剩余空间大小 #ifdef DEBUG printf("addr:%08X size:%hu\r\n", addr, size); //测试用 #endif if(size <= sec_rem) { sec_rem = size; //不大于4096个字节 } while(1) { W25QXX_Read(W25QXX_BUF, sec_pos * 4096, 4096); //读出整个扇区的内容 for (i = 0; i < sec_rem; i++) //校验数据 { if (W25QXX_BUF[sec_off + i] != 0xFF) break; //需要擦除 } if (i < sec_rem) //需要擦除 { W25QXX_SectorErase(sec_pos); //擦除这个扇区 for (i = 0; i < sec_rem; i++) //复制 { W25QXX_BUF[sec_off + i] = pbuf[i]; } W25QXX_Write_NoCheck(W25QXX_BUF, sec_pos * 4096, 4096); //写入整个扇区 } else { W25QXX_Write_NoCheck(pbuf, addr, sec_rem); //写已经擦除了的,直接写入扇区剩余区间. } if (size == sec_rem) { break; //写入结束了 } else //写入未结束 { sec_pos++; //扇区地址增1 sec_off = 0; //偏移位置为0 pbuf += sec_rem; //指针偏移 addr += sec_rem; //写地址偏移 size-=sec_rem; //字节数递减 if (size > 4096) { sec_rem = 4096; //下一个扇区还是写不完 } else { sec_rem = size; //下一个扇区可以写完了 } } } }
uint8_t BSP_QSPI_Erase_Block(uint32_t BlockAddress)
uint8_t BSP_QSPI_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size)