Skip to content

Commit 7bd3c54

Browse files
authored
Merge pull request #110 from adafruit/pxt0
CF2 support
2 parents 27cd385 + 2446d02 commit 7bd3c54

File tree

6 files changed

+190
-3
lines changed

6 files changed

+190
-3
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ else
4141
NRFJPROG = nrfjprog
4242
endif
4343

44+
# auto-detect BMP on macOS, otherwise have to specify
45+
BMP_PORT ?= $(shell ls -1 /dev/cu.usbmodem????????1 | head -1)
46+
4447
ifeq ($(OS),Windows_NT)
4548
PROGFILES = C:/Program Files (x86)
4649
GNU_INSTALL_ROOT = $(PROGFILES)/GNU Tools ARM Embedded/7 2018-q2-update/bin/
@@ -67,6 +70,9 @@ NM := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-nm'
6770
OBJDUMP := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objdump'
6871
OBJCOPY := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-objcopy'
6972
SIZE := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-size'
73+
GDB := '$(GNU_INSTALL_ROOT)$(GNU_PREFIX)-gdb'
74+
75+
GDB_BMP = arm-none-eabi-gdb -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1'
7076

7177
#function for removing duplicates in a list
7278
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
@@ -115,6 +121,7 @@ C_SOURCE_FILES += $(SRC_PATH)/boards.c
115121
C_SOURCE_FILES += $(SRC_PATH)/flash_nrf5x.c
116122
C_SOURCE_FILES += $(SRC_PATH)/dfu_ble_svc.c
117123
C_SOURCE_FILES += $(SRC_PATH)/dfu_init.c
124+
C_SOURCE_FILES += $(SRC_PATH)/pinconfig.c
118125

119126
# nrfx
120127
C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_power.c
@@ -340,6 +347,13 @@ erase:
340347
@echo Erasing chip
341348
$(NRFJPROG) --eraseall -f nrf52
342349

350+
gdbflash: $(BUILD)/$(MERGED_FNAME).hex
351+
@echo Flashing: $<
352+
@$(GDB_BMP) -nx --batch -ex 'load $<' -ex 'compare-sections' -ex 'kill'
353+
354+
gdb: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out
355+
$(GDB_BMP) $<
356+
343357
#******************* Compile rules *******************
344358

345359
## Create build directories
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018 Ha Thach for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef _ARCARDE_FEATHER_NRF52840_H
26+
#define _ARCARDE_FEATHER_NRF52840_H
27+
28+
#define _PINNUM(port, pin) ((port)*32 + (pin))
29+
30+
/*------------------------------------------------------------------*/
31+
/* LED
32+
*------------------------------------------------------------------*/
33+
#define LEDS_NUMBER 2
34+
#define LED_PRIMARY_PIN _PINNUM(1, 15)
35+
#define LED_SECONDARY_PIN _PINNUM(1, 10)
36+
#define LED_STATE_ON 1
37+
38+
#define LED_NEOPIXEL _PINNUM(0, 16)
39+
#define NEOPIXELS_NUMBER 1
40+
#define BOARD_RGB_BRIGHTNESS 0x040404
41+
42+
/*------------------------------------------------------------------*/
43+
/* BUTTON
44+
*------------------------------------------------------------------*/
45+
#define BUTTONS_NUMBER 2
46+
#define BUTTON_1 _PINNUM(1, 02)
47+
#define BUTTON_2 _PINNUM(0, 10)
48+
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
49+
50+
/*------------------------------------------------------------------*/
51+
/* UART (only used by nRF52832)
52+
*------------------------------------------------------------------*/
53+
#define RX_PIN_NUMBER 8
54+
#define TX_PIN_NUMBER 6
55+
#define CTS_PIN_NUMBER 0
56+
#define RTS_PIN_NUMBER 0
57+
#define HWFC false
58+
59+
//--------------------------------------------------------------------+
60+
// BLE OTA
61+
//--------------------------------------------------------------------+
62+
#define BLEDIS_MANUFACTURER "Adafruit Industries"
63+
#define BLEDIS_MODEL "Feather nRF52840 Express"
64+
65+
//--------------------------------------------------------------------+
66+
// USB
67+
//--------------------------------------------------------------------+
68+
#define USB_DESC_VID 0x239A
69+
#define USB_DESC_UF2_PID 0x0029
70+
#define USB_DESC_CDC_ONLY_PID 0x002A
71+
72+
//------------- UF2 -------------//
73+
#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express"
74+
#define UF2_VOLUME_LABEL "ARCADE-N4"
75+
#define UF2_BOARD_ID "nRF52840-Feather-revD"
76+
#define UF2_INDEX_URL "https://www.adafruit.com/product/4062"
77+
78+
#define BOOTLOADER_CONFIG_CF2 \
79+
/* CF2 START */ \
80+
513675505, 539130489, /* magic */ \
81+
49 , 100 , /* used entries, total entries */ \
82+
4 , 0x18 , /* PIN_BTN_A = PIN_RX */ \
83+
5 , 0xa , /* PIN_BTN_B = PIN_D2 */ \
84+
13 , 0x29 , /* PIN_LED = PIN_D13 */ \
85+
18 , 0xf , /* PIN_MISO = PA15 */ \
86+
19 , 0xd , /* PIN_MOSI = PA13 */ \
87+
20 , 0x23 , /* PIN_NEOPIXEL = PB03 */ \
88+
21 , 0x18 , /* PIN_RX = PA24 */ \
89+
23 , 0xe , /* PIN_SCK = PA14 */ \
90+
24 , 0xb , /* PIN_SCL = PA11 */ \
91+
25 , 0xc , /* PIN_SDA = PA12 */ \
92+
28 , 0x19 , /* PIN_TX = PA25 */ \
93+
32 , 0xe , /* PIN_DISPLAY_SCK = PIN_SCK */ \
94+
34 , 0xd , /* PIN_DISPLAY_MOSI = PIN_MOSI */ \
95+
35 , 0x1e , /* PIN_DISPLAY_CS = PIN_A2 */ \
96+
36 , 0x1c , /* PIN_DISPLAY_DC = PIN_A3 */ \
97+
37 , 0xa0 , /* DISPLAY_WIDTH = 160 */ \
98+
38 , 0x80 , /* DISPLAY_HEIGHT = 128 */ \
99+
39 , 0x80 , /* DISPLAY_CFG0 = 0x80 */ \
100+
40 , 0x603 , /* DISPLAY_CFG1 = 0x603 */ \
101+
41 , 0x20 , /* DISPLAY_CFG2 = 0x20 */ \
102+
43 , 0x2 , /* PIN_DISPLAY_RST = PIN_A4 */ \
103+
44 , 0x3 , /* PIN_DISPLAY_BL = PIN_A5 */ \
104+
47 , 0x6 , /* PIN_BTN_LEFT = PIN_D11 */ \
105+
48 , 0x1a , /* PIN_BTN_RIGHT = PIN_D9 */ \
106+
49 , 0x1b , /* PIN_BTN_UP = PIN_D10 */ \
107+
50 , 0x7 , /* PIN_BTN_DOWN = PIN_D6 */ \
108+
51 , 0x8 , /* PIN_BTN_MENU = PIN_D12 */ \
109+
56 , 0x2a , /* PIN_LED2 = PB10 */ \
110+
60 , 0x19 , /* PIN_JACK_TX = PIN_TX */ \
111+
100, 0x4 , /* PIN_A0 = PA04 */ \
112+
101, 0x5 , /* PIN_A1 = PA05 */ \
113+
102, 0x1e , /* PIN_A2 = PA30 */ \
114+
103, 0x1c , /* PIN_A3 = PA28 */ \
115+
104, 0x2 , /* PIN_A4 = PA02 */ \
116+
105, 0x3 , /* PIN_A5 = PA03 */ \
117+
152, 0xa , /* PIN_D2 = PA10 */ \
118+
155, 0x28 , /* PIN_D5 = PB08 */ \
119+
156, 0x7 , /* PIN_D6 = PA07 */ \
120+
159, 0x1a , /* PIN_D9 = PA26 */ \
121+
160, 0x1b , /* PIN_D10 = PA27 */ \
122+
161, 0x6 , /* PIN_D11 = PA06 */ \
123+
162, 0x8 , /* PIN_D12 = PA08 */ \
124+
163, 0x29 , /* PIN_D13 = PB09 */ \
125+
200, 0x1 , /* NUM_NEOPIXELS = 1 */ \
126+
204, 0x100000 , /* FLASH_BYTES = 0x100000 */ \
127+
205, 0x40000 , /* RAM_BYTES = 0x40000 */ \
128+
208, 0xd7688ea1, /* BOOTLOADER_BOARD_ID = 0xd7688ea1 */ \
129+
209, 0xada52840, /* UF2_FAMILY = 0xada52840 */ \
130+
210, 0x20 , /* PINS_PORT_SIZE = PA_32 */ \
131+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
132+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
133+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
134+
0, 0, 0, 0, 0, 0 \
135+
/* CF2 END */
136+
137+
138+
#endif // _ARCARDE_FEATHER_NRF52840_H
139+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MCU_SUB_VARIANT = nrf52840

src/linker/nrf52840_s140_v6.ld

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ MEMORY
1111
* those values do not match. The check is performed in main.c, see
1212
* APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
1313
*/
14-
FLASH (rx) : ORIGIN = 0xF4000, LENGTH = 0xFE000-0xF4000 /* 40 KB */
14+
FLASH (rx) : ORIGIN = 0xF4000, LENGTH = 0xFE000-0xF4000-2048 /* 38 KB */
15+
16+
BOOTLOADER_CONFIG (r): ORIGIN = 0xFE000 - 2048, LENGTH = 2048
1517

1618
/** Location of mbr params page in flash. */
1719
MBR_PARAMS_PAGE (rw) : ORIGIN = 0xFE000, LENGTH = 0x1000
@@ -50,6 +52,11 @@ SECTIONS
5052
PROVIDE( __stop_fs_data = .);
5153
} = 0
5254

55+
.bootloaderConfig :
56+
{
57+
KEEP(*(.bootloaderConfig))
58+
} > BOOTLOADER_CONFIG
59+
5360
/* Place the bootloader settings page in flash. */
5461
.bootloaderSettings(NOLOAD) :
5562
{

src/main.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "nrf_error.h"
6262

6363
#include "boards.h"
64+
#include "uf2/uf2.h"
6465

6566
#include "pstorage_platform.h"
6667
#include "nrf_mbr.h"
@@ -105,12 +106,17 @@ void usb_teardown(void);
105106
#define DFU_MAGIC_UF2_RESET 0x57
106107

107108
#define DFU_DBL_RESET_MAGIC 0x5A1AD5 // SALADS
109+
#define DFU_DBL_RESET_APP 0x4ee5677e
108110
#define DFU_DBL_RESET_DELAY 500
109111
#define DFU_DBL_RESET_MEM 0x20007F7C
110112

111113
#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0]
112114
#define DFU_SERIAL_STARTUP_INTERVAL 1000
113115

116+
// Allow for using reset button essentially to swap between application and bootloader.
117+
// This is controlled by a flag in the app and is the behavior of CPX and all Arcade boards when using MakeCode.
118+
#define APP_ASKS_FOR_SINGLE_TAP_RESET() (*((uint32_t*)(USER_FLASH_START + 0x200)) == 0x87eeb07c)
119+
114120
// These value must be the same with one in dfu_transport_ble.c
115121
#define BLEGAP_EVENT_LENGTH 6
116122
#define BLEGATT_ATT_MTU_MAX 247
@@ -197,9 +203,13 @@ int main(void)
197203
_ota_dfu = _ota_dfu || ( button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) ) ;
198204

199205
bool const valid_app = bootloader_app_is_valid(DFU_BANK_0_REGION_START);
206+
bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP;
207+
208+
if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET())
209+
dfu_start = 1;
200210

201211
// App mode: register 1st reset and DFU startup (nrf52832)
202-
if ( ! (dfu_start || !valid_app) )
212+
if ( ! (just_start_app || dfu_start || !valid_app) )
203213
{
204214
// Register our first reset for double reset detection
205215
(*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
@@ -218,7 +228,10 @@ int main(void)
218228
#endif
219229
}
220230

221-
(*dbl_reset_mem) = 0;
231+
if (APP_ASKS_FOR_SINGLE_TAP_RESET())
232+
(*dbl_reset_mem) = DFU_DBL_RESET_APP;
233+
else
234+
(*dbl_reset_mem) = 0;
222235

223236
if ( dfu_start || !valid_app )
224237
{
@@ -261,6 +274,9 @@ int main(void)
261274
// MBR must be init before start application
262275
if ( !sd_inited ) softdev_mbr_init();
263276

277+
// clear in case we kept DFU_DBL_RESET_APP there
278+
(*dbl_reset_mem) = 0;
279+
264280
// Select a bank region to use as application region.
265281
// @note: Only applications running from DFU_BANK_0_REGION_START is supported.
266282
bootloader_app_start(DFU_BANK_0_REGION_START);

src/pinconfig.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "boards.h"
2+
3+
#ifdef BOOTLOADER_CONFIG_CF2
4+
5+
__attribute__((used, section(".bootloaderConfig")))
6+
const uint32_t bootloaderConfig[] = {
7+
BOOTLOADER_CONFIG_CF2
8+
};
9+
10+
#endif

0 commit comments

Comments
 (0)