Issue with uvm_config_db set and get

Hello everyone,

I tried to write a testbench using configuration objects, but I am facing an error when I get the object in top_spi_tb_env.
I read a lot of forum but I didn’t find the solution of this error.

I activate +UVM_CONFIG_DB_TRACE and see that the “set” is working. Then when the “get” is called in top_env, it is working too. I have the right value. Here are the lines that I have:
reporter [CFGDB/SET] Configuration ‘uvm_test_top.*.my_spi_env_config’ (type spi_env_config) set by uvm_test_top = (spi_env_config)

Name Type Size Value

spi_env_config_i spi_env_config - @42988

reporter [CFGDB/GET] Configuration ‘uvm_test_top.top_tb.my_spi_env_config’ (type spi_env_config) read by uvm_test_top.top_tb = (spi_env_config)

Name Type Size Value

spi_env_config_i spi_env_config - @42988

reporter [CFGDB/GET] Configuration ‘uvm_test_top.top_tb.spi_tb.my_spi_env_config’ (type spi_env_config) read by uvm_test_top.top_tb.spi_tb = null (failed lookup)

The paths seems correct.

Can anybody help me to understand where this error comes from ?

Thank you


//Test
class b_test extends uvm_test;
   top_env top_tb;
   spi_env_config my_spi_env_config;
   
   `uvm_component_utils(b_test)
    
   function new(string name, uvm_component parent=null);
      super.new(name, parent);
   endfunction: new
    
   function void build_phase(uvm_phase phase);
      my_spi_env_config=spi_env_config::type_id::create("spi_env_config");
      uvm_config_db#(spi_env_config)::set(.cntxt(this), .inst_name("*"),.field_name("my_spi_env_config"),.value(my_spi_env_config));

     super.build_phase(phase);
   endfunction: build_phase
endclass: b_test

//Top_env
class top_env extends uvm_env;
   `uvm_component_utils(top_env)

    spi_env_config my_spi_env_config;
    top_spi_tb_env spi_tb;
       
   function new(string name="top_env", uvm_component parent);
      super.new(name, parent);
   endfunction: new
    
   function void build_phase(uvm_phase phase);
      super.build_phase(phase);

      if (!uvm_config_db #(spi_env_config)::get( this,"", "my_spi_env_config", my_spi_env_config)) begin `uvm_error(get_type_name(),$psprintf("SPI ENV not configured")) end

     uvm_config_db #(spi_env_config)::set(this, "*", "spi_env_config", my_spi_env_config);
     spi_tb = top_spi_tb_env::type_id::create("spi_tb", this);
   endfunction: build_phase

   function void connect_phase(uvm_phase phase);
      super.connect_phase(phase);
   endfunction
endclass : top_env

//Top_SPI_Env
class top_spi_tb_env extends uvm_env;
   spi_env_config my_spi_env_config;
 
   spi_port_env spi_topcell_env;
  
   `uvm_component_utils(top_spi_tb_env)
       
    function new(string name="top_spi_tb_env", uvm_component parent);
       super.new(name, parent);
    endfunction: new
    
    function void build_phase(uvm_phase phase);
       super.build_phase(phase);
       if (!uvm_config_db #(spi_env_config)::get( this,"", "my_spi_env_config", my_spi_env_config))
	 begin 
	    `uvm_fatal(get_type_name(),$psprintf("SPI not configured")) 
	 end

       
endfunction
endclass


In reply to ccelie:

Why did you set the configuration again in top_env? The line:


uvm_config_db #(spi_env_config)::set(this, "*", "spi_env_config", my_spi_env_config);

When you set the configuration in b_test with wildcard “*”, all child-components of b_test should be able to get it. Please remove the code line above in top_env and try again.

I also think the same as chris!
Please try it out and let us know.

In reply to chris_le:

In reply to ccelie:
Why did you set the configuration again in top_env? The line:


uvm_config_db #(spi_env_config)::set(this, "*", "spi_env_config", my_spi_env_config);

When you set the configuration in b_test with wildcard “*”, all child-components of b_test should be able to get it. Please remove the code line above in top_env and try again.

The second set in top_env was just a test to try to get the new object “spi_env_config” in top_spi_env, but it didn’t work.

I comment this line and I have the same error.

In reply to ccelie:

What is

spi_env_config

?

You are declring a variable of this type, but you do not assign a value before performing the set to the config_db.

If spi_env_config is a class then you are passing to the config_db ‘null’.
This might cause errors when performing the get.

In reply to chr_sue:

spi_env_config is a class described as follow :


class spi_env_config extends uvm_object;

   `uvm_object_utils(spi_env_config)

   bit topcell_env=0; 
   bit has_scbd=1; 
   bit has_digital_env=1; 
   bit active=1;
   spi_agent_config agent_config;
  
   function new(string name="spi_env_config_i");
      super.new(name);
   endfunction : new
   
endclass 

When I create the object in the test before the set, the object has the default values. I verify this with some displays.

In reply to ccelie:

But you do not show this in your code for class b_test.

In reply to chr_sue:

I use this

my_spi_env_config=spi_env_config::type_id::create("spi_env_config");

in the build_phase to create the object. Must I do this in the constructor ?

In reply to ccelie:

Sorry I did not recognize this. It is fine.
Back to your issue. We see only a part of your code. Can you figure out from which get your error message comes from?

In reply to chr_sue:

The error comes from this part :

if (!uvm_config_db #(spi_env_config)::get( this,"", "my_spi_env_config", my_spi_env_config))
	 begin 
	    `uvm_fatal(get_type_name(),$psprintf("SPI not configured")) 
	 end

in top_spi_tb_env.

When I follow the config_db trace, I see that the path is correct. For the set it is :
uvm_test_top.*.my_spi_env_config
and for the get it is :
uvm_test_top.top_tb.spi_tb.my_spi_env_config

The code is splited in three files (one for the test, one for top and one for top_spi_tb_env). I tried to use the same lines with an integer instead of the class spi_env_config and it’s working.

In reply to ccelie:

If the set()/get() calls work with an integer but not with a class variable, then the issue has to do with the class variables not being type compatible. This is due to compiling spi_env_config multiple times in different scopes.

To fix this, you need to use a package and import the package everywhere that you reference spi_env_config.

In reply to cgales:

Thank you cgales, it is working now.

The issue was not exactly coming from the package and its importation, but I have an issue during the compilation. The class spi_env_config wasn’t correctly compiled. I thought that a compilation issue like that will come before I run the simulation, but it’s not.

Thank you all for your help.