How to printf or println UInt in chisel?












2















I am trying to execute the following code:



val num1 = 10.U
printf(p"num1 = $num1")


I am getting the following error when running this code in an example class.



[error] (run-main-8) chisel3.internal.ChiselException: Error: No implicit clock and reset.
[error] chisel3.internal.ChiselException: Error: No implicit clock and reset.


I am running the code using test:runMain <package.class>



I tried the other options in https://github.com/freechipsproject/chisel3/wiki/Printing-in-Chisel
using the printf and none of them worked.



Also tried the C style printing printf("num1 = %d",num1) and this results in the same error.










share|improve this question

























  • Please give more code context. Where did you wrote these two lines ? In a chisel module ?

    – FabienM
    Nov 26 '18 at 14:38











  • No this is not written in a module. Its written in the test directory object TestPrinting extends App { ... } Maybe this is the problem.

    – caylus
    Nov 26 '18 at 22:07













  • So seems liken the printf(p"num1 - $num1") will generate and fwrite() verilog statement, all I am trying to do here is print thing in the test bench side.

    – caylus
    Nov 28 '18 at 22:49
















2















I am trying to execute the following code:



val num1 = 10.U
printf(p"num1 = $num1")


I am getting the following error when running this code in an example class.



[error] (run-main-8) chisel3.internal.ChiselException: Error: No implicit clock and reset.
[error] chisel3.internal.ChiselException: Error: No implicit clock and reset.


I am running the code using test:runMain <package.class>



I tried the other options in https://github.com/freechipsproject/chisel3/wiki/Printing-in-Chisel
using the printf and none of them worked.



Also tried the C style printing printf("num1 = %d",num1) and this results in the same error.










share|improve this question

























  • Please give more code context. Where did you wrote these two lines ? In a chisel module ?

    – FabienM
    Nov 26 '18 at 14:38











  • No this is not written in a module. Its written in the test directory object TestPrinting extends App { ... } Maybe this is the problem.

    – caylus
    Nov 26 '18 at 22:07













  • So seems liken the printf(p"num1 - $num1") will generate and fwrite() verilog statement, all I am trying to do here is print thing in the test bench side.

    – caylus
    Nov 28 '18 at 22:49














2












2








2








I am trying to execute the following code:



val num1 = 10.U
printf(p"num1 = $num1")


I am getting the following error when running this code in an example class.



[error] (run-main-8) chisel3.internal.ChiselException: Error: No implicit clock and reset.
[error] chisel3.internal.ChiselException: Error: No implicit clock and reset.


I am running the code using test:runMain <package.class>



I tried the other options in https://github.com/freechipsproject/chisel3/wiki/Printing-in-Chisel
using the printf and none of them worked.



Also tried the C style printing printf("num1 = %d",num1) and this results in the same error.










share|improve this question
















I am trying to execute the following code:



val num1 = 10.U
printf(p"num1 = $num1")


I am getting the following error when running this code in an example class.



[error] (run-main-8) chisel3.internal.ChiselException: Error: No implicit clock and reset.
[error] chisel3.internal.ChiselException: Error: No implicit clock and reset.


I am running the code using test:runMain <package.class>



I tried the other options in https://github.com/freechipsproject/chisel3/wiki/Printing-in-Chisel
using the printf and none of them worked.



Also tried the C style printing printf("num1 = %d",num1) and this results in the same error.







chisel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 13:35







caylus

















asked Nov 26 '18 at 13:26









cayluscaylus

12816




12816













  • Please give more code context. Where did you wrote these two lines ? In a chisel module ?

    – FabienM
    Nov 26 '18 at 14:38











  • No this is not written in a module. Its written in the test directory object TestPrinting extends App { ... } Maybe this is the problem.

    – caylus
    Nov 26 '18 at 22:07













  • So seems liken the printf(p"num1 - $num1") will generate and fwrite() verilog statement, all I am trying to do here is print thing in the test bench side.

    – caylus
    Nov 28 '18 at 22:49



















  • Please give more code context. Where did you wrote these two lines ? In a chisel module ?

    – FabienM
    Nov 26 '18 at 14:38











  • No this is not written in a module. Its written in the test directory object TestPrinting extends App { ... } Maybe this is the problem.

    – caylus
    Nov 26 '18 at 22:07













  • So seems liken the printf(p"num1 - $num1") will generate and fwrite() verilog statement, all I am trying to do here is print thing in the test bench side.

    – caylus
    Nov 28 '18 at 22:49

















Please give more code context. Where did you wrote these two lines ? In a chisel module ?

– FabienM
Nov 26 '18 at 14:38





Please give more code context. Where did you wrote these two lines ? In a chisel module ?

– FabienM
Nov 26 '18 at 14:38













No this is not written in a module. Its written in the test directory object TestPrinting extends App { ... } Maybe this is the problem.

– caylus
Nov 26 '18 at 22:07







No this is not written in a module. Its written in the test directory object TestPrinting extends App { ... } Maybe this is the problem.

– caylus
Nov 26 '18 at 22:07















So seems liken the printf(p"num1 - $num1") will generate and fwrite() verilog statement, all I am trying to do here is print thing in the test bench side.

– caylus
Nov 28 '18 at 22:49





So seems liken the printf(p"num1 - $num1") will generate and fwrite() verilog statement, all I am trying to do here is print thing in the test bench side.

– caylus
Nov 28 '18 at 22:49












2 Answers
2






active

oldest

votes


















1














The following ought to work. The withClockAndReset provides the
clock needed to trigger the printf. Its a little picky here, because withClock or withClock and a nested withReset will not work.



class Hello extends RawModule {
val io = IO(new Bundle {
val out = Output(UInt(8.W))
val myClock = Input(Clock())
val myReset = Input(Bool())
})

withClockAndReset(io.myClock, io.myReset) {
printf("out is %dn", io.out)
}
io.out := 42.U
}





share|improve this answer

































    0














    There is a workaround. Printing of UInt type signals from the Chisel PeekPokeTester can be done with the help of the peek() function wrapped in a println().



    println(peek(module_name.io.signal_name).toString(16))



    Still have not found a way to directly print the actual signal module_name.io.signal_name the UInt type does not even have toString function so I am not sure if this can even be done.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482147%2fhow-to-printf-or-println-uint-in-chisel%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      The following ought to work. The withClockAndReset provides the
      clock needed to trigger the printf. Its a little picky here, because withClock or withClock and a nested withReset will not work.



      class Hello extends RawModule {
      val io = IO(new Bundle {
      val out = Output(UInt(8.W))
      val myClock = Input(Clock())
      val myReset = Input(Bool())
      })

      withClockAndReset(io.myClock, io.myReset) {
      printf("out is %dn", io.out)
      }
      io.out := 42.U
      }





      share|improve this answer






























        1














        The following ought to work. The withClockAndReset provides the
        clock needed to trigger the printf. Its a little picky here, because withClock or withClock and a nested withReset will not work.



        class Hello extends RawModule {
        val io = IO(new Bundle {
        val out = Output(UInt(8.W))
        val myClock = Input(Clock())
        val myReset = Input(Bool())
        })

        withClockAndReset(io.myClock, io.myReset) {
        printf("out is %dn", io.out)
        }
        io.out := 42.U
        }





        share|improve this answer




























          1












          1








          1







          The following ought to work. The withClockAndReset provides the
          clock needed to trigger the printf. Its a little picky here, because withClock or withClock and a nested withReset will not work.



          class Hello extends RawModule {
          val io = IO(new Bundle {
          val out = Output(UInt(8.W))
          val myClock = Input(Clock())
          val myReset = Input(Bool())
          })

          withClockAndReset(io.myClock, io.myReset) {
          printf("out is %dn", io.out)
          }
          io.out := 42.U
          }





          share|improve this answer















          The following ought to work. The withClockAndReset provides the
          clock needed to trigger the printf. Its a little picky here, because withClock or withClock and a nested withReset will not work.



          class Hello extends RawModule {
          val io = IO(new Bundle {
          val out = Output(UInt(8.W))
          val myClock = Input(Clock())
          val myReset = Input(Bool())
          })

          withClockAndReset(io.myClock, io.myReset) {
          printf("out is %dn", io.out)
          }
          io.out := 42.U
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 26 '18 at 18:33

























          answered Nov 26 '18 at 16:04









          Chick MarkleyChick Markley

          1,560810




          1,560810

























              0














              There is a workaround. Printing of UInt type signals from the Chisel PeekPokeTester can be done with the help of the peek() function wrapped in a println().



              println(peek(module_name.io.signal_name).toString(16))



              Still have not found a way to directly print the actual signal module_name.io.signal_name the UInt type does not even have toString function so I am not sure if this can even be done.






              share|improve this answer




























                0














                There is a workaround. Printing of UInt type signals from the Chisel PeekPokeTester can be done with the help of the peek() function wrapped in a println().



                println(peek(module_name.io.signal_name).toString(16))



                Still have not found a way to directly print the actual signal module_name.io.signal_name the UInt type does not even have toString function so I am not sure if this can even be done.






                share|improve this answer


























                  0












                  0








                  0







                  There is a workaround. Printing of UInt type signals from the Chisel PeekPokeTester can be done with the help of the peek() function wrapped in a println().



                  println(peek(module_name.io.signal_name).toString(16))



                  Still have not found a way to directly print the actual signal module_name.io.signal_name the UInt type does not even have toString function so I am not sure if this can even be done.






                  share|improve this answer













                  There is a workaround. Printing of UInt type signals from the Chisel PeekPokeTester can be done with the help of the peek() function wrapped in a println().



                  println(peek(module_name.io.signal_name).toString(16))



                  Still have not found a way to directly print the actual signal module_name.io.signal_name the UInt type does not even have toString function so I am not sure if this can even be done.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 8 at 19:46









                  cayluscaylus

                  12816




                  12816






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482147%2fhow-to-printf-or-println-uint-in-chisel%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Contact image not getting when fetch all contact list from iPhone by CNContact

                      count number of partitions of a set with n elements into k subsets

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks