I am building an application in which I need to allocate and free objects, so I thought I'd do this with a memory pool. The problem is that if I call chPoolAlloc when the runtime system state checks are active, the system halts when I try to instantiate a new object from the pool. If the system state checks are disabled, the program runs normally.
Here is some of my code
Code: Select all
typedef struct cvg_block cvg_block_t;
struct cvg_block {
cvg_block_t *next;
uint32_t channel;
uint16_t cv;
uint8_t gate;
uint8_t listeners;
uint8_t read_count;
};
memory_pool_t cvg_block_mempool;
static THD_WORKING_AREA(testwa, 128);
THD_WORKING_AREA(waChainRoutine, 128);
THD_FUNCTION(ChainRoutine, arg) {
cvg_block_t *b = (cvg_block_t *)chPoolAlloc(&cvg_block_mempool);
while(true) {
}
}
void chSetup() {
chPoolObjectInit(&cvg_block_mempool, sizeof(cvg_block_t), chCoreAllocAligned);
chThdCreateStatic(testwa, sizeof(testwa), NORMALPRIO, ChainRoutine, NULL);
}
void setup() {
chBegin(chSetup);
/* chBegin should never return */
while(true) {}
}
This is of course a simplification of the whole code, but I did my best to isolate what I think is the problem.
I am using the following library: https://github.com/greiman/ChRt which is an Arduino port of chibiOS. This is because the platform I'm using is the Teensy4.1. Moreover, because of hardware limitations of the Teensy, I am unable to connect a debugger and look at the panic message.
Any help is appreciated and thank you in advance!