Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CANopenNode_STM32/CO_app_STM32.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "CO_app_STM32.h"
#include "CANopen.h"
#include "main.h"
#include <stdio.h>
#include <inttypes.h>
#include <stdio.h>

#include "CO_storageBlank.h"
#include "OD.h"
Expand Down Expand Up @@ -122,7 +122,7 @@ canopen_app_resetCommunication() {
CO->CANmodule->CANnormal = false;

/* Enter CAN configuration. */
CO_CANsetConfigurationMode((void*)canopenNodeSTM32);
CO_CANsetConfigurationMode(canopenNodeSTM32);
CO_CANmodule_disable(CO->CANmodule);

/* initialize CANopen */
Expand Down Expand Up @@ -176,7 +176,7 @@ canopen_app_resetCommunication() {
}

/* Configure Timer interrupt function for execution every 1 millisecond */
HAL_TIM_Base_Start_IT(canopenNodeSTM32->timerHandle); //1ms interrupt
HAL_TIM_Base_Start_IT(canopenNodeSTM32->timerHandle); // 1ms interrupt

/* Configure CAN transmit and receive interrupt */

Expand Down Expand Up @@ -218,7 +218,7 @@ canopen_app_process() {

if (reset_status == CO_RESET_COMM) {
/* delete objects from memory */
HAL_TIM_Base_Stop_IT(canopenNodeSTM32->timerHandle);
HAL_TIM_Base_Stop_IT(canopenNodeSTM32->timerHandle);
CO_CANsetConfigurationMode((void*)canopenNodeSTM32);
CO_delete(CO);
log_printf("CANopenNode Reset Communication request\n");
Expand Down
53 changes: 30 additions & 23 deletions CANopenNode_STM32/CO_app_STM32.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include "CANopen.h"
#include "main.h"

/* CANHandle : Pass in the CAN Handle to this function and it wil be used for all CAN Communications. It can be FDCan or CAN
/* CANHandle : Pass in the CAN Handle to this function and it wil be used for all CAN Communications. It can be FDCan or
CAN
* and CANOpenSTM32 Driver will take of care of handling that
* HWInitFunction : Pass in the function that initialize the CAN peripheral, usually MX_CAN_Init
* timerHandle : Pass in the timer that is going to be used for generating 1ms interrupt for tmrThread function,
* please note that CANOpenSTM32 Library will override HAL_TIM_PeriodElapsedCallback function, if you also need this function
* please note that CANOpenSTM32 Library will override HAL_TIM_PeriodElapsedCallback function, if you also need this
function
* in your codes, please take required steps

*/
Expand All @@ -24,45 +26,50 @@
extern "C" {
#endif

#if CO_STM32_FDCAN_Driver
typedef FDCAN_HandleTypeDef can_periph_handle_t;
#else /* CO_STM32_FDCAN_Driver */
typedef CAN_HandleTypeDef can_periph_handle_t;
#endif /* CO_STM32_FDCAN_Driver */

typedef struct {
uint8_t
desiredNodeID; /*This is the Node ID that you ask the CANOpen stack to assign to your device, although it might not always
* be the final NodeID, after calling canopen_app_init() you should check ActiveNodeID of CANopenNodeSTM32 structure for assigned Node ID.
*/
uint8_t activeNodeID; /* Assigned Node ID */
uint8_t desiredNodeID; /*This is the Node ID that you ask the CANOpen stack to assign to your device, although it
* might not always be the final NodeID, after calling canopen_app_init() you should check
* ActiveNodeID of CANopenNodeSTM32 structure for assigned Node ID.
*/
uint8_t activeNodeID; /* Assigned Node ID */
uint16_t baudrate; /* This is the baudrate you've set in your CubeMX Configuration */
TIM_HandleTypeDef*
timerHandle; /*Pass in the timer that is going to be used for generating 1ms interrupt for tmrThread function,
* please note that CANOpenSTM32 Library will override HAL_TIM_PeriodElapsedCallback function, if you also need this function in your codes, please take required steps
*/

/*
* Pass in the timer that is going to be used for generating 1ms interrupt for tmrThread function,
* please note that CANOpenSTM32 Library will override HAL_TIM_PeriodElapsedCallback function, if
* you also need this function in your codes, please take required steps
*/
TIM_HandleTypeDef* timerHandle;

/* Pass in the CAN Handle to this function and it wil be used for all CAN Communications. It can be FDCan or CAN
* and CANOpenSTM32 Driver will take of care of handling that*/
#ifdef CO_STM32_FDCAN_Driver
FDCAN_HandleTypeDef* CANHandle;
#else
CAN_HandleTypeDef* CANHandle;
#endif
* and CANOpenSTM32 Driver will take of care of handling that*/
can_periph_handle_t* CANHandle;

void (*HWInitFunction)(); /* Pass in the function that initialize the CAN peripheral, usually MX_CAN_Init */
void (*HWInitFunction)(void); /* Pass in the function that initialize the CAN peripheral, usually MX_CAN_Init */

uint8_t outStatusLEDGreen; // This will be updated by the stack - Use them for the LED management
uint8_t outStatusLEDRed; // This will be updated by the stack - Use them for the LED management
CO_t* canOpenStack;

} CANopenNodeSTM32;


// In order to use CANOpenSTM32, you'll have it have a canopenNodeSTM32 structure somewhere in your codes, it is usually residing in CO_app_STM32.c
// In order to use CANOpenSTM32, you'll have it have a canopenNodeSTM32 structure somewhere in your codes, it is usually
// residing in CO_app_STM32.c
extern CANopenNodeSTM32* canopenNodeSTM32;


/* This function will initialize the required CANOpen Stack objects, allocate the memory and prepare stack for communication reset*/
/* This function will initialize the required CANOpen Stack objects, allocate the memory and prepare stack for
* communication reset*/
int canopen_app_init(CANopenNodeSTM32* canopenSTM32);
/* This function will reset the CAN communication periperhal and also the CANOpen stack variables */
int canopen_app_resetCommunication();
/* This function will check the input buffers and any outstanding tasks that are not time critical, this function should be called regurarly from your code (i.e from your while(1))*/
/* This function will check the input buffers and any outstanding tasks that are not time critical, this function should
* be called regurarly from your code (i.e from your while(1))*/
void canopen_app_process();
/* Thread function executes in constant intervals, this function can be called from FreeRTOS tasks or Timers ********/
void canopen_app_interrupt(void);
Expand Down
Loading