{"id":2578,"date":"2022-07-23T00:37:02","date_gmt":"2022-07-23T04:37:02","guid":{"rendered":"https:\/\/www.yorku.ca\/professor\/drsmith\/?p=2578"},"modified":"2022-07-23T02:43:07","modified_gmt":"2022-07-23T06:43:07","slug":"installing-simavr-on-mac-os-x","status":"publish","type":"post","link":"https:\/\/www.yorku.ca\/professor\/drsmith\/2022\/07\/23\/installing-simavr-on-mac-os-x\/","title":{"rendered":"Installing SIMAVR on Mac OS X"},"content":{"rendered":"\n<p>The SIMAVR package is for simulating AVR processors like the ATMEGA328 on the Arduino UNO.  I'm looking to try to use it with VPL in courses like our computer architecture class, EECS 2021, as a way of simulating the UNO's processor in exercises involving assembler and C programming.<\/p>\n\n\n\n<p>On a Mac, we use HomeBrew.  The instructions for downloading SIM<a href=\"https:\/\/kona.moe\/installation-of-avr-toolchain-gtkwave-and-gnu-debugger-gdb-on-m1-macbooks\/\">AVR as well as GCC and GDB are here: https:\/\/kona.moe\/installation-of-avr-toolchain-gtkwave-and-gnu-debugger-gdb-on-m1-macbooks\/<\/a><\/p>\n\n\n\n<p>The \"home-brew\" AVR package homepage is here: <a href=\"https:\/\/github.com\/osx-cross\/homebrew-avr\">https:\/\/github.com\/osx-cross\/homebrew-avr <\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Here's a walkthrough with an example project: <a href=\"https:\/\/web.archive.org\/web\/20200814070955\/https:\/\/aykevl.nl\/2020\/06\/simavr-debug \">https:\/\/web.archive.org\/web\/20200814070955\/https:\/\/aykevl.nl\/2020\/06\/simavr-debug <\/a>(<a href=\"https:\/\/aykevl.nl\/2020\/06\/simavr-debug\">original<\/a>)<\/p>\n\n\n\n<p>Here's an example of using SIMAVR with breakpoints within GDB: <a href=\"https:\/\/blog.oddbit.com\/post\/2019-01-22-debugging-attiny-code-pt-1\/\">https:\/\/blog.oddbit.com\/post\/2019-01-22-debugging-attiny-code-pt-1\/<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>When installing GDB it's important to note this :<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>gdb requires special privileges to access Mach ports.<\/p>\n\n\n\n<p>You will need to codesign the binary. For instructions, see:<\/p>\n\n\n\n<p><a href=\"https:\/\/sourceware.org\/gdb\/wiki\/BuildingOnDarwin\">https:\/\/sourceware.org\/gdb\/wiki\/BuildingOnDarwin<\/a><\/p>\n\n\n\n<p>On 10.12 (Sierra) or later with SIP, you need to run this:<\/p>\n\n\n\n<p>\u00a0 echo \"set startup-with-shell off\" >> ~\/.gdbinit<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Firing up the simulator: <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.27.52-PM-1024x648.png\" alt=\"terminal view with simavr running on the blink.elf file.\" class=\"wp-image-2579\" width=\"512\" height=\"324\" srcset=\"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.27.52-PM-1024x648.png 1024w, https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.27.52-PM-300x190.png 300w, https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.27.52-PM.png 1170w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><figcaption>terminal view with simavr running on the blink.elf file.<\/figcaption><\/figure><\/div>\n\n\n\n<p>Then firing up the debugger interface:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.29.58-PM-1024x661.png\" alt=\"The debugger interfaced with the simulator on port 1234 (in the other terminal window)\" class=\"wp-image-2580\" width=\"512\" height=\"331\" srcset=\"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.29.58-PM-1024x661.png 1024w, https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.29.58-PM-300x194.png 300w, https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.29.58-PM.png 1162w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><figcaption>The debugger about to interface with the simulator on port 1234 (in the other terminal window)<\/figcaption><\/figure><\/div>\n\n\n\n<p>Now connect with the simulator<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.32.59-PM.png\" alt=\"debugger connected with the simulator\" class=\"wp-image-2582\" width=\"449\" height=\"130\" srcset=\"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.32.59-PM.png 898w, https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-9.32.59-PM-300x87.png 300w\" sizes=\"auto, (max-width: 449px) 100vw, 449px\" \/><figcaption>debugger connected to the simulator<\/figcaption><\/figure><\/div>\n\n\n\n<p>Now, the next stage will be to see if we can integrate unit testing with this.  (e.g <a href=\"https:\/\/maddevs.io\/blog\/avr-mcu-testing\/\">https:\/\/maddevs.io\/blog\/avr-mcu-testing\/<\/a>)<\/p>\n\n\n\n<p>More info on GDB scripting: https:\/\/developers.redhat.com\/blog\/2021\/04\/30\/the-gdb-developers-gnu-debugger-tutorial-part-1-getting-started-with-the-debugger#starting_gdb <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>and to output only print statements to a file: And if you want the output to go\u00a0<em>only<\/em>\u00a0to the log file, use\u00a0<code>set logging redirect on<\/code> (https:\/\/stackoverflow.com\/questions\/5941158\/gdb-print-to-file-instead-of-stdout)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>here, we capture the contents of an AVR register in a file after a certain number of steps following a breakpoint:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"652\" src=\"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-11.41.34-PM.png\" alt=\"\npython print('Hello from python!')\nset pagination off\nset history save on\nset history expansion on\ntarget remote :1234\nb main\nc\nn\nn\nset logging file my_gdb_output2.txt\nset logging overwrite on\nset logging on\nprint DDRB\nset logging off\nq\ny\" class=\"wp-image-2587\" srcset=\"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-11.41.34-PM.png 840w, https:\/\/www.yorku.ca\/professor\/drsmith\/wp-content\/uploads\/sites\/444\/2022\/07\/Screen-Shot-2022-07-22-at-11.41.34-PM-300x233.png 300w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><figcaption>gdbinit file to capture DDRB to a file.<\/figcaption><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The SIMAVR package is for simulating AVR processors like the ATMEGA328 on the Arduino UNO. I'm looking to try to use it with VPL in courses like our computer architecture class, EECS 2021, as a way of simulating the UNO's processor in exercises involving assembler and C programming. On a Mac, we use HomeBrew. The [&hellip;]<\/p>\n","protected":false},"author":762,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","footnotes":""},"categories":[42,43,45,48,294],"tags":[452,451],"class_list":["post-2578","post","type-post","status-publish","format-standard","hentry","category-arduino","category-assembler","category-c-2","category-embedded","category-vpl","tag-air-simulator","tag-simavr"],"taxonomy_info":{"category":[{"value":42,"label":"arduino"},{"value":43,"label":"assembler"},{"value":45,"label":"c"},{"value":48,"label":"embedded"},{"value":294,"label":"VPL"}],"post_tag":[{"value":452,"label":"air simulator"},{"value":451,"label":"simavr"}]},"featured_image_src_large":false,"author_info":{"display_name":"drsmith","author_link":"https:\/\/www.yorku.ca\/professor\/drsmith\/author\/drsmith\/"},"comment_info":"","category_info":[{"term_id":42,"name":"arduino","slug":"arduino","term_group":0,"term_taxonomy_id":42,"taxonomy":"category","description":"","parent":0,"count":30,"filter":"raw","cat_ID":42,"category_count":30,"category_description":"","cat_name":"arduino","category_nicename":"arduino","category_parent":0},{"term_id":43,"name":"assembler","slug":"assembler","term_group":0,"term_taxonomy_id":43,"taxonomy":"category","description":"","parent":0,"count":30,"filter":"raw","cat_ID":43,"category_count":30,"category_description":"","cat_name":"assembler","category_nicename":"assembler","category_parent":0},{"term_id":45,"name":"c","slug":"c-2","term_group":0,"term_taxonomy_id":45,"taxonomy":"category","description":"","parent":0,"count":51,"filter":"raw","cat_ID":45,"category_count":51,"category_description":"","cat_name":"c","category_nicename":"c-2","category_parent":0},{"term_id":48,"name":"embedded","slug":"embedded","term_group":0,"term_taxonomy_id":48,"taxonomy":"category","description":"","parent":0,"count":38,"filter":"raw","cat_ID":48,"category_count":38,"category_description":"","cat_name":"embedded","category_nicename":"embedded","category_parent":0},{"term_id":294,"name":"VPL","slug":"vpl","term_group":0,"term_taxonomy_id":294,"taxonomy":"category","description":"","parent":0,"count":25,"filter":"raw","cat_ID":294,"category_count":25,"category_description":"","cat_name":"VPL","category_nicename":"vpl","category_parent":0}],"tag_info":[{"term_id":452,"name":"air simulator","slug":"air-simulator","term_group":0,"term_taxonomy_id":452,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":451,"name":"simavr","slug":"simavr","term_group":0,"term_taxonomy_id":451,"taxonomy":"post_tag","description":"","parent":0,"count":2,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/posts\/2578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/users\/762"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/comments?post=2578"}],"version-history":[{"count":6,"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/posts\/2578\/revisions"}],"predecessor-version":[{"id":2588,"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/posts\/2578\/revisions\/2588"}],"wp:attachment":[{"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/media?parent=2578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/categories?post=2578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yorku.ca\/professor\/drsmith\/wp-json\/wp\/v2\/tags?post=2578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}