2784 views|3 replies

652

Posts

1

Resources
The OP
 

[Sipeed LicheeRV 86 Panel Review] D1 as a single-chip computer naked programming light - LED-Blinky [Copy link]

 

A great person on the Internet has developed a baremetal programming for D1, which makes D1 a real single-chip microcomputer. The open source project is here: https://github.com/bigmagic123/d1-nezha-baremeta

Learn from this and learn how to program the registers of the various components inside D1.


There is no JTAG debugging environment yet, so you can only compile-download-run and check whether it works properly by the running effect. Download using the xfel tool: https://github.com/xboot/xfel/, just download the Windows version.

You need to remove the SD card, or press and hold the FEL button on the core board when powering on to enter the FEL download mode.

After entering FEL mode, the computer detects the USB device and installs the USB universal driver through Zadig. Then you can use xfel to check whether the connection is correct and whether it has entered FEL mode:

xfel version
AWUSBFEX ID=0x00185900(D1/F133) dflag=0x44 dlength=0x08 scratchpad=0x00045000

xfel sid
d20011005c00481448000505093f760b


The prerequisite is to make sure that the riscv64 toolchain has been installed. You can use elf or linux-gnu toolchain. (I installed it in WSL environment, which should be the same as virtual machine or Linux host)

By looking at D1-H_User Manual.pdf, we can find the GPIO document, and then compare it with the development board schematic diagram. We can find that the LED of Lichee RV 86Panel is connected to PC1 (the BT_WAKE_AP signal of the 86Panel baseboard is also connected to PC1, but in the bare metal programming environment, BT is not enabled and can be ignored. If you are not sure, you can unplug it and run the core board alone);

First, use XFEL's read and write commands to test the read and write GPIO registers to see if the LED can flash:

First, read the PC configuration register PC_CFG0 (0x02000060), where PC1 should be changed from the default Disable mode at power-on to the OUTPUT mode.


// led-blinky: PC1 to output
xfel hexdump 0x02000060 100
xfel write32 0x02000060 0xFFFFFF1F
// Toggle PC1
xfel write32 0x02000070 0x00000002
xfel write32 0x02000070 0x00000000

Each time 0/1 is written to the position corresponding to PC1 of the PC_DAT register, the LED turns off/on accordingly. Therefore, the LED-Blinky program can be implemented by following the same steps.

led-blinky.c

void delay(int);

static int k = 23;

int main(int argc, char argv) {
	int GPIO_BASE_ADDR = 0x02000000;
	int PC_CFG0 = 0x0060;
	int PC_DAT = 0x0070;
	
	unsigned int *PC_CFG0_Addr = (unsigned int *)(GPIO_BASE_ADDR + PC_CFG0);
	unsigned int *PC_DAT_Addr  = (unsigned int *)(GPIO_BASE_ADDR + PC_DAT);
	
        unsigned int PC_CFG0_Value = *PC_CFG0_Addr;
	PC_CFG0_Value &= 0xFFFFFF0F;
	PC_CFG0_Value |= 0x00000010;
	*PC_CFG0_Addr = PC_CFG0_Value;
	

	while(1) {
		delay(1000);
		*PC_DAT_Addr ^= 0x00000002;
	}

	k++;
	
	return k;	
}

void delay(int count)
{
	
	volatile int x = count;
	while(1) {
		volatile int y = 2000;
		for(; y >0; y--)
			__asm__("nop");

		if(x > 0) x--;
		else break;
	}

	return ;
}

led-blinky.ld

OUTPUT_ARCH( "riscv" )
OUTPUT_FORMAT("elf64-littleriscv")
ENTRY( main )
SECTIONS
{
  /* text: test code section */
  . = 0x00020000;
  .text : { *(.text) }
  /* data: Initialized data segment */
  .gnu_build_id : { *(.note.gnu.build-id) }
  .data : { *(.data) }
  .rodata : { *(.rodata) }
  .sdata : { *(.sdata) }
  .debug : { *(.debug) }
  . += 0x8000;
  stack_top = .;

  /* End of uninitalized data segement */
  _end = .;
}

Makefile


PROJECT ?= led-blinky

CROSS_COMPILE ?= riscv64-unknown-linux-gnu

CFLAGS += -fPIC



.PHONY:	${PROJECT}.bin


${PROJECT}.bin:	${PROJECT}.elf
	${CROSS_COMPILE}-objcopy -O binary $< $@

${PROJECT}.elf:	${PROJECT}.o
	${CROSS_COMPILE}-ld -T ${PROJECT}.ld  -o $@ $<

${PROJECT}.o:	${PROJECT}.c
	${CROSS_COMPILE}-gcc ${CFLAGS}  -c -o $@ $<

clean:
	rm *.o *.elf *.bin

It should be noted that in the link file, 0x00020000 is specified as the starting address, which is the address of the SRAM inside the D1 chip. Later tests found that when the PIC (position-independent code) flag of gcc is used, the code can be executed correctly no matter where it is placed.

After the code, .ld and Makefile are written, make can complete the compilation, linking, and convert elf to bin file (make sure riscv64-unknown-linux-gnu-gcc is in PATH)

Then use xfel to download the generated bin file to the SRAM of the D1 chip, as shown in the figure;

At this time, the LED on the core board flashes normally.

This post is from Domestic Chip Exchange

Latest reply

This is a good way to play   Details Published on 2022-4-14 09:32
 
 

5213

Posts

239

Resources
2
 

get a new term, bare metal, check it out, it refers to programming without an operating system

The city is fun, so many embedded developments are not based on operating systems, they are all bare metal.

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
 
 

7422

Posts

2

Resources
3
 

pic should be used when loading, so it still needs a base address.

This post is from Domestic Chip Exchange
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

336

Posts

2

Resources
4
 

This is a good way to play

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Some experience summary on AD conversion design

I saw a blog post about the basic issues in AD conversion design, so I reposted it here to share with you. Understanding ...

A low-power, wireless sensor network design

The explosive development of wireless technology has spawned a variety of industrial, scientific and medical (ISM) ban ...

TI Voltage Reference (VREF) Application Design Tips and Tricks

503433503434503438 503437

A very interesting experiment about KVL and Faraday's law of electromagnetic induction

This post was last edited by Buyixin on 2020-11-8 17:49 Question : https://www.bilibili.com/video/BV1ht411U7q7 Resp ...

I seldom deal with interfaces. Now that the speed is so high, I have to deal with single-ended signals and differential signals. If you see them, please share them.

As for this thing, my personal understanding is that it is a bit beyond the line and is more inclined towards signal in ...

i.MX6ULL Embedded Linux Development 1-Preliminary Study on Uboot Transplantation

This post was last edited by DDZZ669 on 2021-7-27 23:05 This series of tutorials uses the ARM development board of the ...

[HPM-DIY] HPM6750 USB open source protocol stack performance comparison - cherryusb or tinyusb?

Since the current hpm SDK uses tinyusb, the performance speed is still extremely unmatched with the high-speed USB of t ...

[HPM-DIY]littlevgl benchmark score? Xianji hpm6750 or STM32h747 winer?

This post was last edited by RCSN on 2022-8-6 15:55 There is no need for comparative data, but out of curiosity, I wil ...

How to use LOTO oscilloscope to draw frequency response characteristic curve?

In work and projects, we often encounter a functional circuit module to condition the signal, or filter, or amplify, or ...

[Digi-Key Follow me Issue 4] Summary and expansion tasks: Web Server

This post was last edited by alanlan86 on 2024-2-25 18:09 # Comprehensive summary - Post link summary: (https://bbs.eewo ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list