I am integrating the DSP_LIB from ARM with ChibiOS, and I have a strange behavior (well, probably it is normal but I can not explain it).
I have the next main (is a ripped version of the demo for the STM32F4 Discovery).
Code: Select all
#include <math.h>
#include "ch.h"
#include "hal.h"
#include "./math/arm_math.h"
#include "./math/matrix.h"
static MemoryHeap *matricesHeap;
static float matricesBuff[4*1024*sizeof(float)];
static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) {
(void)arg;
chRegSetThreadName("blinker");
while (TRUE) {
palSetPad(GPIOD, GPIOD_LED3); /* Orange. */
chThdSleepMilliseconds(500);
palClearPad(GPIOD, GPIOD_LED3); /* Orange. */
chThdSleepMilliseconds(500);
}
}
int main(void) {
halInit();
chSysInit();
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
float x = 0.3f;
uint8_t led = 0;
systime_t t1tick;
systime_t t1lapse;
chHeapInit(matricesHeap, matricesBuff, 4*1024*sizeof(float));
arm_matrix_instance_f32 A, B, C;
matrixInit(&A, 2, 2, matricesHeap);
matrixInit(&B, 2, 2, matricesHeap);
matrixInit(&C, 2, 2, matricesHeap);
A.pData[0] = 1.1f;
A.pData[1] = 2.1f;
A.pData[2] = 4.1f;
A.pData[3] = 5.1f;
B.pData[0] = 3.1f;
B.pData[1] = 4.1f;
B.pData[2] = 5.1f;
B.pData[3] = 7.1f;
while (TRUE) {
arm_status status;
t1tick = chTimeNow();
x = x + sinf(x);
status = arm_mat_add_f32(&A, &B, &C);
arm_copy_f32(C.pData, A.pData, A.numRows*A.numCols);
led = !led;
if(led){
palSetPad(GPIOD, GPIOD_LED4); /* Green. */
}
else{
palClearPad(GPIOD, GPIOD_LED4); /* Green. */
}
t1lapse = GetTimeInterval(&t1tick);
if(t1lapse < MS2ST(500))
chThdSleepUntil(t1tick + MS2ST(500));
else
palSetPad(GPIOD, GPIOD_LED5);
}
}
The code is working as expected, just doing A+B = C, A = C, each iteration.
But, when I look at the Heap (matricesBuff) with gdb is just empty:
- (gdb) p matricesBuff
$89 = {0, 2.29476637e-41, 0 <repeats 16382 times>}
Here it is the initialization code for the matrices
Code: Select all
void matrixInit(arm_matrix_instance_f32 *m, int rows, int cols,
MemoryHeap *memoryHeap) {
float32_t *data;
data = (float32_t *)chHeapAlloc(memoryHeap,
rows*cols*sizeof(float32_t));
arm_mat_init_f32(m, rows, cols, data);
}
The arm_mat_init just pass the data to the structure arm_matrix_instance_f32.
Probably I am missing how the management of the Heap works in ChibiOS, but... should matricesBuff not be populated with the values of A, B and C?
By the way, these are the pointers given to A, B, and C:
- (gdb) p/u A.pData
$91 = 536939968
(gdb) p/u B.pData
$92 = 536939992
(gdb) p/u C.pData
$93 = 536940016
Why the distance between each other is 24 and not 16 (corresponding to 4 floats)?
Thanks in advance for your help!