Skip to content

Commit f78c241

Browse files
authored
Merge pull request #14325 from AGlass0fMilk/ep-atlas-reg-init
EP Atlas Target Updates
2 parents 44e9e3c + d00699c commit f78c241

File tree

8 files changed

+199
-39
lines changed

8 files changed

+199
-39
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ target_sources(mbed-nrf52
2828
serial_api.c
2929
sleep.c
3030
spi_api.c
31+
subtarget_init.c
3132
trng_api.c
3233
us_ticker.c
3334
watchdog_api.c

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ target_include_directories(mbed-ep-atlas
2525
TARGET_EP_ATLAS
2626
)
2727

28+
target_sources(mbed-ep-atlas
29+
INTERFACE
30+
TARGET_EP_ATLAS/ONBOARD_TELIT_ME310.cpp
31+
TARGET_EP_ATLAS/usb_stdio.cpp
32+
TARGET_EP_ATLAS/atlas_init.c
33+
)
34+
2835
target_include_directories(mbed-nrf52840-dk
2936
INTERFACE
3037
TARGET_NRF52840_DK
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2021 ARM Limited
3+
* Copyright (c) 2021 Embedded Planet, Inc.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <stdint.h>
20+
21+
#include "subtarget_init.h"
22+
23+
#include "nrf.h"
24+
25+
/**
26+
* Override the subtarget sdk init startup hook (specific to nRF2)
27+
* This will configure the internal regulator to operate at 3.3V
28+
*/
29+
void subtarget_sdk_init(void)
30+
{
31+
32+
if (NRF_UICR->REGOUT0 != UICR_REGOUT0_VOUT_3V3) {
33+
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
34+
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
35+
NRF_UICR->REGOUT0 = UICR_REGOUT0_VOUT_3V3;
36+
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
37+
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
38+
39+
// Trigger a soft reset so that the settings take effect
40+
NVIC_SystemReset();
41+
}
42+
}
43+
44+

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_EP_ATLAS/mbed_lib.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
"help" : "Telit ME310C1 AT#PORTCFG Variant value",
1111
"macro_name" : "EP_ATLAS_PORT_CONFIGURATION_VARIANT",
1212
"value" : 0
13+
},
14+
"enable-usb-stdio-console": {
15+
"help" : "Enables using USB Serial for the stdio console. If you use USB in your application, you must disable this feature and implement a composite USB device if you require USB serial output. This feature is disabled by default.",
16+
"value" : false
1317
}
1418
},
1519
"target_overrides": {
1620
"EP_ATLAS": {
17-
"target.network-default-interface-type": "CELLULAR"
18-
21+
"target.network-default-interface-type": "CELLULAR",
22+
"target.mbed_app_start": "0x1000",
23+
"target.mbed_app_size": "0xDF000"
1924
}
2025

2126
}
22-
}
27+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2021 ARM Limited
3+
* Copyright (c) 2021 Embedded Planet, Inc.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "USBSerial.h"
20+
#include "platform/mbed_retarget.h"
21+
22+
#ifndef MBED_CONF_EP_ATLAS_ENABLE_USB_STDIO_CONSOLE
23+
#define MBED_CONF_EP_ATLAS_ENABLE_USB_STDIO_CONSOLE 0
24+
#endif
25+
26+
#if MBED_CONF_EP_ATLAS_ENABLE_USB_STDIO_CONSOLE
27+
28+
/* Retarget stdio to USBSerial */
29+
mbed::FileHandle *mbed::mbed_target_override_console(int fd)
30+
{
31+
static USBSerial usb_serial;
32+
return &usb_serial;
33+
}
34+
35+
#endif
Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
/*
1+
/*
22
* Copyright (c) 2016 Nordic Semiconductor ASA
33
* All rights reserved.
4-
*
4+
*
55
* Redistribution and use in source and binary forms, with or without modification,
66
* are permitted provided that the following conditions are met:
7-
*
8-
* 1. Redistributions of source code must retain the above copyright notice, this list
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this list
99
* of conditions and the following disclaimer.
1010
*
11-
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
12-
* integrated circuit in a product or a software update for such product, must reproduce
13-
* the above copyright notice, this list of conditions and the following disclaimer in
11+
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
12+
* integrated circuit in a product or a software update for such product, must reproduce
13+
* the above copyright notice, this list of conditions and the following disclaimer in
1414
* the documentation and/or other materials provided with the distribution.
1515
*
16-
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
17-
* used to endorse or promote products derived from this software without specific prior
16+
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
17+
* used to endorse or promote products derived from this software without specific prior
1818
* written permission.
1919
*
20-
* 4. This software, with or without modification, must only be used with a
20+
* 4. This software, with or without modification, must only be used with a
2121
* Nordic Semiconductor ASA integrated circuit.
2222
*
23-
* 5. Any software provided in binary or object form under this license must not be reverse
24-
* engineered, decompiled, modified and/or disassembled.
25-
*
23+
* 5. Any software provided in binary or object form under this license must not be reverse
24+
* engineered, decompiled, modified and/or disassembled.
25+
*
2626
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2727
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2828
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -33,9 +33,9 @@
3333
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3434
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3535
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36-
*
36+
*
3737
*/
38-
38+
3939
#include "nrf.h"
4040
#include "cmsis_nvic.h"
4141
#include "stdint.h"
@@ -48,15 +48,18 @@
4848
#endif
4949

5050
#if defined(__ARMCC_VERSION)
51-
__attribute__ ((section(".bss.nvictable")))
52-
uint32_t nrf_dispatch_vector[NVIC_NUM_VECTORS];
51+
__attribute__((section(".bss.nvictable")))
52+
uint32_t nrf_dispatch_vector[NVIC_NUM_VECTORS];
5353
#elif defined(__GNUC__)
54-
__attribute__ ((section(".nvictable")))
55-
uint32_t nrf_dispatch_vector[NVIC_NUM_VECTORS];
54+
__attribute__((section(".nvictable")))
55+
uint32_t nrf_dispatch_vector[NVIC_NUM_VECTORS];
5656
#elif defined(__ICCARM__)
57-
uint32_t nrf_dispatch_vector[NVIC_NUM_VECTORS] @ ".nvictable";
57+
uint32_t nrf_dispatch_vector[NVIC_NUM_VECTORS] @ ".nvictable";
5858
#endif
5959

60+
#include "platform/mbed_toolchain.h"
61+
#include "subtarget_init.h"
62+
6063
extern uint32_t __Vectors[];
6164

6265
#define VECTORS_FLASH_START __Vectors
@@ -70,21 +73,21 @@ extern uint32_t __Vectors[];
7073
void nrf_reloc_vector_table(void)
7174
{
7275
// Copy and switch to dynamic vectors
73-
uint32_t *old_vectors = VECTORS_FLASH_START;
74-
uint32_t i;
75-
for (i = 0; i< NVIC_NUM_VECTORS; i++) {
76-
nrf_dispatch_vector[i] = old_vectors[i];
77-
}
76+
uint32_t *old_vectors = VECTORS_FLASH_START;
77+
uint32_t i;
78+
for (i = 0; i < NVIC_NUM_VECTORS; i++) {
79+
nrf_dispatch_vector[i] = old_vectors[i];
80+
}
7881

7982
#if defined(SOFTDEVICE_PRESENT)
8083

8184
/**
8285
* Before setting the new vector table address in the SoftDevice the MBR must be initialized.
8386
* If no bootloader is present the MBR will be initialized automatically.
8487
* If a bootloader is present nrf_dfu_mbr_init_sd must be called once and only once.
85-
*
88+
*
8689
* By resetting the MBR and SoftDevice VTOR address first, it becomes safe to initialize
87-
* the MBR again regardless of how the application was started.
90+
* the MBR again regardless of how the application was started.
8891
*/
8992

9093
/* Reset MBR VTOR to original state before calling MBR init. */
@@ -98,7 +101,7 @@ void nrf_reloc_vector_table(void)
98101
/* Set SCB->VTOR to go through MBR to trap SoftDevice service calls. */
99102
SCB->VTOR = 0x0;
100103

101-
/* Initialize MBR so SoftDevice service calls are being trapped correctly.
104+
/* Initialize MBR so SoftDevice service calls are being trapped correctly.
102105
* This call sets MBR_VTOR_ADDRESS to point to the SoftDevice's VTOR at address 0x1000.
103106
*/
104107
nrf_dfu_mbr_init_sd();
@@ -109,17 +112,18 @@ void nrf_reloc_vector_table(void)
109112
#else
110113

111114
/* No SoftDevice is present. Set all interrupts to vector table in RAM. */
112-
SCB->VTOR = (uint32_t) nrf_dispatch_vector;
115+
SCB->VTOR = (uint32_t) nrf_dispatch_vector;
113116
#endif
114117
}
115118

116-
117119
void mbed_sdk_init(void)
118120
{
119-
if (STDIO_UART_RTS != NC) {
120-
gpio_t rts;
121-
gpio_init_out(&rts, STDIO_UART_RTS);
122-
/* Set STDIO_UART_RTS as gpio driven low */
123-
gpio_write(&rts, 0);
124-
}
121+
if (STDIO_UART_RTS != NC) {
122+
gpio_t rts;
123+
gpio_init_out(&rts, STDIO_UART_RTS);
124+
/* Set STDIO_UART_RTS as gpio driven low */
125+
gpio_write(&rts, 0);
126+
}
127+
128+
subtarget_sdk_init();
125129
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2021 ARM Limited
3+
* Copyright (c) 2021 Embedded Planet, Inc.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "subtarget_init.h"
20+
#include "platform/mbed_toolchain.h"
21+
22+
MBED_WEAK void subtarget_sdk_init(void)
23+
{
24+
/* Do nothing by default */
25+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2021 ARM Limited
3+
* Copyright (c) 2021 Embedded Planet, Inc.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#ifndef _NORDIC_SUBTARGET_INIT_
20+
#define _NORDIC_SUBTARGET_INIT_
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
/**
27+
* Since Mbed's `mbed_sdk_init` hook is used by the NRF52 family code, this
28+
* initialization hook is provided so subtargets may implement their own startup
29+
* initialization code, if necessary.
30+
*
31+
* By default, it is a blank function that is declared a "weak" symbol
32+
*/
33+
void subtarget_sdk_init(void);
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif
38+
39+
#endif /* _NORDIC_SUBTARGET_INIT_ */

0 commit comments

Comments
 (0)