CTL + ISR on STM32F103xx
Hello,
sorry for my bad english, but i am not from english-speaking country.
However, i have met the following problem:
i am using the ctl-tasking library on an STM32. So everything worked fine until i tried to use a message-queue together with the USB. After some bytes received via USB the porgam jumps into the
void ctl_handle_error(CTL_ERROR_CODE_t e) { while (1); }
the errorcode is: ctl_unsupported_call_from_isr
I was searching in the internet and also in the crossworks reference manual and found the following solutions for my problem:
void USB_LP_CAN1_RX0_IRQHandler(void){
ctl_enter_isr();
USB_Istr();
ctl_exit_isr();
}
or from the manual:
store registers;
ctl_interrupt_count++;
and on exit from an ISR
ctl_interrupt_count--;
if (ctl_interrupt_count == 0 && ctl_reschedule_on_last_isr_exit);
{
ctl_reschedule_on_last_isr_exit = 0;
reschedule
}
else
restore registers
But both of them are not working properly. Is there anything else what i can try?
BR Tarkan
-
Can you backtrace out of the error handler to see what CTL api function was being used? If not then add the source code to the project (it's in $(StudioDir)/ctl/source).
You'll need to ensure that the priority of the interrupt handler is in the lowest half of the priority range if it uses CTL api calls.
-
Sorry but i cannot backtrace.
Now i found out that if there is a new-operator in between a ctl_enter_isr(); and ctl_exit_isr(); this problem pops up.
here is a part of my code:
void USB_LP_CAN1_RX0_IRQHandler(void)
{
ctl_enter_isr();
USB_Istr(); // this function makes some stuff and calls "void EP3_OUT_Callback(void)"
ctl_exit_isr();
}extern "C" void EP3_OUT_Callback(void)
{
////////////////////////////////////// QUEUE with Event
unsigned char* MyPointer;
MyPointer = new unsigned char[67];
unsigned short MyLength;
MyLength = USB_SIL_Read( EP3_OUT , &MyPointer[2] );
Test += MyLength;
MyPointer[0] = (MyLength>>8);
MyPointer[1] = (MyLength & 0xFF);
ctl_message_queue_post_nb( &RxQueue_RawData, (void*)MyPointer );
/* Enable the receive of data on EP3 */
SetEPRxValid(ENDP3);
/////////////////////////////////////////////////////////
}And here is the code which runs not on the ISR (it runs in a single thread)
void Connection_Class::GetData(void)
{
while(1)
{
// wait for receive event
ctl_events_wait(CTL_EVENT_WAIT_ANY_EVENTS, &Events_RawData, 0x01, CTL_TIMEOUT_NONE, 0);
void* Commando;
ctl_message_queue_receive(&RxQueue_RawData, &Commando, CTL_TIMEOUT_NONE, 0);
unsigned char* pData;
pData = (unsigned char*)Commando;
unsigned short MyLength;
MyLength = (pData[0] << 8) | pData[1];
ReceiveFromPort(&pData[2], MyLength);
delete [] pData;
}//END while(1);
}//END GetData();and there is also the following codeline:
ctl_message_queue_setup_events(&RxQueue_RawData, &Events_RawData, 0x01, 0);
-
The new from the ISR will call ctl_events_wait to lock the heap - hence the error. CrossWorks should be able to do a better job of backtracing out of libraries in the 2.2 release - give it a try..
http://www.rowleydownload.co.uk/snapshots/arm_crossworks_crossworks_v2_win_x86_setup.exe
Please sign in to leave a comment.
Comments
6 comments