cancel
Showing results for 
Search instead for 
Did you mean: 

Bad C Code in conjunction with STM32-MAT/TARGET V4.4.1

michaelkotthaus9
Associate II
Posted on February 13, 2017 at 15:59

Dear STM32 supporters,

I recently updated to V4.4.1 of the MATLAB/Simulink library 'STM32-MAT/Target'. (See also the resolved question at

https://community.st.com/thread/36047-matlabsimulink-stm32mattarget-blocks-generate-warnings-regarding-nargchk-function

). I am using MATLAB R2016b.

The code generation works fine. But the generated C codes has misktakes:

H-File:

/* ADC1 Regular channel Converted value DMA buffer */
extern uint16_t ADC1_RegularConvertedValue[0];�?�?

An Array with the size of 0 is invalid. I had expected here the value 2 as my model also shows 'Nb of regular channels: 2'.

The code tries to access invalid array elements (each element is invalid):

C-File:

 /* ADC1 Regular channel DMA buffer pointer initialization*/
 ADC1_DmaBuff = &ADC1_RegularConvertedValue[0];
 /* ADC1 Regular channel DMA Half transfer complete buffer pointer initialization*/
 ADC1_DmaHalf = &ADC1_RegularConvertedValue[0];
 /* ADC1 Regular channel DMA Full transfer complete buffer pointer initialization*/
 ADC1_DmaFull = &ADC1_RegularConvertedValue[0/2 - 1];�?�?�?�?�?�?

0/2-1=-1 is also strange!

Can you confirm this?

Is this an issue of MAT/Target V4.4.1?

#stm32-mat/target
9 REPLIES 9
Oliver Beirne
Senior
Posted on February 13, 2017 at 17:43

Hello

I have moved your question to the

https://community.st.com/community/stm32-community/stm32-forum?sr=search&searchId=c674f8b9-bfb8-49c2-a2a5-9401fcee462f&searchIndex=0

‌ where someone should be able to assist you.

Thanks

Oli

Amel NASRI
ST Employee
Posted on February 14, 2017 at 09:53

Hi @michaeL,

I confirm the bug; this is taken as a priority and will be fixed as soon as possible. We will keep you informed when the new version will be available.

Sorry for such inconvenience.

-Amel

You are an STM32 user and want to express your trust for our products and win a 3D printer? Get your chance participating in

https://community.st.com/community/stm32-community/embedded-world-contest

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

michaelkotthaus9
Associate II
Posted on February 14, 2017 at 13:09

Hello

oliverbeirne

‌ and

st.mcu

‌,

thank you very much for the processing of this request.

I think this issue came up between version 4.4.0 and version 4.4.1.

Best regards,

michaeL

Posted on February 15, 2017 at 09:40

Hello,

we are working on this bug.

It happens when ADC DMA buffer size is 0

Workarround can be to set ADC DMA buffer size to a value greater than 2.

Best regards

Pascal

Posted on February 15, 2017 at 16:15

Hello

REYNAUD.PASCAL

‌,

this workaround does not solve the problem.With Setting the ADCDMA buffer to 2 or 4 the invalid array definition and access went away. But there was still an inclusion of a file called <ProjectName>_External_Functions.h which was not found in the project folder. I remarked this inclusion and the code compiled.

But my model based design does not work like in earlier versions. Sorry, but I can not use this version at all.

Best regards,

michaeL

Posted on February 16, 2017 at 19:24

Hello Michael,

can you please tell me used mode?

Normal, PIL or external mode

Best regards

Pascal

Posted on February 16, 2017 at 19:45

Hello Mickael,

<ProjectName>_External_Functions.h should had been generated in <ProjectName>/Inc repository even if you did not select any external file to include from configuration parameters window > Code Generation > STM32 Project Files.

This file should be empty.

Can you please confirm it is not generated at all?

Then, can you please explain the difference for your design regarding previous versions?

Thank you

Best regards

Pascal 

Posted on February 17, 2017 at 10:29

Hello

REYNAUD.PASCAL

‌,

I am not sure, what you mean with 'normal' or 'external mode'. Referring to page 5 of

http://www.st.com/content/ccc/resource/sales_and_marketing/presentation/product_presentation/a9/9b/32/0f/30/e7/4a/aa/stm32-matlab.pdf/files/stm32-matlab.pdf/jcr:content/translations/en.stm32-matlab.pdf

it is 'Step 3: Everything on STM32'.

michaeL

Posted on February 17, 2017 at 10:33

I confirm, that I did not find any file *_External_Functions.h.

I did not change my model at all, I only updated from V4.4.0 to V4.4.1. (I also moved to the newer MATLAB/Simulink version R2016b, but this was before).