-
Notifications
You must be signed in to change notification settings - Fork 15
Add nice!nano v2 board support #100
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
Open
RandoSY
wants to merge
3
commits into
h2zero:master
Choose a base branch
from
RandoSY:agent/add-nice-nano-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import argparse | ||
| import struct | ||
| import sys | ||
|
|
||
|
|
||
| UF2_MAGIC_START0 = 0x0A324655 | ||
| UF2_MAGIC_START1 = 0x9E5D5157 | ||
| UF2_MAGIC_END = 0x0AB16F30 | ||
| UF2_FLAG_FAMILY_ID_PRESENT = 0x00002000 | ||
| UF2_PAYLOAD_SIZE = 256 | ||
|
|
||
|
|
||
| def parse_int(value): | ||
| return int(value, 0) | ||
|
|
||
|
|
||
| def parse_hex_line(line, line_number): | ||
| line = line.strip() | ||
| if not line: | ||
| return None | ||
| if not line.startswith(":"): | ||
| raise ValueError(f"line {line_number}: missing ':'") | ||
|
|
||
| try: | ||
| raw = bytes.fromhex(line[1:]) | ||
| except ValueError as exc: | ||
| raise ValueError(f"line {line_number}: invalid hex") from exc | ||
|
|
||
| if len(raw) < 5: | ||
| raise ValueError(f"line {line_number}: record is too short") | ||
|
|
||
| count = raw[0] | ||
| if len(raw) != count + 5: | ||
| raise ValueError(f"line {line_number}: record length mismatch") | ||
|
|
||
| if (sum(raw) & 0xFF) != 0: | ||
| raise ValueError(f"line {line_number}: checksum mismatch") | ||
|
|
||
| address = (raw[1] << 8) | raw[2] | ||
| record_type = raw[3] | ||
| payload = raw[4:4 + count] | ||
|
|
||
| required_lengths = {0x01: 0, 0x02: 2, 0x03: 4, 0x04: 2, 0x05: 4} | ||
| if record_type in required_lengths: | ||
| if count != required_lengths[record_type]: | ||
| raise ValueError(f"line {line_number}: invalid record length for type {record_type:#x}") | ||
| if address != 0: | ||
| raise ValueError(f"line {line_number}: non-zero address for type {record_type:#x}") | ||
|
|
||
| return record_type, address, payload | ||
|
|
||
|
|
||
| def read_ihex(filename): | ||
| data = {} | ||
| upper_address = 0 | ||
| eof_seen = False | ||
|
|
||
| with open(filename, "r", encoding="ascii") as hex_file: | ||
| for line_number, line in enumerate(hex_file, 1): | ||
| record = parse_hex_line(line, line_number) | ||
| if record is None: | ||
| continue | ||
| if eof_seen: | ||
| raise ValueError(f"line {line_number}: record after EOF") | ||
|
|
||
| record_type, address, payload = record | ||
| if record_type == 0x00: | ||
| absolute = upper_address + address | ||
| for offset, value in enumerate(payload): | ||
| data[absolute + offset] = value | ||
| elif record_type == 0x01: | ||
| eof_seen = True | ||
| elif record_type == 0x02: | ||
| upper_address = int.from_bytes(payload, "big") << 4 | ||
| elif record_type == 0x04: | ||
| upper_address = int.from_bytes(payload, "big") << 16 | ||
| elif record_type in (0x03, 0x05): | ||
| continue | ||
| else: | ||
| raise ValueError(f"line {line_number}: unsupported record type {record_type:#x}") | ||
|
|
||
| if not eof_seen: | ||
| raise ValueError("input HEX is missing EOF record") | ||
| if not data: | ||
| raise ValueError("input HEX contains no data records") | ||
|
|
||
| return data | ||
|
|
||
|
|
||
| def build_blocks(data): | ||
| blocks = {} | ||
| for address, value in data.items(): | ||
| block_address = address & ~(UF2_PAYLOAD_SIZE - 1) | ||
| if block_address not in blocks: | ||
| blocks[block_address] = bytearray([0xFF] * UF2_PAYLOAD_SIZE) | ||
| blocks[block_address][address - block_address] = value | ||
|
|
||
| return sorted(blocks.items()) | ||
|
|
||
|
|
||
| def write_uf2(blocks, family_id, output): | ||
| total = len(blocks) | ||
| with open(output, "wb") as uf2_file: | ||
| for index, (address, payload) in enumerate(blocks): | ||
| header = struct.pack( | ||
| "<IIIIIIII", | ||
| UF2_MAGIC_START0, | ||
| UF2_MAGIC_START1, | ||
| UF2_FLAG_FAMILY_ID_PRESENT, | ||
| address, | ||
| UF2_PAYLOAD_SIZE, | ||
| index, | ||
| total, | ||
| family_id, | ||
| ) | ||
| block = header + bytes(payload) | ||
| block += bytes(512 - len(block) - 4) | ||
| block += struct.pack("<I", UF2_MAGIC_END) | ||
| uf2_file.write(block) | ||
|
|
||
|
|
||
| def main(argv): | ||
| parser = argparse.ArgumentParser(description="Convert an Intel HEX file to UF2.") | ||
| parser.add_argument("-f", "--family", type=parse_int, required=True, help="UF2 family ID") | ||
| parser.add_argument("-o", "--output", required=True, help="output UF2 file") | ||
| parser.add_argument("input", help="input Intel HEX file") | ||
| args = parser.parse_args(argv) | ||
|
|
||
| data = read_ihex(args.input) | ||
| blocks = build_blocks(data) | ||
| write_uf2(blocks, args.family, args.output) | ||
| print(f"Wrote {args.output} ({len(blocks)} UF2 blocks)") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main(sys.argv[1:]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #include "variant.h" | ||
| #include "wiring_constants.h" | ||
| #include "wiring_digital.h" | ||
| #include "nrf.h" | ||
|
|
||
| const uint32_t g_ADigitalPinMap[] = | ||
| { | ||
| // nice!nano v2 edge castellations | ||
| 8, // D0 is P0.08 | ||
| 6, // D1 is P0.06 | ||
| 17, // D2 is P0.17 | ||
| 20, // D3 is P0.20 | ||
| 22, // D4 is P0.22 | ||
| 24, // D5 is P0.24 | ||
| 32, // D6 is P1.00 | ||
| 11, // D7 is P0.11 | ||
| 36, // D8 is P1.04 | ||
| 38, // D9 is P1.06 | ||
| 9, // D10 is P0.09 | ||
|
|
||
| // Exposed bottom pads | ||
| 33, // D11 is P1.01 | ||
| 34, // D12 is P1.02 | ||
| 39, // D13 is P1.07 | ||
|
|
||
| // nice!nano v2 edge castellations | ||
| 43, // D14 is P1.11 | ||
| 45, // D15 is P1.13 | ||
| 10, // D16 is P0.10 | ||
| 42, // D17 is P1.10 | ||
| 47, // D18 is P1.15 | ||
| 2, // D19 is P0.02 (AIN0) | ||
| 29, // D20 is P0.29 (AIN5) | ||
| 31, // D21 is P0.31 (AIN7) | ||
|
|
||
| 15, // D22 is P0.15 (status LED) | ||
| 4, // D23 is P0.04 (battery voltage) | ||
| 13, // D24 is P0.13 (VCC cutoff) | ||
| }; | ||
|
|
||
| void initVariant() | ||
| { | ||
| pinMode(PIN_LED, OUTPUT); | ||
| ledOff(PIN_LED); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.