Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 128KB flash MCUs #25

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/communication/four_way.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export class FourWay {
const eepromOffset = mcu.getEepromOffset();

try {
const fileNameRead = await this.readAddress(eepromOffset - 32, 32);
const fileNameOffset = (eepromOffset - 32) >> mcu.getEepromAddressShift();
const fileNameRead = await this.readAddress(fileNameOffset, 32);
const fileName = new TextDecoder().decode(fileNameRead!.params.slice(0, fileNameRead?.params.indexOf(0x0)));

if (/[A-Z0-9_]+/.test(fileName)) {
Expand All @@ -162,7 +163,8 @@ export class FourWay {

mcu.getInfo().layoutSize = Mcu!.LAYOUT_SIZE;

const settingsArray = (await this.readAddress(eepromOffset, mcu.getInfo().layoutSize))!.params;
const settingsArrayOffset = eepromOffset >> mcu.getEepromAddressShift();
const settingsArray = (await this.readAddress(settingsArrayOffset, mcu.getInfo().layoutSize))!.params;
mcu.getInfo().settings = bufferToSettings(settingsArray);
mcu.getInfo().settingsBuffer = settingsArray;

Expand Down
28 changes: 26 additions & 2 deletions src/mcu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface McuVariant {
flash_offset: string;
firmware_start: string;
eeprom_offset: string;
eeprom_address_shift: number;
}

export interface McuInfo {
Expand Down Expand Up @@ -54,7 +55,8 @@ class Mcu {
flash_size: 65536,
flash_offset: '0x08000000',
firmware_start: '0x1000',
eeprom_offset: '0x7c00'
eeprom_offset: '0x7c00',
eeprom_address_shift: 0,
},
3506: {
name: 'ARM64K',
Expand All @@ -63,7 +65,18 @@ class Mcu {
flash_size: 65536,
flash_offset: '0x08000000',
firmware_start: '0x1000',
eeprom_offset: '0xF800'
eeprom_offset: '0xF800',
eeprom_address_shift: 0,
},
'2B06': {
name: 'STM32G071 128KB',
signature: '0x2b06',
page_size: 2048,
flash_size: 131072,
flash_offset: '0x08000000',
firmware_start: '0x1000',
eeprom_offset: '0x1F800',
eeprom_address_shift: 2,
}
};

Expand Down Expand Up @@ -137,6 +150,17 @@ class Mcu {
return parseInt(this.mcu.eeprom_offset, 16);
}

/**
* Get shit in number of bits of the EEprom offset for the four way communication.
* This is needed because the address is coded on 2 bytes but for large flash
* MCUs the address goes beyond the range (e.g. 0x1F800)
*
* @returns {number}
*/
getEepromAddressShift() {
return this.mcu.eeprom_address_shift;
}

/**
* Get page size
*
Expand Down