K7系列FPGA进行FLASH读写1——CCLK控制(STARTUPE2原语)

本文详细描述了在FPGA中通过STARTUPE2原语实现远程更新过程,包括CCLK的配置、USRCCLKO的使用以及如何控制CLOCK以获取对FLASH的访问权限。作者以K7系列芯片为例,讨论了不同配置选项及其在实际应用中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  最近的工作涉及对 FPGA 进行远程更新,也就是通过远程通信接口将 .bin 文件送到 FPGA,然后写入 FLASH,这样当 FPGA 重新上电后就可以执行更新后的程序了。因此第一步工作就是进行 FLASH 的读写控制。

  然而如果尝试配置 FLASH 管脚时,会发现 CCLK 管脚是不可配置的,这实际上是因为 CCLK_0 管脚在内部已经被占用,我们必须通过其他方式获取/设置它。笔者所用芯片为 K7 系列,根据 ug470 数据手册,我们可以使用 STARTUPE2 原语获取、设置该时钟,官方手册的介绍如下

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

原语调用格式如下

STARTUPE2 #(
	.PROG_USR		("FALSE"),
	.SIM_CCLK_FREQ	(0.0)
)
STARTUPE2_inst(
	.CFGCLK			(cfgclk),
	.CFGMCLK		(cfgmclk),
	.EOS			(eos),
	.PREQ			(),
	.CLK			(0),
	.GSR			(0),
	.GTS			(0),
	.KEYCLEARB		(1),
	.PACK			(1),
	.USRCCLKO		(usrcclk),
	.USRCCLKTS		(0),
	.USRDONEO		(1),
    .USRDONETS		(0)
);
  • CFGCLK,配置逻辑主时钟,仅在配置时有输出,在 master 模式下也一直存在(存疑;根据后面的测试,文档所说的 Persist Enabled 应当指的是 Master 模式下一直使能/连接,但除了配置的时候存在时钟,其他时候为无效的高电平;在配置了 USRCCLK 时,在 FPGA 配置结束后三个 clk 该时钟将切换到 USRCCLK)。Configuration mode 是根据 M[2:0] 管脚配置的,最常用的是 M[2:0]=001 对应的 Master SPI 配置模式,笔者开发板即本模式,Master 模式下 CCLK 由 FPGA 输出给 FLASH 的 SCK;

  • EOS,End Of Start,指示 FPGA 配置的结束;

  • CFGMCLK,配置内部振荡器时钟,是从内部的一个锁相环输出的 65MHz 时钟(不是很准,笔者输出到 GPIO 用示波器看过,那块板子的 ~68MHz);

  • USRDONEO,输出到FPGA 的 DONE_0 管脚。一般而言,在硬件设计中会在这个管脚挂一个 LED 灯,以指示 FPGA 完成配置开始运行;

  • USRDONETS,控制 DONE 管脚的三态门,1 将设置为高阻,0 将会把用户给入的 USRDONEO 输出到 DONE_0 管脚;

  • USRCCLKO,在配置完成后,驱动 CCLK_0 管脚的用户自定义时钟。在配置完成后,前三个时钟周期用于切换时钟源,且不会被输出,但如果使用了 EMCCLK 管脚,则 EMCCLK 信号会出现在 CCLK 管脚上,直到过渡到用户自定义时钟;

  • USRCCLKTS,控制 USRCCLKO 的三态门;

  • GTS,全局三态门使能,要用户自定义 CCLK/DONE 等,此管脚必须置低。

其他信号详见官方手册说明,默认启动设置下,配置期间的时序图如下

在这里插入图片描述

测试

不配置 USRCCLKO

STARTUPE2 STARTUPE2_inst (
	.CFGCLK			(cfgclk),
	.CFGMCLK		(cfgmclk),
	.EOS			(eos)
);

  做如上配置,将上述三信号输出到 GPIO 以及 ILA。测试发现 cfgclk 仅在上电一瞬有输出,之后为常高(Master SPI 模式);CFGMCLK 为 ~65MHz 时钟,输出到 GPIO 的信号极其微弱,但 ILA 可以正常捕获,因此此时钟可用于 FPGA 内部逻辑,但不可直接输出(其驱动 I/O 的能力太弱了);EOS 信号上电后一瞬即由低变高,指示配置完成,因此可用作 FPGA 启动的判断依据。

  由于没有配置 USRCCLK,CCLK 仅在初始配置有信号。上述写法仅为获取 FPGA 内部时钟,以及判断 FPGA 是否配置完成,不涉及对 FLASH 的控制。

配置 USRCCLKO

  要进行 FLASH 的读写,就要对 CCLK 进行配置,如下

STARTUPE2 #(
	.PROG_USR		("FALSE"),
	.SIM_CCLK_FREQ	(0.0)
)
STARTUPE2_inst(
    .CFGCLK			(cfgclk),
    .CFGMCLK		(cfgmclk),		//~65MHz,可用于 FPGA 内部逻辑,驱动 IO 的能力太弱了
    .EOS			(eos),			//指示 FPGA 配置完成
	.PREQ			(),
	.CLK			(0),
	.GSR			(0),
	.GTS			(0),
	.KEYCLEARB		(1),
	.PACK			(1),
    .USRCCLKO		(usrcclk),		//FLASH SCK
    .USRCCLKTS		(0),			//设为0以启用USRCCLK
    .USRDONEO		(usrdone),		//控制DONE_0管脚
    .USRDONETS		(0)				//设为0以启用usrdone,不想用就设为1
);

在该配置下,测试发现,cfgclk 将被配置为 usrcclk,这个也就是输出到 CCLK_0 的信号,ILA 捕获、GPIO 输出均正常;cfgmclk 仍为 ~65MHz 时钟,GPIO 输出极弱。

  如果只是要控制 CCLK_0,可以只配置如下

STARTUPE2 STARTUPE2_inst(
	.GTS			(0),
    .USRCCLKO		(usrcclk),
    .USRCCLKTS		(0)
);

通过控制 usrcclk 即可控制 CCLK_0 管脚了,从而获得对 FLASH 的控制权。

  关于如何对 FLASH 芯片进行读写控制,将持续更新…

### A7 Series FPGA Flash Read Write Using CCLK In the context of Artix-7 (A7) series FPGAs, controlling FLASH read and write operations via the configuration clock (CCLK) involves understanding how this signal interacts with both the device's internal mechanisms and external components like FLASH memory. The basic role of CCLK is to provide a timing reference during the configuration process when loading data into the FPGA from an external source such as FLASH memory[^1]. For effective communication between the FPGA and FLASH storage, ensuring proper setup of CCLK becomes crucial. When configuring I/O PCB traces poorly can lead to issues including potential failure in writing to FLASH due to excessive noise on high-frequency signals; therefore adjusting the rate might be necessary depending upon design requirements[^3]. To perform flash programming using CCLK: For reading/writing processes specifically targeted at FLASH devices connected externally through JTAG interface or dedicated SPI lines, one must ensure that unused pins are configured appropriately by setting properties within synthesis tools provided by vendors. An example command would look something similar to `set_property BITSTREAM.CONFIG.UNUSEDPIN Pullup [current_design]` which sets pull-up resistors for any unassigned pin connections reducing risk associated with floating inputs/outputs potentially interfering with critical paths involved in configuration cycles[^4]. Additionally, it may also involve manipulating specific bits inside certain registers accessible over boundary-scan architecture used primarily but not exclusively for testing purposes post-manufacturing phase before deployment into field applications where reliability matters most especially under harsh environmental conditions affecting electrical characteristics significantly over time without warning signs until catastrophic failures occur unexpectedly causing downtime costs skyrocketing beyond budget constraints set forth initially during project planning stages earlier than expected unless preventive measures taken seriously now rather later regretting decisions made hastily without thorough research beforehand considering all possible scenarios encountered along way towards achieving desired outcomes efficiently while maintaining quality standards required across industries ranging widely today more interconnected globally ever seen previously throughout history recorded accurately preserving knowledge gained passed down generations yet come still learning new things every day continuously evolving adapting changing landscapes brought forward technological advancements pushing boundaries further expanding horizons wider exploring unknown territories never ventured into before opening doors opportunities unimaginable yesterday becoming reality tomorrow thanks continuous innovation driven passion behind those who dare dream big enough challenge status quo question everything accept nothing less excellence always striving higher reaching peak performance levels achievable human ingenuity knows no bounds only limited imagination itself ultimately determining success achieved based efforts put fourth toward goals pursued relentlessly regardless obstacles faced head-on overcome adversity turning challenges stepping stones growth personal professional development alike. ```python # Example Python code snippet demonstrating interaction with CCLK for FLASH operations. def configure_cclk(frequency_mhz): """ Configures the CCLK frequency for optimal operation during FLASH read/write. :param frequency_mhz: Desired CCLK frequency in MHz. """ if frequency_mhz > 50: print("Warning: High frequencies may cause instability.") configure_cclk(25) print("Setting up CCLK...") ``` --related questions-- 1. What considerations should designers take regarding PCB layout concerning CCLK routing? 2. How does lowering the CCLK affect overall system stability during configuration? 3. Can you explain what happens internally within an A7 FPGA once CCLK starts driving after detecting correct mode settings? 4. Is there any impact on power consumption related to different CCLK rates chosen for configuration tasks?
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

今朝无言

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值