watch memory allocation c++ libraries SW4STM32
Posted: Mon May 18, 2020 7:50 pm
So last week I got my assembled STM32F407 pipe organ interface boards. After cutting a few traces and adding half a dozen blue wires they work.
I had been performing some of my initial testing with an STM429 Nucleo. I went with the F407 for the 100 pin lqfp. The old board used an 83848 PHY Which i had tested with the F407-discovery.
The code is a mix of Arduino C++ libraries and some proprietary C++ code that uses templates. The program works, but started exhibiting some strange errors. In looking at the memory addresses, the stack is crashing into the heap.
I am using SW4STM and gdb to compile and debug. I know enough C++ to be dangerous. (doubt I could create a namespace and template from scratch, but I can use them as black boxes.)
The program is failing in the New operator. The pointer that new is allocating to is in a large array of 256 objects. The last 25 or so pointers are being trashed by the stack.
I noticed that there is a menu option called profile tools with a profile memory option. This seems to require the installation of a tool called valgrind. I looked that up, but most of the online info seems dated patch to run on OSX Mavericks or irrelevant (I am cross compiling and do not want to profile my system memory.)
There really does not seem to be anyway in the GDB to see exactly where the memory is being allocated. I tried increasing the the values in the linker script. But these only seem to affect the compile time allocations. C++ likes to hide things, so it is not always easy to set a watch and see what a value is.
I also got out the reference manual and looked up the section on CCM. It does not look like anything is being linked into this 64K. Perhaps I should put some of the static objects into it. I think there is only 2K or so allocated at compile time in the .BSS section But things like the Ethernet buffers use DMA and If I read things one way DMA can not access CCM. Not exactly sure how one might go about putting some of the dynamic allocated class data (linked lists) into the the CCM. There seems to be 3 different ways to store things in CCM according to the comments in the linker script. I think there is also an attribute for placing a value into a given memory space. Anyone have practical experience with using CCM?
Eventually I need to port the Ethernet boot loader from the AVR32UC3. This deals with protected memory as the code is proprietary and is also technically IoT as the router can be wireless. So parts of the Ethernet packets are encrypted. In the AVR32 one can read the fuses and turn on a LED if the protection is enabled. There is a lot to read and absorb in the app notes. Anyone have experience with Ethernet bootloaders? I think most of the work here is with DFU. I did not connect anything to the usb pins (I need as many GPIO pins as possible well about 8 plus power and ground on a 26 pin ribbon cable.)
I also got mixed up and connected USART6 instead of USART1 so not I do not think the serial bootstrap would work as is. I have been using the ST-Link through the SWD to do the debugging.
Probably the best solution in the long run is to use a 100 pin STM429 with the additional memory. In the meantime, I am looking for ways to get the F407 working. There are 256 possible board addresses, so I can not make the allocation smaller as this works as a lookup table into the array of classes (which are templates to linked lists) It is these objects I need to watch in the debugger.
I had been performing some of my initial testing with an STM429 Nucleo. I went with the F407 for the 100 pin lqfp. The old board used an 83848 PHY Which i had tested with the F407-discovery.
The code is a mix of Arduino C++ libraries and some proprietary C++ code that uses templates. The program works, but started exhibiting some strange errors. In looking at the memory addresses, the stack is crashing into the heap.
I am using SW4STM and gdb to compile and debug. I know enough C++ to be dangerous. (doubt I could create a namespace and template from scratch, but I can use them as black boxes.)
The program is failing in the New operator. The pointer that new is allocating to is in a large array of 256 objects. The last 25 or so pointers are being trashed by the stack.
I noticed that there is a menu option called profile tools with a profile memory option. This seems to require the installation of a tool called valgrind. I looked that up, but most of the online info seems dated patch to run on OSX Mavericks or irrelevant (I am cross compiling and do not want to profile my system memory.)
There really does not seem to be anyway in the GDB to see exactly where the memory is being allocated. I tried increasing the the values in the linker script. But these only seem to affect the compile time allocations. C++ likes to hide things, so it is not always easy to set a watch and see what a value is.
I also got out the reference manual and looked up the section on CCM. It does not look like anything is being linked into this 64K. Perhaps I should put some of the static objects into it. I think there is only 2K or so allocated at compile time in the .BSS section But things like the Ethernet buffers use DMA and If I read things one way DMA can not access CCM. Not exactly sure how one might go about putting some of the dynamic allocated class data (linked lists) into the the CCM. There seems to be 3 different ways to store things in CCM according to the comments in the linker script. I think there is also an attribute for placing a value into a given memory space. Anyone have practical experience with using CCM?
Eventually I need to port the Ethernet boot loader from the AVR32UC3. This deals with protected memory as the code is proprietary and is also technically IoT as the router can be wireless. So parts of the Ethernet packets are encrypted. In the AVR32 one can read the fuses and turn on a LED if the protection is enabled. There is a lot to read and absorb in the app notes. Anyone have experience with Ethernet bootloaders? I think most of the work here is with DFU. I did not connect anything to the usb pins (I need as many GPIO pins as possible well about 8 plus power and ground on a 26 pin ribbon cable.)
I also got mixed up and connected USART6 instead of USART1 so not I do not think the serial bootstrap would work as is. I have been using the ST-Link through the SWD to do the debugging.
Probably the best solution in the long run is to use a 100 pin STM429 with the additional memory. In the meantime, I am looking for ways to get the F407 working. There are 256 possible board addresses, so I can not make the allocation smaller as this works as a lookup table into the array of classes (which are templates to linked lists) It is these objects I need to watch in the debugger.