libdrmconf
0.10.4
A library to program DMR radios.
|
Implements the ST MCU extensions for the DFU protocol, aka DfuSe. More...
#include <dfu_libusb.hh>
Public Member Functions | |
DFUSEDevice (const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), uint16_t blocksize=32, QObject *parent=nullptr) | |
Constructor, also connects to the specified VID/PID device found first. More... | |
void | close () |
Closes the connection. | |
uint16_t | blocksize () const |
Returns the blocksize in bytes. | |
bool | setAddress (uint32_t address, const ErrorStack &err=ErrorStack()) |
Sets the read/write reference address. More... | |
bool | readBlock (unsigned block, uint8_t *data, const ErrorStack &err=ErrorStack()) |
Reads a block of data from the device. More... | |
bool | writeBlock (unsigned block, const uint8_t *data, const ErrorStack &err=ErrorStack()) |
Writes a block of data to the device. More... | |
bool | erasePage (uint32_t address, const ErrorStack &err=ErrorStack()) |
Erases an entire page of memory at the specified address. More... | |
bool | eraseAll (const ErrorStack &err=ErrorStack()) |
Erases the entire memory. More... | |
bool | releaseReadLock (const ErrorStack &err=ErrorStack()) |
Releases the read lock. More... | |
bool | leaveDFU (const ErrorStack &err=ErrorStack()) |
Leaves the DFU mode, may boot into the application code. | |
Public Member Functions inherited from DFUDevice | |
DFUDevice (const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr) | |
Opens a connection to the USB-DFU device at vendor vid and product pid . | |
virtual | ~DFUDevice () |
Destructor. | |
bool | isOpen () const |
Returns true if the DFU device interface is open. | |
void | close () |
Closes the DFU interface. | |
int | download (unsigned block, uint8_t *data, unsigned len, const ErrorStack &err=ErrorStack()) |
Downloads some data to the device. | |
int | upload (unsigned block, uint8_t *data, unsigned len, const ErrorStack &err=ErrorStack()) |
Uploads some data from the device. | |
Protected Attributes | |
uint16_t | _blocksize |
Holds the block size in bytes. | |
Protected Attributes inherited from DFUDevice | |
libusb_context * | _ctx |
USB context. | |
libusb_device_handle * | _dev |
USB device object. | |
status_t | _status |
Device status. | |
Additional Inherited Members | |
Static Public Member Functions inherited from DFUDevice | |
static QList< USBDeviceDescriptor > | detect (uint16_t vid, uint16_t pid) |
Finds all DFU interfaces with the specified VID/PID combination. | |
Protected Member Functions inherited from DFUDevice | |
int | detach (int timeout, const ErrorStack &err=ErrorStack()) |
Internal used function to detach the device. | |
int | get_status (const ErrorStack &err=ErrorStack()) |
Internal used function to read the current status. | |
int | clear_status (const ErrorStack &err=ErrorStack()) |
Internal used function to clear the status. | |
int | get_state (int &pstate, const ErrorStack &err=ErrorStack()) |
Internal used function to read the state. | |
int | abort (const ErrorStack &err=ErrorStack()) |
Internal used function to abort the current operation. | |
int | wait_idle (const ErrorStack &err=ErrorStack()) |
Internal used function to busy-wait for a response from the device. | |
Implements the ST MCU extensions for the DFU protocol, aka DfuSe.
This class implements the extensions to the DFU protocaol used by ST for their MCUs. This is also known as DfuSe.
DFUSEDevice::DFUSEDevice | ( | const USBDeviceDescriptor & | descr, |
const ErrorStack & | err = ErrorStack() , |
||
uint16_t | blocksize = 32 , |
||
QObject * | parent = nullptr |
||
) |
Constructor, also connects to the specified VID/PID device found first.
The blocksize
specifies the blocksize for every read and write operation.
bool DFUSEDevice::eraseAll | ( | const ErrorStack & | err = ErrorStack() | ) |
Erases the entire memory.
Not reconmended.
bool DFUSEDevice::erasePage | ( | uint32_t | address, |
const ErrorStack & | err = ErrorStack() |
||
) |
Erases an entire page of memory at the specified address.
A page is usually 0x10000 bytes large.
bool DFUSEDevice::readBlock | ( | unsigned | block, |
uint8_t * | data, | ||
const ErrorStack & | err = ErrorStack() |
||
) |
Reads a block of data from the device.
The address is computed as base address + block*blocksize, where the base address is set using the setAddress
method.
bool DFUSEDevice::releaseReadLock | ( | const ErrorStack & | err = ErrorStack() | ) |
Releases the read lock.
This usually also erases the entire memory. Not reconmended.
bool DFUSEDevice::setAddress | ( | uint32_t | address, |
const ErrorStack & | err = ErrorStack() |
||
) |
Sets the read/write reference address.
By default this is 0x08000000
(flash program memory address on ST devices).
bool DFUSEDevice::writeBlock | ( | unsigned | block, |
const uint8_t * | data, | ||
const ErrorStack & | err = ErrorStack() |
||
) |
Writes a block of data to the device.
The address is computed as base address + block*blocksize, where the base address is set using the setAddress
method.