Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kr return -536854449 error #15

Open
WadeZhao23 opened this issue May 13, 2019 · 5 comments
Open

kr return -536854449 error #15

WadeZhao23 opened this issue May 13, 2019 · 5 comments

Comments

@WadeZhao23
Copy link

First, Thanks to the good repo.
I use the demo to send a command to USB device.
But the kr is -536854449.
`func getStatus() throws -> [UInt8] {
//Getting device interface from our pointer
guard let deviceInterface = self.deviceInfo.deviceInterfacePtrPtr?.pointee?.pointee else {
throw STM32DeviceError.DeviceInterfaceNotFound
}

    var kr:Int32 = 0
    let length:Int = 2
    var requestPtr:[UInt8] = [UInt8](repeating: 0, count: length)
    // Creating request
    var request = IOUSBDevRequest(bmRequestType: 161,
                                  bRequest: STM32REQUEST.DNLOAD.rawValue,
                                  wValue: 0,
                                  wIndex: 0,
                                  wLength: UInt16(length),
                                  pData: &requestPtr,
                                  wLenDone: 255)
    
    kr = deviceInterface.DeviceRequest(self.deviceInfo.deviceInterfacePtrPtr, &request)
    
    if (kr != kIOReturnSuccess) {
        throw STM32DeviceError.RequestError(desc: "Get device status request error: \(kr)")
    }
    
    return requestPtr
}`
@Arti3DPlayer
Copy link
Owner

What usb device are you using ? You should use bRequest, bmRequestType according to your usb device specs

@WadeZhao23
Copy link
Author

What usb device are you using ? You should use bRequest, bmRequestType according to your usb device specs

OK,Thanks for your reply.
I am not familiar with USB device, so I met this stupid issue.

@gioele-santi
Copy link

Hi, I am facing similar problems and found out this is the way to read kernel return errors.

let systemError = String(format:"%02X", ((kr >> 26) & 0x3f))
let subError =  String(format:"%02X", ((kr >> 14) & 0xfff))
let codeError = String(format:"%02X",  ( kr & 0x3fff))

Meaning of errors for system and subsystem are in this header: https://opensource.apple.com/source/xnu/xnu-201/iokit/IOKit/
While USB errors are in this one:
https://opensource.apple.com/source/IOUSBFamily/IOUSBFamily-402.4.1/IOUSBFamily/Headers/USB.h.auto.html

@gioele-santi
Copy link

I am trying to understand better how the IOKit for USB works but it is very hard to find documentation (I am trying to send a custom data packet to an USB sensor that appears as a STM32 Mass Storage device). I am looking for device docs but it would be nice to understand the name of the variables. eg: What does the b and bm stand for in bRequest and bmRequestType? Do you know? Or maybe there's some kind of documentation you can suggest me?

@Arti3DPlayer
Copy link
Owner

I am trying to understand better how the IOKit for USB works but it is very hard to find documentation (I am trying to send a custom data packet to an USB sensor that appears as a STM32 Mass Storage device). I am looking for device docs but it would be nice to understand the name of the variables. eg: What does the b and bm stand for in bRequest and bmRequestType? Do you know? Or maybe there's some kind of documentation you can suggest me?

only on apple: https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/Introduction/Introduction.html#//apple_ref/doc/uid/TP0000011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants