1.软件
Diamond 3.11 (64-bit)
LMS 1.0 for Diamond 3.11
2.硬件
ECP5U-25F
3.目的
实现ecp5u-25f使用lattice软核mico32,用c语言实现串口打印,并且实现LED闪烁。
4.建立eclipse工程
使用LMS 1.0 for Diamond 3.11 生成软核。
4.1.打开LMS 1.0 for Diamond 3.11,设置workspace
4.2.新建platform,选择模板PlatformF
4.3.由于模板没有提供串口,需要另外添加,确定即可
4.4.连接到总线,如下
4.5.去掉调试接口
4.6.依次点击A、I、D、G图标生成项目相关文件
4.7.进入C/C++项目窗口,新建工程
4.8.Building Workspace ,生成test.elf说明编译成功
4.9.修改mian.c文件,如下:
/**************************************************************
* This example exercises LEDs on LatticeMico32 Development *
* board. *
* *
* *
* *
*------------------------------------------------------------*
* PREREQUISITES: *
* *
* - GPIO with 8-bit output named LED connected to the *
* board's LED pins. *
**************************************************************/
#include "DDStructs.h"
#include "LookupServices.h"
#include "stdio.h"
#include "MicoUtils.h"
#include "DDStructs.h"
#include "MicoUart.h"
#include "MicoGPIO.h"
const char *LED_GPIO_INSTANCE = "LED";
const char *UART_INSTANCE = "uart";
int main(void)
{
unsigned int led_status = 0;
MicoUartCtx_t *uarts = (MicoUartCtx_t *)MicoGetDevice(UART_INSTANCE);
if (uarts == 0) {
return(0);
}
MicoUart_setRate(uarts, 115200);
MicoUart_putC(uarts, 'o');
MicoUart_putC(uarts, 'k');
MicoUart_putC(uarts, '!');
MicoUart_putC(uarts, '\r');
MicoUart_putC(uarts, '\n');
printf("found UART instance named LED\r\n");
/* Fetch GPIO instance named "LED" */
MicoGPIOCtx_t *leds = (MicoGPIOCtx_t *)MicoGetDevice(LED_GPIO_INSTANCE);
if (leds == 0) {
printf("failed to find GPIO instance named LED\r\n");
return(0);
}
printf("found GPIO instance named LED\r\n");
/* scroll the LEDs, every 100 msecs forever */
while(1) {
if (led_status) {
led_status = 0x0;
}
else {
led_status = (~0x0);
}
MICO_GPIO_WRITE_DATA(leds, led_status);
printf("runing...\r\n");
MicoSleepMilliSecs(1000);
}
/* all done */
return(0);
}
4.10.重新编译,转elf文件为mem文件,Tool->Software Deployment Tools
正常的情况下会出现问题:0 [main] bin_to_verilog 8884 find_fast_cwd: WARNING: Couldn't compute FAST_CWD pointer
解决方法:
这个问题是cygwin出现的问题,需要打补丁,cygwin_patch.zip,将补丁(附件)放在C:\lscc\diamond\3.11_x64\micosystem目录下解压即可解决问题。
链接:https://pan.baidu.com/s/1tHvqO2xbMcYY9hpssMPG0A
提取码:59kb
重新编译成功生成program.mem
4.11.将program.mem路径和文件名添加入platform,如下:
4.12.重新点击四个图标A、I、D、G生成项目文件
5.建立Lattice Diamod 工程
使用Diamond 3.11 (64-bit)工具,用硬件描述语言verilog,建立管脚、时钟配置
5.1.打开Diamond 3.11 (64-bit)软件,New Project
5.2.去掉 Copy souce to implementation directory
5.3.选择目标芯片
5.4.选择综合工具,必须选择Synplify Pro
5.5.添加前面platform生成的软核的verlog文件
5.6.新建一个工程文件
5.7.添加如下的代码
module test (
input clk,
input reset,
output led,
/* uart接口 */
input uart_rxd,
output uart_txd
);
wire clk_100MHz = clk;
reg clk_25MHz;
//reg define
reg [1:0] counter;
always @(posedge clk_100MHz or negedge reset) begin
if (!reset) begin
counter <= 2'd0;
clk_25MHz <= 0;
end
else if (counter < 2'd1) begin
counter <= counter + 1'b1;
end
else begin
counter <= 2'd0;
clk_25MHz <= !clk_25MHz;
end
end
/* mico32 接口 */
platform platform_u (
.clk_i(clk_25MHz),
.reset_n(reset),
.LEDPIO_OUT(led),
.uartSIN(uart_rxd),
.uartSOUT(uart_txd)
);
endmodule
5.8.双击Export Files 编译
5.9.分配管脚,保存重新编译
5.10.通过Lattice烧录器,烧录程序
5.11.正常情况下可看到LED在闪烁,串口工具可看到有数据打印
6.例程
上述建立工程如下,但是直接是不能使用的,因为项目使用的都是绝对路径,只能用来做参考。
链接:https://pan.baidu.com/s/1hELGl_10j0UvAPHHFjMHXw
提取码:r8my