0

I am working in a space limited environment. I collect an array of unsigned 32 bit ints via DMA, but I need to work on them as single precision floats using DSP extensions in the MCU. Copying the array is not possible - it takes up almost all existing SRAM. Is there a neat way to do this?

[Note] The data values are only 12 bits so out of range problems will not exist

5
  • What OS, CPU, programming language ? Commented Sep 10, 2014 at 7:48
  • Sorry! plain vanilla C Commented Sep 10, 2014 at 7:52
  • Just for completion, no OS, STM32F303x, Cortex M4 Commented Sep 10, 2014 at 8:04
  • "Copying the array is not possible - it takes up almost all existing SRAM" what? you MCU has only 4 bytes of RAM? Commented Sep 10, 2014 at 10:16
  • I mean that the array is 16KB and the total space remaining is around 4KB Commented Sep 10, 2014 at 10:19

1 Answer 1

3

You can just do it like this:

uint32_t a[N];

float *f = (float *)a;

for (i = 0; i < N; ++i)
{
    f[i] = (float)a[i];
}

Note that this breaks strict aliasing rules so you should compile with -fno-strict-aliasing or equivalent.

Sign up to request clarification or add additional context in comments.

1 Comment

ahh he means to convert the uint32 value to float32 right? I though that he wants to convert the float value from raw binary in uint32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.