Skip to content

Commit 9488528

Browse files
authored
Merge pull request ARMmbed#763 from microbit-foundation/microbit_features
Microbit v2 specific features
2 parents 78c5193 + 44a2522 commit 9488528

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+14225
-110
lines changed

docs/MSD_COMMANDS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ data fast enough from DAPLink and an overflow occurs the text ```<DAPLink:Overfl
8282
will show up in the serial data. Serial overflow reporting is turned off by default.
8383

8484
``ovfl_off.cfg`` This file turns off serial overflow reporting.
85+
86+
87+
``comp_on.cfg`` This file turns on the incompatible target image detection. The interface project must define a board specific `board_detect_incompatible_image()` function with the criteria to validate the target image over the first 12 vectors. Otherwise, the incompatible target image detection won't have an effect.
88+
89+
``comp_off.cfg`` This file turns off the incompatible target image detection (off by default).

projects.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ projects:
9494
- *module_if
9595
- *module_hic_kl27z
9696
- records/family/all_family.yaml
97+
kl27z_microbit_bl:
98+
- *module_bl
99+
- records/hic_hal/kl27z.yaml
100+
- records/board/kl27z_microbit_bl.yaml
97101
k20dx_bl:
98102
- *module_bl
99103
- records/hic_hal/k20dx.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
common:
2+
macros:
3+
- MICROBIT_LOCK_BOOTLOADER
4+
sources:
5+
board:
6+
- source/board/kl27z_microbit_bl.c

records/board/microbitv2.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ common:
44
- CDC_LED_DEF=GPIO_LED_ON
55
- MSC_LED_DEF=GPIO_LED_ON
66
- USB_PROD_STR="BBC micro:bit CMSIS-DAP"
7+
- IO_CONFIG_OVERRIDE
8+
- DELAY_FAST_CYCLES=2U # Fast delay needed to reach 8MHz SWD clock speed
9+
- DAP_DEFAULT_SWJ_CLOCK=8000000
10+
- BOARD_USB_BMAXPOWER=0x96
11+
- BOARD_EXTRA_BUFFER=100
12+
includes:
13+
- source/board/microbitv2
714
sources:
815
board:
9-
- source/board/microbitv2/microbitv2.c
16+
- source/board/microbitv2/
1017
target:
1118
- source/family/nordic/nrf5x/target.c
1219
- source/family/nordic/target_reset_nrf52.c

source/board/kl27z_microbit_bl.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @file kl27z_microbit_bl.c
3+
* @brief board ID and meta-data for the hardware interface circuit (HIC) based on the NXP KL27Z
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright 2020 NXP
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#include "target_config.h"
23+
#include "daplink_addr.h"
24+
#include "compiler.h"
25+
#include "target_board.h"
26+
#include "target_family.h"
27+
#include "fsl_device_registers.h"
28+
#include "gpio.h"
29+
30+
// Warning - changing the interface start will break backwards compatibility
31+
COMPILER_ASSERT(DAPLINK_ROM_IF_START == KB(32));
32+
COMPILER_ASSERT(DAPLINK_ROM_IF_SIZE == (KB(128) - KB(32) - KB(1)));
33+
34+
/**
35+
* List of start and size for each size of flash sector
36+
* The size will apply to all sectors between the listed address and the next address
37+
* in the list.
38+
* The last pair in the list will have sectors starting at that address and ending
39+
* at address start + size.
40+
*/
41+
static const sector_info_t sectors_info[] = {
42+
{DAPLINK_ROM_IF_START, 1024},
43+
};
44+
45+
// kl26z128 target information
46+
target_cfg_t target_device = {
47+
.sectors_info = sectors_info,
48+
.sector_info_length = (sizeof(sectors_info))/(sizeof(sector_info_t)),
49+
.flash_regions[0].start = DAPLINK_ROM_IF_START,
50+
.flash_regions[0].end = DAPLINK_ROM_IF_START + DAPLINK_ROM_IF_SIZE,
51+
.flash_regions[0].flags = kRegionIsDefault,
52+
.ram_regions[0].start = 0x1FFFE000,
53+
.ram_regions[0].end = 0x20006000,
54+
};
55+
56+
//bootloader has no family
57+
const target_family_descriptor_t *g_target_family = NULL;
58+
59+
const board_info_t g_board_info = {
60+
.info_version = kBoardInfoVersion,
61+
.board_id = "0000",
62+
.daplink_url_name = "HELP_FAQHTM",
63+
.daplink_drive_name = "MAINTENANCE",
64+
.daplink_target_url = "https://microbit.org/device/?id=@B&v=@V&bl=1",
65+
.target_cfg = &target_device,
66+
};
67+
68+
bool reset_button_pressed()
69+
{
70+
bool btn_pressed = false;
71+
// Bypass button check if we are waking from Low Leakage Wakeup Reset
72+
if (RCM->SRS0 & RCM_SRS0_WAKEUP_MASK) {
73+
btn_pressed = false;
74+
}
75+
else {
76+
btn_pressed = gpio_get_reset_btn();
77+
}
78+
79+
return btn_pressed;
80+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/**
2+
* @file IO_Config_Override.h
3+
* @brief Alternative IO for KL27Z based Hardware Interface Circuit
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#ifndef __IO_CONFIG_H__
23+
#define __IO_CONFIG_H__
24+
25+
#include "MKL27Z4.h"
26+
#include "compiler.h"
27+
#include "daplink.h"
28+
29+
// This GPIO configuration is only valid for the KL27 HIC
30+
COMPILER_ASSERT(DAPLINK_HIC_ID == DAPLINK_HIC_ID_KL27Z);
31+
32+
33+
// Debug Port I/O Pins
34+
35+
// SWCLK Pin PTC6
36+
#define PIN_SWCLK_PORT PORTC
37+
#define PIN_SWCLK_GPIO FGPIOC
38+
#define PIN_SWCLK_BIT (6)
39+
#define PIN_SWCLK (1<<PIN_SWCLK_BIT)
40+
41+
// SWDIO Pin PTC5
42+
#define PIN_SWDIO_PORT PORTC
43+
#define PIN_SWDIO_GPIO FGPIOC
44+
#define PIN_SWDIO_BIT (5)
45+
#define PIN_SWDIO (1<<PIN_SWDIO_BIT)
46+
47+
// nRESET Pin PTA20
48+
#define PIN_nRESET_PORT PORTA
49+
#define PIN_nRESET_GPIO PTA
50+
#define PIN_nRESET_BIT (20)
51+
#define PIN_nRESET (1<<PIN_nRESET_BIT)
52+
53+
// Debug Unit LEDs
54+
55+
// HID_LED PTB0
56+
#define PIN_HID_LED_PORT PORTB
57+
#define PIN_HID_LED_GPIO PTB
58+
#define PIN_HID_LED_BIT (0)
59+
#define PIN_HID_LED (1<<PIN_HID_LED_BIT)
60+
#define PIN_HID_LED_MUX_ALT (0)
61+
62+
// MSC_LED PTB0
63+
#define PIN_MSC_LED_PORT PORTB
64+
#define PIN_MSC_LED_GPIO PTB
65+
#define PIN_MSC_LED_BIT (0)
66+
#define PIN_MSC_LED (1<<PIN_MSC_LED_BIT)
67+
#define PIN_MSC_LED_MUX_ALT (0)
68+
69+
// CDC_LED PTB0
70+
#define PIN_CDC_LED_PORT PORTB
71+
#define PIN_CDC_LED_GPIO PTB
72+
#define PIN_CDC_LED_BIT (0)
73+
#define PIN_CDC_LED (1<<PIN_CDC_LED_BIT)
74+
#define PIN_CDC_LED_MUX_ALT (0)
75+
76+
// Volatge monitor pins
77+
78+
// Battery Voltage monitor PTB1
79+
#define PIN_VMON_BAT_PORT PORTB
80+
#define PIN_VMON_BAT_GPIO PTB
81+
#define PIN_VMON_BAT_BIT (1)
82+
#define PIN_VMON_BAT (1<<PIN_VMON_BAT_BIT)
83+
#define PIN_VMON_BAT_ALT_MODE (kPORT_PinDisabledOrAnalog)
84+
#define PIN_VMON_BAT_ADC_CH (9)
85+
#define PIN_VMON_BAT_ADC_MUX (0)
86+
87+
// Enable Battery Voltage monitor PTC3
88+
#define PIN_RUN_VBAT_SENSE_PORT PORTC
89+
#define PIN_RUN_VBAT_SENSE_GPIO PTC
90+
#define PIN_RUN_VBAT_SENSE_BIT (3)
91+
#define PIN_RUN_VBAT_SENSE (1<<PIN_RUN_VBAT_SENSE_BIT)
92+
93+
// Reset pins
94+
95+
// SW RESET BUTTON PTD4
96+
#define PIN_SW_RESET_PORT PORTD
97+
#define PIN_SW_RESET_GPIO PTD
98+
#define PIN_SW_RESET_BIT (4)
99+
#define PIN_SW_RESET (1<<PIN_SW_RESET_BIT)
100+
#define SW_RESET_PRESSED (0)
101+
#define SW_RESET_NOT_PRESSED (1)
102+
#define PIN_SW_RESET_LLWU_PIN (14)
103+
#define PIN_SW_RESET_LLWU_WAKEUP_TYPE kLLWU_ExternalPinFallingEdge
104+
#define PIN_SW_RESET_PORT_WAKEUP_TYPE kPORT_InterruptFallingEdge
105+
106+
// WAKE_ON_EDGE PTC4
107+
#define PIN_WAKE_ON_EDGE_PORT PORTC
108+
#define PIN_WAKE_ON_EDGE_GPIO PTC
109+
#define PIN_WAKE_ON_EDGE_BIT (4)
110+
#define PIN_WAKE_ON_EDGE (1<<PIN_WAKE_ON_EDGE_BIT)
111+
#define PIN_WAKE_ON_EDGE_LLWU_PIN (8)
112+
#define PIN_WAKE_ON_EDGE_LLWU_WAKEUP_TYPE kLLWU_ExternalPinFallingEdge
113+
#define PIN_WAKE_ON_EDGE_PORT_WAKEUP_TYPE kPORT_InterruptEitherEdge
114+
115+
// Power LEDs
116+
117+
// Yellow LED PTB0, configured as HID/MSC/CDC LEDs
118+
119+
// Red Spare LED PTD7
120+
#define PIN_RED_LED_PORT PORTD
121+
#define PIN_RED_LED_GPIO PTD
122+
#define PIN_RED_LED_BIT (7)
123+
#define PIN_RED_LED (1<<PIN_RED_LED_BIT)
124+
125+
126+
// define the reset button presses
127+
#define RESET_SHORT_PRESS 10 // x 30ms debounce time = 300ms
128+
#define RESET_MID_PRESS 80 // x 30ms debounce time = 2400ms
129+
#define RESET_LONG_PRESS 120 // x 30ms debounce time = 3600ms
130+
#define RESET_MAX_LENGTH_PRESS RESET_LONG_PRESS
131+
132+
// BOARD REV ID
133+
#define PIN_BOARD_REV_ID_PORT PORTD
134+
#define PIN_BOARD_REV_ID_GPIO PTD
135+
#define PIN_BOARD_REV_ID_BIT (6)
136+
#define PIN_BOARD_REV_ID (1<<PIN_BOARD_REV_ID_BIT)
137+
#define PIN_BOARD_REV_ID_ADC_CH (7)
138+
#define PIN_BOARD_REV_ID_ADC_MUX (1)
139+
140+
// COMBINED_SENSOR_INT PTA1
141+
#define COMBINED_SENSOR_INT_PORT PORTA
142+
#define COMBINED_SENSOR_INT_GPIO GPIOA
143+
#define COMBINED_SENSOR_INT_PIN (1)
144+
145+
// Connected LED Not available
146+
147+
// Target Running LED Not available
148+
149+
// UART
150+
#define UART_PORT PORTA
151+
#define UART_NUM (1)
152+
// RX PTA18
153+
#define PIN_UART_RX_GPIO PTA
154+
#define PIN_UART_RX_BIT (18)
155+
#define PIN_UART_RX (1<<PIN_UART_RX_BIT)
156+
#define PIN_UART_RX_MUX_ALT (3)
157+
// TX PTA19
158+
#define PIN_UART_TX_GPIO PTA
159+
#define PIN_UART_TX_BIT (19)
160+
#define PIN_UART_TX (1<<PIN_UART_TX_BIT)
161+
#define PIN_UART_TX_MUX_ALT (3)
162+
163+
#define UART LPUART1
164+
#define UART_RX_TX_IRQn LPUART1_IRQn
165+
#define UART_RX_TX_IRQHandler LPUART1_IRQHandler
166+
167+
#endif

0 commit comments

Comments
 (0)