Skip to content

Commit facf89a

Browse files
authored
Merge pull request #669 from BitMaker-hub/prerelease
v1.8.1
2 parents a8bbd8d + d31cbc9 commit facf89a

File tree

8 files changed

+104
-57
lines changed

8 files changed

+104
-57
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ jobs:
6767
generate_release_notes: true
6868
make_latest: true
6969
fail_on_unmatched_files: true
70-
files: ${{ github.workspace }}/firmware/*/*.bin
70+
files: ${{ github.workspace }}/**/*.bin
7171

platformio.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ framework = arduino
594594
extra_scripts =
595595
pre:auto_firmware_version.py
596596
post:post_build_merge.py
597-
post:post_build_merge.py
597+
board_build.f_cpu = 240000000L
598598
monitor_filters =
599599
esp32_exception_decoder
600600
time
@@ -613,7 +613,10 @@ build_flags =
613613
-D ARDUINO_USB_MODE=1
614614
-D ARDUINO_USB_CDC_ON_BOOT=1
615615
-D NERDMINERV2=1
616+
-D CORE_DEBUG_LEVEL=0
617+
-D CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL=0
616618
;-D DEBUG_MINING=1
619+
;To enable I2C mining in future: -D ENABLE_I2C_MINING=1
617620
lib_deps =
618621
https://github.com/takkaO/OpenFontRender#v1.2
619622
bblanchon/ArduinoJson@^6.21.5

src/NerdMinerV2.ino.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,24 @@ void setup()
130130
// Higher prio monitor task
131131
Serial.println("");
132132
Serial.println("Initiating tasks...");
133-
char *name = (char*) malloc(32);
134-
sprintf(name, "(%s)", "Monitor");
135-
BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 10000, (void*)name, 5, NULL,1);
133+
static const char monitor_name[] = "(Monitor)";
134+
#if defined(CONFIG_IDF_TARGET_ESP32)
135+
// Reduced stack for ESP32 classic to save memory
136+
BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 8000, (void*)monitor_name, 5, NULL,1);
137+
#else
138+
BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 10000, (void*)monitor_name, 5, NULL,1);
139+
#endif
136140

137141
/******** CREATE STRATUM TASK *****/
138-
sprintf(name, "(%s)", "Stratum");
139-
#if defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB)
140-
// Free a little bit of the heap to the screen
141-
BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 13500, (void*)name, 4, NULL,1);
142+
static const char stratum_name[] = "(Stratum)";
143+
#if defined(CONFIG_IDF_TARGET_ESP32) && !defined(ESP32_2432S028R) && !defined(ESP32_2432S028_2USB)
144+
// Reduced stack for ESP32 classic to save memory
145+
BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 12000, (void*)stratum_name, 4, NULL,1);
146+
#elif defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB)
147+
// Free a little bit of the heap to the screen
148+
BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 13500, (void*)stratum_name, 4, NULL,1);
142149
#else
143-
BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 15000, (void*)name, 4, NULL,1);
150+
BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 15000, (void*)stratum_name, 4, NULL,1);
144151
#endif
145152

146153
/******** CREATE MINER TASKS *****/
@@ -152,14 +159,27 @@ void setup()
152159
//BaseType_t res = xTaskCreate(runWorker, name, 35000, (void*)name, 1, NULL);
153160
TaskHandle_t minerTask1, minerTask2 = NULL;
154161
#ifdef HARDWARE_SHA265
162+
#if defined(CONFIG_IDF_TARGET_ESP32)
163+
//xTaskCreate(minerWorkerHw, "MinerHw-0", 3584, (void*)0, 3, &minerTask1); // Reduced for ESP32 classic
164+
xTaskCreate(minerWorkerSw, "MinerSw-0", 5000, (void*)0, 1, &minerTask1); // Reduced for ESP32 classic
165+
#else
155166
xTaskCreate(minerWorkerHw, "MinerHw-0", 4096, (void*)0, 3, &minerTask1);
167+
#endif
156168
#else
169+
#if defined(CONFIG_IDF_TARGET_ESP32)
170+
xTaskCreate(minerWorkerSw, "MinerSw-0", 5000, (void*)0, 1, &minerTask1); // Reduced for ESP32 classic
171+
#else
157172
xTaskCreate(minerWorkerSw, "MinerSw-0", 6000, (void*)0, 1, &minerTask1);
173+
#endif
158174
#endif
159175
esp_task_wdt_add(minerTask1);
160176

161177
#if (SOC_CPU_CORES_NUM >= 2)
178+
#if defined(CONFIG_IDF_TARGET_ESP32)
179+
xTaskCreate(minerWorkerSw, "MinerSw-1", 5000, (void*)1, 1, &minerTask2); // Reduced for ESP32 classic
180+
#else
162181
xTaskCreate(minerWorkerSw, "MinerSw-1", 6000, (void*)1, 1, &minerTask2);
182+
#endif
163183
esp_task_wdt_add(minerTask2);
164184
#endif
165185

src/drivers/displays/tDisplayV1Driver.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void tDisplay_BTCprice(unsigned long mElapsed)
206206

207207
// Hashrate
208208
render.setFontSize(25);
209-
render.setCursor(19, 122);
209+
render.setCursor(19, 120);
210210
render.setFontColor(TFT_BLACK);
211211
render.rdrawString(data.currentHashRate.c_str(), 70, 103, TFT_BLACK);
212212

@@ -222,11 +222,11 @@ void tDisplay_BTCprice(unsigned long mElapsed)
222222
background.drawString(data.currentTime.c_str(), 148, 1, GFXFF);
223223

224224
// Print BTC Price
225-
background.setFreeFont(FF24);
226-
background.setTextDatum(TR_DATUM);
225+
background.setFreeFont(FF23);
226+
background.setTextDatum(TL_DATUM);
227227
background.setTextSize(1);
228228
background.setTextColor(0xDEDB, TFT_BLACK);
229-
background.drawString(data.btcPrice.c_str(), 70, 25, GFXFF);
229+
background.drawString(data.btcPrice.c_str(), 82, 50, GFXFF);
230230

231231
// Push prepared background to screen
232232
background.pushSprite(0, 0);
@@ -253,7 +253,7 @@ void tDisplay_DoLedStuff(unsigned long frame)
253253
{
254254
}
255255

256-
CyclicScreenFunction tDisplayCyclicScreens[] = {tDisplay_MinerScreen, tDisplay_ClockScreen, tDisplay_GlobalHashScreen};
256+
CyclicScreenFunction tDisplayCyclicScreens[] = {tDisplay_MinerScreen, tDisplay_ClockScreen, tDisplay_GlobalHashScreen, tDisplay_BTCprice};
257257

258258
DisplayDriver tDisplayV1Driver = {
259259
tDisplay_Init,

src/mining.cpp

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,24 @@
1717
#include <list>
1818
#include <map>
1919
#include "mbedtls/sha256.h"
20+
//I2C mining support (disabled by default for performance)
21+
#ifdef ENABLE_I2C_MINING
2022
#include "i2c_master.h"
23+
#define I2C_SLAVE_ENABLED
24+
#endif
2125

22-
//10 Jobs per second
23-
#define NONCE_PER_JOB_SW 4096
24-
#define NONCE_PER_JOB_HW 16*1024
25-
26-
//#define I2C_SLAVE
26+
// Reduce memory usage for ESP32 classic to prevent crashes
27+
#if defined(CONFIG_IDF_TARGET_ESP32)
28+
#define NONCE_PER_JOB_SW 2048 // Reduced from 4096
29+
#define NONCE_PER_JOB_HW 8*1024 // Reduced from 16*1024
30+
#define JOB_QUEUE_SIZE 2 // Reduced queue size
31+
#define RESULT_QUEUE_SIZE 8 // Reduced result queue
32+
#else
33+
#define NONCE_PER_JOB_SW 4096 // Normal for S3/S2/C3
34+
#define NONCE_PER_JOB_HW 16*1024
35+
#define JOB_QUEUE_SIZE 4 // Normal queue size
36+
#define RESULT_QUEUE_SIZE 16 // Normal result queue
37+
#endif
2738

2839
//#define SHA256_VALIDATE
2940
//#define RANDOM_NONCE
@@ -93,8 +104,11 @@ bool checkPoolConnection(void) {
93104
//Try connecting pool IP
94105
if (!client.connect(serverIP, Settings.PoolPort)) {
95106
Serial.println("Imposible to connect to : " + Settings.PoolAddress);
96-
WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP);
97-
Serial.printf("Resolved DNS got: %s\n", serverIP.toString());
107+
// Only retry DNS resolution if we have an invalid IP
108+
if (serverIP == IPAddress(1,1,1,1)) {
109+
WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP);
110+
Serial.printf("Resolved DNS got: %s\n", serverIP.toString());
111+
}
98112
return false;
99113
}
100114

@@ -229,7 +243,7 @@ void runStratumWorker(void *name) {
229243

230244
std::map<uint32_t, std::shared_ptr<Submition>> s_submition_map;
231245

232-
#ifdef I2C_SLAVE
246+
#ifdef I2C_SLAVE_ENABLED_ENABLED
233247
std::vector<uint8_t> i2c_slave_vector;
234248

235249
//scan for i2c slaves
@@ -330,7 +344,8 @@ void runStratumWorker(void *name) {
330344
//Read pending messages from pool
331345
while(client.connected() && client.available())
332346
{
333-
String line = client.readStringUntil('\n');
347+
static String line; // Reutilizar el mismo objeto String
348+
line = client.readStringUntil('\n');
334349
//Serial.println(" Received message from pool");
335350
stratum_method result = parse_mining_method(line);
336351
switch (result)
@@ -384,7 +399,7 @@ void runStratumWorker(void *name) {
384399
#ifdef RANDOM_NONCE
385400
nonce_pool = RandomGet() & RANDOM_NONCE_MASK;
386401
#else
387-
#ifdef I2C_SLAVE
402+
#ifdef I2C_SLAVE_ENABLED
388403
if (!i2c_slave_vector.empty())
389404
nonce_pool = 0x10000000;
390405
else
@@ -419,7 +434,7 @@ void runStratumWorker(void *name) {
419434
#endif
420435
}
421436
}
422-
#ifdef I2C_SLAVE
437+
#ifdef I2C_SLAVE_ENABLED
423438
//Nonce for nonce_pool starts from 0x10000000
424439
//For i2c slave we give nonces from 0x20000000, that is 0x10000000 nonces per slave
425440
i2c_feed_slaves(i2c_slave_vector, job_pool & 0xFF, 0x20, currentPoolDifficulty, mMiner.bytearray_blockheader);
@@ -468,7 +483,7 @@ void runStratumWorker(void *name) {
468483
}
469484

470485
std::list<std::shared_ptr<JobResult>> job_result_list;
471-
#ifdef I2C_SLAVE
486+
#ifdef I2C_SLAVE_ENABLED
472487
if (i2c_slave_vector.empty() || job_pool == 0xFFFFFFFF)
473488
{
474489
vTaskDelay(50 / portTICK_PERIOD_MS); //Small delay
@@ -516,7 +531,7 @@ void runStratumWorker(void *name) {
516531
s_job_result_list.clear();
517532

518533
#if 1
519-
while (s_job_request_list_sw.size() < 4)
534+
while (s_job_request_list_sw.size() < JOB_QUEUE_SIZE)
520535
{
521536
JobPush( s_job_request_list_sw, job_pool, nonce_pool, NONCE_PER_JOB_SW, currentPoolDifficulty, mMiner.bytearray_blockheader, diget_mid, bake);
522537
#ifdef RANDOM_NONCE
@@ -528,7 +543,7 @@ void runStratumWorker(void *name) {
528543
#endif
529544

530545
#ifdef HARDWARE_SHA265
531-
while (s_job_request_list_hw.size() < 4)
546+
while (s_job_request_list_hw.size() < JOB_QUEUE_SIZE)
532547
{
533548
#if defined(CONFIG_IDF_TARGET_ESP32)
534549
JobPush( s_job_request_list_hw, job_pool, nonce_pool, NONCE_PER_JOB_HW, currentPoolDifficulty, sha_buffer_swap, hw_midstate, bake);
@@ -598,7 +613,7 @@ void minerWorkerSw(void * task_id)
598613
std::lock_guard<std::mutex> lock(s_job_mutex);
599614
if (result)
600615
{
601-
if (s_job_result_list.size() < 16)
616+
if (s_job_result_list.size() < RESULT_QUEUE_SIZE)
602617
s_job_result_list.push_back(result);
603618
result.reset();
604619
}
@@ -804,7 +819,7 @@ void minerWorkerHw(void * task_id)
804819
std::lock_guard<std::mutex> lock(s_job_mutex);
805820
if (result)
806821
{
807-
if (s_job_result_list.size() < 16)
822+
if (s_job_result_list.size() < RESULT_QUEUE_SIZE)
808823
s_job_result_list.push_back(result);
809824
result.reset();
810825
}
@@ -835,17 +850,13 @@ void minerWorkerHw(void * task_id)
835850
uint32_t nend = job->nonce_start + job->nonce_count;
836851
for (uint32_t n = job->nonce_start; n < nend; ++n)
837852
{
838-
//nerd_sha_hal_wait_idle();
839853
nerd_sha_ll_write_digest(digest_mid);
840-
//nerd_sha_hal_wait_idle();
841854
nerd_sha_ll_fill_text_block_sha256(sha_buffer, n);
842-
//sha_ll_continue_block(SHA2_256);
843855
REG_WRITE(SHA_CONTINUE_REG, 1);
844856

845857
sha_ll_load(SHA2_256);
846858
nerd_sha_hal_wait_idle();
847859
nerd_sha_ll_fill_text_block_sha256_inter();
848-
//sha_ll_start_block(SHA2_256);
849860
REG_WRITE(SHA_START_REG, 1);
850861
sha_ll_load(SHA2_256);
851862
nerd_sha_hal_wait_idle();
@@ -1045,7 +1056,7 @@ void minerWorkerHw(void * task_id)
10451056
std::lock_guard<std::mutex> lock(s_job_mutex);
10461057
if (result)
10471058
{
1048-
if (s_job_result_list.size() < 16)
1059+
if (s_job_result_list.size() < RESULT_QUEUE_SIZE)
10491060
s_job_result_list.push_back(result);
10501061
result.reset();
10511062
}
@@ -1067,32 +1078,27 @@ void minerWorkerHw(void * task_id)
10671078
memcpy(sha_buffer, job->sha_buffer, 80);
10681079

10691080
esp_sha_lock_engine(SHA2_256);
1081+
uint32_t processed_nonces = 0; // Track actually processed nonces
10701082
for (uint32_t n = 0; n < job->nonce_count; ++n)
10711083
{
1072-
//((uint32_t*)(sha_buffer+64+12))[0] = __builtin_bswap32(job->nonce_start+n);
1073-
1074-
//sha_hal_hash_block(SHA2_256, s_test_buffer, 64/4, true);
1075-
//nerd_sha_hal_wait_idle();
10761084
nerd_sha_ll_fill_text_block_sha256(sha_buffer);
10771085
sha_ll_start_block(SHA2_256);
10781086

1079-
//sha_hal_hash_block(SHA2_256, s_test_buffer+64, 64/4, false);
10801087
nerd_sha_hal_wait_idle();
10811088
nerd_sha_ll_fill_text_block_sha256_upper(sha_buffer+64, job->nonce_start+n);
10821089
sha_ll_continue_block(SHA2_256);
10831090

10841091
nerd_sha_hal_wait_idle();
10851092
sha_ll_load(SHA2_256);
10861093

1087-
//sha_hal_hash_block(SHA2_256, interResult, 64/4, true);
1088-
nerd_sha_hal_wait_idle();
10891094
nerd_sha_ll_fill_text_block_sha256_double();
10901095
sha_ll_start_block(SHA2_256);
10911096

10921097
nerd_sha_hal_wait_idle();
10931098
sha_ll_load(SHA2_256);
10941099
if (nerd_sha_ll_read_digest_swap_if(hash))
10951100
{
1101+
processed_nonces++; // Only count successful hash operations
10961102
//~5 per second
10971103
double diff_hash = diff_from_target(hash);
10981104
if (diff_hash > result->difficulty)
@@ -1109,10 +1115,12 @@ void minerWorkerHw(void * task_id)
11091115
(uint8_t)(n & 0xFF) == 0 &&
11101116
s_working_current_job_id != job_in_work)
11111117
{
1112-
result->nonce_count = n+1;
1118+
result->nonce_count = processed_nonces; // Use actual processed count
11131119
break;
11141120
}
11151121
}
1122+
// Update final count with actual processed nonces
1123+
result->nonce_count = processed_nonces;
11161124
esp_sha_unlock_engine(SHA2_256);
11171125
} else
11181126
vTaskDelay(2 / portTICK_PERIOD_MS);

0 commit comments

Comments
 (0)