Hi,
I'm developping a CAN application on a STM3220G eval board, using the RTX kernel.
The example presented by Keil works fine, but runs in privileged mode.
In my application, which is not running in privileged mode, as specified on the documentation, I tried to put the CAN initialization in a service function.
void __SVC_2 (void) { /* A protected function to configure CAN 1 */ CAN_ERROR err; //initialisation du contrôleur err = CAN_init (1, 1000000); /* CAN controller 1 init, 1000 kbit/s */ if(!err) { //Définition des messages en réception CAN_rx_object (1, 2, 0x43, DATA_TYPE | STANDARD_TYPE); /* Enable reception */ //Démarrage du CAN CAN_start (1); /* Start controller 1 */ } else return; }
This function is called when it should (inside a OS task), but I get a hardware fault error when in the Can_init function, when it calls an os function (in red)
CAN_ERROR CAN_init (U32 ctrl, U32 baudrate) { static U8 first_run_flag = 0; CAN_ERROR error_code; U32 ctrl0 = ctrl-1; /* Controller index 0 .. x-1 */ /* Initialize the Semaphore before the first use */ os_sem_init (wr_sem[ctrl0], 1); /* When function is called for the first time it will initialize and setup all of the resources that are common to CAN functionality */ if (first_run_flag == 0) { first_run_flag = 1; if (_init_box (CAN_mpool, sizeof(CAN_mpool), sizeof(CAN_msg)) == 1) return CAN_MEM_POOL_INIT_ERROR; } os_mbx_init (MBX_tx_ctrl[ctrl0], sizeof(MBX_tx_ctrl[ctrl0])); os_mbx_init (MBX_rx_ctrl[ctrl0], sizeof(MBX_rx_ctrl[ctrl0])); error_code = CAN_hw_setup (ctrl); if (error_code != CAN_OK) return error_code; return (CAN_hw_init (ctrl, baudrate)); }
My questions : Are the "os_" functions forbidden in _SVC functions ? Should I break the Can_init function from the RTX CAN library and call one part in the task, the other in the SVC function ? Is the privileged mode mandatory ?