cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Bug When using Simulink with STM32-MAT/TARGET 4.4.2 and STM32F7 FW V_1.11.0

Radu Ghiga
Associate II
Posted on May 03, 2018 at 14:53

Hello,

I am currently learning about STM32 devices and I am working with a Nucleo-F767ZI which I am programing using a toolchain that consists of Simulink with the STM32-MAT/TARGET support package, STM32CubeMX with the STM32F7 FW V1.11.0, and TrueSTUDIO.

I am interested in configuring and using the CAN interface available on the Nucleo F767ZI and I have built a simple example in Simulink with a CAN1 Send block and a MCU Config block. The code generation is successful and I can load the project in TrueSTUDIO. However, when compiling I get the following error: 

'unknown type name 'CanTxMsgTypeDef'

After some reading I found out that the HAL CAN Driver has been changed since STM32F7 FW V1.9.0 and there is no typedef struct with the above name any longer. It has been replaced by the following structure which can be found in stm32f7xx_hal_can.h:

/**

* @brief CAN Tx message header structure definition

*/

typedef struct

{

uint32_t StdId; /*!< Specifies the standard identifier.

                           This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF. */

uint32_t ExtId; /*!< Specifies the extended identifier.

                            This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF. */

uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted.

                             This parameter can be a value of @ref CAN_identifier_type */

uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted.

                              This parameter can be a value of @ref CAN_remote_transmission_request */

uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted.

                              This parameter must be a number between Min_Data = 0 and Max_Data = 8. */

                              FunctionalState TransmitGlobalTime; /*!< Specifies whether the timestamp counter value captured                               on start of frame transmission, is sent in DATA6 and DATA7 replacing pData[6] and pData[7].

                              @note: Time Triggered Communication Mode must be enabled.

                              @note: DLC must be programmed as 8 bytes, in order these 2 bytes are sent.

                              This parameter can be set to ENABLE or DISABLE. */

} CAN_TxHeaderTypeDef;

For some reason when using the STM32-MAT/Target 4.4.2 support package library in Simulink, the generated code still refers back to the old structure and, of course, the project doesn't compile since '

CanTxMsgTypeDef' cannot be found anymore. I believe this is also true for the CAN Receive.

Any ideas on how to bypass this issue? I have tried using STM32F7

mailto:F@

1.8.0 which has the old CAN Drivers, but I had no success, probably because Simulink is generating part of the code according to the old Driver and part of it according to the new one?! I am not really sure if this is true, though.

Maybe STM32-MAT/Target package needs an update to fix this? Or is there something that I am doing wrong?

Any ideas to help me achieve some progress would be very appreciated.

Thank you.

Radu Ghiga

#stm32-mat/target-matlab #can #stm32f7 #stm32cubemx #simulink
13 REPLIES 13
Imen.D
ST Employee
Posted on May 03, 2018 at 17:34

Hello

radu.ghiga

,

HAL CAN driver has been reworked with new API to bypass limitations in the old releases.

Please, ensurethat you use latest tools (STM32CubeMx and

STM32MAT/Target),

then let me know whether the problem here persists or not.

We will check this issue internally.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on May 04, 2018 at 07:53

Hello Imen,

I have checked the versions I am using and I have the following:

STM32CubeMx Version 4.25.0

STM32-Mat/Target Version 4.4.2

STM32F7 FW 1.11.0

Matlab/Simulink 2017b

Atolic TrueStudio for STM32 Version 9.0.0

I have also checked on my.st.com website to see which are the active versions and these are the latest I could find.

Thank you and best regards,

Radu

Amel NASRI
ST Employee
Posted on May 04, 2018 at 13:15

With .ioc file from

https://community.st.com/0D50X00009XkWQdSAN

.

________________

Attachments :

Nucleo_CAN.ioc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxeA&d=%2Fa%2F0X0000000b0S%2FQw13h2SnZbKAJZM0ouHsbvr25r6F69fqXDW0qseJNmY&asPdf=false

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.

Posted on May 04, 2018 at 13:53

Yes Amel that is correct.

Thank you. I will keep this discussion here to avoid having multiple places with the same questions!

Best regards,

Radu

Jose Gil
Associate II
Posted on May 19, 2018 at 18:48

Hello 

Same problem here... but just using bare STM32 tools.

STM32CubeMx Version 4.25.1 to generate the project

STM32F7 FW 1.11.0

STM32F769I-Disco and

SystemWorkbench

Only the following structures are defined in stm32f7xx_hal_can.h

CAN_InitTypeDef

CAN_FilterTypeDef

CAN_TxHeaderTypeDef

CAN_RxHeaderTypeDef

CAN_HandleTypeDef

The last one has no pointer fields for CAN packets... as stated in section 8.1.5 in document UM1905 User manual Description of STM32F7 HAL and Low-layer drivers DocID027932 Rev 3

Any hint on what I am doing wrong?

T J
Lead
Posted on May 21, 2018 at 01:15

dont forget to pull up the Rx pin, if you are not using the CanBus Transceiver chip.

Posted on May 23, 2018 at 17:43

Thank you four your kind advise... I had designed an arduino board with a transceiver on it to connect the board with an existing design.

Any update or hint on the original issue?

Thank you.

Posted on May 24, 2018 at 00:40

In my personal code I have this :

void CAN_Config() {

  CAN_FilterConfTypeDef  sFilterConfig;

  static CanTxMsgTypeDef        TxMessage;

  static CanRxMsgTypeDef        RxMessage;

....}

in STM32F7xx_hal_can.h

typedef struct

{

  CAN_TypeDef                 *Instance;  /*!< Register base address                                */

  CAN_InitTypeDef             Init;       /*!< CAN required parameters                              */

  CanTxMsgTypeDef*            pTxMsg;     /*!< Pointer to transmit structure                        */

  CanRxMsgTypeDef*            pRxMsg;     /*!< Pointer to reception structure for RX FIFO0 msg      */

  CanRxMsgTypeDef*            pRx1Msg;    /*!< Pointer to reception structure for RX FIFO1 msg      */

  __IO HAL_CAN_StateTypeDef   State;      /*!< CAN communication state                              */

  HAL_LockTypeDef             Lock;       /*!< CAN locking object                                   */

  __IO uint32_t               ErrorCode;  /*!< CAN Error code. This parameter can be a value of @ref CAN_Error_Code */

}CAN_HandleTypeDef;
Posted on May 29, 2018 at 17:17

Thank you TJ, In my case and with the given toolchain installation (see above) I get

/**

* @brief CAN handle Structure definition

*/

typedef struct __CAN_HandleTypeDef

{

CAN_TypeDef *Instance; /*!< Register base address */

CAN_InitTypeDef Init; /*!< CAN required parameters */

__IO HAL_CAN_StateTypeDef State; /*!< CAN communication state */

__IO uint32_t ErrorCode; /*!< CAN Error code.

This parameter can be a value of @ref CAN_Error_Code */

} CAN_HandleTypeDef;

I ended up generating the driver with an older version of the tools (CubeMx 4.17 and FW 1.5.1 ) and adapting/renaming the fields names to match the ones generated by the newer version... With these adapted files I have been able to run my own loopback demo.

Now I notice I had overlooked the 

RX FIFO1

  field.... but so far, so good.

Regards