{"id":5817,"date":"2020-03-24T19:45:04","date_gmt":"2020-03-25T02:45:04","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=5817"},"modified":"2021-07-20T09:20:33","modified_gmt":"2021-07-20T16:20:33","slug":"editing-hardware-register-definitions","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/documentation\/hwregs\/","title":{"rendered":"Editing Hardware Register Definitions"},"content":{"rendered":"<p>Most of the device families supported by VisualGDB include definitions for the peripheral registers that allow viewing and modifying those registers conveniently via the Hardware Registers window:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/hwregs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5818\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/hwregs.png\" alt=\"\" width=\"683\" height=\"349\" \/><\/a>For legacy projects that are created by manually specifying the compiler settings, the hardware registers won&#8217;t be automatically shown. To fix this, open the VisualGDB Project Properties window and set the peripheral register definition file:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/defs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5819\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/defs.png\" alt=\"\" width=\"774\" height=\"754\" \/><\/a>You can also use the link at the bottom of the Hardware Registers window to import the definition file into VisualGDB:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/hwregs-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7436\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/hwregs-1.png\" alt=\"\" width=\"691\" height=\"291\" \/><\/a>If you are using Quick Debug without a BSP, you can specify the path to a hardware register definition file as shown below:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/qd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7438\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/03\/qd.png\" alt=\"\" width=\"965\" height=\"277\" \/><\/a><\/p>\n<p>The register definition file is an XML file with the following structure:<\/p>\n<pre class=\"\">&lt;?xml version=\"1.0\"?&gt;\r\n&lt;MCUDefinition xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:xsd=\"http:\/\/www.w3.org\/2001\/XMLSchema\"&gt;\r\n&lt;MCUName&gt;DeviceName&lt;\/MCUName&gt;\r\n&lt;RegisterSets&gt;\r\n    &lt;HardwareRegisterSet&gt;\r\n        &lt;ExpressionPrefix&gt;TIM2-&amp;gt;&lt;\/ExpressionPrefix&gt;\r\n        &lt;UserFriendlyName&gt;TIM2&lt;\/UserFriendlyName&gt;\r\n        &lt;Registers&gt;\r\n            &lt;HardwareRegister&gt;\r\n            &lt;!-- ... --&gt;\r\n            &lt;\/HardwareRegister&gt;\r\n        &lt;\/Registers&gt;\r\n    &lt;\/HardwareRegisterSet&gt;\r\n&lt;\/RegisterSets&gt;\r\n&lt;\/MCUDefinition&gt;<\/pre>\n<p>Each register set corresponds to a group of registers corresponding to the same peripheral (e.g. timer or USB). The <strong>UserFriendlyName<\/strong> element contains the name of the group as shown in the Hardware Registers window. The <strong> ExpressionPrefix<\/strong> element allows matching C\/C++ Watch expressions (e.g. TIM2-&gt;CR1 to specific hardware registers defined in a peripheral register definition file).<\/p>\n<p>Each <strong>HardwareRegister<\/strong> element corresponds to one register inside a register set. It has the following structure:<\/p>\n<pre class=\"\">&lt;HardwareRegister&gt;\r\n    &lt;Name&gt;CR1&lt;\/Name&gt;\r\n    &lt;SizeInBits&gt;32&lt;\/SizeInBits&gt;\r\n    &lt;Address&gt;0x40000000&lt;\/Address&gt;\r\n    &lt;ReadOnly&gt;false&lt;\/ReadOnly&gt;\r\n    &lt;SubRegisters&gt;\r\n        &lt;HardwareSubRegister&gt;\r\n            &lt;Name&gt;CEN&lt;\/Name&gt;\r\n            &lt;FirstBit&gt;0&lt;\/FirstBit&gt;\r\n            &lt;SizeInBits&gt;1&lt;\/SizeInBits&gt;\r\n        &lt;\/HardwareSubRegister&gt;\r\n        &lt;HardwareSubRegister&gt;\r\n            &lt;Name&gt;UDIS&lt;\/Name&gt;\r\n            &lt;FirstBit&gt;1&lt;\/FirstBit&gt;\r\n            &lt;SizeInBits&gt;1&lt;\/SizeInBits&gt;\r\n        &lt;\/HardwareSubRegister&gt;\r\n        &lt;HardwareSubRegister&gt;\r\n            &lt;Name&gt;CMS&lt;\/Name&gt;\r\n            &lt;FirstBit&gt;5&lt;\/FirstBit&gt;\r\n            &lt;SizeInBits&gt;2&lt;\/SizeInBits&gt;\r\n            &lt;KnownValues&gt;\r\n                &lt;KnownSubRegisterValue&gt;\r\n                    &lt;Name&gt;EDGE&lt;\/Name&gt;\r\n                &lt;\/KnownSubRegisterValue&gt;\r\n                &lt;KnownSubRegisterValue&gt;\r\n                    &lt;Name&gt;CENTER1&lt;\/Name&gt;\r\n                &lt;\/KnownSubRegisterValue&gt;\r\n                &lt;KnownSubRegisterValue&gt;\r\n                    &lt;Name&gt;CENTER2&lt;\/Name&gt;\r\n                &lt;\/KnownSubRegisterValue&gt;\r\n                &lt;KnownSubRegisterValue&gt;\r\n                    &lt;Name&gt;CENTER3&lt;\/Name&gt;\r\n                &lt;\/KnownSubRegisterValue&gt;\r\n            &lt;\/KnownValues&gt;\r\n        &lt;\/HardwareSubRegister&gt;\r\n    &lt;\/SubRegisters&gt;\r\n&lt;\/HardwareRegister&gt;<\/pre>\n<p>Each <strong>HardwareSubRegister<\/strong> element corresponds to a meaningful group of bits inside the hardware register: VisualGDB will use the following rules when showing subregisters:<\/p>\n<ul>\n<li>Subregisters with size of 1 will be displayed as checkboxes<\/li>\n<li>Subregisters with size of k having exactly 2<sup>k<\/sup> KnownSubRegisterValue elements specified will be shown as combo boxes.<\/li>\n<li>All other subregisters will be shown as editable text fields containing raw values<\/li>\n<\/ul>\n<p>The <strong>SubRegisters<\/strong> and <strong>KnownValues <\/strong>elements are optional; a simple register definition file may skip them.<\/p>\n<p>Generated register definition files for real-world devices can be quite large. To save space VisualGDB allows storing them in a compressed format. Simply compress it with gzip and append .gz to the extension (e.g. device.xml.gz) and VisualGDB will automatically recognize and decompress it on-the-fly.<\/p>\n<h2>SVD Files<\/h2>\n<p>Many device vendors provide descriptions for the peripheral registers of their devices in the <a href=\"https:\/\/www.keil.com\/pack\/doc\/CMSIS\/SVD\/html\/svd_Format_pg.html\">SVD format<\/a>. You can normally locate these definitions by searching for <strong>*.svd<\/strong> files (or <strong>*.xml<\/strong> files in the <strong>svd<\/strong> subdirectory) in the SDKs. VisualGDB supports automatically importing the SVD files: once you select a <strong>.svd<\/strong> file instead of an file in the VisualGDB&#8217;s XML format, it will be automatically converted and imported.<\/p>\n<h2>Examples<\/h2>\n<p>To see examples of working register definition files, go to the <strong>%LOCALAPPDATA%\\VisualGDB\\EmbeddedBSPs<\/strong> directory and search for <strong>.xml.gz<\/strong> files. Unpack one of those files and open it in a text editor to get a real-world example of a device definition file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of the device families supported by VisualGDB include definitions for the peripheral registers that allow viewing and modifying those<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[197],"tags":[],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5817"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=5817"}],"version-history":[{"count":5,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5817\/revisions"}],"predecessor-version":[{"id":7439,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5817\/revisions\/7439"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=5817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=5817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=5817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}