YosysHQ / picorv32

PicoRV32 - A Size-Optimized RISC-V CPU
ISC License
3.15k stars 759 forks source link

picovr32 picosoc hx8demo, static and global vars have weird values! #143

Open splinedrive opened 4 years ago

splinedrive commented 4 years ago

Hello @cliffordwolf ,

I would like to express my sincere thanks to (yosys, picovr, nextpnr, ...) :) It's a lot of fun.

One question! I have modified firmware.c and i inserted static vars but they doesn't work. Any idea?

br,

HD

splinedrive commented 4 years ago

Hi @stv0g ,

I was completely surprised when I found the root causes of the problem.

commit f3b1246c862c37108f2a472816e2ed2e5b37e269 Author: Steffen Vogel post@steffenvogel.de Date: Mon Feb 11 23:14:56 2019 +0100

picosoc: added memtest

cmd_memtest() will be called once at the start of the firmware.c But it destroys the _sdata section of e.g. global vars, static vars in function etc. I was debugging with leds your start.s :) and learned a little bit risc v assembler :). It was a good learning process to understand hx8kdemo_sections.lds and start.s how it copies data from _sidata (flash memory, 0x0100000) to _sdata (ram starts at 0x000000) to initialize data. But I do not understand why cmd_memtest() is implemented to destroy data, bss and heap section. I modified the cmd_test only to have something. It will allocate test memory on stack, you can define the size with SIZE_OF_TESTMEM.

@@ -37,10 +37,14 @@ extern uint32_t sram;

define reg_uart_data ((volatile uint32_t)0x02000008)

define reg_leds ((volatile uint32_t)0x03000000)

+#define SIZE_OF_TESTMEM 50

@@ -295,8 +329,8 @@ void cmd_memtest() int stride = 256; uint32_t state;

@@ -304,13 +338,13 @@ void cmd_memtest() for (int i = 1; i <= cyc_count; i++) { state = i;

br,

Hirosh.