Using Matrix multiplication function of CMSIS DSP Library for STM32DISCOVERY - Page 1
Forum section: electronics / general

author: syntax333
author_rank: Regular Contributor
timestamp: January 19, 2020, 11:28:07 am
content: Hi, I am trying to take two matrices and multiply them. I am using CMSIS library source and .h files which compiled and uploaded correctly.The vector addition function works correctly. However, when I tried to multiply one vector and one matrix stm32 stops working. I tried to debug the code and find out when the program comes to arm_mat_mult_f32(...) it bricks and waits at "startup_stm32f4xx.S" lineCode:Default_Handler:Infinite_Loop: b Infinite_Loopand doesn't proceed to next step.Has anyone encountered this problem? or used library functions?Below you can see my code:Code:#include "stm32f4xx.h"#include "stm32f4_discovery.h"#include "DSPLib/arm_math.h"float32_t Vector1[] = {1,2,3};float32_t Vector2[] = {1,2,3};float32_t ResultVec;void Initialization(){RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;GPIOD->MODER = (GPIOD->MODER | GPIO_MODER_MODER15_0) & ~(GPIO_MODER_MODER15_1);GPIOD->OTYPER &= ~(GPIO_OTYPER_OT_15);GPIOD->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR15;GPIOD->PUPDR &= ~(GPIO_PUPDR_PUPDR15);}int main(void){Initialization();arm_matrix_instance_f32 V1;arm_matrix_instance_f32 V2;arm_matrix_instance_f32 RV;arm_mat_init_f32(&V1,3,1,(float32_t *)Vector1);arm_mat_init_f32(&V2,1,3,(float32_t *)Vector2);arm_mat_init_f32(&RV,3,3,ResultVec);arm_mat_mult_f32(&V1,&V2,&RV);while(1){if(ResultVec == 1){GPIOD->BSRRL |= GPIO_BSRR_BS_15;}}}

author: mikerj
author_rank: Super Contributor
timestamp: January 19, 2020, 12:31:53 pm
content: 'Default_Handler' is a very simple function with an infinite loop that is assigned to any interrupt that hasn't had it's own handler defined. I suspect you are getting an exception that has the default handler assigned to it, but having a common handler does not make it obvious which exception was raised.Specifically which STM32 Discovery board are you using? There are a huge number of different boards with different processors. If your processor does not include a floating point unit then make sure your compiler and linker are configured to use software floating point with the correct calling conventions.

author: andersm
author_rank: Super Contributor
timestamp: January 19, 2020, 02:14:10 pm
content: You initialize RV as a 3*3 matrix, but ResultVec only has space for 3 values.

author: syntax333
author_rank: Regular Contributor
timestamp: January 19, 2020, 06:25:34 pm
content: I solved my problem it was due to library files being missing.

author: syntax333
author_rank: Regular Contributor
timestamp: January 19, 2020, 06:29:13 pm
content: I got a new problemit computes matrices perfectly but after computing 12 times it stucks in that function. When I stop debugging I see that it stucks on:"startup_stm32f407xx.s" lineSysTick_Handler PROCEXPORT SysTick_Handler This line >> B .ENDPI am using STM32F4Discovery kit which has stm32f407vgt6.I tried a simple code, just switching pin. After 1second the code stucks at same place. Probably posting another topic would be right thing to do. Thank you for your responses.

author: newbrain
author_rank: Super Contributor
timestamp: January 20, 2020, 12:33:50 pm
content: Quote from: syntax333 on January 19, 2020, 06:29:13 pmIf you still have the result matrix pointing to a 3 elements vector rather than 3x3 matrix, I doubt it.Since you are invoking undefined behaviour, any result is acceptable even the lock-up you are experiencing.Now, UB aside, another possible cause is that you have the System Tick interrupt enabled somewhere - AFAICS, it's not enabled by default in the startup and system init files, are you showing all the code?The default handler for SysTick (and other exceptions) is simply an infinite loop, as you have seen.You can provide an empty handler just by defining it:Code:void SysTick_Handler(void) {}

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 20, 2020, 04:17:25 pm
content: Yep, the default SysTick interrupt is normally set to fire every 1 ms? so here that means your 12 matrix multiplications last over 1 ms.If you're using the HAL, the SysTick_Handler() is normally defined (also weakly, so you can override it) as a function incrementing some global counter, but if not, then it's just an infinite loop as newbrain showed you.And yes we don't know if you fixed the memory access issue andersm pointed out, so if not, fix that as well.