Author Topic: Using Matrix multiplication function of CMSIS DSP Library for STM32DISCOVERY  (Read 3019 times)

0 Members and 1 Guest are viewing this topic.

Offline syntax333Topic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: 00
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" line
Code: [Select]
Default_Handler:Infinite_Loop: b  Infinite_Loop and doesn't proceed to next step.

Has anyone encountered this problem? or used library functions?

Below you can see my code:
Code: [Select]

#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[3];



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[0] == 1)
{
GPIOD->BSRRL |= GPIO_BSRR_BS_15;
}


}
}


« Last Edit: January 19, 2020, 11:33:00 am by syntax333 »
 

Online mikerj

  • Super Contributor
  • ***
  • Posts: 3468
  • Country: gb
'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.
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
You initialize RV as a 3*3 matrix, but ResultVec only has space for 3 values.

Offline syntax333Topic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: 00
I solved my problem it was due to library files being missing.
 

Offline syntax333Topic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: 00
I got a new problem  ;D it 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" line

      SysTick_Handler PROC
                     EXPORT  SysTick_Handler            [WEAK]
This line  >>  B       .
                     ENDP

I 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.
« Last Edit: January 20, 2020, 04:50:21 am by syntax333 »
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1849
  • Country: se
it computes matrices perfectly
If 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. >:D

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: [Select]
void SysTick_Handler(void) {}
Nandemo wa shiranai wa yo, shitteru koto dake.
 
The following users thanked this post: thm_w

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 16370
  • Country: fr
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf