AT-START-L021开发板为了便于用户扩展存储空间,在开发板上特意配备了一个供外挂存储器件的接口J7,其提供的引脚资源如图1所示。 图1 外挂接口
为了对W25Q系列的存储器件进行测试,便选取了一个W25Q16的存储模块来进行连接,其引脚连接关系为: CS ---PB12 CLK---PB13 DO ---PB14 DI ---PB15 TX1---PA9
图2 实物连接
相应的测试主程序为: - int main(void)
- {
- __IO uint32_t index = 0;
- __IO uint32_t flash_id_index = 0;
- system_clock_config();
- at32_board_init();
- tx_data_fill();
- uart_print_init(115200);
- spiflash_init();
- flash_id_index = spiflash_read_id();
- if((flash_id_index != W25Q128)&&(flash_id_index != W25Q80)&&(flash_id_index != W25Q16)&&(flash_id_index != W25Q32)&&(flash_id_index != W25Q64))
- {
- printf("flash id check error!\r\n");
- for(index = 0; index < 50; index++)
- {
- at32_led_toggle(LED2);
- at32_led_toggle(LED3);
- delay_ms(200);
- }
- return 1;
- }
- else
- {
- printf("flash id check success! id: %x\r\n", flash_id_index);
- }
- /* erase sector */
- spiflash_sector_erase(FLASH_TEST_ADDR / SPIF_SECTOR_SIZE);
- /* write data */
- spiflash_write(tx_buffer, FLASH_TEST_ADDR, BUF_SIZE);
- /* read data */
- spiflash_read(rx_buffer, FLASH_TEST_ADDR, BUF_SIZE);
- /* printf read data */
- printf("Read Data: ");
- for(index = 0; index < BUF_SIZE; index++)
- {
- printf("%x ", rx_buffer[index]);
- }
- /* test result:the data check */
- transfer_status = buffer_compare(rx_buffer, tx_buffer, BUF_SIZE);
- /* test result indicate:if SUCCESS ,led2 lights */
- if(transfer_status == SUCCESS)
- {
- printf("\r\nflash data read write success!\r\n");
- at32_led_on(LED2);
- }
- else
- {
- printf("\r\nflash data read write ERROR!\r\n");
- at32_led_off(LED2);
- }
- while(1)
- {
- }
- }
经程序的编译与下载,其测试结果如图3所示,说明测试成功。 由测试程序及结果可以看出,其处理过程为: 首先进行spiflash的初始化,随后是读取芯片的ID并显示,再对测试扇区进行擦除。在完成扇区擦除后,先是写入256个字节的数据,再将其读出以供验证,并以LED2和串口给出判别结果,即LED2亮表示成功;LED2灭表示设备。 图3 测试结果
但说好的256个数据咋输出了怎么多呢? 通过对数据量的计算可知: 256+256=512+86=598 原来编写程序这位老兄错把256写成 0x256,正好0x256=598,通过查看相应的定义也确实是这样,即:#define BUF_SIZE 0x256
进行修改后,其测试结果如图4所示,这才是常规的预期结果。 图4 测试效果
|