Gowin PicoRV32

Similar documents
Tel:

untitled

第4章 系统设置

ICD ICD ICD ICD ICD

Bus Hound 5

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

P4i45GL_GV-R50-CN.p65

P4V88+_BIOS_CN.p65

untitled

P4VM800_BIOS_CN.p65

775i65PE_BIOS_CN.p65

P4Dual-915GL_BIOS_CN.p65

PCM-3386用户手册.doc

穨control.PDF

User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2

目 录

(Guangzhou) AIT Co, Ltd V 110V [ ]! 2

USB解决方案.ppt

Edge-Triggered Rising Edge-Triggered ( Falling Edge-Triggered ( Unit 11 Latches and Flip-Flops 3 Timing for D Flip-Flop (Falling-Edge Trigger) Unit 11

bingdian001.com

Microsoft Word - MTK平台生产软件使用说明.doc

Ác Åé å Serial ATA ( Sil3132) S A T A (1) SATA (2) BIOS SATA (3)* RAID BIOS RAID (4) SATA (5) SATA (a) S A T A ( S A T A R A I D ) (b) (c) Windows XP

C/C++ - 文件IO

untitled

PTS7_Manual.PDF

ch08.PDF

untitled

MICROCHIP EVM Board : APP APP001 PICmicro Microchip APP001 40pin PDIP PICmicro Design Tips Character LCM Temperature Sensor Application I/O Pi

audiogram3 Owners Manual

NORCO-740 CPU M/00M NORCO-740 NORCO-740E NORCO-740G NORCO-740GE Intel 845GL Intel 845G

KL DSC DEMO 使用说明

T

Arduino 1-1 Arduino 1-2 Arduino 1-3 Arduino IDE

新建 Microsoft Word 文档.doc

投影片 1

SPHE8202R Design Guide Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provi

中文手册

Simulator By SunLingxi 2003

Huawei Technologies Co

FM1935X智能非接触读写器芯片

邏輯分析儀的概念與原理-展示版

50-FB23-24_BES_V_ z1_ b

JLX

Computer Architecture

EK-STM32F

DR2010.doc

System Design and Setup of a Robot to Pass over Steps Abstract In the research, one special type of robots that can pass over steps is designed and se

untitled

员工签到录

行业

RAID RAID 0 RAID 1 RAID 5 RAID * ( -1)* ( /2)* No Yes Yes Yes A. B. BIOS SATA C. RAID BIOS RAID ( ) D. SATA RAID/AHCI ( ) SATA M.2 SSD ( )

ARM JTAG实时仿真器安装使用指南

SDP

AL-M200 Series

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

行业

T

OSI OSI 15% 20% OSI OSI ISO International Standard Organization 1984 OSI Open-data System Interface Reference Model OSI OSI OSI OSI ISO Prototype Prot

2 Keil µ vision 2.1 1) Keil µ vision2 V2.34 µ vision3 2) Sino_Keil.exe Keil c:\keil\ 3) JET51 USB PC C:\Keil\ USB PC 4) S-L

行业

行业

Table of Contents A. Product Outline.. 3 B. Features.. 4 C. Block Diagram... 5 D. Pin Assignments. 6 E. Physical Specifications... 7 F. DC Characteris

Serial ATA ( Silicon Image SiI3114)...2 (1) SATA... 2 (2) B I O S S A T A... 3 (3) RAID BIOS RAID... 5 (4) S A T A... 8 (5) S A T A... 10

untitled

<4D F736F F D20B5DAC8FDCBC4D5C2D7F7D2B5B4F0B0B82E646F63>

ATMEL AT90S8515 AVR CPU AVR AVR AVR ATMEL RISC 32 8 r0 r X Y Z R0 R1 R2 R13 R14 R15 R16 R17 R26 R27 R28 R29 R30 R31 0x00 0x

证券代码(A股/H股):000063/ 证券简称:中兴通讯 公告编号:

Microsoft PowerPoint - C15_LECTURE_NOTE_08.ppt

IEC 传输帧格式

lan03_yen

Guide to Install SATA Hard Disks

12232A LED LED LED EL EL CCFL EL CCF

典型自编教材

Microsoft Word - MSP430 Launchpad 指导书.docx

Microsoft PowerPoint - C15_LECTURE_NOTE_08.ppt

a b c d e f g C2 C1 2

EC51/52 GSM /GPRS MODEN

84

逢甲大學

GA-8IG P4 533 Pentium Rev MC-8IG-1201

Measurement Studio Expands Your Test and Measurement Programming Power

T

2_dvdr3380_97_CT_21221b.indd

ARM Cortex-M3 (STM32F) STMicroelectronics ( ST) STM32F103 Core: ARM 32-bit Cortex -M3 CPU 72 MHz, 90 DMIPS with 1.25 DMIPS/MHz Single-cycle multiplica

1

LK110_ck

Tel: Fax: TTP-344M/246M /

行业

K7VT2_QIG_v3

說 說 留 說 參 了 不 弄 弄 不 落 不 異 列 切 TOA 連 異 異 落 露 2

Section1_16bit Arc.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_09

/ / (FC 3)...

IP505SM_manual_cn.doc

逢 甲 大 學

Serial ATA ( nvidia nforce4 Ultra/SLI)...2 (1) SATA... 2 (2) B I O S S A T A... 3 (3) RAID BIOS RAID... 6 (4) S A T A... 9 (5) S A T A (6) Micro

Microsoft PowerPoint - C15_LECTURE_NOTE_11

FM1935X智能非接触读写器芯片

untitled

Transcription:

Gowin PicoRV32 软件编程 参考手册 IPUG911-1.3,2022-02-08

版权所有 2022 广东高云半导体科技股份有限公司,Gowin, 高云均为广东高云半导体科技股份有限公司注册商标, 本手册中提到的其他任何商标, 其所有权利属其拥有者所有 未经本公司书面许可, 任何单位和个人都不得擅自摘抄 复制 翻译本文档内容的部分或全部, 并不得以任何形式传播 免责声明 本文档并未授予任何知识产权的许可, 并未以明示或暗示, 或以禁止发言或其它方式授予任何知识产权许可 除高云半导体在其产品的销售条款和条件中声明的责任之外, 高云半导体概不承担任何法律或非法律责任 高云半导体对高云半导体产品的销售和 / 或使用不作任何明示或暗示的担保, 包括对产品的特定用途适用性 适销性或对任何专利权 版权或其它知识产权的侵权责任等, 均不作担保 高云半导体对文档中包含的文字 图片及其它内容的准确性和完整性不承担任何法律或非法律责任, 高云半导体保留修改文档中任何内容的权利, 恕不另行通知 高云半导体不承诺对这些文档进行适时的更新

版本信息 日期版本说明 2020/01/16 1.0 初始版本 2020/03/12 1.1 2020/06/01 1.2 2022/02/08 1.3 MCU 支持 Wishbone 总线接口的外部设备 GPIO; MCU 支持扩展 AHB 总线接口 ; MCU 支持片外 SPI-Flash 下载及运行 ; MCU 支持外部设备 SPI-Flash 读 写和擦除功能 ; MCU 支持 Hardware Stack Protection 和 Trap Stack Overflow 功能 支持 MCU 软件在线调试功能 ; 增强 MCU 内核中断处理功能 ; 优化 MCU 内核指令 更新外部设备 Simple UART 的寄存器地址映射 ; 更新外部设备 I2C Master 和 GPIO 的寄存器定义 ; 更新外部设备 SPI-Flash 的驱动函数定义 ; 完善中断处理程序

目录 目录 目录... i 表目录... iii 1 软件编程库... 1 2 存储系统... 2 3 中断处理... 3 3.1 中断特征... 3 3.2 中断控制... 3 3.3 中断编号... 4 4 Simple UART... 5 4.1 特征... 5 4.2 寄存器定义... 5 4.3 驱动程序使用方法... 5 5 Wishbone I2C Master... 7 5.1 特征... 7 5.2 寄存器定义... 7 5.3 驱动程序使用方法... 8 6 Wishbone SPI Master/Slave... 10 6.1 特征... 10 6.2 寄存器定义... 10 6.3 驱动程序使用方法... 11 7 Wishbone UART... 12 7.1 特征... 12 7.2 寄存器定义... 12 7.3 驱动程序使用方法... 12 8 Wishbone GPIO... 13 8.1 特征... 13 8.2 寄存器定义... 13 8.3 驱动程序使用方法... 14 IPUG911-1.3 i

目录 9 Wishbone SPI-Flash... 15 9.1 特征... 15 9.2 寄存器定义... 15 9.3 驱动程序使用方法... 20 IPUG911-1.3 ii

表目录 表目录 表 1-1 软件编程库定义... 1 表 2-1 标准外设内存映射定义... 2 表 3-1 中断控制函数定义... 3 表 3-2 中断编号定义... 4 表 4-1 Simple UART 寄存器定义... 5 表 4-2 Simple UART 驱动程序使用方法... 5 表 5-1 Wishbone I2C Master 寄存器定义... 7 表 5-2 Wishbone I2C Master 驱动程序使用方法... 8 表 6-1 Wishbone SPI 寄存器定义... 10 表 6-2 Wishbone SPI 驱动程序使用方法... 11 表 7-1 Wishbone UART 寄存器定义... 12 表 7-2 Wishbone UART 驱动程序使用方法... 12 表 8-1 Wishbone GPIO 寄存器定义... 13 表 8-2 Wishbone GPIO 驱动程序使用方法... 14 表 9-1 SPI-Flash 寄存器定义... 15 表 9-2 SPI-Flash 驱动程序使用方法... 20 IPUG911-1.3 iii

1 软件编程库 1 软件编程库 Gowin_PicoRV32 提供软件编程库 Gowin_PicoRV32\src\c_lib, 如表 1-1 所示 表 1-1 软件编程库定义 文件 start.s custom_ops.s config.h picorv32.h irq.c sections.lds sections_xip.lds sections_debug.lds firmware.c loader.c printf.c simpleuart.c wbi2c.c wbspi.c wbuart.c wbgpio.c wbspiflash.c 描述 MCU 内核启动引导程序 自定义中断处理指令宏定义 用户配置启动运行方式 寄存器 地址映射 时钟信号 系统配置等定义 中断处理函数 Flash 链接器 : MCU boot from external Flash and run in ITCM 和 MCU boot and run in ITCM 方式 Flash 链接器 : MCU boot and run in external Flash 方式 Flash 链接器 : MCU 软件在线调试模式 性能统计 延时等定义 启动引导方式定义 Simple UART/WB UART 打印输出 Simple UART 的驱动函数定义 Wishbone I2C Master 的驱动函数定义 Wishbone SPI Master/Slave 的驱动函数定义 Wishbone UART 的驱动函数定义 Wishbone GPIO 的驱动函数定义 Wishbone SPI-Flash 的驱动函数定义 IPUG911-1.3 1(21)

2 存储系统 2 存储系统 Gowin_PicoRV32 标准外部设备内存映射地址定义, 如表 2-1 所示 Gowin_PicoRV32 标准外部设备内存映射地址定义位置 :picorv32.h 表 2-1 标准外设内存映射定义 标准外设类型地址映射描述 DTCM 0x01000000 ITCM 0x02000000 Size: 8KB, 16KB, 32KB, 64KB, 128KB, 256KB Size:8KB, 16KB, 32KB, 64KB, 128KB, 256KB SIMPLEUART SIMPLEUART_RegDef 0x03000000 Simple UART WBUART WBUART_RegDef 0x11000000 Wishbone UART WBGPIO WBGPIO_RegDef 0x11001000 Wishbone GPIO WBSPI_MASTER WBSPI_RegDef 0x11002000 Wishbone SPI Master WBSPI_SLAVE WBSPI_RegDef 0x11003000 Wishbone SPI Slave WBSPI_FLASH SPI_FLASH_RegDef 0x11004000 Wishbone SPI-Flash WBI2C_Master OPEN_WB_INTE RFACE OPEN_AHB_INT ERFACE WBI2CMASTER_RegD ef 0x11005000-0x20000000-0x80000000 Wishbone I2C Master Open Wishbone Interface for Customized Peripherals Open AHB Interface for Cunstomized Peripherals IPUG911-1.3 2(21)

3 中断处理 3.1 中断特征 3 中断处理 3.1 中断特征 3.2 中断控制 中断控制器包括以下特征 : 轻量化的中断控制器和中断控制指令 中断由上升沿触发 提供最多 32 个用户可用的中断处理信号 软件可控制的中断优先级 不支持中断嵌套 Gowin_PicoRV32 中断控制函数定义, 如表 3-1 所示 表 3-1 中断控制函数定义 中断控制函数参数描述 mask_irq irq_enable_one_bit irq_disable_one_bit 32 位屏蔽码 32 位中断编号 32 位中断编号 中断屏蔽函数 屏蔽码中为 0 的位对应的中断为开放状态 ; 屏蔽码中为 1 的位对应的中断为屏蔽状态 单个中断使能函数 该编号对应的中断位被使能 单个中断关闭函数 该编号对应的中断位被关闭 enable_external_interrupt - 使能外部中断 disable_external_interrupt - 关闭外部中断 enable_timer_interrupt - 使能计时器中断 disable_timer_interrupt - 关闭计时器中断 enable_interrupt_global - 使能全局中断 disable_interrupt_global - 关闭全局中断 IPUG911-1.3 3(21)

3 中断处理 3.3 中断编号 中断控制函数参数描述 set_timer irq 3.3 中断编号 32 位的计时长度 timer_val 32 位中断寄存器 32 位中断编号 计时器中断设置函数 自动开始计时, 当计时达到 timer_val 个时钟周期时, 触发计时器中断 中断处理函数 : 当触发中断后, 自动进入该函数, 根据触发中断的中断位编号, 调用相应的中断处理函数 Gowin_PicoRV32 预置的中断编号定义, 如表 3-2 所示 Gowin_PicoRV32 中断处理函数定义位置 :irq.c 表 3-2 中断编号定义 编号 描述 0 32 位计时器中断 1 执行调试断点指令 (ebreak) 2 内存非对齐访问错误 (bus error) 3 非法指令错误 4 调试模块中断 5 硬件栈保护中断 6~9 Reserved 10 Wishbone SPI Master 中断 11 Wishbone SPI Slave 中断 12 Wishbone I2C Master 中断 13 Wishbone UART 中断 14 ~ 19 Reserved 20 ~ 31 预留给 Wishbone 扩展总线接口和 AHB 扩展总线接口, 供用户扩展 Wishbone 和 AHB 外部设备使用 IPUG911-1.3 4(21)

4 Simple UART 4.1 特征 4 Simple UART 4.1 特征 4.2 寄存器定义 Gowin_PicoRV32, 包含一个轻量级的通用异步收发器 Simple UART: 无奇偶校验位 8 位数据位 1 位停止位 不支持中断 用户在使能 Simple UART 时, 请设置波特率分频寄存器 例如, 如果系统时钟频率运行在 12MHz, 需要波特率为 9600, 则可以设置波特率分频寄存器为 12000000/9600=1250 Simple UART 寄存器定义, 如表 4-1 所示 表 4-1 Simple UART 寄存器定义 寄存器名称地址偏移类型宽度初始值描述 RESERVED 0x000 - - - Reserved CLKDIV 0x004 RW 32 0x1 分频系数寄存器, 用于配置波特 率 DATA 0x008 RW 32 0x- 输入 / 输出数据寄存器 4.3 驱动程序使用方法 Simple UART 驱动程序使用方法, 如表 4-2 所示 表 4-2 Simple UART 驱动程序使用方法 名称 uart_init outbyte uart_putchar 描述 对 Simple UART 进行初始化, 配置波特率 输出一个字符, 当输出换行符时自动返回行首 输出一个字符 IPUG911-1.3 5(21)

4 Simple UART 4.3 驱动程序使用方法 名称 getchar_prompt uart_getchar 描述 返回 UART RX 接收到的字符 返回 UART RX 接收到的字符 IPUG911-1.3 6(21)

5 Wishbone I2C Master 5.1 特征 5 Wishbone I2C Master 5.1 特征 5.2 寄存器定义 Gowin_PicoRV32, 包含一个通过 Wishbone 总线访问的内部集成电路 I2C Master 模块 : Wishbone 总线接口 符合业界标准的 I2C 总线协议 总线仲裁及仲裁丢失检测 总线忙状态检测 产生中断标志 产生起始 终止 重复起始和应答信息 支持起始 终止和重复起始检测 支持 7 位寻址模式 Wishbone I2C Master 寄存器定义, 如表 5-1 所示 表 5-1 Wishbone I2C Master 寄存器定义 寄存器名称地址偏移类型宽度初始值描述 PRER 0x00 RW 32 CTR 0x04 RW 32 TXR 0x08 WO 32 0x000 0FFFF 0x000 00000 0x000 00000 Clock prescale register [31:15] Reserved [15:0] Prescale value = sys_clk/(5*scl)-1 Control register [31:8] Reserved [7] Enable I2C function [6] Enable I2C interrupt [5:0] Reserved Transmit data register [31:8] Reserved [7:1] Next transmission data IPUG911-1.3 7(21)

5 Wishbone I2C Master 5.3 驱动程序使用方法 寄存器名称 地址偏移 类型 宽度 初始值 描述 [0] Data direction RXR 0x08 RO 32 CR 0x0c WO 32 SR 0x0c RO 32 CHANNEL 0x10 RW 32 5.3 驱动程序使用方法 0x000 00000 0x000 00000 0x000 00000 0x000 00000 Receive data register [31:8] Reserved [7:0] Last received data Command register [31:8] Reserved [7] STA, Start transmission status [6] STO, Over transmission status [5] RD, Read enable, read data from slave [4] WR, Write enable, write data to slave [3] Acknowledge [2:1] Reserved [0] Interrupt acknowledge Status register [31:8] Reserved [7] Receive acknowledge signal from slave [6] I2C busy status [5] Arbitration loss [4:2] Reserved [1] Data transmission status flag [0] Interrupt flag Channel select register [31:1] Reserved [0] Channel select 0 = Channel 0 1 = Channel 1 Wishbone I2C Master 驱动程序使用方法, 如表 5-2 所示 表 5-2 Wishbone I2C Master 驱动程序使用方法 名称 I2C_Init I2C_SendByte I2C_SendBytes I2C_SendWord I2C_SendArray I2C_ReceiveByte I2C_ReadBytes I2C_ReceiveWord 描述 I2C Initialization Send a byte to I2C bus Send multiple bytes to I2C bus Send a word to I2C bus Send an array bytes to I2C bus Read a byte from I2C bus Read multiple bytes from I2C bus Read a word from I2C bus IPUG911-1.3 8(21)

5 Wishbone I2C Master 5.3 驱动程序使用方法 名称 I2C_RecevieArray I2C_Rate_Set I2C_Enable I2C_Disable I2C_InterruptOpen I2C_InterruptClose 描述 Read an array bytes from I2C bus Set I2C traffic rate Enable I2C bus Disable I2C bus Open I2C interrupt Close I2C interrupt IPUG911-1.3 9(21)

6 Wishbone SPI Master/Slave 6.1 特征 6 Wishbone SPI Master/Slave 6.1 特征 6.2 寄存器定义 Gowin_PicoRV32, 包含一个通过 Wishbone 总线访问的串行外设 Master 接口 SPI Master 和一个通过 Wishbone 总线访问的串行外设 Slave 接口 SPI Slave: Wishbone 总线接口 全双工同步串行数据传输 可配置时钟极性和相位 SPI 产生的串行时钟频率可配置 可配置的数据接收寄存器和数据发送寄存器位宽 Wishbone SPI 寄存器定义, 如表 6-1 所示 表 6-1 Wishbone SPI 寄存器定义 寄存器名称地址偏移类型宽度初始值描述 RXDATA 0x00 RO 32 TXDATA 0x04 WO 32 STATUS 0x08 RW 32 0x000 00000 0x000 00000 0x000 00000 Receive data register [31:8] Reserved [7:0] Receive data Transmit data register [31:8] Reserved [7:0] Transmit data Status register [31:8] Reserved [7] Overflow error status [6] Receive ready status [5] Transmit ready status [4] Be transmitting [3] Transmit overrun error status [2] Receive overrun error status [1:0] Reserved IPUG911-1.3 10(21)

6 Wishbone SPI Master/Slave 6.3 驱动程序使用方法 寄存器名称地址偏移类型宽度初始值描述 CONTROL 0x0C RW 32 SSMASK 0x10 RW 32 6.3 驱动程序使用方法 0x000 00000 0x000 00000 Wishbone SPI 驱动程序使用方法, 如表 6-2 所示 表 6-2 Wishbone SPI 驱动程序使用方法 名称 wbspi_master_select_slave wbspi_enable_interrupt wbspi_disable_interrupt wbspi_master_txdata wbspi_master_rxdata wbspi_slave_prepare_txdata wbspi_slave_read_data 描述 Control register [31:5] Reserved [4:3] Clock selected, CLK_I / 2/4/6/8 [2] Clock polarity [1] Clock phase [0] Direction, 1 is MSB first [31:1] Reserved [0] Select and enable slave WBSPI Master 选择一个从设备进行通信 开启 WBSPI 的中断 关闭 WBSPI 的中断 WBSPI Master 向从设备发送数据 WBSPI Master 读取从设备的数据 WBSPI Slave 预备数据, 等待主设备读取 WBSPI Slave 读取主设备发送过来的数据 IPUG911-1.3 11(21)

7 Wishbone UART 7.1 特征 7 Wishbone UART 7.1 特征 7.2 寄存器定义 Gowin_PicoRV32, 包含一个通过 Wishbone 总线访问的通用异步收发器 UART: Wishbone 总线接口 无奇偶校验位 8 位数据位 1 位停止位 Wishbone UART 寄存器定义, 如表 7-1 所示 表 7-1 Wishbone UART 寄存器定义 寄存器名称地址偏移类型宽度初始值描述 SETUP 0x00 RW 32 0x00000000 UART 参数 / 设置寄存器 FIFO 0x04 RO 32 0x00000000 输入 FIFO 和输出 FIFO 的状态寄存器 RXREG 0x08 RO 32 0x00000000 UART 接受数据寄存器 TXREG 0x0C RW 32 0x00000000 UART 发送数据寄存器 7.3 驱动程序使用方法 Wishbone UART 驱动程序使用方法, 如表 7-2 所示 表 7-2 Wishbone UART 驱动程序使用方法 名称 wbuart_init wbuart_putc wbuart_getc wbuart_outbyte 描述 Wishbone UART 初始化, 配置波特率 Wishbone UART 发送一个字节 Wishbone UART 接受一个字节 Wishbone UART 发送一个字节, 并在输出换行时自动返回行首 IPUG911-1.3 12(21)

8 Wishbone GPIO 8.1 特征 8 Wishbone GPIO 8.1 特征 8.2 寄存器定义 Gowin_PicoRV32, 包含一个通过 Wishbone 总线访问的 GPIO: Wishbone 总线接口 32 位, 每位可以独立配置输入和输出状态 Wishbone GPIO 寄存器定义, 如表 8-1 所示 表 8-1 Wishbone GPIO 寄存器定义 寄存器名称地址偏移类型宽度初始值描述 CFG 0x00 RW 32 0x00000000 IE 0x04 RW 32 0x00000000 GPIO configuration register [31:0] Each pin configuration RSV[2] 0x08-0x0C - - - Reserved DIR 0x10 RW 32 0xFFFFFFFF IN 0x14 RO 32 0x00000000 OUT 0x18 WO 32 0x00000000 GPIO interrupt enable register [31:0] Each pin interrupt enable GPIO input/output direction register [31:0] Control each pin input/output direction 1 = Output 0 = Input GPIO input register [31:0] Each pin input GPIO output register [31:0] Each pin output IPUG911-1.3 13(21)

8 Wishbone GPIO 8.3 驱动程序使用方法 8.3 驱动程序使用方法 Wishbone GPIO 驱动程序使用方法, 如表 8-2 所示 表 8-2 Wishbone GPIO 驱动程序使用方法 名称 描述 GPIO_Init Wishbone GPIO 初始化 GPIO_SetDir Wishbone GPIO 设置输入 / 输出方向 GPIO_GetDir Wishbone GPIO 获取输入 / 输出方向 GPIO_EnableWriteBit Wishbone GPIO 使能每位输出 GPIO_EnableReadBit Wishbone GPIO 使能每位输入 GPIO_WriteData Wishbone GPIO 输出 GPIO_ReadData Wishbone GPIO 输入 IPUG911-1.3 14(21)

9 Wishbone SPI-Flash 9.1 特征 9 Wishbone SPI-Flash 9.1 特征 9.2 寄存器定义 Gowin_PicoRV32, 包含 1 个通过 Wishbone 总线访问的 SPI-Flash: SPI-Flash 支持软件编程设计 BIN 文件下载启动和指令运行功能 SPI-Flash Memory 支持读 写和擦除功能 SPI-Flash Controller 默认为高云开发板板载 Winbond W25Q64BV 芯片 SPI-Flash 寄存器定义, 如表 9-1 所示 表 9-1 SPI-Flash 寄存器定义 寄存器名称地址偏移类型宽度初始值描述 IDREV 0x00 RO 32 RESERVED 0[3] 0x04-0x0 C TRANSFMT 0x10 RW 32 0x020 02000 - - - Reserved 0x000 20780 ID and revision register [31:8] ID number [7:4] Major revision number [3:0] Minor revision number SPI transfer format register [31:18] Reserved [17:16] Address length in bytes 00 = 1 byte 01 = 2 bytes 10 = 3 bytes 11 = 4 bytes [15:13] Reserved [12:8] Data length [7] Enable data merge mode [6:5] Reserved [4] Bi-directional MOSI in single mode 0 = MOSI is uni-directional signal 1 = MOSI is bi-directional signal IPUG911-1.3 15(21)

9 Wishbone SPI-Flash 9.2 寄存器定义 寄存器名称 地址偏移 类型 宽度 初始值 描述 [3] Transfer data with the lease significant bit first 0 = Most significant bit first 1 = Least significant bit first [2] SPI master/slave mode selection 0 = Master mode 1 = Slave mode [1] SPI clock polarity 0 = SCLK is LOW in the idle states 1 = SCLK is HIGH in the idle states [0] SPI clock phase 0 = Sampling data at odd SCLK edges 1 = Sampling data at even SCLK edges DIRECTIO 0x14 RW 32 0x0 SPI direct IO control register [31:25] Reserved [24] Enable direct IO 0 = Disable 1 = Enable [23:22] Reserved [21] Output enable for SPI-Flash hold signal [20] Output enable for SPI-Flash write protect signal [19] Output enable for the SPI MISO signal [18] Output enable for the SPI MOSI signal [17] Output enable for SPI SCLK signal [16] Output enable for SPI CS signal [15:14] Reserved [13] Output value for SPI-Flash hold signal [12] Output value for SPI-Flash write protect signal [11] Output value for SPI MISO signal [10] Output value for SPI MOSI signal [9] Output value for SPI SCLK signal [8] Output value for SPI CS signal [7:6] Reserved IPUG911-1.3 16(21)

9 Wishbone SPI-Flash 9.2 寄存器定义 寄存器名称 地址偏移 类型 宽度 初始值 描述 [5] Status of SPI-Flash hold signal [4] Status of SPI-Flash write protect signal [3] Status of SPI MISO signal [2] Status of SPI MOSI signal [1] Status of SPI SCLK signal [0] Status of SPI CS signal RESERVED 1[2] TRANSCTR L 0x18-0x1 C - - - Reserved 0x20 RW 32 0x0 SPI transfer control register [31] Reserved [30] SPI command phase enable 0 = Disable the command phase 1 = Enable the command phase (Master mode only) [29] SPI address phase enable 0 = Disable the address phase 1 = Enable the address phase (Master mode only) [28] SPI address phase format 0 = Address phase is single mode 1 = The format of the address phase is the same as the DualQuad data phase (Master mode only) [27:24] Transfer mode 0000 = Write and read at the same time 0001 = Write only 0010 = Read only 0011 = Write, Read 0100 = Read, Write 0101 = Write, Dummy, Read 0110 = Read, Dummy, Write 0111 = None data 1000 = Dummy, Write 1001 = Dummy, Read 1010~1111 = Reserved [23:22] SPI data phase format 00 = Single mode 01 = Dual I/O mode 10 = Quad I/O mode 11 = Reserved [21] Append and one-byte special token following the address phase for SPI read transfers IPUG911-1.3 17(21)

9 Wishbone SPI-Flash 9.2 寄存器定义 寄存器名称 地址偏移 类型 宽度 初始值 描述 [20:12] Transfer count for write data [11] The value of the one-byte special token following the address phase for SPI read transfers 0 = token value is 0x00 1 = token value is 0x69 [10:9] Dummy data count [8:0] Transfer count for read data CMD 0x24 RW 32 0x0 ADDR 0x28 RW 32 0x0 DATA 0x2C RW 32 0x0 CTRL 0x30 RW 32 0x0 STATUS 0x34 RO 32 0x0 INTREN 0x38 RW 32 0x0 SPI command register [31:8] Reserved [7:0] SPI command SPI address register [31:0] SPI address (Master mode only) SPI data register [31:0] Data to transmit or the received data SPI controller register [31:21] Reserved [20:16] Transmit FIFO threshold [15:13] Reserved [12:8] Receive FIFO threshold [7:5] Reserved [4] TX DMA enable [3] RX DMA enable [2] Transmit FIFO reset [1] Receive FIFO reset [0] SPI reset SPI status register [31:24] Reserved [23] Transmit FIFO full flag [22] Transmit FIFO empty flag [21] Reserved [20:16] Number of valid entries int the transmit FIFO [15] Receive FIFO full flag [14] Receive FIFO empty flag [13] Reserved [12:8] Number of valid entries in the receive FIFO [7:1] Reserved [0] SPI register programming is in progress SPI interrupt enable register [31:6] Reserved [5] Enable the slave command IPUG911-1.3 18(21)

9 Wishbone SPI-Flash 9.2 寄存器定义 寄存器名称 地址偏移 类型 宽度 初始值 描述 interrupt [4] Enable the end of SPI transfer interrupt [3] Enable the SPI transmit FIFO threshold interrupt [2] Enable the SPI receive FIFO threshold interrupt [1] Enable SPI transmit FIFO underrun interrupt (Slave mode only) [0] Enable SPI receive FIFO overrun interrupt (Slave mode only) INTRST 0x3C WO 32 0x0 TIMING 0x40 RW 32 0x0 RESERVED 2[3] 0x44-0x4 c - - - Reserved MEMCTRL 0x50 RW 32 0x0 RESERVED 3[3] 0x54-0x5 C - - - Reserved SLVST 0x60 RW 32 0x0 SPI interrupt status register [31:6] Reserved [5] Slave command interrupt (Slave mode only) [4] End of SPI transfer interrupt [3] TX FIFO threshold interrupt [2] RX FIFO threshold interrupt [1] TX FIFO underrun interrupt (Slave mode only) [0] RX FIFO overrun interrupt (Slave mode only) SPI interface timing register [31:14] Reserved [13:12] The minimum time between the edges of SPI CS and the edges of SCLK [11:8] The minimum time the SPI CS should stay HIGH [7:0] The clock frequency ratio between the clock source and SPI interface SCLK SPI memory access control register [31:9] Reserved [8] This bit is set when MEMCTRL / TIMING is written [7:4] Reserved [3:0] Selects the SPI command SPI slave status register [31:19] Reserved [18] Data underrun occurs in the last transaction IPUG911-1.3 19(21)

9 Wishbone SPI-Flash 9.3 驱动程序使用方法 寄存器名称 地址偏移 类型 宽度 初始值 描述 [17] Data overrun occurs in the last transaction [16] SPI is ready for data transaction [15:0] User defined status flags SLVDATAC NT RESERVED 4[5] 0x64 RO 32 0x0 0x68-0x7 8 - - - Reserved CONFIG 0x7C RO 32 0x0 9.3 驱动程序使用方法 SPI-Flash 驱动程序使用方法, 如表 9-2 所示 表 9-2 SPI-Flash 驱动程序使用方法 名称 spi_flash_init spi_get_fifo_depth change_mode_spi_flash spi_flash_read 描述 Initialize SPI-Flash Get SPI fifo depth SPI slave data count register [31:25] Reserved [24:16] Slave transmitted data count [15:9] Reserved [8:0] Slave received data count Configuration register [31:15] Reserved [14] Support for SPI slave mode [13] Reserved [12] Support for memory-mapped access through AHB bus [11] Support for direct SPI IO [10] Reserved [9] Support for Quad I/O SPI [9] Support for Dual I/O SPI [7:6] Reserved [5:4] Depth of TX FIFO 00 = 2 words 01 = 4 words 10 = 8 words 11 = 16 words [3:2] Reserved [1:0] Depth of RX FIFO 00 = 2 words 01 = 4 words 10 = 8 words 11 = 16 words Switch SPI-Flash mode between download and read, write, erase memory Read data from SPI-Flash IPUG911-1.3 20(21)

9 Wishbone SPI-Flash 9.3 驱动程序使用方法 名称 spi_flash_write spi_flash_page_program spi_flash_sector_erase spi_flash_write_cmd spi_flash_read_status 描述 Write data into SPI-Flash Write data into SPI-Flash with pages Erase SPI-Flash with sector Write command to SPI-Flash Read SPI-Flash status IPUG911-1.3 21(21)