cancel
Showing results for 
Search instead for 
Did you mean: 

STM32-MAT/TARGET not working correctly, code is generated only for one block of each type, the rest of the blocks are eliminated

MRegg
Associate

Hi,

i have a problem with generating C-code for a STM32F407VG microcontroller unsing the STM32-MAT/TARGET package and embedded coder. I can generate the code using the simulink library blocks supplied by the support package (CAN_Send, GPIO_Read, etc). But for every type of block from this package, only one segment of code is generated. This is not a problem for most of these block, as the functions can be called multiple times. But for some other blocks this does not work, as you can set certain settings in the properties of the block, which are then lost if code is only generated for one of them.

An example: the CAN_Filter block has to be configured correctly for the microcontroller to recieve CAN messages. With each CAN_Filter block i can configure the microcontroller to a limited number of messages, so i need multiple of these blocks in my model. But when gnerating code, all but one of these is eliminated, leaving only the code for the block placed first. This means that the other blocks in the model now do not work in the code. There are similar problems for the other blocks in the library.

As far as i understand, this behaviour is somewhat intended, as the embedded coder removes duplicate code. The problem here seeems to be that these blocks, when there are multiple of them, are detected as duplicate, even though their settings make them, and their generated code, unique.

Is there a way to restrict the embedded coder from doing these optimisations, either for certain blocks or just for the entire model?

I know there is the "code reduction" setting, but turing that off did not fix the problem. I also tried to insert the missing code manually by hand and that works, but that is hardly a good solution if i have to add half the code myself after each change to the model.

I am using Matlab2021a and STM32CubeMX 5.6.0

This is the code generated for one of the CAN_Filters, and below you can see the corresponding settings of the block. As you can see, the parameters are written into the code directly instead of as a function call argument, which is why the code cannot be reused in the C-code.

/* Start for S-Function (CAN_Filter): 'CAN_Filter1' (':925') */

{

/* HAL CAN2 filter configuration structure definition. */

CAN_FilterTypeDef sFilterConfig = { 0 };

sFilterConfig.FilterIdHigh = 0x80;

sFilterConfig.FilterIdLow = 0x0;

sFilterConfig.FilterMaskIdHigh = 0x0;

sFilterConfig.FilterMaskIdLow = 0x0;

sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;

sFilterConfig.FilterBank = 14;

sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;

sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

sFilterConfig.FilterActivation = ENABLE;

sFilterConfig.SlaveStartFilterBank = 14;

/* Configure CAN2 filter on dedicated FIFO0. */

if (HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig)!= HAL_OK) {

Error_Handler();

}

}0693W00000NrvXAQAZ.png

0 REPLIES 0