Skip to content

STM32F303 DMA1 bytewise read access causes error #36

@diggit

Description

@diggit

Type: Bug Report

Description

This extension uses byte access to read (at least) DMA1 registers at 0x4002000 (and for some reasons decides to read 145B). When DMA1 has clocks disabled (RCC->AHBENR), read returns zeros. When DMA1 clocks are enabled, same read attempts fails.

It looks like main memory readout function is readMemoryChunks in

public static async readMemoryChunks(
session: vscode.DebugSession, startAddr: number, specs: AddrRange[], storeTo: number[]): Promise<Error[]>{
const errors: Error[] = [];
for (const spec of specs) {
const memoryReference = '0x' + spec.base.toString(16);
const request: DebugProtocol.ReadMemoryArguments = {
memoryReference,
count: spec.length
};
try {
const responseBody = await session.customRequest('readMemory', request);
if (responseBody && responseBody.data) {
const bytes = Buffer.from(responseBody.data, 'base64');
let dst = spec.base - startAddr;
for (const byte of bytes) {
storeTo[dst++] = byte;
}
}
} catch (e: unknown) {
const err = e ? e.toString() : 'Unknown error';
errors.push(new Error(`peripheral-viewer: readMemory failed @ ${memoryReference} for ${request.count} bytes: ${err}, session=${session.id}`));
}
}
return errors;
. It uses vscode.debugProtocol.ReadMemoryArguments which does not specify access type.

Environment

  • OS and Version: Archlinux (up to date)
  • VS Code Version: 1.95.3
  • Extension Version: v1.4.6
  • Target Device: STM32F303RE + J-link compact base (up to date FW, SW 8.12)
  • Other extensions you installed (and if the issue persists after disabling them): cortex-debug and many more, but this is isolated to peripheral viewer.
  • SVD file STM32F303.svd.txt (hand modified), SVDconv does not report errors in strict mode.

To Reproduce

Steps to reproduce the behavior:

  1. Use attached SVD
  2. Break somewhere before enabling DMA1 clocks
  3. Check DMA1 contents (zeros)
  4. Enable DMA1 clocks
  5. Attempt to read DMA1 contents fails
  6. Attempt reading 4 bytes x/4ub 0x40020000 (FAIL)
  7. Attempt reading 1 word x/1uw 0x40020000 (PASS)

Expected behavior

Readout succeeds. Extension respects memory access size (same as register - mostly 4B words).

Code sample and logs

MCU debug tracker with log level 2. Events triggered by unfolding DMA1 in peripheral tree view.

Before enabling clocks

<-- {"command":"readMemory","arguments":{"memoryReference":"0x40020000","count":145},"type":"request","seq":26}
--> {"seq":242,"type":"event","event":"output","body":{"category":"stderr","output":"34-data-read-memory-bytes \"0x40020000\" 145\n"}}
--> {"seq":243,"type":"event","event":"output","body":{"category":"stderr","output":"-> 34^done,memory=[{begin=\"0x40020000\",offset=\"0x00000000\",end=\"0x40020091\",contents=\"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"}]\n"}}
--> {"seq":244,"type":"event","event":"output","body":{"category":"stderr","output":"GDB -> App: {\"output\":\"\",\"token\":34,\"outOfBandRecord\":[],\"resultRecords\":{\"resultClass\":\"done\",\"results\":[[\"memory\",[[[\"begin\",\"0x40020000\"],[\"offset\",\"0x00000000\"],[\"end\",\"0x40020091\"],[\"contents\",\"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"]]]]]}}\n"}}
--> {"seq":245,"type":"response","request_seq":26,"command":"readMemory","success":true,"body":{"address":"0x40020000","data":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="}}

After enabling clocks

<-- {"command":"readMemory","arguments":{"memoryReference":"0x40020000","count":145},"type":"request","seq":210}
--> {"seq":1234,"type":"event","event":"output","body":{"category":"stderr","output":"234-data-read-memory-bytes \"0x40020000\" 145\n"}}
--> {"seq":1235,"type":"event","event":"output","body":{"category":"stderr","output":"-> 234^error,msg=\"Unable to read memory.\"\n"}}
--> {"seq":1236,"type":"event","event":"output","body":{"category":"stderr","output":"GDB -> App: {\"output\":\"\",\"token\":234,\"outOfBandRecord\":[],\"resultRecords\":{\"resultClass\":\"error\",\"results\":[[\"msg\",\"Unable to read memory.\"]]}}\n"}}
--> {"seq":1237,"type":"response","request_seq":210,"command":"readMemory","success":false,"body":{"address":"0x40020000","data":"","error":{"id":114,"format":"Read memory error: Unable to read memory. (from data-read-memory-bytes \"0x40020000\" 145)","showUser":true}},"message":"Read memory error: Unable to read memory. (from data-read-memory-bytes \"0x40020000\" 145)"}
--> {"seq":1238,"type":"event","event":"record-event","body":{"category":"Error","action":"Reading Memory","label":"data-read-memory-bytes \"0x40020000\" 145","parameters":{}}}

Let me know if there are any other logs I could provide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions