Skip to content

Commit

Permalink
refactoring; move firmware code out of python module
Browse files Browse the repository at this point in the history
Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
  • Loading branch information
Ho-Ro committed Feb 24, 2024
1 parent 1c46ba5 commit 0ddab5e
Show file tree
Hide file tree
Showing 207 changed files with 11,804 additions and 1,720 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2024-02-23: rework the serial number routine [1c46ba5]
2024-02-20: Merge branch 'main' of github.com:Ho-Ro/Hantek6022API [c8cee4c]
2024-02-20: add warning to dangerous example program reset_eeprom_6022.py [d1ad1a0]
2023-11-05: Merge pull request #22 from BMecke/main [cde80ef]
Expand Down
File renamed without changes.
288 changes: 288 additions & 0 deletions Firmware/DDS120/dds120-firmware.hex

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
285 changes: 285 additions & 0 deletions Firmware/DSO6021/dso6021-firmware.hex

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
287 changes: 287 additions & 0 deletions Firmware/DSO6022BE/dso6022be-firmware.hex

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) 2009 Ubixum, Inc.
* Copyright (C) 2015 Jochen Hoenicke
* Copyright (C) 2019-2024 Martin Homuth-Rosemann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -18,10 +19,13 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/


// CLK_12M; CLK_24M; CLK_48M
#define CPU_FREQ CLK_48M

// 12 MHz: 500; 24 MHz: 1000; 48 MHz: 2000
#define TIMER2_VAL 2000

// CLK_48M & IFCLK30 -> 4 delays
#define SYNCDELAY SYNCDELAY4

Expand Down Expand Up @@ -94,7 +98,7 @@ void timer2_isr( void ) __interrupt TF2_ISR {
}


void set_aadj() {
static void set_aadj() {
if ( samplerate >= 24000 / numchannels ) {
EP2ISOINPKTS &= 0x7f;
} else {
Expand Down Expand Up @@ -191,6 +195,7 @@ static void select_interface( BYTE alt ) {
}
}


#include "waveforms.inc"

struct samplerate_info {
Expand Down Expand Up @@ -228,6 +233,7 @@ static const struct samplerate_info samplerates[] = {
{ 102, waveform_102, ifconfig_102 }, // 20 kS/s
};


static BOOL set_samplerate( BYTE rate ) {
BYTE i = 0;
const BYTE *waveform;
Expand Down Expand Up @@ -257,6 +263,7 @@ static BOOL set_samplerate( BYTE rate ) {
return TRUE;
}


// new functon to set the calibration pulse frequency that allows
// to set all possible frequencies between 32 Hz and 100 kHz
// integer dividers of 2MHz will be exact
Expand Down Expand Up @@ -330,7 +337,7 @@ BOOL handle_set_configuration( BYTE cfg ) {


// handle reading and writing EEPROM data
BOOL eeprom() {
static BOOL eeprom() {
WORD addr = SETUP_VALUE(), len = SETUP_LENGTH();
// 24C02 (small adr mode) recognizes i2c adresses 0x50..0x57
// 24C128 (large adr mode) must be wired to address 0x51
Expand Down Expand Up @@ -448,6 +455,7 @@ static void init( void ) {
select_interface( 0 );
}


// EZ-USB® FX2LP™ Unique ID Registers – KBA89285
// Question:
// Is there a die ID or a unique ID on each EZ-USB® FX2LP™ chip
Expand All @@ -468,20 +476,22 @@ extern __code BYTE serial_num; // defined in descriptor.asm file for the serial
static const char hex2Ascii[ 16 ] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

static void insert_serial_number() {
WORD p_serial_num = (WORD)&serial_num;

// IMPORTANT: be compatible with previous (wrong) implementation
// write lower nibble before upper nibble to get same serial number
// string starts at position 2 of string_descriptor
BYTE __xdata * p_serial_num = (BYTE __xdata *)&serial_num + 2;

BYTE bbb = 6; // start with MSB
while ( bbb-- ) {
*( (BYTE __xdata *)( p_serial_num += 2 ) ) = hex2Ascii[ UNIQID[ bbb ] & 0x0F ]; // 1. lower nibble
*( (BYTE __xdata *)( p_serial_num += 2 ) ) = hex2Ascii[ UNIQID[ bbb ] >> 4 ]; // 2. upper nibble
// IMPORTANT: be compatible with previous (wrong) implementation
// write lower nibble before upper nibble to get same serial number
*p_serial_num++ = hex2Ascii[ UNIQID[ bbb ] & 0x0F ]; // 1. lower nibble
*p_serial_num++ = 0; // (UTF-16 coding)
*p_serial_num++ = hex2Ascii[ UNIQID[ bbb ] >> 4 ]; // 2. upper nibble
*p_serial_num++ = 0; // (UTF-16 coding)
}
}


static void main( void ) {
void main( void ) {
/* set to 48 MHz */
SETCPUFREQ( CPU_FREQ );

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
287 changes: 287 additions & 0 deletions Firmware/DSO6022BL/dso6022bl-firmware.hex

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions Firmware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# About the firmware
The 6022BE (and 6022BL) has only limited persistent storage so the firmware must be uploaded to the device's RAM
every time the oscilloscope is powered up.
The dump of the packet transfer to the 6022BE was captured by [Robert](https://github.com/rpcope1/Hantek6022API)
and is given as `firmware_packet_dump.csv` and was used by him to build the **stock_firmware** in this module.

This stock version was later analysed and improved by [Jochen](https://github.com/jhoenicke/Hantek6022API)
and Robert to create the two **mod_firmware** versions.
Without source code this was a not so easy task - good work!
If you're interested in the details read the huge EEVBLOG thread, this is a
[good starting point](https://www.eevblog.com/forum/testgear/hantek-6022be-20mhz-usb-dso/msg656059/#msg656059).

The original custom firmware (for 6022BE) is based on fx2lib code. The latest version also allows reading/writing of EEPROMs and thus has all features like the stock and modded versions and allows an easy implementation of new features.

My project [OpenHantek6022](https://github.com/OpenHantek/OpenHantek6022) uses the improved final versions [DSO6022BE](https://github.com/Ho-Ro/Hantek6022API/tree/master/PyHT6022/Firmware/DSO6022BE), [DSO6022BL](https://github.com/Ho-Ro/Hantek6022API/tree/master/PyHT6022/Firmware/DSO6022BL) and [DDS120](https://github.com/Ho-Ro/Hantek6022API/tree/master/PyHT6022/Firmware/DDS120) for the currently supported scope variants. These FWs provide more sampling rates (20 kS/s .. 30 MS/s) and more calibration-out frequencies as well as support for AC/DC coupling (small HW mod requred for Hantek scopes).

Provided are different FW flavours as part of the python package:

| **Name** | **Path** | **Comment** |
|--------------------|------------------------------|------------------------------------------------------------------|
| stock_firmware | stock/stock_fw.ihex | Firmware that was originally uploaded to the device by vendor SW |
| mod_firmware_01 | modded/mod_fw_01.ihex | Patched stock firmware with sample rate and stability improvements |
| mod_firmware_iso | modded/mod_fw_iso.ihex | Patched stock firmware that allows isochronous transfer (instead of bulk) |
| dso6022be_firmware | DSO6022BE/dso6022be-firmware.hex | backported from sigrok-fw |
| dso6022bl_firmware | DSO6022BL/dso6022bl-firmware.hex | backported from sigrok-fw |
| dds120_firmware | DDS120/dds120-firmware.hex | backported from sigrok-fw |

Default:
firmware = default_firmware = dso6022be_firmware
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const uint16_t DSO602x_FW_VER = 0x0210;

// setup.py: __version__ = '2.10.6'
// setup.py: __version__ = '2.10.7'
// PyHT6022/LibUsbScope.py: FIRMWARE_VERSION = 0x0210
// PyHT6022/Firmware/DSO6022BE/descriptor.inc: FIRMWARE_VERSION = 0x1002
// Firmware/DSO6022BE/descriptor.inc: FIRMWARE_VERSION = 0x1002

21 changes: 21 additions & 0 deletions Firmware/fx2lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*~
.*~
*.orig
*.new
*.asm
*.rel
*.lst
*.sym
*.adb
*.cdb
*.ihx
*.bix
*.rst
*.mem
*.map
*.lnk
*.kpf
*.swp
*.iic
docs/html
build
32 changes: 32 additions & 0 deletions Firmware/fx2lib/CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
0.2
* Change I2C routines to return FALSE intead of infinite loop possibility.
* Addition of fx2load script to load eeprom information.
* EEprom upload/download example.
* New SETUP_TYPE macro
* Removed printfs from setupdat module.
* Add usb "other speed" descriptor handling to setupdat
* Support for usb suspend/wakeup
* Enhanced renumerate macro to handle properly when loading from eeprom
* Addition of framework files. Allows quick starting of new firmware projects.
* ihx2iic helper script. Allows easy converting of ihx files to iic for
loading to eeprom.
* New GPIF macros to set TC with 16 or 32 bit values.
* Addtional enable/disable macros for endpoint interrupts.
* Additional ep0 utilities (writeep0)
* Additional i2c write functionality for i2c parts requiring different
address width's or even no address data.
* Correct fx2 register documentation.
* Addition of serial io example.
* Added cancel_i2c_trans extern bool to allow canceling a blocked i2c transaction.
* FX1 development board debug light addresses.
* Various other minor bug fixes/optimizations.
* remove usbjt.h. In place, use autovector.h. jump table routines no longer
need defined in your firmware. fx2.lib contains default routines. Override
them with interrupt handlers you want to handle.
* added fx2ints.h. Interrupt numbers/macros for standard fx2 interrupts.
* added timer example
* Moved examples and firmwware framework to use common lib/fx2.mk Makefile.
fx2.mk can be easily adapted for any firmware project.

0.1
* Initial Release.
Loading

0 comments on commit 0ddab5e

Please sign in to comment.