Skip to content

DMA glitch? #17890

Aug 11, 2025 · 3 comments · 7 replies
Discussion options

You must be logged in to vote

Thanks @GitHubsSilverBullet and @peterhinch for the explanations!
I sedimented the information, and now the code works.

BUFFER_SIZE = 2**8  

placeholder = array('H', (0 for _ in range(512*2+2)))
_base = uctypes.addressof(placeholder) # get base address
_end_base = _base + len(placeholder)-1
_masked = _base & ~(511)
_offset = _masked + 512

buffer = uctypes.bytearray_at(_offset, BUFFER_SIZE*2)
for i in range(BUFFER_SIZE):
    v = (math.sin(2 * math.pi * i / BUFFER_SIZE + math.pi/2) + 1) * 0.5
    value = int(round(v * (top_value-1)))
    struct.pack_into('H', buffer, i*2, value)

_end_buffer = uctypes.addressof(buffer) + len(buffer)
assert _end_buffer < _end_base  # assert space allocation

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
7 replies
@Ludo-lab
Comment options

@peterhinch
Comment options

@GitHubsSilverBullet
Comment options

@Ludo-lab
Comment options

@GitHubsSilverBullet
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Ludo-lab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants