Forum Discussion

MOliv45's avatar
MOliv45
Icon for New Contributor rankNew Contributor
1 month ago

Integrating Cocotb to Quartus using Native link

To integrate cocotb to Quartus Prime Native link and Questa, among a few environment variables needed, one has to set the following `vsim` option: 

`-foreign "cocotb_init $(cocotb-config --lib-name-path fli questa)"`

see here:

https://docs.cocotb.org/en/stable/custom_flows.html

This needs to be actually slightly adapted to questa, and the following option should be used instead:

`-foreign \"cocotb_init [exec cocotb-config --lib-name-path fli questa]\"`

With all this information in hand, I try to add `questa=-foreign \"cocotb_init [exec cocotb-config --lib-name-path fli questa]\"` in Assignments >> Settings >> EDA Tools Settings >> Simulation Flow Settings >> Simulation Options, and I get the following error in Quartus: 

Info(125063): set_global_assignment -name EDA_EXTRA_SIM_OPTION "questa=-foreign \\\"cocotb_init [exec cocotb-config --lib-name-path fli questa]\\\"" -section_id eda_simulation 
Error(125048): Error reading Quartus Prime Settings file /home/msilvaol/LATOME_HLS/firmware/src/latome_fw/s2p_bram/s2p_bram.qsf, line 49 

And then when I try to start the simulation, I get the following error:

Error(23031): Evaluation of Tcl script /home/sw/intel/25.3/quartus/common/tcl/internal/nativelink/qnativesim.tcl unsuccessful

The workaround I have at the moment is to do the following: 

I set Assignments >> Settings >> EDA Tools Settings >> Simulation Flow Settings >> Simulation Options to `questa=COCOTB_CFG`

Then, I start the simulation that fails because COCOTB_CFG is not a valid vsim option. 

I open the file `./simulation/questa/rtlsim/s2p_bram_run_msim_rtl_vhdl.do`, and I replace the line 42

from:
`

eval "vsim -t 1ps $pd_libs -L work -L rtl_work -voptargs=\"+acc\" COCOTB_CFG $ELAB_OPTIONS $DPI_LIBRARIES_ELAB s2p_bram_showahead"

`

to the actual option that I tried to set in Quartus Prime, as follows: 

eval "vsim -t 1ps $pd_libs -L work -L rtl_work -voptargs=\"+acc\" -foreign \"cocotb_init [exec cocotb-config --lib-name-path fli questa]\" $ELAB_OPTIONS $DPI_LIBRARIES_ELAB s2p_bram_showahead"

Then, I run the .do script again in questa and the simulation with cocotb works using Quartus Prime as the build flow. However, every time the simulation is started again from Quartus Prime, the generated scripts are overwritten, and I have to edit the automatically generated file again.  

It seems Quartus is parsing the simulation option and adding escape characters in a way that the automatically generated TCL code no longer works. 

Can you please point out a way that I can set the simulation option correctly? 

9 Replies

  • MOliv45's avatar
    MOliv45
    Icon for New Contributor rankNew Contributor

    Hi ShengN_altera​,

    Is it possible to request from the factory a solution that works without workarounds? 
    Maybe in a future release, they could fix the translation from the Quartus GUI to the QSF file so that it does not modify the string entered. And also make sure that the respective .do file generated works. 

  • ShengN_altera's avatar
    ShengN_altera
    Icon for Super Contributor rankSuper Contributor

    The Simulation Option has difficulty at handling the \ and " because it's not a Tcl interpreter—it’s just a text field that Quartus (NativeLink) concatenates into a command line. Also nested quoting/escaping in a GUI field is fragile.

    I would suggest using another .do script to set path and call the s2p_bram_run_msim_rtl_vhdl.do. For example like below:

    parent.do:                                                                                                                                                                                      set FLI_LIB {"cocotb_init [exec cocotb-config --lib-name-path fli questa]\"}                                                                   do s2p_bram_run_msim_rtl_vhdl.do $FLI_LIB

    s2p_bram_run_msim_rtl_vhdl.do:                                                                                                                                                eval "vsim -t 1ps $pd_libs -L work -L rtl_work -voptargs=\"+acc\" -foreign \$1 $ELAB_OPTIONS $DPI_LIBRARIES_ELAB s2p_bram_showahead"

    In GUI, you set like this questa=-foreign $1 then it'll become like this questa=-foreign \$1 in .qsf

    Then you run parent.do to call the auto-generated s2p_bram_run_msim_rtl_vhdl.do

          

    • MOliv45's avatar
      MOliv45
      Icon for New Contributor rankNew Contributor

      Hi ShengN_altera​ ,

      Thanks for the suggestion, I find it a bit cumbersome to add an extra file in a folder that is automatically generated and cleaned by Quartus. But based on your insights, I found an alternative. Perhaps it is not yet the best solution, but it avoids creating an extra file. 

      1) First, set an environment variable as follows:

      export FLI_LIB='\"cocotb_init [exec cocotb-config --lib-name-path fli questa]\"'

      2) Then, set the simulation option as you suggested, `questa=-foreign $1 `

      3) The first simulation attempt will fail, but then one restarts with the following argument parameter:

      do user2mon_run_msim_rtl_vhdl.do {$::env(FLI_LIB)}

      4) Then it works

      It is not ideal, because it is hard to make it work with Continuous integration.

      Based on this feedback, can you imagine a way that it could already work without restarting the simulation? 

      • ShengN_altera's avatar
        ShengN_altera
        Icon for Super Contributor rankSuper Contributor

        export as env variable is a way as well.

        If you run from nativelink, it'll definitely fail. If the do script s2p_bram_run_msim_rtl_vhdl.do had been generated, not need to run from the nativelink just straight run the do script will do unless there's changes to the path in the do script.

  • MOliv45's avatar
    MOliv45
    Icon for New Contributor rankNew Contributor

    Hi ShengN_altera​,

    Yes sure, overwriting is expected. Me editing the automatically generated file was more of a workaround, but not a final solution. 

    The question is more whether there is a way that the Quartus GUI preserves the simulation option exactly as I entered without giving the Error(125048) reported before. 

    • ShengN_altera's avatar
      ShengN_altera
      Icon for Super Contributor rankSuper Contributor

      May I know you're using Quartus Pro or Quartus Standard for nativelink?

  • ShengN_altera's avatar
    ShengN_altera
    Icon for Super Contributor rankSuper Contributor

    That is expected behaviour if using nativelink. The .do script will be overwritten.

    To prevent from overwritten, please don't use nativelink and straight away run the .do script using simulator. Or rename the .do script to prevent from overwritten.