Alright, I am quite the beginner at C, so I might not understand everything yet, so here I go:
We need to program a stm32f0 using c without any hal libraries. For an exercise, we needed to change the example usart code from sequential to interrupt driven (for the receiving part). Now that wasn't too difficult. Another assignment was to add a fifo buffer. (actual assignment stated we needed to use a fixed buffer size of about 100 characters). I wanted to implement a dynamic buffer size. A bit of googling gave me the answer to use a pointer and use malloc to allocate memory for the required characters. So I did this:
volatile char *fifo_char_buffer;
void USART_init(int bufsize){
fifo_char_buffer = (char *)malloc(bufsize * sizeof *fifo_char_buffer);
//setting bunch of registers for usart1
}
//functions for writing/reading fifobuffer
It's all working fine and dandy on the microcontroller. But I started reading some more about malloc, and I found out that it's more or less mandatory to do a free after the malloc.
Now my question is: since this buffer in its current state will never be cleared all at once, and will be used continuously until you literally shut down the device, do I really need to free that pointer? To my, possibly limited, knowledge, every time you restart the MCU it will just do all the allocation again, right?