高云GW1NSR-4C开发板M3硬核应用

2023-12-13 23:55:38

1.M3硬核IP下载:Embedded M3 Hard Core in GW1NS-4C - 科技 - 广东高云半导体科技股份有限公司 (gowinsemi.com.cn)

特别说明:IDE必须是1.9.9及以后版本,1.9.8会导致编译失败(1.9.8下1.1.3版本IP核可用)

以下根据官方提供的开发包,在GW1NSR-4C开发板上实现8个led点灯及串口通信测试。

2.FPGA综合:

解压文件,打开\Gowin_EMPU(GW1NS-4C)_V1.2\solution\running_in_sram_from_emb_userflash\ref_design\FPGA_RefDesign\DK_START_GW1NSR4C_QN48P_V1.1\gowin_empu下工程,添加器件GW1NSR-4C,正常的话应该可以综合(Synthesize)。

由于板卡实际晶振为27M,且需要点亮8个led,串口引脚也需要重新配置,故作出一定修改。修改gowin_pllvr.v文件,相关参数更改如下:

defparam pllvr_inst.FCLKIN = "27";
defparam pllvr_inst.DYN_IDIV_SEL = "false";
defparam pllvr_inst.IDIV_SEL = 8;
defparam pllvr_inst.DYN_FBDIV_SEL = "false";
defparam pllvr_inst.FBDIV_SEL = 25;
defparam pllvr_inst.DYN_ODIV_SEL = "false";
defparam pllvr_inst.ODIV_SEL = 8;
defparam pllvr_inst.PSDA_SEL = "0000";
defparam pllvr_inst.DYN_DA_EN = "true";
defparam pllvr_inst.DUTYDA_SEL = "1000";
defparam pllvr_inst.CLKOUT_FT_DIR = 1'b1;
defparam pllvr_inst.CLKOUTP_FT_DIR = 1'b1;
defparam pllvr_inst.CLKOUT_DLY_STEP = 0;
defparam pllvr_inst.CLKOUTP_DLY_STEP = 0;
defparam pllvr_inst.CLKFB_SEL = "internal";
defparam pllvr_inst.CLKOUT_BYPASS = "false";
defparam pllvr_inst.CLKOUTP_BYPASS = "false";
defparam pllvr_inst.CLKOUTD_BYPASS = "false";
defparam pllvr_inst.DYN_SDIV_SEL = 2;
defparam pllvr_inst.CLKOUTD_SRC = "CLKOUT";
defparam pllvr_inst.CLKOUTD3_SRC = "CLKOUT";
defparam pllvr_inst.DEVICE = "GW1NSR-4C";

修改gowin_empu_template.v文件:

//sys_clk max 78MHz
//GPIO
//UART0

`resetall

module Gowin_EMPU_Template (
  sys_clk,
  reset_n,
  led,
  uart0_rxd,
  uart0_txd
);

input sys_clk;
input reset_n;

//GPIO
output [7:0] led;

//UART0
input uart0_rxd;
output uart0_txd;

/*--------------------Gowin_EMPU_Top---------------------------*/
wire mclk;              //mcu clock
wire clkin = sys_clk;
wire [7:0] gpioout_o;
wire [15:0] gpioouten_o;

//MCU system clock = 78MHz
Gowin_PLLVR u_Gowin_PLLVR(
  .clkout(mclk),            //MCU 78MHz
  .clkin(clkin)             //input clkin 27MHz
);

Gowin_EMPU_Top u_Gowin_EMPU_Top (
  .sys_clk(mclk),
  .reset_n(reset_n),
  //GPIO
  .gpioin(16'h0000),
  .gpioout({gpioout_o,led}),
  .gpioouten(gpioouten_o),
  //UART0
  .uart0_rxd(uart0_rxd),
  .uart0_txd(uart0_txd)
);

endmodule

修改引脚约束文件:

//MCU system clock
IO_LOC "sys_clk" 22;//F_CLK
IO_PORT "sys_clk" IO_TYPE=LVCMOS18;

//MCU system reset
IO_LOC "reset_n" 23;//KEY2
IO_PORT "reset_n" IO_TYPE=LVCMOS25;

//LED
IO_LOC "led[7]" 34;
IO_PORT "led[7]" IO_TYPE=LVCMOS25;
IO_LOC "led[6]" 35;
IO_PORT "led[6]" IO_TYPE=LVCMOS25;
IO_LOC "led[5]" 31;
IO_PORT "led[5]" IO_TYPE=LVCMOS25;
IO_LOC "led[4]" 32;
IO_PORT "led[4]" IO_TYPE=LVCMOS25;
IO_LOC "led[3]" 29;
IO_PORT "led[3]" IO_TYPE=LVCMOS25;
IO_LOC "led[2]" 30;
IO_PORT "led[2]" IO_TYPE=LVCMOS25;
IO_LOC "led[1]" 27;
IO_PORT "led[1]" IO_TYPE=LVCMOS25;
IO_LOC "led[0]" 28;
IO_PORT "led[0]" IO_TYPE=LVCMOS25;

//UART0
IO_LOC "uart0_rxd" 45;//UART_RXD
IO_LOC "uart0_txd" 43;//UART_TXD
IO_PORT "uart0_rxd" IO_TYPE=LVCMOS25;
IO_PORT "uart0_txd" IO_TYPE=LVCMOS25;

4.MCU工程:

打开\Gowin_EMPU(GW1NS-4C)_V1.2\ref_design\MCU_RefDesign\Keil_RefDesign\uart\PROJECT下的Keil工程,在此基础上修改main.c文件,波特率改为14400bps。:

/* Includes ------------------------------------------------------------------*/
#include "gw1ns4c.h"
#include <stdio.h>

/* Declarations ------------------------------------------------------------------*/
void UartInit(void);
void delay_ms(__IO uint32_t delay_ms);
void GPIOInit(void);
/* Functions ------------------------------------------------------------------*/
int main()
{??
? SystemInit();?? ?//Initializes system
? UartInit();?? ??? ?//Initializes UART0
? GPIOInit();?? ??? ?//Initializes GPIO
? printf("\nUart Initialed!\r\n");
? printf("\n");
? while(1)
? {

? ? ? ?GPIO_ResetBit(GPIO0, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7);//|GPIO_Pin_1|GPIO_Pin_2);?? ?//LED?on
?? ??? ?printf("Led ON\r\n");
?? ??? ?delay_ms(1000);
?? ??? ?GPIO_SetBit(GPIO0, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7);//|GPIO_Pin_1|GPIO_Pin_2);?? ?//LED?off
?? ??? ?printf("Led OFF\r\n");
?? ??? ?delay_ms(1000);
??? }
}

//Initializes UART0
void UartInit(void)
{
? UART_InitTypeDef UART_InitStruct;
? UART_InitStruct.UART_Mode.UARTMode_Tx = ENABLE;
? UART_InitStruct.UART_Mode.UARTMode_Rx = ENABLE;
? UART_InitStruct.UART_Int.UARTInt_Tx = DISABLE;
? UART_InitStruct.UART_Int.UARTInt_Rx = DISABLE;
? UART_InitStruct.UART_Ovr.UARTOvr_Tx = DISABLE;
? UART_InitStruct.UART_Ovr.UARTOvr_Rx = DISABLE;
? UART_InitStruct.UART_Hstm = DISABLE;
? UART_InitStruct.UART_BaudRate = 14400;//Baud Rate
?? UART_Init(UART0,&UART_InitStruct);
}

//delay ms
void delay_ms(__IO uint32_t delay_ms)
{
?? ?for(delay_ms=(SystemCoreClock/16000)*delay_ms; delay_ms != 0; delay_ms--);
}
//Initializes GPIO
void GPIOInit(void)
{
?? ?GPIO_InitTypeDef GPIO_InitType;
????GPIO_InitType.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
?? ?GPIO_InitType.GPIO_Mode = GPIO_Mode_OUT;
?? ?GPIO_InitType.GPIO_Int = GPIO_Int_Disable;
? ? GPIO_Init(GPIO0,&GPIO_InitType);

? ?}

如下图,在编译时,Option for Target?'uart'->User->After Build/Rebuild->Run#1处的D:\Keil_v5目录,根据个人实际进行修改,例如本人的为E:\Keil_v5\。
5.下载:

选择“MCU Mode”,如下图,需要两个文件:“.fs”FPGA文件和".bin"单片机文件。完成后需要长按Reset按键(即核心板上靠近中间的按键,23引脚)。分别接上led和USB-TTL,可以看出8个led按照约1秒的间隔时间闪烁,串口调试助手则交替收到“Led?ON”和“Led OFF”。

6.完整的工程文件:

https://download.csdn.net/download/weixin_41784968/88614259
https://download.csdn.net/download/weixin_41784968/88614264

文章来源:https://blog.csdn.net/weixin_41784968/article/details/134904774
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。