From da0fea8a338eddba944b570d426998d1734757e3 Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Tue, 9 Sep 2025 11:34:22 +0700 Subject: [PATCH 1/4] =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=20?= =?UTF-8?q?=D0=B1=D1=83=D1=84=D0=B5=D1=80=D0=B0=20=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D0=B5=D0=BC=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C,=20=D1=82?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B5=D1=81=D0=BB=D0=B8=20?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=B5=20=D0=BD=D0=B5=20=D0=B1=D1=8B?= =?UTF-8?q?=D0=BB=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/arduino/HardwareSerial.cpp | 10 ++++------ cores/arduino/HardwareSerial.h | 12 ++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index a0a6642..6eb0bf9 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -121,18 +121,16 @@ int HardwareSerial::availableForWrite(void) void HardwareSerial::rx_complete_irq(void) { // which UART to use - UART_TypeDef* uart = UART_0; - if (uartNum == 1) - uart = UART_1; - - // find next index in buffer with upper limit - uint8_t i = (uint8_t)(_rx_buffer_head + 1)%SERIAL_RX_BUFFER_SIZE; + UART_TypeDef* uart = (uartNum == 1) ? UART_1 : UART_0; + rx_buffer_index_t i; unsigned char c; // while there is something to receive, put the data into the buffer // and edit the buffer index while(!UART_IS_RX_FIFO_EMPTY(uart)) { c = UART_READ_BYTE(uart); + // find next index in buffer with upper limit + i = (unsigned int)(_rx_buffer_head + 1)%SERIAL_RX_BUFFER_SIZE; if (i != _rx_buffer_tail) { // write if there is space in the buffer diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h index 792bf13..5791740 100644 --- a/cores/arduino/HardwareSerial.h +++ b/cores/arduino/HardwareSerial.h @@ -41,7 +41,15 @@ // often work, but occasionally a race condition can occur that makes // Serial behave erratically. See https://github.com/arduino/Arduino/issues/2405 +#if !defined(SERIAL_RX_BUFFER_SIZE) #define SERIAL_RX_BUFFER_SIZE 64 +#endif + +#if (SERIAL_RX_BUFFER_SIZE>256) +typedef uint16_t rx_buffer_index_t; +#else +typedef uint8_t rx_buffer_index_t; +#endif // Define config for Serial.begin(baud, config); // parity: 7...4 bits = 0 (no), 2 (even), 3 (odd) @@ -68,8 +76,8 @@ class HardwareSerial : public Stream { protected: - volatile uint8_t _rx_buffer_head; - volatile uint8_t _rx_buffer_tail; + volatile rx_buffer_index_t _rx_buffer_head; + volatile rx_buffer_index_t _rx_buffer_tail; unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE]; private: -- 2.43.0 From 0bc9e50b660d5ee9273dc1fb25d08918eb852251 Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Mon, 20 Apr 2026 07:35:28 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit В главной ветке меняли ссылки, перенос в dev тоже Co-authored-by: KLASSENTS Co-committed-by: KLASSENTS --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1db3f64..e2397bc 100644 --- a/README.md +++ b/README.md @@ -102,10 +102,11 @@ extern "C" __attribute__((section(".ram_text"))) bool ISR(void) Для всех плат, входящих в состав пакета, доступен режим отладки скетча в Arduino IDE версии 2.3.4 на Windows 10 x64. Подготовка к работе в режиме отладки описана в [инструкции.](./docs/debug_description.md) Функция отладки является экспериментальной. ## Полезные ссылки -* [Описание плат ELBEAR](https://elron.tech/russian-arduino-compatible-board/) -* [Материалы по платам ELBEAR ACE-UNO](https://elron.tech/support/#elbear) -* [Материалы по платам ELBEAR ACE-NANO](https://elron.tech/support/#elbearacenano) -* [Материалы по платам ELSOMIK](https://elron.tech/support/#elsomik) +* [Проблемы и их решения при работе с пакетом в Arduino IDE](https://docs.elron.tech/arduino/available-ide/arduinoIDE-bsp/bsp-troubleshooting) +* [Описание плат ELBEAR](https://docs.elron.tech/arduino/) +* [Материалы по платам ELBEAR ACE-UNO](https://docs.elron.tech/arduino/elbear-ace-uno) +* [Материалы по платам ELBEAR ACE-NANO](https://docs.elron.tech/arduino/elbear-ace-nano) +* [Материалы по платам ELSOMIK](https://docs.elron.tech/som/) * [Материалы по плате START-MIK32](https://docs.mikron.ru/wiki/boards/start.html) * [Телеграмм-канал компании](https://t.me/elrontech) -- 2.43.0 From 3c6dcd2f30c9e326ed8063c753c4f4abb1026104 Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Wed, 13 May 2026 11:17:48 +0700 Subject: [PATCH 3/4] =?UTF-8?q?-=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=20EEPROM.put()=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= =?UTF-8?q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=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D1=83,=20=D0=B5=D1=81=D0=BB=D0=B8=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=BD=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=D0=B8=D1=81=D1=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries/EEPROM/README.md | 3 +- libraries/EEPROM/src/EEPROM.cpp | 25 ++++----- libraries/EEPROM/src/EEPROM.h | 95 +++++++++++++++++++++------------ 3 files changed, 74 insertions(+), 49 deletions(-) diff --git a/libraries/EEPROM/README.md b/libraries/EEPROM/README.md index 9ca761d..30a2043 100644 --- a/libraries/EEPROM/README.md +++ b/libraries/EEPROM/README.md @@ -134,6 +134,5 @@ This is useful for STL objects, custom iteration and C++11 style ranged for loop #### **`EEPROM.end()`** This function returns an `EEPtr` pointing at the location after the last EEPROM cell. -Used with `begin()` to provide custom iteration. -**Note:** The `EEPtr` returned is invalid as it is out of range. In fact the hardware causes wrapping of the address (overflow) and `EEPROM.end()` actually references the first EEPROM cell. +**Note:** The `EEPtr` returned is invalid as it is out of range and must not be dereferenced. diff --git a/libraries/EEPROM/src/EEPROM.cpp b/libraries/EEPROM/src/EEPROM.cpp index 10f5a89..4a7b6af 100644 --- a/libraries/EEPROM/src/EEPROM.cpp +++ b/libraries/EEPROM/src/EEPROM.cpp @@ -20,13 +20,13 @@ uint8_t read_byte( int idx ) // check if idx is valid if (idx < 0) { - idx = -idx; ErrorMsgHandler("EEPROM.read(): The eeprom cell address must be non-negative"); + return 0xFF; } - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) + if ((uint32_t)idx >= (uint32_t)EEPROM_LENGTH) { - idx = (int)((uint32_t)idx % EEPROM_LENGHT); ErrorMsgHandler("EEPROM.read(): The address of the eeprom cell goes beyond the eeprom"); + return 0xFF; } uint32_t read_data_buf[EEPROM_PAGE_WORDS] = {}; @@ -50,13 +50,13 @@ void write_byte( int idx, uint8_t val ) // check if idx is valid if (idx < 0) { - idx = -idx; ErrorMsgHandler("EEPROM.write(): The eeprom cell address must be non-negative"); + return; } - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) + if ((uint32_t)idx >= (uint32_t)EEPROM_LENGTH) { - idx = (int)((uint32_t)idx % EEPROM_LENGHT); ErrorMsgHandler("EEPROM.write(): The address of the eeprom cell goes beyond the eeprom"); + return; } update_byte(idx, val); } @@ -66,13 +66,13 @@ void update_byte( int idx, uint8_t val ) // check if idx is valid if (idx < 0) { - idx = -idx; ErrorMsgHandler("EEPROM.update(): The eeprom cell address must be non-negative"); + return; } - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) + if ((uint32_t)idx >= (uint32_t)EEPROM_LENGTH) { - idx = (int)((uint32_t)idx % EEPROM_LENGHT); ErrorMsgHandler("EEPROM.update(): The address of the eeprom cell goes beyond the eeprom"); + return; } uint32_t write_data_buf[EEPROM_PAGE_WORDS] = {}; @@ -88,15 +88,16 @@ void update_byte( int idx, uint8_t val ) // byte number in a word uint32_t byte_idx = ((uint32_t)idx) % EEPROM_WORD_SIZE; // get desired byte - uint32_t byte = ((uint32_t)val) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8); - uint8_t oldVal = (uint8_t)(*((uint8_t*)write_data_buf + word_idx * EEPROM_WORD_SIZE + (EEPROM_WORD_SIZE - byte_idx - 1))); + uint32_t shift = (EEPROM_WORD_SIZE - byte_idx - 1) * 8; + uint32_t byte = ((uint32_t)val) << shift; + uint8_t oldVal = (uint8_t)((write_data_buf[word_idx] >> shift) & 0xFF); // checking if written byte is different from the new one if(oldVal != val) { // clear page HAL_EEPROM_Erase(&heeprom, (uint16_t)addr, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); // get and replace the desired byte - write_data_buf[word_idx] = (write_data_buf[word_idx] & (~((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)))) | byte; + write_data_buf[word_idx] = (write_data_buf[word_idx] & (~((uint32_t)(0xFF) << shift))) | byte; HAL_EEPROM_Write(&heeprom, (uint16_t)addr, write_data_buf, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); } diff --git a/libraries/EEPROM/src/EEPROM.h b/libraries/EEPROM/src/EEPROM.h index 780a89e..fa1875d 100644 --- a/libraries/EEPROM/src/EEPROM.h +++ b/libraries/EEPROM/src/EEPROM.h @@ -12,7 +12,7 @@ #define EEPROM_WORD_SIZE 4 // word takes 4 bytes #define EEPROM_PAGE_SIZE ( EEPROM_PAGE_WORDS * EEPROM_WORD_SIZE ) // page takes 32*4 = 128 bytes #define EEPROM_END 0x1FFF -#define EEPROM_LENGHT (EEPROM_PAGE_SIZE * EEPROM_PAGE_COUNT) +#define EEPROM_LENGTH (EEPROM_PAGE_SIZE * EEPROM_PAGE_COUNT) void HAL_read(uint16_t addr, uint32_t * data); void HAL_write(uint16_t addr, uint32_t * data); @@ -81,6 +81,14 @@ struct EEPtr{ int index; }; +static inline uint32_t eeprom_reverse_word(uint32_t word) +{ + return ((word & 0x000000FFUL) << 24) | + ((word & 0x0000FF00UL) << 8) | + ((word & 0x00FF0000UL) >> 8) | + ((word & 0xFF000000UL) >> 24); +} + struct EEPROMClass{ //Basic user access methods. @@ -91,7 +99,7 @@ struct EEPROMClass{ void begin(); EEPtr end() { return length(); } // Standards requires this to be the item after the last valid entry. The returned pointer is invalid. - uint16_t length() { return (uint16_t)EEPROM_LENGHT; } + uint16_t length() { return (uint16_t)EEPROM_LENGTH; } template< typename T > const T &put(int idx, const T &data) @@ -100,20 +108,26 @@ struct EEPROMClass{ // check if idx is valid if (idx < 0) { - idx = -idx; ErrorMsgHandler("EEPROM.put(): The eeprom cell address must be non-negative"); + return data; } - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) + if ((uint32_t)idx >= (uint32_t)EEPROM_LENGTH) { - idx = (int)((uint32_t)idx % EEPROM_LENGHT); ErrorMsgHandler("EEPROM.put(): The address of the eeprom cell goes beyond the eeprom"); + return data; + } + if (sizeof(data) > ((uint32_t)EEPROM_LENGTH - (uint32_t)idx)) + { + ErrorMsgHandler("EEPROM.put(): The data goes beyond the eeprom"); + return data; } uint32_t write_data_buf[EEPROM_PAGE_WORDS] = {}; + uint32_t old_data_buf[EEPROM_PAGE_WORDS]; uint32_t dataSize = sizeof(data); // writing data size uint32_t dataShift = 0; // shift of the data writing start address uint32_t writeSize = dataSize; - + // calc start address of the desired page uint32_t addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_PAGE_SIZE) * EEPROM_PAGE_SIZE; // address of the searched word in eeprom: EEPROM_START_ADDR + (uint32_t)idx @@ -126,45 +140,56 @@ struct EEPROMClass{ uint32_t byte_idx = ((uint32_t)idx) % EEPROM_WORD_SIZE; // read first page HAL_read((uint16_t)addr, write_data_buf); + memcpy(old_data_buf, write_data_buf, sizeof(write_data_buf)); // if data does not fit on the first page, then write down only what fits if (EEPROM_PAGE_SIZE - byte_addr < dataSize) writeSize = EEPROM_PAGE_SIZE - byte_addr; uint32_t lastWord = (writeSize + byte_idx - 1) / EEPROM_WORD_SIZE + word_idx; dataSize -= writeSize; + // Convert affected words to byte order suitable for memcpy() + for(uint8_t i = word_idx; i <= lastWord; i++) + { + write_data_buf[i] = eeprom_reverse_word(write_data_buf[i]); + } // write data page by page, first separately write the first page memcpy((void *)((uint8_t *)write_data_buf + byte_addr), (void*)dataPointer, writeSize); // prepare words for writing for(uint8_t i = word_idx; i <= lastWord; i++) { - uint32_t word = write_data_buf[i]; - write_data_buf[i] = 0; - write_data_buf[i] = ((word & 0xFF)<<24) | ((word & (0xFF<<8))<<8) | ((word & (0xFF<<16))>>8) | ((word & (0xFF<<24))>>24); + write_data_buf[i] = eeprom_reverse_word(write_data_buf[i]); + } + if (memcmp(old_data_buf, write_data_buf, sizeof(write_data_buf)) != 0) + { + HAL_erase((uint16_t)addr); + HAL_write((uint16_t)addr, write_data_buf); } - HAL_erase((uint16_t)addr); - HAL_write((uint16_t)addr, write_data_buf); // if there is data left after writing the first page, then write it page by page until it runs out while (dataSize > 0) { addr += EEPROM_PAGE_SIZE; - // if reaching the eeprom end address, return to the initial address - if (addr == EEPROM_START_ADDR + EEPROM_LENGHT) - addr = EEPROM_START_ADDR; HAL_read((uint16_t)addr, write_data_buf); + memcpy(old_data_buf, write_data_buf, sizeof(write_data_buf)); dataShift += writeSize; writeSize = dataSize; if (EEPROM_PAGE_SIZE < dataSize) writeSize = EEPROM_PAGE_SIZE; lastWord = (writeSize - 1) / EEPROM_WORD_SIZE; + // Convert affected words to byte order suitable for memcpy() + for(uint8_t i = 0; i <= lastWord; i++) + { + write_data_buf[i] = eeprom_reverse_word(write_data_buf[i]); + } memcpy((void *)(write_data_buf), (void*)((uint8_t *)dataPointer + dataShift), writeSize); // prepare words for writing for(uint8_t i = 0; i <= lastWord; i++) { - uint32_t word = write_data_buf[i]; - write_data_buf[i] = 0; - write_data_buf[i] = ((word & 0xFF)<<24) | ((word & (0xFF<<8))<<8) | ((word & (0xFF<<16))>>8) | ((word & (0xFF<<24))>>24); + write_data_buf[i] = eeprom_reverse_word(write_data_buf[i]); + } + if (memcmp(old_data_buf, write_data_buf, sizeof(write_data_buf)) != 0) + { + HAL_erase((uint16_t)addr); + HAL_write((uint16_t)addr, write_data_buf); } - HAL_erase((uint16_t)addr); - HAL_write((uint16_t)addr, write_data_buf); dataSize -= writeSize; } return data; @@ -177,13 +202,18 @@ struct EEPROMClass{ // check if idx is valid if (idx < 0) { - idx = -idx; ErrorMsgHandler("EEPROM.get(): The eeprom cell address must be non-negative"); + return data; } - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) + if ((uint32_t)idx >= (uint32_t)EEPROM_LENGTH) { - idx = (int)((uint32_t)idx % EEPROM_LENGHT); ErrorMsgHandler("EEPROM.get(): The address of the eeprom cell goes beyond the eeprom"); + return data; + } + if (sizeof(data) > ((uint32_t)EEPROM_LENGTH - (uint32_t)idx)) + { + ErrorMsgHandler("EEPROM.get(): The data goes beyond the eeprom"); + return data; } uint32_t read_data_buf[EEPROM_PAGE_WORDS] = {}; @@ -210,9 +240,7 @@ struct EEPROMClass{ // prepare words for(uint8_t i = word_idx; i <= lastWord; i++) { - uint32_t word = read_data_buf[i]; - read_data_buf[i] = 0; - read_data_buf[i] = ((word & 0xFF)<<24) | ((word & (0xFF<<8))<<8) | ((word & (0xFF<<16))>>8) | ((word & (0xFF<<24))>>24); + read_data_buf[i] = eeprom_reverse_word(read_data_buf[i]); } // read data page by page, first separately read the first page memcpy((void *)dataPointer, (void*)((uint8_t *)read_data_buf + byte_addr), readSize); @@ -221,21 +249,16 @@ struct EEPROMClass{ while (dataSize > 0) { addr += EEPROM_PAGE_SIZE; - // if reaching the eeprom end address, return to the initial address - if (addr == EEPROM_START_ADDR + EEPROM_LENGHT) - addr = EEPROM_START_ADDR; HAL_read((uint16_t)addr, read_data_buf); dataShift += readSize; readSize = dataSize; if (EEPROM_PAGE_SIZE < dataSize) readSize = EEPROM_PAGE_SIZE; - lastWord = (dataSize - 1) / EEPROM_WORD_SIZE; + lastWord = (readSize - 1) / EEPROM_WORD_SIZE; // prepare words for(uint8_t i = 0; i <= lastWord; i++) { - uint32_t word = read_data_buf[i]; - read_data_buf[i] = 0; - read_data_buf[i] = ((word & 0xFF)<<24) | ((word & (0xFF<<8))<<8) | ((word & (0xFF<<16))>>8) | ((word & (0xFF<<24))>>24); + read_data_buf[i] = eeprom_reverse_word(read_data_buf[i]); } memcpy((void *)((uint8_t *)dataPointer + dataShift), (void*)(read_data_buf), readSize); dataSize -= readSize; @@ -244,7 +267,9 @@ struct EEPROMClass{ } }; -#pragma GCC diagnostic ignored "-Wunused-variable" // for GCC and Clang - +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" static EEPROMClass EEPROM; -#endif +#pragma GCC diagnostic pop + +#endif \ No newline at end of file -- 2.43.0 From 9de51ea5218b0b6f8b5ef3717f8e04deea703464 Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Wed, 13 May 2026 11:37:17 +0700 Subject: [PATCH 4/4] =?UTF-8?q?=D0=B4=D1=80=D0=B0=D0=B9=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D0=B5=20=D0=B2=20eeprom=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=BB=D0=B0=D1=82=D1=8B=20start?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boards.txt | 6 ++++++ platform.txt | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/boards.txt b/boards.txt index 3abbb50..e61f89d 100644 --- a/boards.txt +++ b/boards.txt @@ -14,6 +14,7 @@ aceUno8Mb.upload.speed=230400 # tool for bootloader update aceUno8Mb.bootloader.tool=mik32_upload aceUno8Mb.bootloader.tool.default=mik32_upload +aceUno8Mb.bootloader.driver_option=--no-driver aceUno8Mb.bootloader.file=elbear/bootloader.hex aceUno8Mb.bootloader.interface=ftdi/mikron-link.cfg aceUno8Mb.bootloader.params.verbose= @@ -41,6 +42,7 @@ aceUno16Mb.upload.speed=230400 # tool for bootloader update aceUno16Mb.bootloader.tool=mik32_upload aceUno16Mb.bootloader.tool.default=mik32_upload +aceUno16Mb.bootloader.driver_option=--no-driver aceUno16Mb.bootloader.file=elbear/bootloader.hex aceUno16Mb.bootloader.interface=ftdi/mikron-link.cfg aceUno16Mb.bootloader.params.verbose= @@ -68,6 +70,7 @@ aceUno32Mb.upload.speed=230400 # tool for bootloader update aceUno32Mb.bootloader.tool=mik32_upload aceUno32Mb.bootloader.tool.default=mik32_upload +aceUno32Mb.bootloader.driver_option=--no-driver aceUno32Mb.bootloader.file=elbear/bootloader.hex aceUno32Mb.bootloader.interface=ftdi/mikron-link.cfg aceUno32Mb.bootloader.params.verbose= @@ -94,6 +97,7 @@ aceNano.upload.speed=230400 # tool for bootloader update aceNano.bootloader.tool=mik32_upload aceNano.bootloader.tool.default=mik32_upload +aceNano.bootloader.driver_option=--no-driver aceNano.bootloader.file=elbear/bootloader.hex aceNano.bootloader.interface=ftdi/mikron-link.cfg aceNano.bootloader.params.verbose= @@ -120,6 +124,7 @@ elsomik.upload.speed=230400 # tool for bootloader update elsomik.bootloader.tool=mik32_upload elsomik.bootloader.tool.default=mik32_upload +elsomik.bootloader.driver_option=--no-driver elsomik.bootloader.file=elsomik/bootloader.hex elsomik.bootloader.interface=ftdi/mikron-link.cfg elsomik.bootloader.params.verbose= @@ -147,6 +152,7 @@ start-mik32-v1.upload.speed=120000 # tool for bootloader update start-mik32-v1.bootloader.tool=mik32_upload start-mik32-v1.bootloader.tool.default=mik32_upload +start-mik32-v1.bootloader.driver_option= start-mik32-v1.bootloader.file=start-mik32/bootloader.hex start-mik32-v1.bootloader.interface=start-link.cfg start-mik32-v1.bootloader.params.verbose= diff --git a/platform.txt b/platform.txt index 93dcef1..6d7429d 100644 --- a/platform.txt +++ b/platform.txt @@ -126,10 +126,10 @@ tools.mik32_upload.erase.params.quiet= tools.mik32_upload.erase.params.verbose= # For Tools > Burn Bootloader -tools.mik32_upload.bootloader.pattern="{path}/{cmd}" "{runtime.platform.path}/bootloaders/{bootloader.file}" --run-openocd --no-driver --openocd-exec "{runtime.tools.openocd.path}/bin/openocd{cmd.extension}" --openocd-interface "{path}/openocd-scripts/interface/{bootloader.interface}" --openocd-target "{path}/openocd-scripts/target/mik32.cfg" +tools.mik32_upload.bootloader.pattern="{path}/{cmd}" "{runtime.platform.path}/bootloaders/{bootloader.file}" --run-openocd {bootloader.driver_option} --openocd-exec "{runtime.tools.openocd.path}/bin/openocd{cmd.extension}" --openocd-interface "{path}/openocd-scripts/interface/{bootloader.interface}" --openocd-target "{path}/openocd-scripts/target/mik32.cfg" tools.mik32_upload.bootloader.params.quiet= # For Sketch > Upload Using Programmer -tools.mik32_upload.program.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.hex" --run-openocd --no-driver --openocd-exec "{runtime.tools.openocd.path}/bin/openocd{cmd.extension}" --openocd-interface "{path}/openocd-scripts/interface/{bootloader.interface}" --openocd-target "{path}/openocd-scripts/target/mik32.cfg" +tools.mik32_upload.program.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.hex" --run-openocd {bootloader.driver_option} --openocd-exec "{runtime.tools.openocd.path}/bin/openocd{cmd.extension}" --openocd-interface "{path}/openocd-scripts/interface/{bootloader.interface}" --openocd-target "{path}/openocd-scripts/target/mik32.cfg" tools.mik32_upload.program.params.quiet= tools.mik32_upload.program.params.verbose= \ No newline at end of file -- 2.43.0