svd2ada generates wrong default value for array fields
Open
Nobody has claimed this yet.
- Dominant language
- Ada
- Stars
- 71
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
Using the following minimal SVD example, svd2ada generates a wrong initialization value.
Relevant section in SVD:
<register>
<resetValue>0x00FFFFFF</resetValue>
...
</register>
Output:
type MY_REG_Register is record
PAD : MY_REG_PAD_Field := (As_Array => False, Val => 16#F#);
...
end record
Expected:
type MY_REG_Register is record
PAD : MY_REG_PAD_Field := (As_Array => False, Val => 16#FF_FFFF#);
...
end record
or
type MY_REG_Register is record
PAD : MY_REG_PAD_Field := (As_Array => True, Arr => (others => 16#F#));
...
end record
Command: svd2ada -o svd -p Test --base-types-package=HAL --gen-uint-always --no-uint-subtypes --boolean device.svd
Full input SVD:
<?xml version="1.0" encoding="utf-8"?>
<device schemaVersion="1.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd">
<name>MY_DEVICE</name>
<version>1.0</version>
<description>Minimal SVD example</description>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
<size>32</size>
<access>read-write</access>
<resetValue>0x00000000</resetValue>
<resetMask>0xFFFFFFFF</resetMask>
<peripherals>
<peripheral>
<name>MY_PERIPHERAL</name>
<baseAddress>0x40000000</baseAddress>
<addressBlock>
<offset>0x0</offset>
<size>0x400</size>
<usage>registers</usage>
</addressBlock>
<registers>
<register>
<name>MY_REG</name>
<addressOffset>0x0</addressOffset>
<size>32</size>
<access>read-write</access>
<resetValue>0x00FFFFFF</resetValue>
<fields>
<field>
<name>PAD13</name>
<bitOffset>20</bitOffset>
<bitWidth>4</bitWidth>
<access>read-write</access>
</field>
<field>
<name>PAD12</name>
<bitOffset>16</bitOffset>
<bitWidth>4</bitWidth>
<access>read-write</access>
</field>
<field>
<name>PAD11</name>
<bitOffset>12</bitOffset>
<bitWidth>4</bitWidth>
<access>read-write</access>
</field>
<field>
<name>PAD10</name>
<bitOffset>8</bitOffset>
<bitWidth>4</bitWidth>
<access>read-write</access>
</field>
<field>
<name>PAD9</name>
<bitOffset>4</bitOffset>
<bitWidth>4</bitWidth>
<access>read-write</access>
</field>
<field>
<name>PAD8</name>
<bitOffset>0</bitOffset>
<bitWidth>4</bitWidth>
<access>read-write</access>
</field>
</fields>
</register>
</registers>
</peripheral>
</peripherals>
</device>
Full output ADS:
pragma Style_Checks (Off);
-- This spec has been automatically generated from device.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package Test.MY_PERIPHERAL is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- MY_REG_PAD array
type MY_REG_PAD_Field_Array is array (8 .. 13) of HAL.UInt4
with Component_Size => 4, Size => 24;
-- Type definition for MY_REG_PAD
type MY_REG_PAD_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- PAD as a value
Val : HAL.UInt24;
when True =>
-- PAD as an array
Arr : MY_REG_PAD_Field_Array;
end case;
end record
with Unchecked_Union, Size => 24;
for MY_REG_PAD_Field use record
Val at 0 range 0 .. 23;
Arr at 0 range 0 .. 23;
end record;
type MY_REG_Register is record
PAD : MY_REG_PAD_Field := (As_Array => False, Val => 16#F#);
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for MY_REG_Register use record
PAD at 0 range 0 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
type MY_PERIPHERAL_Peripheral is record
MY_REG : aliased MY_REG_Register;
end record
with Volatile;
for MY_PERIPHERAL_Peripheral use record
MY_REG at 0 range 0 .. 31;
end record;
MY_PERIPHERAL_Periph : aliased MY_PERIPHERAL_Peripheral
with Import, Address => MY_PERIPHERAL_Base;
end Test.MY_PERIPHERAL;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided device.svd input and run the svd2ada command from the issue to reproduce the generated Ada declaration. Compare the PAD initialization with the register resetValue and the two expected forms. Done means the generated default preserves the full reset value and the result is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- xml
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100