mostly @mikroe team:
Since the network/ethernet transfer is not reliable (see viewtopic.php?f=172&t=76904), I was looking to alternatives, such as PIC32MZ and even USB. My current experiment is to use the mentioned project on PIC32MZ2048EFM144 (some old Microchip board), with both networking and USB (compiler: mP for PIC32 v4.0.0). For now, I want to use USB as a debugging channel, which sends debugging data to PC "as fast as possible".
First encountered problem was that the USB Device Library (https://libstock.mikroe.com/projects/vi ... ce-library) does not support PIC32MZ. So I went on looking at the built-in USB HID library.
The only option which works (and yes, this is also unstable), is the polling mode. If I want to use the interrupt mode (enabled from USB_dsc), the PC (Win 8.1) does not recognize the device. It appears that the PIC enters some loop, because on Windows, it keeps connecting and disconnecting. Although the help mentions only one type of USB interrupts, the library exposes a second one, with dma. So either using USB_Interrupt_Proc or USB_Dma_Interrupt_Proc, allocated at the proper vector addresses, the behaviour is the same as described above. The example, provided by the compiler installation, has some additional interrupt priority and DMA settings, which are not mentioned in the help.
I went back to using polling, because this is the only working option, however sending data from PIC to PC, the transfer misses data. I don't know at which side the problem is, but it looks like some of the HID_Write calls are ignored.
The mP help mentions using a while loop and call HID_Write until success, but it is a blocking call from which it cannot recover. The mentioned solution is to call USB_Break, which is not available on PIC32MZ.
Anyway, USB_Break should be called from an interrupt, but by using polling, which interrupt should be used? The help does not mention if an USB interrupt should be used or a timer interrupt.
Also, the help says that that HID_Write and Gen_Write are blocking calls. Not sure about Gen_Write, but HID_Write by itself is not blocking. Only using the mentioned while loop, which calls HID_Write, is blocking.
Another issue with the help is that it misses Gen_RegisterEndpoint routine. I may not use it, but I thought to mention it.
BTW, the USB HID bootloader, works just fine. It does not appear to miss any data.
I want my application (at least this experiment) to send data to PC as fast as possible, so it won't interfere with the network transfer. So, the big question, will we see support for the USB Device library for PIC32MZ? I hope that by using CDC, the speed will be higher. These devices (MZ) support Hi-Speed, so that should do it.
I don't have a working project at the moment, but for the record, here is how I use the HID_Write call, without the blocking loop:
Code: Select all
var
USBRecBuffer, USBSendBuffer: array[64] of Byte;
USBBufferSuccessfullySentToPC: Boolean;
ItemRemovedFromFIFO: Boolean;
procedure SendDynTFTFIFOItemToUSB;
begin
if USBBufferSuccessfullySentToPC then
ItemRemovedFromFIFO := GetItemFromFIFO(@USBSendBuffer);
if ItemRemovedFromFIFO then
begin
USBBufferSuccessfullySentToPC := False;
if HID_Write(@USBSendBuffer, 64) <> 0 then
begin
USBBufferSuccessfullySentToPC := True;
ItemRemovedFromFIFO := False;
end;
end;
LED_R := not LED_R;
end;
//main loop:
repeat
//other stuff
Net_Ethernet_Intern_doPacket;
USB_Polling_Proc;
SendDynTFTFIFOItemToUSB;
until False;
Thank you