Skip to content

Commit

Permalink
Merge pull request #763 from microbit-foundation/microbit_features
Browse files Browse the repository at this point in the history
Microbit v2 specific features
  • Loading branch information
mathias-arm authored Aug 20, 2021
2 parents 78c5193 + 44a2522 commit 9488528
Show file tree
Hide file tree
Showing 75 changed files with 14,225 additions and 110 deletions.
5 changes: 5 additions & 0 deletions docs/MSD_COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ data fast enough from DAPLink and an overflow occurs the text ```<DAPLink:Overfl
will show up in the serial data. Serial overflow reporting is turned off by default.

``ovfl_off.cfg`` This file turns off serial overflow reporting.


``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.

``comp_off.cfg`` This file turns off the incompatible target image detection (off by default).
4 changes: 4 additions & 0 deletions projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ projects:
- *module_if
- *module_hic_kl27z
- records/family/all_family.yaml
kl27z_microbit_bl:
- *module_bl
- records/hic_hal/kl27z.yaml
- records/board/kl27z_microbit_bl.yaml
k20dx_bl:
- *module_bl
- records/hic_hal/k20dx.yaml
Expand Down
6 changes: 6 additions & 0 deletions records/board/kl27z_microbit_bl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
common:
macros:
- MICROBIT_LOCK_BOOTLOADER
sources:
board:
- source/board/kl27z_microbit_bl.c
9 changes: 8 additions & 1 deletion records/board/microbitv2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ common:
- CDC_LED_DEF=GPIO_LED_ON
- MSC_LED_DEF=GPIO_LED_ON
- USB_PROD_STR="BBC micro:bit CMSIS-DAP"
- IO_CONFIG_OVERRIDE
- DELAY_FAST_CYCLES=2U # Fast delay needed to reach 8MHz SWD clock speed
- DAP_DEFAULT_SWJ_CLOCK=8000000
- BOARD_USB_BMAXPOWER=0x96
- BOARD_EXTRA_BUFFER=100
includes:
- source/board/microbitv2
sources:
board:
- source/board/microbitv2/microbitv2.c
- source/board/microbitv2/
target:
- source/family/nordic/nrf5x/target.c
- source/family/nordic/target_reset_nrf52.c
80 changes: 80 additions & 0 deletions source/board/kl27z_microbit_bl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* @file kl27z_microbit_bl.c
* @brief board ID and meta-data for the hardware interface circuit (HIC) based on the NXP KL27Z
*
* DAPLink Interface Firmware
* Copyright 2020 NXP
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "target_config.h"
#include "daplink_addr.h"
#include "compiler.h"
#include "target_board.h"
#include "target_family.h"
#include "fsl_device_registers.h"
#include "gpio.h"

// Warning - changing the interface start will break backwards compatibility
COMPILER_ASSERT(DAPLINK_ROM_IF_START == KB(32));
COMPILER_ASSERT(DAPLINK_ROM_IF_SIZE == (KB(128) - KB(32) - KB(1)));

/**
* List of start and size for each size of flash sector
* The size will apply to all sectors between the listed address and the next address
* in the list.
* The last pair in the list will have sectors starting at that address and ending
* at address start + size.
*/
static const sector_info_t sectors_info[] = {
{DAPLINK_ROM_IF_START, 1024},
};

// kl26z128 target information
target_cfg_t target_device = {
.sectors_info = sectors_info,
.sector_info_length = (sizeof(sectors_info))/(sizeof(sector_info_t)),
.flash_regions[0].start = DAPLINK_ROM_IF_START,
.flash_regions[0].end = DAPLINK_ROM_IF_START + DAPLINK_ROM_IF_SIZE,
.flash_regions[0].flags = kRegionIsDefault,
.ram_regions[0].start = 0x1FFFE000,
.ram_regions[0].end = 0x20006000,
};

//bootloader has no family
const target_family_descriptor_t *g_target_family = NULL;

const board_info_t g_board_info = {
.info_version = kBoardInfoVersion,
.board_id = "0000",
.daplink_url_name = "HELP_FAQHTM",
.daplink_drive_name = "MAINTENANCE",
.daplink_target_url = "https://microbit.org/device/?id=@B&v=@V&bl=1",
.target_cfg = &target_device,
};

bool reset_button_pressed()
{
bool btn_pressed = false;
// Bypass button check if we are waking from Low Leakage Wakeup Reset
if (RCM->SRS0 & RCM_SRS0_WAKEUP_MASK) {
btn_pressed = false;
}
else {
btn_pressed = gpio_get_reset_btn();
}

return btn_pressed;
}
167 changes: 167 additions & 0 deletions source/board/microbitv2/IO_Config_Override.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/**
* @file IO_Config_Override.h
* @brief Alternative IO for KL27Z based Hardware Interface Circuit
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef __IO_CONFIG_H__
#define __IO_CONFIG_H__

#include "MKL27Z4.h"
#include "compiler.h"
#include "daplink.h"

// This GPIO configuration is only valid for the KL27 HIC
COMPILER_ASSERT(DAPLINK_HIC_ID == DAPLINK_HIC_ID_KL27Z);


// Debug Port I/O Pins

// SWCLK Pin PTC6
#define PIN_SWCLK_PORT PORTC
#define PIN_SWCLK_GPIO FGPIOC
#define PIN_SWCLK_BIT (6)
#define PIN_SWCLK (1<<PIN_SWCLK_BIT)

// SWDIO Pin PTC5
#define PIN_SWDIO_PORT PORTC
#define PIN_SWDIO_GPIO FGPIOC
#define PIN_SWDIO_BIT (5)
#define PIN_SWDIO (1<<PIN_SWDIO_BIT)

// nRESET Pin PTA20
#define PIN_nRESET_PORT PORTA
#define PIN_nRESET_GPIO PTA
#define PIN_nRESET_BIT (20)
#define PIN_nRESET (1<<PIN_nRESET_BIT)

// Debug Unit LEDs

// HID_LED PTB0
#define PIN_HID_LED_PORT PORTB
#define PIN_HID_LED_GPIO PTB
#define PIN_HID_LED_BIT (0)
#define PIN_HID_LED (1<<PIN_HID_LED_BIT)
#define PIN_HID_LED_MUX_ALT (0)

// MSC_LED PTB0
#define PIN_MSC_LED_PORT PORTB
#define PIN_MSC_LED_GPIO PTB
#define PIN_MSC_LED_BIT (0)
#define PIN_MSC_LED (1<<PIN_MSC_LED_BIT)
#define PIN_MSC_LED_MUX_ALT (0)

// CDC_LED PTB0
#define PIN_CDC_LED_PORT PORTB
#define PIN_CDC_LED_GPIO PTB
#define PIN_CDC_LED_BIT (0)
#define PIN_CDC_LED (1<<PIN_CDC_LED_BIT)
#define PIN_CDC_LED_MUX_ALT (0)

// Volatge monitor pins

// Battery Voltage monitor PTB1
#define PIN_VMON_BAT_PORT PORTB
#define PIN_VMON_BAT_GPIO PTB
#define PIN_VMON_BAT_BIT (1)
#define PIN_VMON_BAT (1<<PIN_VMON_BAT_BIT)
#define PIN_VMON_BAT_ALT_MODE (kPORT_PinDisabledOrAnalog)
#define PIN_VMON_BAT_ADC_CH (9)
#define PIN_VMON_BAT_ADC_MUX (0)

// Enable Battery Voltage monitor PTC3
#define PIN_RUN_VBAT_SENSE_PORT PORTC
#define PIN_RUN_VBAT_SENSE_GPIO PTC
#define PIN_RUN_VBAT_SENSE_BIT (3)
#define PIN_RUN_VBAT_SENSE (1<<PIN_RUN_VBAT_SENSE_BIT)

// Reset pins

// SW RESET BUTTON PTD4
#define PIN_SW_RESET_PORT PORTD
#define PIN_SW_RESET_GPIO PTD
#define PIN_SW_RESET_BIT (4)
#define PIN_SW_RESET (1<<PIN_SW_RESET_BIT)
#define SW_RESET_PRESSED (0)
#define SW_RESET_NOT_PRESSED (1)
#define PIN_SW_RESET_LLWU_PIN (14)
#define PIN_SW_RESET_LLWU_WAKEUP_TYPE kLLWU_ExternalPinFallingEdge
#define PIN_SW_RESET_PORT_WAKEUP_TYPE kPORT_InterruptFallingEdge

// WAKE_ON_EDGE PTC4
#define PIN_WAKE_ON_EDGE_PORT PORTC
#define PIN_WAKE_ON_EDGE_GPIO PTC
#define PIN_WAKE_ON_EDGE_BIT (4)
#define PIN_WAKE_ON_EDGE (1<<PIN_WAKE_ON_EDGE_BIT)
#define PIN_WAKE_ON_EDGE_LLWU_PIN (8)
#define PIN_WAKE_ON_EDGE_LLWU_WAKEUP_TYPE kLLWU_ExternalPinFallingEdge
#define PIN_WAKE_ON_EDGE_PORT_WAKEUP_TYPE kPORT_InterruptEitherEdge

// Power LEDs

// Yellow LED PTB0, configured as HID/MSC/CDC LEDs

// Red Spare LED PTD7
#define PIN_RED_LED_PORT PORTD
#define PIN_RED_LED_GPIO PTD
#define PIN_RED_LED_BIT (7)
#define PIN_RED_LED (1<<PIN_RED_LED_BIT)


// define the reset button presses
#define RESET_SHORT_PRESS 10 // x 30ms debounce time = 300ms
#define RESET_MID_PRESS 80 // x 30ms debounce time = 2400ms
#define RESET_LONG_PRESS 120 // x 30ms debounce time = 3600ms
#define RESET_MAX_LENGTH_PRESS RESET_LONG_PRESS

// BOARD REV ID
#define PIN_BOARD_REV_ID_PORT PORTD
#define PIN_BOARD_REV_ID_GPIO PTD
#define PIN_BOARD_REV_ID_BIT (6)
#define PIN_BOARD_REV_ID (1<<PIN_BOARD_REV_ID_BIT)
#define PIN_BOARD_REV_ID_ADC_CH (7)
#define PIN_BOARD_REV_ID_ADC_MUX (1)

// COMBINED_SENSOR_INT PTA1
#define COMBINED_SENSOR_INT_PORT PORTA
#define COMBINED_SENSOR_INT_GPIO GPIOA
#define COMBINED_SENSOR_INT_PIN (1)

// Connected LED Not available

// Target Running LED Not available

// UART
#define UART_PORT PORTA
#define UART_NUM (1)
// RX PTA18
#define PIN_UART_RX_GPIO PTA
#define PIN_UART_RX_BIT (18)
#define PIN_UART_RX (1<<PIN_UART_RX_BIT)
#define PIN_UART_RX_MUX_ALT (3)
// TX PTA19
#define PIN_UART_TX_GPIO PTA
#define PIN_UART_TX_BIT (19)
#define PIN_UART_TX (1<<PIN_UART_TX_BIT)
#define PIN_UART_TX_MUX_ALT (3)

#define UART LPUART1
#define UART_RX_TX_IRQn LPUART1_IRQn
#define UART_RX_TX_IRQHandler LPUART1_IRQHandler

#endif
Loading

0 comments on commit 9488528

Please sign in to comment.