Hello,
I've been extending the nRF blink example (1. thanks a lot to all those who put up the examples together, 2. I'll publish blog posts and code repos when I've got some more interesting stuff) and I'm now facing some weird issue with the memalign implementation.
My simple swift code is
print("a")
var iPtr: UnsafeMutablePointer<UInt16> = UnsafeMutablePointer<UInt16>.allocate(capacity: 1)
print("b")
and this prints a to the console, then is stuck.
I did add a couple of print statements to the memalign implementation from the repo:
int
posix_memalign(void **memptr, size_t alignment, size_t size)
{
printk(">>posix_memalign\n");
void *p = aligned_alloc(alignment, size);
printk("Returned from aligned_alloc\n");
if (p) {
*memptr = p;
return 0;
}
return errno;
}
and that's what I see in the console
a
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
>>posix_memalign
and the code halts there.
This would suggest some kind of recursive call from aligned_alloc to posix_memalloc, but looking at the Zephyr source code, I could not see how that would happen.
If I use malloc() instead of aligned_alloc(), code works properly and I can use the UnsafeMutablePointer normally.
However, I suppose not respecting the alignment could lead to some issues down the road.
I've seen that Zephyr should have a k_aligned_alloc but this results in an undefined reference when linking (that I have not yet taken the time to investigate further).
Has anyone faced anything similar ? Does anybody have an explanation or ideas on what/how I could further debug the issue ?
This is much lower level that the code I'm usually working with, so bear with me if I don't understand some of the mechanisms at play here.
Thanks,
Eric