Hi everybody!
I am not sure this is the right section of the forum to ask the question, however I have the following question.
I have opened the STM32F4xx-CAN project embedded in Chibistudio GCC 4.9 that contains the thread :
[spoil]static THD_FUNCTION(can_tx, p) {
CANTxFrame txmsg;
(void)p;
chRegSetThreadName("transmitter");
txmsg.IDE = CAN_IDE_EXT;
txmsg.EID = 0x01234567;
txmsg.RTR = CAN_RTR_DATA;
txmsg.DLC = 8;
txmsg.data32[0] = 0x55AA55AA;
txmsg.data32[1] = 0x00FF00FF;
while (!chThdShouldTerminateX()) {
canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
canTransmit(&CAND2, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
chThdSleepMilliseconds(500);
}
}[/spoil]
I have tried to move the declaration and the data assignment of txmsg outside the thread (I want to use it on a callback of an interrupt), but the compiler gave me the following result:
[spoil]11:20:49 **** Incremental Build of configuration Default for project STM32F4xx-CAN ****
make -j4 all
Compiling main.c
main.c:72:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.IDE = CAN_IDE_EXT;
^
main.c:73:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.EID = 0x01234567;
^
main.c:74:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.RTR = CAN_RTR_DATA;
^
main.c:75:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.DLC = 8;
^
main.c:76:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.data32[0] = 0x55AA55AA;
^
main.c:77:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
txmsg.data32[1] = 0x00FF00FF;
^
make: *** [build/obj/main.o] Error 1
11:20:53 Build Finished (took 4s.720ms)[/spoil]
It seems that I cannot use this type outside of the thread. Why?
P.S. obviously I have commented the code in the thread that I moved outside.
I thank you in advance for your help.
CANTxFrame outside threads.
Moderator: RoccoMarco
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: CANTxFrame outside threads.
It is just above the thread.
[spoil]CANTxFrame txmsg;
txmsg.IDE = CAN_IDE_EXT;
txmsg.EID = 0x01234567;
txmsg.RTR = CAN_RTR_DATA;
txmsg.DLC = 8;
txmsg.data32[0] = 0x55AA55AA;
txmsg.data32[1] = 0x00FF00FF;
static THD_WORKING_AREA(can_tx_wa, 256);
static THD_FUNCTION(can_tx, p) {
// CANTxFrame txmsg;
(void)p;
chRegSetThreadName("transmitter");
// txmsg.IDE = CAN_IDE_EXT;
// txmsg.EID = 0x01234567;
// txmsg.RTR = CAN_RTR_DATA;
// txmsg.DLC = 8;
// txmsg.data32[0] = 0x55AA55AA;
// txmsg.data32[1] = 0x00FF00FF;
while (!chThdShouldTerminateX()) {
canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
canTransmit(&CAND2, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
chThdSleepMilliseconds(500);
}
}[/spoil]
[spoil]CANTxFrame txmsg;
txmsg.IDE = CAN_IDE_EXT;
txmsg.EID = 0x01234567;
txmsg.RTR = CAN_RTR_DATA;
txmsg.DLC = 8;
txmsg.data32[0] = 0x55AA55AA;
txmsg.data32[1] = 0x00FF00FF;
static THD_WORKING_AREA(can_tx_wa, 256);
static THD_FUNCTION(can_tx, p) {
// CANTxFrame txmsg;
(void)p;
chRegSetThreadName("transmitter");
// txmsg.IDE = CAN_IDE_EXT;
// txmsg.EID = 0x01234567;
// txmsg.RTR = CAN_RTR_DATA;
// txmsg.DLC = 8;
// txmsg.data32[0] = 0x55AA55AA;
// txmsg.data32[1] = 0x00FF00FF;
while (!chThdShouldTerminateX()) {
canTransmit(&CAND1, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
canTransmit(&CAND2, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
chThdSleepMilliseconds(500);
}
}[/spoil]
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: CANTxFrame outside threads.
You cannot initialize the variable that way outside a function, use a C initializer:
var = {
....
};
Giovanni
var = {
....
};
Giovanni
Re: CANTxFrame outside threads.
That would become:
(can't find the code tag either. Let's go with spoiler too..
)
[spoil]CANTxFrame txmsg = {
.IDE = CAN_IDE_EXT;
.EID = 0x01234567;
.RTR = CAN_RTR_DATA;
.DLC = 8;
.data32 = {0x55AA55AA, 0x00FF00FF};
};[/spoil]
(can't find the code tag either. Let's go with spoiler too..
[spoil]CANTxFrame txmsg = {
.IDE = CAN_IDE_EXT;
.EID = 0x01234567;
.RTR = CAN_RTR_DATA;
.DLC = 8;
.data32 = {0x55AA55AA, 0x00FF00FF};
};[/spoil]
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times