stm32/matlab system object data conversion problem

2 ビュー (過去 30 日間)
ali
ali 2024 年 1 月 18 日
回答済み: ali 2024 年 2 月 14 日
I want to implement stm32 as USB_cdc using Simulink block and because Simulink stm32 doesn’t support usb so I have to create a block for this purpose. I used block driver method to do this. As you see below I created a system object and it is sending data correctly.
But when I want to use “oout” in Simulink, data is corrupted and meaningless.
Here is my procedure :
function y = stepImpl(obj) %#ok<MANU>
y =uint64(0);
if isempty(coder.target)
% Place simulation output code here
else
% Call C-function implementing device output
y = coder.ceval('data_change');
end
end
when data_cgange function called it dose:
1: send "oout" value to host with "CDC_Transmit_FS" function.(it is hardware layer function and work properly)
2: return "oout" value so i can use it in simulink.(it is not working)
"oout" value is filled in hardware layer and is declared "uint8_t oout[APP_RX_DATA_SIZE];" in code.
long double data_change(void)
{
CDC_Transmit_FS(oout, 5);
memset (a,'\0',10);
memcpy( a, oout, 10);
fout = *a;
//strtod(oout,endpoint);
return fout;
}

採用された回答

ali
ali 2024 年 2 月 14 日
By configuring this part, it worked properly
function varargout =
getOutputSizeImpl(~)
varargout{1} = [10];

その他の回答 (1 件)

Goutham Varanasi
Goutham Varanasi 2024 年 1 月 30 日
編集済み: Goutham Varanasi 2024 年 1 月 30 日
This seems to be an issue with the code. Debug the generated code in cube IDE using the below mentioned process.
  1. In Model, set Build configuration as Debug: Open Model settings from Modeling tab. Go to Code Generation -> Build process. Select Debug in Build configuration
  2. Build the project from Simulink.
  3. Create a new STM32 Project in STM32CubeIDE. Select the required board on which you are going to debug the Simulink-generated code.
  4. Click on Debug -> Debug Configuration
  5. Right Click on STM32 Cortex-M C/C++ Application -> New Configuration
  6. Browse the STM32 project created in Step 3 as Project
  7. Browse the elf generated from Simulink in C/C++ Application and Click Debug
Note:
• Close all open files before starting debug session.
• Debugging starts in ert_main.c file. Add breakpoints and use Step Into to go inside functions. It will open the relevant source files.
• To add a specify source file for debugging, go to File -> Open File… Browse the file and use it for debugging.
  1 件のコメント
ali
ali 2024 年 2 月 10 日
Thank you for your answer, the problem was due to output size configuration in m file, and after correcting this, it work properly.

サインインしてコメントする。

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by