How to convert a (u32 *) to (u8 *)???

Ok, this question is rather simple.

My STM32 SDIO+SDCard example’s functions give their result in a 32bit pointer, like: u32 *readbuff.

Now, I want to implement a filesystem library like dosfs or efsl. They all require to have a read/write function wich use a 8 bit pointer, like: u8 *buffer.

Now, is there an easy way to pass/convert one to another, without have to transfer the u32* buffer to another u8*buffer 8bits at a time?

I was looking at something like “u8 *buffer8 = (u8 *) buffer32” …

Is it doable?

Thanks!

If you aren’t using anything that is outside a U8 range, then you can just cast it to a U8. Just be careful with sequential read, it may skip 32 bits at a time, so you might have to create a new U8 that points to the U32 and read 4 bytes out of it then call the library read again.

Thanks shifted!

Now, this actually works:

u32 Buffer32[2] = {0x33323130, 0x37363534};

u32 *PtrBuffer32 = Buffer32;

u8 *PtrBuffer8;

PtrBuffer8 = (u8*) PtrBuffer32;

printf(“%d\n”, *(PtrBuffer8+0));

printf(“%d\n”, *(PtrBuffer8+1));

printf(“%d\n”, *(PtrBuffer8+2));

printf(“%d\n”, *(PtrBuffer8+3));

printf(“%d\n”, *(PtrBuffer8+4));

printf(“%d\n”, *(PtrBuffer8+5));

//////////

And as you can see, I’m not recreating a whole new buffer, just changing the pointer :stuck_out_tongue:

-Jaylimo84