Skip to content

Commit

Permalink
Merge pull request skot#25 from shufps/nerdaxe
Browse files Browse the repository at this point in the history
initial nerdaxe support
  • Loading branch information
shufps authored Oct 15, 2024
2 parents 1f319b3 + 72c31c5 commit c83a3df
Show file tree
Hide file tree
Showing 42 changed files with 62,278 additions and 36 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
- board: NERDQAXEPLUS2
upload_www: false
label: NerdQAxe++
- board: NERDAXE
upload_www: false
label: NerdAxe

steps:
- name: Checkout repository
Expand Down Expand Up @@ -60,19 +63,19 @@ jobs:
- name: Rename Build Artifacts
run: |
sudo mv build/esp-miner.bin build/esp-miner-${{ matrix.label }}.bin
- name: Create files list
run: |
echo "esp-miner-factory-${{ matrix.label }}-${{ env.VERSION_TAG }}.bin" > file_list.txt
echo "build/esp-miner-${{ matrix.label }}.bin" >> file_list.txt
if [ "${{ matrix.upload_www }}" == "true" ]; then
echo "build/www.bin" >> file_list.txt
fi
- name: Set files variable
id: set_files_var
run: echo "files=$(cat file_list.txt | tr '\n' ',')" >> $GITHUB_ENV

- name: Upload to Existing Release
if: always()
uses: softprops/action-gh-release@v1
Expand Down
1 change: 1 addition & 0 deletions components/bm1397/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
idf_component_register(
SRCS
"asic.cpp"
"bm1366.cpp"
"bm1368.cpp"
"bm1370.cpp"
"serial.cpp"
Expand Down
136 changes: 136 additions & 0 deletions components/bm1397/bm1366.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include <endian.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>

#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "asic.h"
#include "bm1366.h"

#include "crc.h"
#include "serial.h"
#include "utils.h"

static const uint64_t BM1366_CORE_COUNT = 112;
static const uint64_t BM1366_SMALL_CORE_COUNT = 894;

static const char *TAG = "bm1366Module";

static const uint8_t chip_id[6] = {0xaa, 0x55, 0x13, 0x66, 0x00, 0x00};

BM1366::BM1366() : Asic() {
// NOP
}

const uint8_t* BM1366::getChipId() {
return (uint8_t*) chip_id;
}

uint8_t BM1366::init(uint64_t frequency, uint16_t asic_count, uint32_t difficulty)
{
// reset is done externally to not have board dependencies

// enable and set version rolling mask to 0xFFFF
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF);

// enable and set version rolling mask to 0xFFFF (again)
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF);

// enable and set version rolling mask to 0xFFFF (again)
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF);

// enable and set version rolling mask to 0xFFFF (again)
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF);

int chip_counter = count_asics();
ESP_LOGI(TAG, "%i chip(s) detected on the chain, expected %i", chip_counter, asic_count);

// enable and set version rolling mask to 0xFFFF (again)
send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF);

// Reg_A8
send6(CMD_WRITE_ALL, 0x00, 0xA8, 0x00, 0x07, 0x00, 0x00);

// Misc Control
send6(CMD_WRITE_ALL, 0x00, 0x18, 0xFF, 0x0F, 0xC1, 0x00);

// chain inactive
sendChainInactive();

// set chip address
for (uint8_t i = 0; i < chip_counter; i++) {
setChipAddress(i * 2);
}

// Core Register Control
send6(CMD_WRITE_ALL, 0x00, 0x3C, 0x80, 0x00, 0x85, 0x40);

// Core Register Control
send6(CMD_WRITE_ALL, 0x00, 0x3C, 0x80, 0x00, 0x80, 0x20);

setJobDifficultyMask(difficulty);

// Analog Mux Control
send6(CMD_WRITE_ALL, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03);

// Set the IO Driver Strength on chip 00
send6(CMD_WRITE_ALL, 0x00, 0x58, 0x02, 0x11, 0x11, 0x11);

for (uint8_t i = 0; i < chip_counter; i++) {
// Reg_A8
send6(CMD_WRITE_SINGLE, i * 2, 0xA8, 0x00, 0x07, 0x01, 0xF0);
// Misc Control
send6(CMD_WRITE_SINGLE, i * 2, 0x18, 0xF0, 0x00, 0xC1, 0x00);
// Core Register Control
send6(CMD_WRITE_SINGLE, i * 2, 0x3C, 0x80, 0x00, 0x85, 0x40);
// Core Register Control
send6(CMD_WRITE_SINGLE, i * 2, 0x3C, 0x80, 0x00, 0x80, 0x20);
// Core Register Control
send6(CMD_WRITE_SINGLE, i * 2, 0x3C, 0x80, 0x00, 0x82, 0xAA);
}

doFrequencyTransition(frequency);

// register 10 is still a bit of a mystery. discussion: https://github.com/skot/ESP-Miner/pull/167

// send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x00, 0x11, 0x5A); //S19k Pro Default
// send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x00, 0x14, 0x46); //S19XP-Luxos Default
send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x00, 0x15, 0x1C); //S19XP-Stock Default
// send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x0F, 0x00, 0x00); //supposedly the "full" 32bit nonce range
//send6(CMD_WRITE_ALL, 0x00, 0x10, 0x00, 0x00, 0x15, 0xA4); // S21-Stock Default

send6(CMD_WRITE_ALL, 0x00, 0xA4, 0x90, 0x00, 0xFF, 0xFF);

return chip_counter;
}

int BM1366::setMaxBaud(void)
{
// return 115749;
ESP_LOGI(TAG, "Setting max baud of 1000000 ");
send6(CMD_WRITE_ALL, 0x00, 0x28, 0x11, 0x30, 0x02, 0x00);
return 1000000;
}

void BM1366::requestChipTemp() {
// NOP
}

uint8_t BM1366::jobToAsicId(uint8_t job_id) {
return (job_id * 8) & 0x7f;
}

uint8_t BM1366::asicToJobId(uint8_t asic_id) {
return asic_id & 0xf8;
}

uint16_t BM1366::getSmallCoreCount() {
return BM1366_SMALL_CORE_COUNT;
}
1 change: 1 addition & 0 deletions components/bm1397/include/asic.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Asic {

public:
Asic();
virtual const char* getName() = 0;
uint8_t sendWork(uint32_t job_id, bm_job *next_bm_job);
bool processWork(task_result *result);
void setJobDifficultyMask(int difficulty);
Expand Down
23 changes: 23 additions & 0 deletions components/bm1397/include/bm1366.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "driver/gpio.h"
#include "mining.h"
#include "rom/gpio.h"
#include "asic.h"

class BM1366 : public Asic {
protected:
virtual const uint8_t* getChipId();

virtual uint8_t jobToAsicId(uint8_t job_id);
virtual uint8_t asicToJobId(uint8_t asic_id);

public:
BM1366();
virtual const char* getName() { return "BM1366"; };
virtual uint8_t init(uint64_t frequency, uint16_t asic_count, uint32_t difficulty);
virtual int setMaxBaud(void);
virtual void requestChipTemp();
virtual uint16_t getSmallCoreCount();
};

1 change: 1 addition & 0 deletions components/bm1397/include/bm1368.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BM1368 : public Asic {

public:
BM1368();
virtual const char* getName() { return "BM1368"; };
virtual uint8_t init(uint64_t frequency, uint16_t asic_count, uint32_t difficulty);
virtual int setMaxBaud(void);
virtual void requestChipTemp();
Expand Down
1 change: 1 addition & 0 deletions components/bm1397/include/bm1370.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class BM1370 : public BM1368 {

public:
BM1370();
virtual const char* getName() { return "BM1370"; };
virtual uint8_t init(uint64_t frequency, uint16_t asic_count, uint32_t difficulty);
virtual void requestChipTemp();
virtual uint16_t getSmallCoreCount();
Expand Down
5 changes: 5 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ SRCS
"nvs_config.cpp"
"system.cpp"
"boards/board.cpp"
"boards/nerdaxe.cpp"
"boards/nerdqaxeplus.cpp"
"boards/nerdqaxeplus2.cpp"
"boards/nerdoctaxeplus.cpp"
"boards/drivers/EMC2302.cpp"
"boards/drivers/TMP1075.cpp"
"boards/drivers/TPS53647.cpp"
"boards/drivers/nerdaxe/DS4432U.cpp"
"boards/drivers/nerdaxe/INA260.cpp"
"boards/drivers/nerdaxe/EMC2101.cpp"
"boards/drivers/nerdaxe/adc.cpp"
"boards/drivers/i2c_master.cpp"
"history.cpp"

Expand Down
4 changes: 2 additions & 2 deletions main/boards/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ Board::Board() {
void Board::loadSettings()
{
m_asicFrequency = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY);
m_asicVoltage = nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE);
m_asicVoltage = nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0f;
m_fanInvertPolarity = nvs_config_get_u16(NVS_CONFIG_INVERT_FAN_POLARITY, 1);
m_fanPerc = nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100);

ESP_LOGI(TAG, "NVS_CONFIG_ASIC_FREQ %.3f", (float) m_asicFrequency);
ESP_LOGI(TAG, "NVS_CONFIG_ASIC_VOLTAGE %.3f", (float) m_asicVoltage / 1000.0f);
ESP_LOGI(TAG, "NVS_CONFIG_ASIC_VOLTAGE %.3f", (float) m_asicVoltage);
ESP_LOGI(TAG, "NVS_CONFIG_INVERT_FAN_POLARITY %s", m_fanInvertPolarity ? "true" : "false");
ESP_LOGI(TAG, "NVS_CONFIG_FAN_SPEED %d%%", (int) m_fanPerc);
}
Expand Down
1 change: 0 additions & 1 deletion main/boards/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Board {

// abstract common methos
virtual bool setVoltage(float core_voltage) = 0;
virtual uint16_t getVoltageMv() = 0;

virtual void setFanSpeed(float perc) = 0;
virtual void getFanSpeed(uint16_t *rpm) = 0;
Expand Down
2 changes: 1 addition & 1 deletion main/boards/drivers/TPS53647.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ int TPS53647_init(int num_phases)
smb_write_byte(PMBUS_MFR_SPECIFIC_12, 0x20); // default value

// set maximum current
smb_write_byte(PMBUS_MFR_SPECIFIC_10, TPS43647_INIT_IMAX);
smb_write_byte(PMBUS_MFR_SPECIFIC_10, TPS53647_INIT_IMAX);

// operation mode
// VR12 Mode
Expand Down
36 changes: 19 additions & 17 deletions main/boards/drivers/TPS53647.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,27 @@
#define TPS53647_INIT_VOUT_MAX 1.4

#ifdef NERDQAXEPLUS
#define TPS43647_INIT_IMAX 60 /* A (int) */
/* iout current */
#define TPS53647_INIT_IOUT_OC_WARN_LIMIT 50.00 /* A */
#define TPS53647_INIT_IOUT_OC_FAULT_LIMIT 55.00 /* A */
#define TPS53647_INIT_IMAX 60 /* A (int) */
/* iout current */
#define TPS53647_INIT_IOUT_OC_WARN_LIMIT 50.00 /* A */
#define TPS53647_INIT_IOUT_OC_FAULT_LIMIT 55.00 /* A */
#elif defined(NERDQAXEPLUS2)
#define TPS53647_INIT_IMAX 90 /* A (int) */
/* iout current */
#define TPS53647_INIT_IOUT_OC_WARN_LIMIT 80.00 /* A */
#define TPS53647_INIT_IOUT_OC_FAULT_LIMIT 85.00 /* A */
#elif defined(NERDOCTAXEPLUS)
#define TPS53647_INIT_IMAX 90 /* A (int) */
/* iout current */
#define TPS53647_INIT_IOUT_OC_WARN_LIMIT 80.00 /* A */
#define TPS53647_INIT_IOUT_OC_FAULT_LIMIT 85.00 /* A */
#else
/* Default values if none of the conditions match */
#define TPS53647_INIT_IMAX 60 /* Default A (int) */
#define TPS53647_INIT_IOUT_OC_WARN_LIMIT 50.00 /* Default A */
#define TPS53647_INIT_IOUT_OC_FAULT_LIMIT 55.00 /* Default A */
#endif

#ifdef NERDQAXEPLUS2
#define TPS43647_INIT_IMAX 90 /* A (int) */
/* iout current */
#define TPS53647_INIT_IOUT_OC_WARN_LIMIT 80.00 /* A */
#define TPS53647_INIT_IOUT_OC_FAULT_LIMIT 85.00 /* A */
#endif

#ifdef NERDOCTAXEPLUS
#define TPS43647_INIT_IMAX 90 /* A (int) */
/* iout current */
#define TPS53647_INIT_IOUT_OC_WARN_LIMIT 80.00 /* A */
#define TPS53647_INIT_IOUT_OC_FAULT_LIMIT 85.00 /* A */
#endif

#define TPS53647_INIT_IOUT_OC_FAULT_RESPONSE 0xC0 /* shut down, no retries */

Expand Down
48 changes: 48 additions & 0 deletions main/boards/drivers/nerdaxe/DS4432U.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <math.h>
#include "esp_log.h"

#include "i2c_master.h"

#include "DS4432U.h"

// DS4432U+ -- Adjustable current DAC
#define DS4432U_SENSOR_ADDR 0x48 // Slave address of the DS4432U+
#define DS4432U_OUT0_REG 0xF8 // register for current output 0
#define DS4432U_OUT1_REG 0xF9 // register for current output 1

static const char *TAG = "DS4432U";

/**
* @brief Set the current DAC code for a specific DS4432U output.
*
* @param output The output channel (0 or 1).
* @param code The current code value to set.
* @return esp_err_t ESP_OK on success, or an error code on failure.
*/
esp_err_t DS4432U_set_current_code(uint8_t output, uint8_t code) {
uint8_t reg = (output == 0) ? DS4432U_OUT0_REG : DS4432U_OUT1_REG;
return i2c_master_register_write_byte(DS4432U_SENSOR_ADDR, reg, code);
}

/**
* @brief Get the current DAC code value for a specific DS4432U output.
*
* @param output The output channel (0 or 1).
* @param code Pointer to store the current code value.
* @return esp_err_t ESP_OK on success, or an error code on failure.
*/
esp_err_t DS4432U_get_current_code(uint8_t output, uint8_t *code) {
uint8_t reg = (output == 0) ? DS4432U_OUT0_REG : DS4432U_OUT1_REG;
return i2c_master_register_read(DS4432U_SENSOR_ADDR, reg, code, 1);
}

bool DS4432U_test(void)
{
uint8_t data;

/* Read the DS4432U+ WHO_AM_I register, on power up the register should have the value 0x00 */
esp_err_t register_result = i2c_master_register_read(DS4432U_SENSOR_ADDR, DS4432U_OUT0_REG, &data, 1);
ESP_LOGI(TAG, "DS4432U+ OUT0 = 0x%02X", data);
return register_result == ESP_OK;
}
13 changes: 13 additions & 0 deletions main/boards/drivers/nerdaxe/DS4432U.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef DS4432U_H_
#define DS4432U_H_

#include <stdbool.h>
#include "esp_check.h"

#define DS4432_VRFS 0.997

bool DS4432U_test(void);
esp_err_t DS4432U_set_current_code(uint8_t output, uint8_t code);
esp_err_t DS4432U_get_current_code(uint8_t output, uint8_t *code);

#endif /* DS4432U_H_ */
Loading

0 comments on commit c83a3df

Please sign in to comment.