diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f7fd1..5fe2255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## [Unreleased] +- Fix peripheral inheriting size, accessType and resetValue from device + ## [v1.6.0] - 2025-08-30 - PR[#11](https://github.com/mcu-debug/peripheral-viewer/issues/11): An alternative way to load peripherals information (see [extending-peripheral-viewer.md](https://github.com/mcu-debug/peripheral-viewer/blob/main/docs/extending-peripheral-viewer.md)) diff --git a/src/svd-parser.ts b/src/svd-parser.ts index 9501229..9fa7e8b 100644 --- a/src/svd-parser.ts +++ b/src/svd-parser.ts @@ -473,12 +473,16 @@ export class SVDParser { name: p.name[0], baseAddress: parseInteger(p.baseAddress ? p.baseAddress[0] : '0'), description: this.cleanupDescription(p.description ? p.description[0] : ''), - totalLength: totalLength + totalLength: totalLength, + // initialize from device-level defaults + accessType: _defaults.accessType, + size: _defaults.size, + resetValue: _defaults.resetValue }; if (p.access) { options.accessType = accessTypeFromString(p.access[0]); } - if (p.size) { options.size = parseInteger(p.size[0]); } - if (p.resetValue) { options.resetValue = parseInteger(p.resetValue[0]); } + if (p.size) { options.size = parseInteger(p.size[0]) ?? options.size; } + if (p.resetValue) { options.resetValue = parseInteger(p.resetValue[0]) ?? options.resetValue; } if (p.groupName) { options.groupName = p.groupName[0]; } const peripheral = new PeripheralNode(this.gapThreshold, options); diff --git a/src/views/nodes/peripheralnode.ts b/src/views/nodes/peripheralnode.ts index dbf9701..b638386 100644 --- a/src/views/nodes/peripheralnode.ts +++ b/src/views/nodes/peripheralnode.ts @@ -49,7 +49,7 @@ export class PeripheralNode extends PeripheralBaseNode { public readonly description: string; public readonly groupName: string; public readonly totalLength: number; - public readonly accessType = AccessType.ReadOnly; + public readonly accessType: AccessType; public readonly size: number; public readonly resetValue: number; protected addrRanges: AddrRange[]; @@ -65,6 +65,7 @@ export class PeripheralNode extends PeripheralBaseNode { this.description = options.description; this.groupName = options.groupName || ''; this.resetValue = options.resetValue || 0; + this.accessType = options.accessType || AccessType.ReadOnly; this.size = options.size || 32; this.children = []; this.addrRanges = [];