Skip to content

Commit c93a596

Browse files
committed
Use the new TbxMemPoolAllocateAuto().
1 parent fac8f32 commit c93a596

File tree

3 files changed

+17
-46
lines changed

3 files changed

+17
-46
lines changed

demos/ARMCM4_STM32F4_Olimex_STM32P405_CubeIDE/App/ffsyscall.c

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,13 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block */
105105
{
106106
void * result;
107107

108-
/* Attempt to allocate a block from the best fitting memory pool. */
109-
result = TbxMemPoolAllocate(msize);
110-
/* Was the allocation not successful? */
111-
if (result == NULL)
112-
{
113-
/* The allocation failed. This can have two reasons:
114-
* 1. A memory pool for the requested size hasn't yet been created.
115-
* 2. The memory pool for the requested size has no more free blocks.
116-
* Both situations can be solved by calling TbxMemPoolCreate(), as this
117-
* function automatically extends a memory pool, if it was created before.
118-
* Note that ther is not need to check the return value, because we will
119-
* attempts to allocate again right afterwards. We can catch the error
120-
* there in case the allocation fails.
121-
*/
122-
(void)TbxMemPoolCreate(1U, msize);
123-
124-
/* Assuming sufficient heap was available, the memory pool was extended.
125-
* Attempt to allocate the block again. Note that if it fails, the result
126-
* is already NULL to flag this error.
127-
*/
128-
result = TbxMemPoolAllocate(msize);
129-
130-
/* Assert the allocation result for debugging purposes. */
131-
TBX_ASSERT(result != NULL);
132-
}
108+
/* Attempt to allocate a block from a memory pool with the same size. If non-existant,
109+
* automatically create the memory pool. If no more free blocks are available in the
110+
* memory pool, automatically expand the memory pool by adding one more block.
111+
*/
112+
result = TbxMemPoolAllocateAuto(msize);
113+
/* Assert the allocation result for debugging purposes. */
114+
TBX_ASSERT(result != NULL);
133115

134116
/* Give the result back to the caller. */
135117
return result;

demos/ARMCM4_STM32F4_Olimex_STM32P405_CubeIDE/Demo Debug.launch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_check_serial_number" value="false"/>
3737
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value="52FF73065185525338230187"/>
3838
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="none"/>
39-
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Software system reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Software system reset&quot;,&quot;fLaunchAttribute&quot;:&quot;system_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Hardware reset&quot;,&quot;fLaunchAttribute&quot;:&quot;hardware_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset hardware\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Core reset&quot;,&quot;fLaunchAttribute&quot;:&quot;core_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset core\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[&quot;-g&quot;]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]}}]}"/>
39+
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fVersion&quot;:1,&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Software system reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Software system reset&quot;,&quot;fLaunchAttribute&quot;:&quot;system_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Hardware reset&quot;,&quot;fLaunchAttribute&quot;:&quot;hardware_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset hardware\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Core reset&quot;,&quot;fLaunchAttribute&quot;:&quot;core_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset core\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[&quot;-g&quot;]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]},&quot;fStartApplication&quot;:true}]}"/>
4040
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.swv.swv_wait_for_sync" value="true"/>
4141
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doHalt" value="false"/>
4242
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doReset" value="false"/>
@@ -51,7 +51,7 @@
5151
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
5252
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
5353
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
54-
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="true"/>
54+
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="false"/>
5555
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
5656
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
5757
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>

source/srecreader.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -322,28 +322,17 @@ static uint8_t SRecReaderFileOpen(char const * firmwareFile)
322322
if (segment == NULL)
323323
{
324324
/* Attempt to allocate memory to store the new segment. */
325-
segment = TbxMemPoolAllocate(sizeof(tSRecSegment));
326-
/* Automatically create or increase the memory pool if it was too small. */
325+
segment = TbxMemPoolAllocateAuto(sizeof(tSRecSegment));
326+
/* Verify segment allocation. */
327327
if (segment == NULL)
328328
{
329-
/* No need to check the return value, because we'll attempt to allocate
330-
* from the memory pool right way. That will tell us if the memory pool
331-
* increase was successful.
329+
/* Could not allocate memory. Heap is probably configured too small.
330+
* Increase TBX_CONF_HEAP_SIZE to resolve the problem. All we can
331+
* do now is flag the error.
332332
*/
333-
(void)TbxMemPoolCreate(1, sizeof(tSRecSegment));
334-
/* Allocation should now work. */
335-
segment = TbxMemPoolAllocate(sizeof(tSRecSegment));
336-
/* Verify segment allocation. */
337-
if (segment == NULL)
338-
{
339-
/* Could not allocate memory. Heap is probably configured too small.
340-
* Increase TBX_CONF_HEAP_SIZE to resolve the problem. All we can
341-
* do now is flag the error.
342-
*/
343-
result = TBX_ERROR;
344-
stopLineLoop = TBX_TRUE;
345-
continue;
346-
}
333+
result = TBX_ERROR;
334+
stopLineLoop = TBX_TRUE;
335+
continue;
347336
}
348337
/* Initialize the newly created segment. */
349338
segment->addr = lineAddress;

0 commit comments

Comments
 (0)