cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS and function pointers for CDC_Receive_FS

ErX
Associate III

Hi,

STM32G484 is running well with FreeRTOS.

The only thing left is to transfer the USB communication into the RTOS-task.

Is it possible to redirect the function pointer, which is used now, to another function?

Greetings,

ErX

3 REPLIES 3
ErX
Associate III

Hi,

I used a static class method to put in the 'USB_CDC_RxHandler'-method.

To get the CDC USB communication to work, I had to add this in the main.cpp:

void USB_CDC_RxHandler(uint8_t* Buf, uint32_t Len)
{
  if (Len)
  {
    HAL_GPIO_WritePin(GPIOA, LED_STATUS_Pin, Buf[0] == 'a' ? GPIO_PIN_SET : GPIO_PIN_RESET);
    if (Buf[0] == 'b')
    {
      *ibs_boot_flag = IBS_BOOT_FLAG;
      HAL_NVIC_SystemReset();
    }
    for (uint32_t i=0; i < Len; i++)
      Buf[i]++;
    CDC_Transmit_FS(Buf, Len);
  }
}

This example can jump to my boot loader. The 'a' key will light up a LED. All other keys will switch the LED off.

All data is echoed back, just after adding 1 ('a' -> 'b', etc).

I have a controller class, which handles the main-task. I've added a static method 'static void DataReceived(uint8_t* Buf, uint32_t Len);'. And two static variables:

  static uint8_t m_Buffer[1024];
  static bool m_bMessageReceived;

 

Changed the 'USB_CDC_RxHandler'-method to:

void USB_CDC_RxHandler(uint8_t* Buf, uint32_t Len)
{
  if (Len)
  {
    controller->DataReceived(Buf, Len);
    if (Buf[0] == 'b')
    {
      *ibs_boot_flag = IBS_BOOT_FLAG;
      HAL_NVIC_SystemReset();
    }
    for (uint32_t i=0; i < Len; i++)
      Buf[i]++;
    CDC_Transmit_FS(Buf, Len);
  }
}

'Controller::DataReceived' looks like this:

void Controller::DataReceived(uint8_t* Buf, uint32_t Len)
{
  memcpy(&m_Buffer, Buf, Len);
  m_bMessageReceived = true;
  if (Buf[0] && Buf[0] == 'c')
    return;
}

In the task-while loop, I'm checking the 'm_bMessageReceived'. If set to true, the contents of the buffer is handled.

This is not the best idea in the world (so can really get some better solutions). But at least I can continue testing.

Greetings,

ErX

FBL
ST Employee

Hi @ErX 

First, are you using STM32 as device or host?

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.




Best regards,
FBL
ErX
Associate III

@FBL I'm using it as a device. Basically, just as a virtual com port.

Greetings,

ErX