Test the data and address buses
Find stuck data lines and stuck or shorted address lines in external RAM. A hard embedded C problem (Board bring-up, step by step), run and graded in the…
hard · Board bring-up, step by step · bring-up · memory-test · bits
Write the two classic bring-up tests for an external RAM. Run on a good board, both return 0. The address test trusts what it reads back, so it is only run after the data test passes.
test_data_bus(): at index 0, write each single-bit pattern from 0x00000001 up to 0x80000000 and read it straight back. Return the first pattern that does not read back, or 0.
test_address_bus(): uses the indexes 0 and each power of two below MEM_WORDS (1, 2, 4, ... 32), the "test offsets".
- Write
PATTERNat every test offset, thenANTIPATTERNat index 0. If any test offset no longer readsPATTERN, its address line is stuck: return that offset. - Write
PATTERNback at 0. Then for each test offsettin turn: writeANTIPATTERNatt; if index 0 no longer readsPATTERN, returnt; if any other test offsetono longer readsPATTERN, the two lines are shorted: returnt | o. Then writePATTERNback att. - Return 0.
Starter code
uint32_t test_data_bus(void) {
mem_write(0, 0xFFFFFFFFu);
if (mem_read(0) != 0xFFFFFFFFu) return 0xFFFFFFFFu;
return 0;
}
uint32_t test_address_bus(void) {
return 0;
}Example tests
A good board, then a broken data line
run("good");
data_stuck = 1u << 13;
run("D13 open");Expected output:
good: data ok, address 0
D13 open: data 0x00002000, address not testedAn address line stuck low
addr_low = 4;
run("A2 stuck low");Expected output:
A2 stuck low: data ok, address 4Learn it first
- Board bring-up, step by step · From first probe connection to clocks, console, memory tests and a power-on self-test.
More Board bring-up, step by step problems
- Check the chips on the board · Read every expected chip's ID register and report missing or wrong parts.
- Start the crystal, or fall back · Switch to an external crystal with a timeout, fall back to the internal oscillator, and set the baud rate for whichever clock you got.