基于NANO 9K 开发板加载PICORV32软核,并建立交叉编译环境

目录

0. 环境准备

1. 安装交叉编译器 

2. 理解makefile工作机理

3. 熟悉示例程序的代码结构,理解软核代码的底层驱动原理

4. 熟悉烧录环节的工作机理, 建立下载环境 

5. 编写例子blink, printf等, 加载运行

6. 后续任务

 


0. 环境准备

NANO 9K低成本体验FPGA开发,还是挺香的,官方例子有加载PICORV32软核的例子,可以建立简单的ISP编程环境,通过串口就可以加载程序,很方便。 

Tang Nano 9K picoRV 简单示例 - Sipeed Wiki

运行效果 

可以通过命令行进行点灯喝运行benchmark等操作。 

相当于例子包括了: 

  • 串口打印,
  • 串口接收指令
  • GPIO控制

等基本操作。 

如果要基于RISCV软核,进一步熟悉工作机制和编程环境,需要参考例子建立交叉编译环境。 

step by step.......,以下基于虚拟机运行ubuntu18.04环境,少一点干扰。 

为帮助理解, 可以看看高云的官方文档对于picorv32内核架构的介绍: 

1. 安装交叉编译器 

 在虚拟机环境下,解压toolchain到目标目录即可。编译器路径可以在makefile文件里进行指定。 

当然,虚拟机依赖环境至少需要安装make工具,gcc也一起

sudo apt-get install make gcc 

下载地址: 

riscv32交叉编译器,ubuntu18.04亲测可用资源-CSDN文库

2. 理解makefile工作机理

参考文章: 

 从零开始:一步步教你如何写Makefile_makefile菜鸟教程-CSDN博客

makefile组成三要素:目标,依赖, 命令 

picotiny工作示例里有两层makefile, 先看主目录下的: 

PYTHON_NAME ?= python
RISCV_NAME 	?= riscv-none-embed
RISCV_PATH 	?= /home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004
MAKE		?= makeFW_FILE 	 = fw/fw-flash/build/fw-flash.vPROG_FILE	?= $(FW_FILE)
COMx	 	?= COM14export PYTHON_NAME
export RISCV_NAME
export RISCV_PATH.PHONY: all brom flash clean programall: brom flash$(FW_FILE): flashbrom:$(MAKE) -C fw/fw-bromflash:$(MAKE) -C fw/fw-flashclean:$(MAKE) -C fw/fw-brom clean$(MAKE) -C fw/fw-flash cleanprogram: $(PROG_FILE)$(PYTHON_NAME) sw/pico-programmer.py $(PROG_FILE) $(COMx)

第一部分:指定环境变量

第二部分:指定分支

第三部分:分支命令编写

这个根目录下的makefile主要功能:一是执行不同的子目录下 ,二是program命令分支。 

真正编译项目代码的makefile是在子目录下。 

再来看子目录下的makefile

PROJ_NAME=blink-flash
DEBUG=no
BENCH=no
MULDIV=no
COMPRESSED=noSRCS = 	$(wildcard *.c)       		\$(wildcard *.S)LDSCRIPT = ./linker_flash.ldRISCV_NAME ?= riscv-none-embed
RISCV_PATH ?= /home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004MABI=ilp32
MARCH := rv32i
ifeq ($(MULDIV),yes)MARCH := $(MARCH)m
endif
ifeq ($(COMPRESSED),yes)MARCH := $(MARCH)ac
endifCFLAGS += -march=$(MARCH)  -mabi=$(MABI)  -ffunction-sections -fdata-sections
LDFLAGS += -march=$(MARCH)  -mabi=$(MABI)  -Wl,--gc-sectionsifeq ($(DEBUG),yes)CFLAGS += -g3 -O0 
endififeq ($(DEBUG),no)CFLAGS += -g -O3 
endififeq ($(BENCH),yes)CFLAGS += -fno-inline  
endifRISCV_CLIB=$(RISCV_PATH)/$(RISCV_NAME)/lib/$(MARCH)/$(MABI)/RISCV_OBJCOPY = $(RISCV_PATH)/bin/$(RISCV_NAME)-objcopy
RISCV_OBJDUMP = $(RISCV_PATH)/bin/$(RISCV_NAME)-objdump
RISCV_CC = $(RISCV_PATH)/bin/$(RISCV_NAME)-gccCFLAGS +=  -MD -fstrict-volatile-bitfields 
LDFLAGS +=  -nostdlib -lgcc -mcmodel=medany -nostartfiles -ffreestanding -Wl,-Bstatic,-T,$(LDSCRIPT),-Map,$(OBJDIR)/$(PROJ_NAME).map,--print-memory-usageOBJDIR = build
OBJS := $(SRCS)
OBJS := $(OBJS:.c=.o)
OBJS := $(OBJS:.cpp=.o)
OBJS := $(OBJS:.S=.o)
OBJS := $(addprefix $(OBJDIR)/,$(OBJS))SUBOBJ := $(addprefix $(OBJDIR)/,$(SUBDIRS))
SUBOBJ := $(addsuffix /*.o,$(SUBOBJ))export RISCV_CC CFLAGS LDFLAGS OBJDIRall: $(SUBDIRS) $(OBJDIR)/$(PROJ_NAME).elf $(OBJDIR)/$(PROJ_NAME).hex $(OBJDIR)/$(PROJ_NAME).asm $(OBJDIR)/$(PROJ_NAME).v$(SUBDIRS): ECHOmake -C $@ECHO:@echo $(SUBDIRS)$(OBJDIR)/%.elf: $(OBJS) | $(OBJDIR)$(RISCV_CC) $(CFLAGS) -o $@ $^ $(SUBOBJ) $(LDFLAGS) $(LIBS)%.hex: %.elf$(RISCV_OBJCOPY) -O ihex $^ $@%.bin: %.elf$(RISCV_OBJCOPY) -O binary $^ $@%.v: %.elf$(RISCV_OBJCOPY) -O verilog $^ $@%.asm: %.elf$(RISCV_OBJDUMP) -S -d $^ > $@$(OBJDIR)/%.o: %.cmkdir -p $(dir $@)$(RISCV_CC) -c $(CFLAGS)  $(INC) -o $@ $^$(OBJDIR)/%.o: %.cppmkdir -p $(dir $@)$(RISCV_CC) -c $(CFLAGS)  $(INC) -o $@ $^	$(OBJDIR)/%.o: %.Smkdir -p $(dir $@)$(RISCV_CC) -c $(CFLAGS) -o $@ $^ -D__ASSEMBLY__=1$(OBJDIR):mkdir -p $@clean:rm -f $(OBJDIR)/$(PROJ_NAME).elfrm -f $(OBJDIR)/$(PROJ_NAME).hexrm -f $(OBJDIR)/$(PROJ_NAME).maprm -f $(OBJDIR)/$(PROJ_NAME).vrm -f $(OBJDIR)/$(PROJ_NAME).asmfind $(OBJDIR) -type f -name '*.d' -print0 | xargs -0 -r rmfind $(OBJDIR) -type f -name '*.o' -print0 | xargs -0 -r rm.SECONDARY: $(OBJS)

主要完成的工作: 指定了环境变量,编译输出目标文件,编译后的处理(文件转换等) 。 

编写完示例代码后,可以在子目录下运行make命令,执行响应的makefile即可完成目标代码编译。 

3. 熟悉示例程序的代码结构,理解软核代码的底层驱动原理

4. 熟悉烧录环节的工作机理, 建立下载环境 

 烧录的riscv软核支持ISP(串口在线烧录)功能。 所以make program xxx命令调用的python脚本主要是握手协议和烧录固件的传输。 

简单理解: 软核的ISP功能完成了flash固件的调用启动和程序引导运行工作。 

小知识: 理解ISP

ISP的全称是:In System Programming,即在系统编程,该操作是通过MCU厂商出厂BootLoader来实现,通过ISP可以对主flash区域进行擦除、编程操作,还可以修改芯片的选项字节等。

ISP的实现逻辑是出厂“芯片”(我们这里是软核)自带了BootLoader程序,即出厂引导程序,通过BootLoader可以将程序从串口(上位机)下载到Flash中,实际的时序是通过RST来区分正常启动还是烧录状态,然后上位机的烧录脚本来控制串口时序, 用户程序实际上是通过串口最终下载到了FLASH中,然后程序从flash启动。

5. 编写例子blink, printf等, 加载运行

 1)点灯--blink

blink主要是调用GPIO寄存器写入功能

#include <stdint.h>
#include <stdbool.h>// a pointer to this is a null pointer, but the compiler does not
// know that because "sram" is a linker symbol from sections.lds.
extern uint32_t sram;typedef struct {volatile uint32_t OUT;volatile uint32_t IN;volatile uint32_t OE;
} PICOGPIO;// 寄存器地址
#define GPIO0 ((PICOGPIO*)0x82000000)#define FLASHIO_ENTRY_ADDR ((void *)0x80000054)volatile int i;
// --------------------------------------------------------void main()
{GPIO0->OE = 0x3F;GPIO0->OUT = 0x3F;while (1){for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x01;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x02;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x04;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x08;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x10;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x20;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x00;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F;for ( i = 0 ; i < 10000; i++);}}void irqCallback() {}

 makefile,其实之修改了PROJ_NAME

PROJ_NAME=blink-demo
DEBUG=no
BENCH=no
MULDIV=no
COMPRESSED=noSRCS = 	$(wildcard *.c)       		\$(wildcard *.S)LDSCRIPT = ./linker_flash.ldRISCV_NAME ?= riscv-none-embed
RISCV_PATH ?= /home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004MABI=ilp32
MARCH := rv32i
ifeq ($(MULDIV),yes)MARCH := $(MARCH)m
endif
ifeq ($(COMPRESSED),yes)MARCH := $(MARCH)ac
endifCFLAGS += -march=$(MARCH)  -mabi=$(MABI)  -ffunction-sections -fdata-sections
LDFLAGS += -march=$(MARCH)  -mabi=$(MABI)  -Wl,--gc-sectionsifeq ($(DEBUG),yes)CFLAGS += -g3 -O0 
endififeq ($(DEBUG),no)CFLAGS += -g -O3 
endififeq ($(BENCH),yes)CFLAGS += -fno-inline  
endifRISCV_CLIB=$(RISCV_PATH)/$(RISCV_NAME)/lib/$(MARCH)/$(MABI)/RISCV_OBJCOPY = $(RISCV_PATH)/bin/$(RISCV_NAME)-objcopy
RISCV_OBJDUMP = $(RISCV_PATH)/bin/$(RISCV_NAME)-objdump
RISCV_CC = $(RISCV_PATH)/bin/$(RISCV_NAME)-gccCFLAGS +=  -MD -fstrict-volatile-bitfields 
LDFLAGS +=  -nostdlib -lgcc -mcmodel=medany -nostartfiles -ffreestanding -Wl,-Bstatic,-T,$(LDSCRIPT),-Map,$(OBJDIR)/$(PROJ_NAME).map,--print-memory-usageOBJDIR = build
OBJS := $(SRCS)
OBJS := $(OBJS:.c=.o)
OBJS := $(OBJS:.cpp=.o)
OBJS := $(OBJS:.S=.o)
OBJS := $(addprefix $(OBJDIR)/,$(OBJS))SUBOBJ := $(addprefix $(OBJDIR)/,$(SUBDIRS))
SUBOBJ := $(addsuffix /*.o,$(SUBOBJ))export RISCV_CC CFLAGS LDFLAGS OBJDIRall: $(SUBDIRS) $(OBJDIR)/$(PROJ_NAME).elf $(OBJDIR)/$(PROJ_NAME).hex $(OBJDIR)/$(PROJ_NAME).asm $(OBJDIR)/$(PROJ_NAME).v$(SUBDIRS): ECHOmake -C $@ECHO:@echo $(SUBDIRS)$(OBJDIR)/%.elf: $(OBJS) | $(OBJDIR)$(RISCV_CC) $(CFLAGS) -o $@ $^ $(SUBOBJ) $(LDFLAGS) $(LIBS)%.hex: %.elf$(RISCV_OBJCOPY) -O ihex $^ $@%.bin: %.elf$(RISCV_OBJCOPY) -O binary $^ $@%.v: %.elf$(RISCV_OBJCOPY) -O verilog $^ $@%.asm: %.elf$(RISCV_OBJDUMP) -S -d $^ > $@$(OBJDIR)/%.o: %.cmkdir -p $(dir $@)$(RISCV_CC) -c $(CFLAGS)  $(INC) -o $@ $^$(OBJDIR)/%.o: %.cppmkdir -p $(dir $@)$(RISCV_CC) -c $(CFLAGS)  $(INC) -o $@ $^	$(OBJDIR)/%.o: %.Smkdir -p $(dir $@)$(RISCV_CC) -c $(CFLAGS) -o $@ $^ -D__ASSEMBLY__=1$(OBJDIR):mkdir -p $@clean:rm -f $(OBJDIR)/$(PROJ_NAME).elfrm -f $(OBJDIR)/$(PROJ_NAME).hexrm -f $(OBJDIR)/$(PROJ_NAME).maprm -f $(OBJDIR)/$(PROJ_NAME).vrm -f $(OBJDIR)/$(PROJ_NAME).asmfind $(OBJDIR) -type f -name '*.d' -print0 | xargs -0 -r rmfind $(OBJDIR) -type f -name '*.o' -print0 | xargs -0 -r rm.SECONDARY: $(OBJS)

项目目录下编译: 

/blink-demo$ make
mkdir -p build/
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-gcc -c -march=rv32i  -mabi=ilp32  -ffunction-sections -fdata-sections -g -O3  -MD -fstrict-volatile-bitfields    -o build/main.o main.c
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-gcc -march=rv32i  -mabi=ilp32  -ffunction-sections -fdata-sections -g -O3  -MD -fstrict-volatile-bitfields  -o build/blink-demo.elf build/main.o build/crt_flash.o  -march=rv32i  -mabi=ilp32  -Wl,--gc-sections -nostdlib -lgcc -mcmodel=medany -nostartfiles -ffreestanding -Wl,-Bstatic,-T,./linker_flash.ld,-Map,build/blink-demo.map,--print-memory-usage 
Memory region         Used Size  Region Size  %age UsedFLASH:         728 B         8 MB      0.01%RAM:        1040 B         8 KB     12.70%
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-objcopy -O ihex build/blink-demo.elf build/blink-demo.hex
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-objdump -S -d build/blink-demo.elf > build/blink-demo.asm
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-objcopy -O verilog build/blink-demo.elf build/blink-demo.v

生成的.v文件即用于执行的文件。 

执行根目录下的make program来烧录

 烧录成功: 

...../picotiny$ make programBlink
python sw/pico-programmer.py fw/blink-demo/build/blink-demo.v /dev/ttyUSB1
Read program with 736 bytes- Waiting for reset -...
Total sectors 1
Total pages 3
Flashing 1 / 1Flashing completed

 RISCV例程执行--blink-CSDN直播

 

 2)单独编写串口交互: 

main.c: 

#include <stdint.h>
#include <stdbool.h>// a pointer to this is a null pointer, but the compiler does not
// know that because "sram" is a linker symbol from sections.lds.
extern uint32_t sram;typedef struct {volatile uint32_t DATA;volatile uint32_t CLKDIV;
} PICOUART;typedef struct {volatile uint32_t OUT;volatile uint32_t IN;volatile uint32_t OE;
} PICOGPIO;typedef struct {union {volatile uint32_t REG;volatile uint16_t IOW;struct {volatile uint8_t IO;volatile uint8_t OE;volatile uint8_t CFG;volatile uint8_t EN; };};
} PICOQSPI;#define QSPI0 ((PICOQSPI*)0x81000000)
#define GPIO0 ((PICOGPIO*)0x82000000)
#define UART0 ((PICOUART*)0x83000000)#define FLASHIO_ENTRY_ADDR ((void *)0x80000054)void (*spi_flashio)(uint8_t *pdata, int length, int wren) = FLASHIO_ENTRY_ADDR;int putchar(int c)
{	if (c == '\n')UART0->DATA = '\r';UART0->DATA = c;return c;
}void print(const char *p)
{while (*p)putchar(*(p++));
}void print_hex(uint32_t v, int digits)
{for (int i = 7; i >= 0; i--) {char c = "0123456789abcdef"[(v >> (4*i)) & 15];if (c == '0' && i >= digits) continue;putchar(c);digits = i;}
}void print_dec(uint32_t v)
{if (v >= 100) {print(">=100");return;}if      (v >= 90) { putchar('9'); v -= 90; }else if (v >= 80) { putchar('8'); v -= 80; }else if (v >= 70) { putchar('7'); v -= 70; }else if (v >= 60) { putchar('6'); v -= 60; }else if (v >= 50) { putchar('5'); v -= 50; }else if (v >= 40) { putchar('4'); v -= 40; }else if (v >= 30) { putchar('3'); v -= 30; }else if (v >= 20) { putchar('2'); v -= 20; }else if (v >= 10) { putchar('1'); v -= 10; }if      (v >= 9) { putchar('9'); v -= 9; }else if (v >= 8) { putchar('8'); v -= 8; }else if (v >= 7) { putchar('7'); v -= 7; }else if (v >= 6) { putchar('6'); v -= 6; }else if (v >= 5) { putchar('5'); v -= 5; }else if (v >= 4) { putchar('4'); v -= 4; }else if (v >= 3) { putchar('3'); v -= 3; }else if (v >= 2) { putchar('2'); v -= 2; }else if (v >= 1) { putchar('1'); v -= 1; }else putchar('0');
}char getchar_prompt(char *prompt)
{int32_t c = -1;uint32_t cycles_begin, cycles_now, cycles;__asm__ volatile ("rdcycle %0" : "=r"(cycles_begin));if (prompt)print(prompt);// if (prompt)// GPIO0->OUT = ~0;// reg_leds = ~0;while (c == -1) {__asm__ volatile ("rdcycle %0" : "=r"(cycles_now));cycles = cycles_now - cycles_begin;if (cycles > 12000000) {if (prompt)print(prompt);cycles_begin = cycles_now;// if (prompt)// GPIO0->OUT = ~GPIO0->OUT;// reg_leds = ~reg_leds;}c = UART0->DATA;}// if (prompt)// GPIO0->OUT = 0;// reg_leds = 0;return c;
}char getchar()
{return getchar_prompt(0);
}#define QSPI_REG_CRM  0x00100000
#define QSPI_REG_DSPI 0x00400000void cmd_set_crm(int on)
{if (on) {QSPI0->REG |= QSPI_REG_CRM;} else {QSPI0->REG &= ~QSPI_REG_CRM;}
}int cmd_get_crm() {return QSPI0->REG & QSPI_REG_CRM;
}volatile int i;
// --------------------------------------------------------#define CLK_FREQ        25175000
#define UART_BAUD       115200void main()
{UART0->CLKDIV = CLK_FREQ / UART_BAUD - 2;GPIO0->OE = 0x3F;GPIO0->OUT = 0x3F;cmd_set_crm(1);print("\n");print("  ____  _          ____         ____\n");print(" |  _ \\(_) ___ ___/ ___|  ___  / ___|\n");print(" | |_) | |/ __/ _ \\___ \\ / _ \\| |\n");print(" |  __/| | (_| (_) |__) | (_) | |___\n");print(" |_|   |_|\\___\\___/____/ \\___/ \\____|\n");print("\n");print("        On Lichee Tang Nano-9K\n");print("\n");for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x01;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x02;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x04;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x08;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x10;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F ^ 0x20;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x00;for ( i = 0 ; i < 10000; i++);GPIO0->OUT = 0x3F;for ( i = 0 ; i < 10000; i++);while (1){print("\n");print("Select an action:\n");print("\n");print("   [1] Toggle led 1\n");print("   [2] Toggle led 2\n");print("   [3] Toggle led 3\n");print("   [4] Toggle led 4\n");print("   [5] Toggle led 5\n");print("   [6] Toggle led 6\n");for (int rep = 10; rep > 0; rep--){print("\n");print("IO State: ");print_hex(GPIO0->IN, 8);print("\n");print("\n");print("Command> ");char cmd = getchar();if (cmd > 32 && cmd < 127)putchar(cmd);print("\n");switch (cmd){case '1':GPIO0->OUT ^= 0x00000001;break;case '2':GPIO0->OUT ^= 0x00000002;break;case '3':GPIO0->OUT ^= 0x00000004;break;case '4':GPIO0->OUT ^= 0x00000008;break;case '5':GPIO0->OUT ^= 0x00000010;break;case '6':GPIO0->OUT ^= 0x00000020;break;default:continue;}}}
}void irqCallback() {}

makefile: 

PROJ_NAME=uart-demo
DEBUG=no
BENCH=no
MULDIV=no
COMPRESSED=noSRCS = 	$(wildcard *.c)       		\$(wildcard *.S)LDSCRIPT = ./linker_flash.ldRISCV_NAME ?= riscv-none-embed
RISCV_PATH ?= /home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004MABI=ilp32
MARCH := rv32i
ifeq ($(MULDIV),yes)MARCH := $(MARCH)m
endif
ifeq ($(COMPRESSED),yes)MARCH := $(MARCH)ac
endifCFLAGS += -march=$(MARCH)  -mabi=$(MABI)  -ffunction-sections -fdata-sections
LDFLAGS += -march=$(MARCH)  -mabi=$(MABI)  -Wl,--gc-sectionsifeq ($(DEBUG),yes)CFLAGS += -g3 -O0 
endififeq ($(DEBUG),no)CFLAGS += -g -O3 
endififeq ($(BENCH),yes)CFLAGS += -fno-inline  
endifRISCV_CLIB=$(RISCV_PATH)/$(RISCV_NAME)/lib/$(MARCH)/$(MABI)/RISCV_OBJCOPY = $(RISCV_PATH)/bin/$(RISCV_NAME)-objcopy
RISCV_OBJDUMP = $(RISCV_PATH)/bin/$(RISCV_NAME)-objdump
RISCV_CC = $(RISCV_PATH)/bin/$(RISCV_NAME)-gccCFLAGS +=  -MD -fstrict-volatile-bitfields 
LDFLAGS +=  -nostdlib -lgcc -mcmodel=medany -nostartfiles -ffreestanding -Wl,-Bstatic,-T,$(LDSCRIPT),-Map,$(OBJDIR)/$(PROJ_NAME).map,--print-memory-usageOBJDIR = build
OBJS := $(SRCS)
OBJS := $(OBJS:.c=.o)
OBJS := $(OBJS:.cpp=.o)
OBJS := $(OBJS:.S=.o)
OBJS := $(addprefix $(OBJDIR)/,$(OBJS))SUBOBJ := $(addprefix $(OBJDIR)/,$(SUBDIRS))
SUBOBJ := $(addsuffix /*.o,$(SUBOBJ))export RISCV_CC CFLAGS LDFLAGS OBJDIRall: $(SUBDIRS) $(OBJDIR)/$(PROJ_NAME).elf $(OBJDIR)/$(PROJ_NAME).hex $(OBJDIR)/$(PROJ_NAME).asm $(OBJDIR)/$(PROJ_NAME).v$(SUBDIRS): ECHOmake -C $@ECHO:@echo $(SUBDIRS)$(OBJDIR)/%.elf: $(OBJS) | $(OBJDIR)$(RISCV_CC) $(CFLAGS) -o $@ $^ $(SUBOBJ) $(LDFLAGS) $(LIBS)%.hex: %.elf$(RISCV_OBJCOPY) -O ihex $^ $@%.bin: %.elf$(RISCV_OBJCOPY) -O binary $^ $@%.v: %.elf$(RISCV_OBJCOPY) -O verilog $^ $@%.asm: %.elf$(RISCV_OBJDUMP) -S -d $^ > $@$(OBJDIR)/%.o: %.cmkdir -p $(dir $@)$(RISCV_CC) -c $(CFLAGS)  $(INC) -o $@ $^$(OBJDIR)/%.o: %.cppmkdir -p $(dir $@)$(RISCV_CC) -c $(CFLAGS)  $(INC) -o $@ $^	$(OBJDIR)/%.o: %.Smkdir -p $(dir $@)$(RISCV_CC) -c $(CFLAGS) -o $@ $^ -D__ASSEMBLY__=1$(OBJDIR):mkdir -p $@clean:rm -f $(OBJDIR)/$(PROJ_NAME).elfrm -f $(OBJDIR)/$(PROJ_NAME).hexrm -f $(OBJDIR)/$(PROJ_NAME).maprm -f $(OBJDIR)/$(PROJ_NAME).vrm -f $(OBJDIR)/$(PROJ_NAME).asmfind $(OBJDIR) -type f -name '*.d' -print0 | xargs -0 -r rmfind $(OBJDIR) -type f -name '*.o' -print0 | xargs -0 -r rm.SECONDARY: $(OBJS)

项目子目录下编译结果,生成目标文件: 

/uart-demo$ make
mkdir -p build/
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-gcc -c -march=rv32i  -mabi=ilp32  -ffunction-sections -fdata-sections -g -O3  -MD -fstrict-volatile-bitfields    -o build/main.o main.c
mkdir -p build/
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-gcc -c -march=rv32i  -mabi=ilp32  -ffunction-sections -fdata-sections -g -O3  -MD -fstrict-volatile-bitfields  -o build/crt_flash.o crt_flash.S -D__ASSEMBLY__=1
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-gcc -march=rv32i  -mabi=ilp32  -ffunction-sections -fdata-sections -g -O3  -MD -fstrict-volatile-bitfields  -o build/uart-demo.elf build/main.o build/crt_flash.o  -march=rv32i  -mabi=ilp32  -Wl,--gc-sections -nostdlib -lgcc -mcmodel=medany -nostartfiles -ffreestanding -Wl,-Bstatic,-T,./linker_flash.ld,-Map,build/uart-demo.map,--print-memory-usage 
Memory region         Used Size  Region Size  %age UsedFLASH:        3152 B         8 MB      0.04%RAM:        1040 B         8 KB     12.70%
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-objcopy -O ihex build/uart-demo.elf build/uart-demo.hex
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-objdump -S -d build/uart-demo.elf > build/uart-demo.asm
/home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/riscv-none-embed-objcopy -O verilog build/uart-demo.elf build/uart-demo.v

根目录下烧录运行: 

makefile增加选项programUart: 


PYTHON_NAME ?= python
RISCV_NAME 	?= riscv-none-embed
RISCV_PATH 	?= /home/hy/riscv/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004
MAKE		?= makeFW_FILE_BLINK 	 = fw/blink-demo/build/blink-demo.v
FW_FILE_UART	 = fw/uart-demo/build/uart-demo.vPROG_FILE_BLINK	?= $(FW_FILE_BLINK)
PROG_FILE_UART	?= $(FW_FILE_UART)COMx	 	?= /dev/ttyUSB1export PYTHON_NAME
export RISCV_NAME
export RISCV_PATH.PHONY: all brom flash clean programall: brom flash$(FW_FILE): flashbrom:$(MAKE) -C fw/fw-bromflash:$(MAKE) -C fw/blink-democlean:$(MAKE) -C fw/fw-brom clean$(MAKE) -C fw/fw-flash cleanprogram: $(PROG_FILE)$(PYTHON_NAME) sw/pico-programmer.py $(PROG_FILE) $(COMx)programBlink: $(PROG_FILE_BLINK)$(PYTHON_NAME) sw/pico-programmer.py $(PROG_FILE_BLINK) $(COMx)	programUart: $(PROG_FILE_UART)$(PYTHON_NAME) sw/pico-programmer.py $(PROG_FILE_UART) $(COMx)		

运行烧录: 

/picotiny$ make programUart
python sw/pico-programmer.py fw/uart-demo/build/uart-demo.v /dev/ttyUSB1
Read program with 3152 bytes- Waiting for reset -..
Total sectors 1
Total pages 13
Flashing 1 / 1Flashing completed

调用cutecom运行页面: 

 

输入框输入1-6可以控制对应的LED亮灭。 

6. 后续任务

1)延申理解,通过官方开发包,编写更易于移植和开发的库

2)理解配合软核的SDK架构(理解指令集) 和HAL库的基本逻辑。 理解SDK应该按什么逻辑来规划

3)移植FREERTOS, 理解操作系统移植的基本逻辑

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/337198.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

卷积网络迁移学习:实现思想与TensorFlow实践

摘要&#xff1a;迁移学习是一种利用已有知识来改善新任务学习性能的方法。 在深度学习中&#xff0c;迁移学习通过迁移卷积网络&#xff08;CNN&#xff09;的预训练权重&#xff0c;实现了在新领域或任务上的高效学习。 下面我将详细介绍迁移学习的概念、实现思想&#xff0c…

【成品设计】基于STM32单片机的饮水售卖机

基于STM32单片机的饮水售卖机 所需器件&#xff1a; STM32最小系统板。RFID&#xff1a;MFRC-522用于IC卡检测。OLED屏幕&#xff1a;用于显示当前水容量、系统状态等。水泵软管&#xff1a;用于抽水。水位传感器&#xff08;3个&#xff09;&#xff1a;用于分别标定&#x…

低代码赋能企业数字化转型:数百家软件公司的成功实践

本文转载于葡萄城公众号&#xff0c;原文链接&#xff1a;https://mp.weixin.qq.com/s/gN8Rq9TDmkMpCtNMMsBUXQ 导读 在当今的软件开发时代&#xff0c;以新技术助力企业数字化转型已经成为一个热门话题。如何快速适应技术变革&#xff0c;构建符合时代需求的技术能力和业务模…

【STM32F103】HC-SR04超声波测距

【STM32F103】HC-SR04超声波测距 一、HC-SR041、工作原理2、其他参数及时序图 二、代码编写思路三、HAL配置四、代码实现五、实验结果 前言 本次实验主要实现用stm32f103HC-SR04实现超声波测距&#xff0c;将测距数值通过串口上传到上位机串口助手 一、HC-SR04 1、工作原理 (…

【Unity知识点详解】Addressables的资源加载

今天来简单介绍一下Addressables&#xff0c;并介绍一下如何通过AssetName加载单个资源、如何通过Label加载多个资源、以及如何通过List<string>加载多个资源。由于Addressables的资源加载均为异步加载&#xff0c;所以今天给大家介绍如何使用StartCoroutine、如何使用As…

计算机算法中的数字表示法——浮点数

目录 1.前言2.浮点数的形式3.举例说明4.浮点数四则运算 微信公众号含更多FPGA相关源码&#xff1a; 1.前言 前面讲了定点表示法&#xff0c;定点表示法有一个主要的限制&#xff0c;那就是它不能有效地表示非常大或非常小的数&#xff0c;因为小数点的位置是固定的。为了解决这…

ios:文本框默认的copy、past改成中文复制粘贴

问题 ios 开发&#xff0c;对于输入框的一些默认文案展示&#xff0c;如复制粘贴是英文的&#xff0c;那么如何改为中文的呢 解决 按照路径找到这个文件 ios/项目/Info.plist&#xff0c;增加 <key>CFBundleAllowMixedLocalizations</key> <true/> <…

Echarts报警告Legend data should be same with series name or data name.

问题排查&#xff1a; 1. 确保 legend中的data中名字和series中每一项的name要匹配。 2. 仔细查看报警规律发现次数有在变化&#xff0c;因此找到代码中是动态修改legend,series的位置&#xff0c;检查一下这两个list的赋值逻辑。 果然&#xff0c;检查发现问题出现在了遍历里…

数据分析案例-在线食品订单数据可视化分析与建模分类

&#x1f935;‍♂️ 个人主页&#xff1a;艾派森的个人主页 ✍&#x1f3fb;作者简介&#xff1a;Python学习者 &#x1f40b; 希望大家多多支持&#xff0c;我们一起进步&#xff01;&#x1f604; 如果文章对你有帮助的话&#xff0c; 欢迎评论 &#x1f4ac;点赞&#x1f4…

2.5Bump Mapping 凹凸映射

一、Bump Mapping 介绍 我们想要在屏幕上绘制物体的细节&#xff0c;从尺度上讲&#xff0c;一个物体的细节分为&#xff1a;宏观、中观、微观宏观尺度中其特征会覆盖多个像素&#xff0c;中观尺度只覆盖几个像素&#xff0c;微观尺度的特征就会小于一个像素宏观尺度是由顶点或…

在鲲鹏服务器搭建k8s高可用集群分享

高可用架构 本文采用kubeadm方式搭建k8s高可用集群&#xff0c;k8s高可用集群主要是对apiserver、etcd、controller-manager、scheduler做的高可用&#xff1b;高可用形式只要是为&#xff1a; 1. apiserver利用haproxykeepalived做的负载&#xff0c;多apiserver节点同时工作…

【主动均衡和被动均衡】

文章目录 1.被动均衡2.主动均衡1.被动均衡 被动均衡一般通过电阻放电的方式,对电压较高的电池进行放电,以热量形式释放电量,为其他电池争取更多充电时间。这样整个系统的电量受制于容量最少的电池。充电过程中,锂电池一般有一个充电上限保护电压值,当某一串电池达到此电压…

docker+vue云服务器打包镜像相关操作

dockervue云服务器打包镜像相关操作 容器化部署似乎成了当前一个非常主流的趋势&#xff0c;无论是前端还是后端&#xff0c;流行的操作就是给你一个镜像地址&#xff0c;让你自己去拉取镜像并运行镜像。这似乎是运维的工作&#xff0c;但是在没有专有运维的情况下&#xff0c…

Vue中,点击提交按钮,路由多了个问号

问题 当点击提交按钮是路由多了问号&#xff1a; http://localhost:8100/#/ 变为 http://localhost:8100/?#/原因 路由中出现问号通常是由于某些路径或参数处理不当造成的。在该情况下&#xff0c;是因为表单的默认行为导致的。提交表单时&#xff0c;如果没有阻止表单的默…

【CH32V305FBP6】调试入坑指南

1. 无法烧录程序 现象 MounRiver Studio WXH-LinkUtility 解决方法 前提&#xff1a;连接复位引脚 或者 2. 无法调试 main.c 与调试口冲突&#xff0c;注释后调试 // USART_Printf_Init(115200);

2024年5月31日 (周五) 叶子游戏新闻

《Granblue Fantasy: Relink》版本更新 新增可操控角色及功能世嘉股份有限公司现已公开《Granblue Fantasy: Relink》&#xff08;以下简称 Relink&#xff09;免费版本更新ver.1.3.1于5月31日&#xff08;周五&#xff09;上线的消息。该作是由Cygames Inc.&#xff08;下称Cy…

【class18】人工智能初步----语音识别(4)

【class17】 上节课&#xff0c;我们学习了: 语音端点检测的相关概念&#xff0c;并通过代码切分和保存了音频。 本节课&#xff0c;我们将学习这些知识点&#xff1a;1. 序列到序列模型2. 循环神经网络3. 调用短语音识别接口 知其然&#xff0c;知其所以然 在调用语…

Java项目对接redis,客户端是选Redisson、Lettuce还是Jedis?

JAVA项目对接redis&#xff0c;客户端是选Redisson、Lettuce还是Jedis&#xff1f; 一、客户端简介1. Jedis介绍2. Lettuce介绍3. Redisson介绍 二、横向对比三、选型说明 在实际的项目开发中&#xff0c;对于一个需要对接Redis的项目来说&#xff0c;就面临着选择合适的Redis客…

【html+css(大作业)】二级菜单导航栏

目录 实现效果 代码及其解释 html部分 CSS部分 hello&#xff0c;hello好久不见&#xff01; 今天我们来写二级导航栏&#xff0c;所谓二级导航栏&#xff0c;简单来说就是鼠标放上去就有菜单拉出&#xff1a; 实现效果 代码及其解释 html部分 <!DOCTYPE html> &l…

【网络原理】HTTP|认识请求“报头“|Host|Content-Length|Content-Type|UA|Referer|Cookie

目录 认识请求"报头"(header) Host Content-Length Content-Type User-Agent(简称UA) Referer &#x1f4a1;Cookie&#xff08;最重要的一个header&#xff0c;开发&面试高频问题&#xff09; 1.Cookie是啥&#xff1f; 2.Cookie怎么存的&#xff1f; …