Skip to content

Commit

Permalink
uicr: Interface members should not be capitalised and add to docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-carlos committed Feb 22, 2019
1 parent 1990f90 commit 2cf666c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
14 changes: 14 additions & 0 deletions docs/quick-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,17 @@ if (microbitFs.isAppendedScriptPresent(finalHexStr)) {
var pythonCode = microbitFs.getIntelHexAppendedScript(finalHexStr)
}
```

### Read UICR data

```js
var uicrData = getIntelHexUicrData(IntelHexStr);
console.log('' + );
console.log('Flash Page Size:' + uicrData.flashPageSize);
console.log('Runtime Start Page:' + uicrData.runtimeStartPage);
console.log('Runtime Start Address:' + uicrData.runtimeStartAddress);
console.log('Runtime End Used:' + uicrData.runtimeEndUsed);
console.log('Runtime End Address:' + uicrData.runtimeEndAddress);
console.log('Version Address:' + uicrData.versionAddress);
console.log('Version: ' + uicrData.version);
```
14 changes: 7 additions & 7 deletions src/__tests__/uicr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ describe('Read MicroPython UICR data.', () => {

const result = getIntelHexUicrData(uPyHexFile);

expect(result.FlashPageSize).toEqual(expectedPageSize);
expect(result.RuntimeStartPage).toEqual(expectedRuntimeStartPage);
expect(result.RuntimeStartAddress).toEqual(
expect(result.flashPageSize).toEqual(expectedPageSize);
expect(result.runtimeStartPage).toEqual(expectedRuntimeStartPage);
expect(result.runtimeStartAddress).toEqual(
expectedRuntimeStartPage * expectedPageSize
);
expect(result.RuntimeEndUsed).toEqual(expectedRuntimeEndPage);
expect(result.RuntimeEndAddress).toEqual(
expect(result.runtimeEndUsed).toEqual(expectedRuntimeEndPage);
expect(result.runtimeEndAddress).toEqual(
expectedRuntimeEndPage * expectedPageSize
);
expect(result.VersionAddress).toEqual(expectedVersionAddress);
expect(result.Version).toEqual(expectedVersion);
expect(result.versionAddress).toEqual(expectedVersionAddress);
expect(result.version).toEqual(expectedVersion);
});

it('UICR data without MicroPython magic number', () => {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './micropython-appended';
export * from './micropython-fs-hex';
export * from './uicr';
2 changes: 1 addition & 1 deletion src/micropython-fs-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function getFreeChunks(intelHexMap: MemoryMap): number[] {
*/
function getStartAddress(intelHexMap: MemoryMap): number {
const uicrData = getHexMapUicrData(intelHexMap);
const startAddress = uicrData.RuntimeEndAddress;
const startAddress = uicrData.runtimeEndAddress;
// Ensure the start address aligns with the page size
if (startAddress % FLASH_PAGE_SIZE) {
throw new Error(
Expand Down
30 changes: 15 additions & 15 deletions src/uicr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ enum MicropythonUicrAddress {

/** MicroPython data stored in the UICR Customer area. */
interface MicropythonUicrData {
FlashPageSize: number;
RuntimeStartPage: number;
RuntimeStartAddress: number;
RuntimeEndUsed: number;
RuntimeEndAddress: number;
VersionAddress: number;
Version: string;
flashPageSize: number;
runtimeStartPage: number;
runtimeStartAddress: number;
runtimeEndUsed: number;
runtimeEndAddress: number;
versionAddress: number;
version: string;
}

/**
Expand Down Expand Up @@ -186,7 +186,7 @@ function getVersionLocation(intelHexMap: MemoryMap): number {
function getHexMapUicrData(intelHexMap: MemoryMap): MicropythonUicrData {
const uicrMap = intelHexMap.slice(UICR_UPY_START);
if (!confirmMagicValue(uicrMap)) {
throw new Error('Could not find valid UICR data in Intel Hex data.');
throw new Error('Could not find valid MicroPython UICR data.');
}
const pageSize: number = getPageSize(uicrMap);
const startPage: number = getStartPage(uicrMap);
Expand All @@ -195,13 +195,13 @@ function getHexMapUicrData(intelHexMap: MemoryMap): MicropythonUicrData {
const version: string = getStringFromIntelHexMap(intelHexMap, versionAddress);

return {
FlashPageSize: pageSize,
RuntimeStartPage: startPage,
RuntimeStartAddress: startPage * pageSize,
RuntimeEndUsed: pagesUsed,
RuntimeEndAddress: pagesUsed * pageSize,
VersionAddress: versionAddress,
Version: version,
flashPageSize: pageSize,
runtimeStartPage: startPage,
runtimeStartAddress: startPage * pageSize,
runtimeEndUsed: pagesUsed,
runtimeEndAddress: pagesUsed * pageSize,
versionAddress,
version,
};
}

Expand Down

0 comments on commit 2cf666c

Please sign in to comment.