Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbiflow-classroom: Initialization of memories using $readmemh() #281

Open
nelsobe opened this issue Mar 24, 2022 · 4 comments
Open

Symbiflow-classroom: Initialization of memories using $readmemh() #281

nelsobe opened this issue Mar 24, 2022 · 4 comments

Comments

@nelsobe
Copy link

nelsobe commented Mar 24, 2022

SYMBIFLOW-CLASSROOM-PROJECT

Using Yosys front end.

The following code does NOT initialize the memory:

	// Load the Instruction Memory
	if (TEXT_MEMORY_FILENAME == "") begin
		$display("**** Top-Level I/O System: No instruction memory defined");
		$finish;
	end
	else begin
		// Initialize memory with NOPs
		for (i = 0; i < INSTRUCTION_WORDS; i=i+1)
			inst_memory[i] = NOP_INSTRUCTION;
		// Update memory with contents of memory file
    	$readmemh(TEXT_MEMORY_FILENAME,inst_memory);
	end

Experimentation shows that the testing of the TEXT_MEMORY_FILENAME works just fine. The problem turns out to be the for loop which initializes the memory to NOP_INSTRUCTION values before the #readmemh(). Commenting out the for loop makes everything work. However this is code that works just fine with Vivado.

@rkapuscik
Copy link
Contributor

Thank you for reporting this. Can you confirm that this does not work in either frontend? If so, it would probably be a problem in Yosys itself and worth reporting in its repository.
Alternatively, do you have a complete test case we could use to look into this?

@nelsobe
Copy link
Author

nelsobe commented Mar 29, 2022

@rkapuscik

I am unsure how to get the latest surelog with the f4pga-examples tools - thus my question on #269.

However, attached is a full test case up through bitfile showing that the $readmem is ignored when the initialization loop is included. This is for the Yosys front end.

readmem.zip

@rkapuscik
Copy link
Contributor

Thanks for the test case. The error is indeed in Yosys itself - both frontends parse the loop and $readmemh call and generate the AST, but the simplify step in Yosys incorrectly removes some of the nodes. Unfortunately it's not trivial (if possible) to prevent that in a frontend.

As a workaround, could you create a complete memory file to be loaded (with the NOPs)? It should be fairly easy to script.

@nelsobe
Copy link
Author

nelsobe commented Apr 8, 2022

Thanks for the reply. Yes, we did do a workaround as you suggest. Interestingly, I never would have thought to put anything in an initial block other than a $readmem() call. But, one of the other faculty did - that is why we are having lots of people's designs be part of our testing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants