2013-11-04 03:10 AM
Hi u guys
I have in a old powerpoint slide from ST, seen that ST can provide a usb printer Class, does anyone know if the can and/or where to find it?Best regards. #usb-printer2013-11-06 05:00 AM
Hi Soeren,
Unfortunately, we don't have an implementation of the USB printer class. But, starting from our other classes like CDC or MassStorage, you should get it by your self. -Mayla-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.
2014-08-12 02:43 AM
Dear Panduro Soeren,
We are very interested to know if you managed to write your own USB Printer Class ?We are trying to do so based on STM32Cube and the USB Host Library from ST. Any work we can do in common ?Best Regards,Georges2014-08-12 11:08 AM
Hi GPTechinno,
> We are very interested to know if you managed to write your own USB Printer Class ? > We are trying to do so based on STM32Cube As ST’s staff said in above post, you may start with one of existing host class driver implementation, like MSC (Mass-Storage Class). But surely, just showing a starting point isn’t helpful answer ;-) You’ll need some guidance, how to modify the implementation. Here is brief outline of modification, based on STM32Cube_FW_F4_V1.3.0 0) Start with - \STM32Cube_FW_F4_V1.3.0\Projects\STM324xG_EVAL\Applications\USB_Host\MSC_Standalone\Src\main.c - \STM32Cube_FW_F4_V1.3.0\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c 1) make Class driver object (structure instance), and register it usbh_msc.c defines this class driver structureusbh_msc.c
USBH_ClassTypeDef USBH_msc =
{
''MSC'',
USB_MSC_CLASS,
USBH_MSC_InterfaceInit,
USBH_MSC_InterfaceDeInit,
USBH_MSC_ClassRequest,
USBH_MSC_Process,
USBH_MSC_SOFProcess,
NULL,
};
usbh_msc.h
/* MSC Class Codes */
#define USB_MSC_CLASS 0x08
extern USBH_ClassTypeDef USBH_msc;
#define USBH_MSC_CLASS &USBH_msc
This structure is modified for printer class, by replacing ''MSC'' to ''PRN'', like
#define USB_PRN_CLASS 0x07
extern USBH_ClassTypeDef USBH_prn;
#define USBH_PRN_CLASS &USBH_prn
USBH_ClassTypeDef USBH_prn =
{
''MSC'',
USB_PRN_CLASS,
USBH_PRN_InterfaceInit,
USBH_PRN_InterfaceDeInit,
USBH_PRN_ClassRequest,
USBH_PRN_Process,
USBH_PRN_SOFProcess,
NULL,
};
main.c registers this class driver object.
main.c
int main(void)
{
...
/* Add Supported Class */
//USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS);
USBH_RegisterClass(&hUSBHost, USBH_PRN_CLASS);
2) code class driver routines
2-1) USBH_PRN_InterfaceInit() <- USBH_MSC_InterfaceInit()
This routine find printer interface on the descriptor set using USBH_FindInterface()
//interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, MSC_TRANSPARENT, MSC_BOT);
#define PRN_PRINTERS 0x01 // sub-class
#define PRN_UNIDIRECTIONAL 0x01 // protocols
#define PRN_BIDIRECTIONAL 0x02
#define PRN_1284_4 0x03
#define PRN_VENDOR 0xFF
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, PRN_PRINTERS, PRN_BIDIRECTIONAL);
Your target printer may have other class-protocol value than PRN_BIDIRECTIONAL.
Find it using a utility, like USBView
http://www.ftdichip.com/Support/Utilities/usbview.zip
The rest of code lines are (almost) usable as is, except
- replace every ''MSC'' into ''PRN'' on the variable names
- you don’t need these MSC-specific code lines in this routine.
MSC_Handle->current_lun = 0;
MSC_Handle->rw_lun = 0;
USBH_MSC_BOT_Init(phost);
/* De-Initialize LUNs information */
USBH_memset(MSC_Handle->unit, 0, sizeof(MSC_Handle->unit));
2-2) USBH_PRN_InterfaceDeInit() <- USBH_MSC_InterfaceDeInit()
No change required.
2-3) USBH_PRN_ClassRequest() <- USBH_MSC_ClassRequest()
In the code lines under ''case MSC_REQ_GET_MAX_LUN:'', the original puts Get_Max_Lun request to the target USB stick. Instead, GET_DEVICE_ID request is put to the printer.
By GET_DEVICE_ID request, the printer returns DEVICE_ID string, which holds supported PDLs (Page Description Language) after ''CMD:'' tag. You need a ''PCL'' printer, as you said your other post. Confirm the printer should support one of ''PCL'' protocols.
For DEVICE_ID string, refer to this port.
http://www.keil.com/forum/57021/
2-4) USBH_PRN_Process() <- USBH_MSC_Process()
This routine is repeatedly called by the main loop, by USBH_Process(), to run the class.
The original code is fully MSC-specific. Then rewrite entire code lines.
For printer class, the printer status (paper empty, on-line, error) is retrieved by GET_PORT_STATUS request
2-5) The PCL data is sent to the printer over the bulk OUT endpoint, using USBH_BulkSendData(PRN_Handle->OutPipe)
The completion of transfer is detected by polling USBH_LL_GetURBState(), until it returns USBH_URB_DONE.
Tsuneo
2015-08-14 10:23 AM
Hi Tsuneo,
I'm trying to develop the printer class, but I'm facing a strange situation. When I plug my printer (HP LaserJet P1102W) to the USB port, ir reports as class 8 (MSC). I debugged this with a USB viewing utility running on the PC, connected the printer to the PC USB port, and I see that for a moment it detects the printer as MSC, then it gets disconected, and the returns a composite USB device with class 7 (printer).Do you know something about this, and/or what to do?Thank you.Fernando2015-08-14 01:33 PM
I have an HP LaserJet P1102W, it presents a MSC to provide drivers/installation for Windows. Perhaps you should check what Windows sends with a protocol analyzer to disconnect/eject the MSC and come back as a printer.
2015-08-18 05:07 AM
ah ok Clive, that's good information. Thank you very much.
I will investigate with an analyzer tool.RegardsFernando2016-11-24 05:35 AM
Hi Tsuneo,
I am trying to implement USB printer class.
Instead of STM324xG_EVAL I am using STM32F429I-Discovery. I have tried to convert FWupgrade_Standalone example to Printer class as per the steps mentioned by you.I am unable to detect printer. I am using HP Laserjet P1606dn printer. But I have also tried to convert FWupgrade_Standalone example to HID class, I am able to detect it successfully.
Can you suggest me why I am unable to detect printer?