cancel
Showing results for 
Search instead for 
Did you mean: 

CDC_Receive_FS() is undefinded in code generated by the cubemx plugin??

andreas kellermann
Associate II

I set up a very simple test project. It is a .ioc file from another project to which I wanted to add a virtual com port interface. I added the vcp in the cube plugin and generated the code. However, if I include a CDC_Receive_FS() function this gets flagged as undefined.

If I click on the function and open declearation the function declaration does pop up.

I tried to include the paths again manualy. No change.

Attached is the code I'm working with. There is only the FastNeopixel.ioc and the two lines in main:

uint8_t buf[2] = {0x01};
CDC_Receive_FS(buf, 2);

Which have been added / changed.

Thank you in advance.

Andreas

Build Console Output:

22:43:12 **** Incremental Build of configuration Debug for project FastNeopixel ****
make -j16 all 
arm-none-eabi-gcc -o "FastNeopixel.elf" @"objects.list"   -mcpu=cortex-m3 -T"C:\Users\justRandom\STM32CubeIDE\workspace_1.3.0\FastNeopixel\STM32F103C8TX_FLASH.ld" --specs=nosys.specs -Wl,-Map="FastNeopixel.map" -Wl,--gc-sections -static --specs=nano.specs -mfloat-abi=soft -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
Core/Src/main.o: In function `main':
C:/Users/justRandom/STM32CubeIDE/workspace_1.3.0/FastNeopixel/Debug/../Core/Src/main.c:115: undefined reference to `CDC_Receive_FS'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:48: FastNeopixel.elf] Error 1
"make -j16 all" terminated with exit code 2. Build might be incomplete.
 
22:43:13 Build Failed. 2 errors, 0 warnings. (took 738ms)

2 REPLIES 2
andreas kellermann
Associate II

So.. cdc_receive_fs() is a callback only locally available...

I found this: https://controllerstech.com/send-and-receive-data-to-pc-without-uart-stm32-usb-com/

(Thank you ST for this helpfull tutorial! ^^).

I extended it a bit and also define the lenght variable to acces it in the main:

	 if(dataInBuffer > 0)
 
	 {
 
		 CDC_Transmit_FS(buffer, dataInBuffer);
 
		 dataInBuffer = 0;
 
	 }

Then you need to define in main.c

uint8_t buffer[1024];
uint32_t dataInBuffer = 0;

In usbd_cdc_if.c

/* USER CODE BEGIN PRIVATE_TYPES */
 
extern uint8_t buffer[1024]; //USERCODE
extern dataInBuffer; //USERCODE
 
/* USER CODE END PRIVATE_TYPES */

Finaly modify the receive callback:

static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceFS);
 
  dataInBuffer = 0;
  memset (buffer, '\0', 1024);  // clear the buffer
  uint8_t len = (uint8_t)*Len;
  memcpy(buffer, Buf, len);  // copy the data to the buffer
  memset(Buf, '\0', len);   // clear the Buf also
  dataInBuffer = len;
 
  return (USBD_OK);
  /* USER CODE END 6 */
}

Hope this helps ^^

How do you scan the input from the user with this code?