cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS and function pointers for CDC_Receive_FS

ErX
Associate II

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

1 REPLY 1
ErX
Associate II

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