0

On my application I have a Cortex M0 running inside the nRF51422 IC from Nordic Semiconductor.

When trying to use the Basic Compression Library, I got LZ and Rice working, but Huffman_Compress gives me a Hardware Fault. I suspect that the processor is accessing a non-aligned memory address, but how to be sure?

Can you take a quick look on the code to see if you can find the error? Here is the code from the developer website. On this code, I tried printing stuff before the processor hanged using RTT, and it finished the _Huffman_Hist( in, sym, insize ); but didn't even enter the _Huffman_MakeTree( sym, &stream ); function.

Thanks in advance! =)

  • Putting the `Huffman_Compress()` on the very beginning of `int main()` I can print more stuff: I enter the `_MakeTree` routine and the `while( nodes_left > 1 )` runs until `nodes_left == 4` for some reason. – Victor Nascimento Jun 21 '15 at 16:41
  • In a word, no. It's simply not possible to look at 500 lines of library code and know whether all _your_ invocations of those functions were correct, with the heap and stack set up correctly, passing valid addresses as buffers, etc. We also don't know what your particular combination of toolchain and options has turned that C code into - there's a whole class of subtle bugs there too. I'd suggest looking at the exception context on the stack from within the hard fault handler - knowing which instruction faulted, and what it was trying to do at the time, goes a long way towards pinning it down. – Notlikethat Jun 21 '15 at 16:46

1 Answers1

0

You might see a stack overflow here. Huffman_Compress() needs a bit more than 1 KB, and _Huffman_MakeTree() more than 2 KB addidtional stack space, so you get ~3 KB total at this point.

The default linker scripts only allocates 2 KB for the stack, and most of this space is needed for soft device radio operations.

Turbo J
  • 7,563
  • 1
  • 23
  • 43