2

我正在尝试在 STM32F4 Discovery 嵌入式板上使用 Eigen C++ 库来执行一些矩阵运算,特别是对传感器数据进行一些卡尔曼滤波。

我尝试链接标准 c++ 库,甚至尝试使用 g++ arm 编译器编译程序。

typedef Eigen::Matrix<float, 10, 10> Matrix10d;
Matrix10d mat1 = Matrix10d::Constant(10, 10, 1);
Matrix10d mat2 = Matrix10d::Constant(10, 10, 2);
Matrix10d result;
result = mat1 * mat2;

如果矩阵大小设置为 7,我可以编译相同的代码。如果我越过它,那么代码将不会编译,并且特征会给我一个警告:

warning: argument 1 value '4294967295' exceeds maximum object size 2147483647

这些是我收到的部分错误消息

n function 'throw_std_bad_alloc,
    inlined from 'check_size_for_overflow at bla/bla/Eigen/src/Core/util/Memory.h:289:24

这是我正在使用的链接器脚本中的内存分配

/*
 * STM32F407xG memory setup.
 * Note: Use of ram1 and ram2 is mutually exclusive with use of ram0.
 */
MEMORY
{
    flash0  : org = 0x08000000, len = 1M
    flash1  : org = 0x00000000, len = 0
    flash2  : org = 0x00000000, len = 0
    flash3  : org = 0x00000000, len = 0
    flash4  : org = 0x00000000, len = 0
    flash5  : org = 0x00000000, len = 0
    flash6  : org = 0x00000000, len = 0
    flash7  : org = 0x00000000, len = 0
    ram0    : org = 0x20000000, len = 128k      /* SRAM1 + SRAM2 */
    ram1    : org = 0x20000000, len = 112k      /* SRAM1 */
    ram2    : org = 0x2001C000, len = 16k       /* SRAM2 */
    ram3    : org = 0x00000000, len = 0
    ram4    : org = 0x10000000, len = 64k       /* CCM SRAM */
    ram5    : org = 0x40024000, len = 4k        /* BCKP SRAM */
    ram6    : org = 0x00000000, len = 0
    ram7    : org = 0x00000000, len = 0
}

我只是在运行 STM32F4 发现板,但 Chibios 配置不变

# Stack size to be allocated to the Cortex-M process stack. This stack is
# the stack used by the main() thread.
ifeq ($(USE_PROCESS_STACKSIZE),)
  USE_PROCESS_STACKSIZE = 0x400
endif

更新

我无法再重现此错误。可悲的是,我没有做任何事情来解决这个问题。

arm-none-eabi-gcc -c -mcpu=cortex-m4 -O3 -Os -ggdb -fomit-frame-pointer -falign-functions=16 -ffunction-sections -fdata-sections -fno-common -flto -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wall -Wextra -Wundef -Wstrict-prototypes -Wa,-alms=build/lst/ -DCORTEX_USE_FPU=TRUE -DCHPRINTF_USE_FLOAT=TRUE -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -MD -MP -MF .dep/build.d -I.

如果有人感兴趣,以上是我正在使用的编译器选项。

现在我可以毫无问题地乘以 20x20 矩阵。

Matrix20d mat1 = Matrix20d::Constant(20, 20, 2);
// Multiply the matrix with a vector.
Vector20d vec = Vector20d::Constant(20, 1, 2);
Vector20d result;
systime_t startTime = chVTGetSystemTimeX();
result = mat1 * vec;
// Calculate the timedifference
systime_t endTime = chVTGetSystemTimeX();
systime_t timeDifference = chTimeDiffX(startTime, endTime);
chprintf(chp,"Time taken for the multiplication in milliseconds : %d\n", (int)timeDifference);
chprintf(chp, "System time : %d \n", startTime);
chprintf(chp, "Systime end : %d \n", endTime);
chprintf(chp, "Values in the vector : \n [");
for(Eigen::Index i=0; i < result.size();i++)
{
    chprintf(chp, "%0.3f, ", result(i));
}
chprintf(chp, "] \n");
chThdSleepMilliseconds(1000);

完成上述计算大约需要 1 毫秒。

我认为我的编译器可能有问题。所以我尝试了两个版本的编译器

版本 - 1

arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

版本 2

arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437]
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4

0 回答 0