Skip to content

Commit 9325514

Browse files
authored
A few fixes for LPC55xx HIC (#927)
2 parents be2b4f7 + bc3e5a0 commit 9325514

File tree

10 files changed

+86
-37
lines changed

10 files changed

+86
-37
lines changed

docs/hic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
| [kl27z](kl27z.md) | M0+ | 48 Mhz | 32 KB | 128 KB | FS |
99
| [lpc11u35](lpc11u35.md) | M0 | 48 Mhz | 12 KB | 64 KB | FS |
1010
| [lpc4322](lpc4322.md) | M4 | 120 MHz | 256 KB | 256 KB | HS |
11-
| [lpc55xx](lpc55xx.md) | M33 | 150 MHz | 272 KB | 320 KB | HS |
11+
| [lpc55xx](lpc55xx.md) | M33 | 96 MHz | 272 KB | 320 KB | HS |
1212
| [max32625](max32625.md) | M4 | 96 MHz | 160 KB | 512 KB | FS |
1313
| [nrf52820](nrf52820.md) | M4 | 64 MHz | 32 KB | 256 KB | FS |
1414
| [sam3u2c](sam3u2c.md) | M3 | 96 MHz | 32 KB | 128 KB | HS |

docs/hic/lpc55xx.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# lpc55xx HIC
22

33
Based on LPC55S69JBD64 chip ([Data Sheet](https://www.nxp.com/docs/en/nxp/data-sheets/LPC55S6x_DS.pdf)):
4-
- Cortex-M33 150 Mhz (cores)
4+
- Cortex-M33 96 MHz (2 cores up to 150 Mhz)
55
- 640 KB Flash
66
- 320 KB RAM
77
- High-speed USB 2.0 host/device controller: 8 bi-directional endpoints including EP0 (*)

projects.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,11 @@ projects:
590590
- *module_if
591591
- *module_hic_stm32f103xb
592592
- records/board/ublox_evk_odin_w2.yaml
593+
594+
595+
# Test projects
596+
lpc55s69_nrf52840dk_test_if:
597+
- *module_if
598+
- *module_hic_lpc55s69
599+
- records/board/lpc55s69_nrf52840dk.yaml
600+
- records/board/mcu_link.yaml
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
common:
2+
macros:
3+
- SWO_UART=1
4+
sources:
5+
board:
6+
- source/board/lpc55s69_nrf52840dk.c
7+
family:
8+
- source/family/nordic/nrf52/target.c
9+
- source/family/nordic/target_reset_nrf52.c

records/hic_hal/lpc55s69.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ common:
77
- INTERFACE_LPC55XX
88
- CPU_LPC55S69JBD64_cm33_core0
99
- DAPLINK_HIC_ID=0x4C504355 # DAPLINK_HIC_ID_LPC55XX
10-
- OS_CLOCK=150000000
10+
- OS_CLOCK=96000000
1111
includes:
1212
- source/hic_hal/nxp/lpc55xx
1313
- source/hic_hal/nxp/lpc55xx/LPC55S69

source/board/lpc55s69_nrf52840dk.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @file lpc55S69_nrf52840dk.c
3+
* @brief board file for test project MCU-LINK + nRF52840-DK
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2009-2019, 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+
#include "target_family.h"
23+
#include "target_board.h"
24+
25+
extern target_cfg_t target_device_nrf52840;
26+
27+
const board_info_t g_board_info = {
28+
.info_version = kBoardInfoVersion,
29+
.board_id = "1102",
30+
.family_id = kNordic_Nrf52_FamilyID,
31+
.flags = kEnablePageErase,
32+
.target_cfg = &target_device_nrf52840,
33+
.board_vendor = "Nordic Semiconductor",
34+
.board_name = "nRF52840-DK",
35+
};

source/hic_hal/nxp/lpc55xx/hic_init.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,14 @@ void sdk_init(void)
172172
//! - Configure the USB PHY and USB1 clocks.
173173
void hic_enable_usb_clocks(void)
174174
{
175-
// For the interface, switch to 150 MHz before enabling USB. The bootloader will stay at 96 MHz
176-
// so it can always write internal flash.
177-
#if defined(DAPLINK_IF)
178-
BOARD_BootClockPLL150M();
179-
#endif
175+
// Switching to 150 MHz for interface is disabled because it prevents
176+
// interface from writing configuration and updating bootloader.
177+
// #if defined(DAPLINK_IF)
178+
// // For the interface, switch to 150 MHz before enabling USB.
179+
// // The bootloader will stay at 96 MHz so it can always write
180+
// // internal flash.
181+
// BOARD_BootClockPLL150M();
182+
// #endif
180183

181184
NVIC_ClearPendingIRQ(USB1_IRQn);
182185
NVIC_ClearPendingIRQ(USB1_NEEDCLK_IRQn);

source/hic_hal/nxp/lpc55xx/uart.c

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct {
5050
volatile uint32_t tx_size;
5151

5252
uint8_t rx;
53+
uint8_t tx;
5354
} cb_buf;
5455

5556
void uart_handler(uint32_t event);
@@ -192,41 +193,23 @@ int32_t uart_write_free(void)
192193
return circ_buf_count_free(&write_buffer);
193194
}
194195

195-
// Start a new TX transfer if there are bytes pending to be transferred on the
196-
// write_buffer buffer. The transferred bytes are not removed from the circular
197-
// by this function, only the event handler will remove them once the transfer
198-
// is done.
199-
static void uart_start_tx_transfer() {
200-
uint32_t tx_size = 0;
201-
const uint8_t* buf = circ_buf_peek(&write_buffer, &tx_size);
202-
if (tx_size > BUFFER_SIZE / 4) {
203-
// The bytes being transferred remain on the circular buffer memory
204-
// until the transfer is done. Limiting the UART transfer size
205-
// allows the uart_handler to clear those bytes earlier.
206-
tx_size = BUFFER_SIZE / 4;
207-
}
208-
cb_buf.tx_size = tx_size;
209-
if (tx_size) {
210-
USART_INSTANCE.Send(buf, tx_size);
211-
}
212-
}
213-
214196
int32_t uart_write_data(uint8_t *data, uint16_t size)
215197
{
216198
if (size == 0) {
217199
return 0;
218200
}
219201

202+
// Disable interrupts to prevent the uart_handler from modifying the
203+
// circular buffer at the same time.
204+
NVIC_DisableIRQ(USART_IRQ);
220205
uint32_t cnt = circ_buf_write(&write_buffer, data, size);
221-
if (cb_buf.tx_size == 0) {
222-
// There's no pending transfer and the value of cb_buf.tx_size will not
223-
// change to non-zero by the event handler once it is zero. Note that it
224-
// is entirely possible that we transferred all the bytes we added to
225-
// the circular buffer in this function by the time we are in this
226-
// branch, in that case uart_start_tx_transfer() would not schedule any
227-
// transfer.
228-
uart_start_tx_transfer();
206+
if (cb_buf.tx_size == 0 && circ_buf_count_used(&write_buffer) > 0) {
207+
// There's no pending transfer, so we need to start the process.
208+
cb_buf.tx = circ_buf_pop(&write_buffer);
209+
USART_INSTANCE.Send(&(cb_buf.tx), 1);
210+
cb_buf.tx_size = 1;
229211
}
212+
NVIC_EnableIRQ(USART_IRQ);
230213

231214
return cnt;
232215
}
@@ -250,7 +233,13 @@ void uart_handler(uint32_t event) {
250233
}
251234

252235
if (event & ARM_USART_EVENT_SEND_COMPLETE) {
253-
circ_buf_pop_n(&write_buffer, cb_buf.tx_size);
254-
uart_start_tx_transfer();
236+
if (circ_buf_count_used(&write_buffer) > 0) {
237+
cb_buf.tx = circ_buf_pop(&write_buffer);
238+
USART_INSTANCE.Send(&(cb_buf.tx), 1);
239+
} else {
240+
// Signals that next call to uart_write_data() should start a
241+
// transfer.
242+
cb_buf.tx_size = 0;
243+
}
255244
}
256245
}

test/info.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ def VENDOR_TO_FAMILY(x, y) : return (VENDOR_ID[x] <<8) | y
235235
( 0x0000, VENDOR_TO_FAMILY('Stub', 1), 'nrf52820_if', None, None ),
236236
( 0x0000, VENDOR_TO_FAMILY('Stub', 1), 'sam3u2c_if', None, None ),
237237
( 0x0000, VENDOR_TO_FAMILY('Stub', 1), 'stm32f103xb_if', None, None ),
238+
239+
# Test projects
240+
( 0x1102, VENDOR_TO_FAMILY('Nordic', 2), 'lpc55s69_nrf52840dk_test_if', 'lpc55s69_bl', 'Nordic-nRF52840-DK' ),
238241
]
239242

240243
# Add new HICs here

tools/progen_compile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def get_core_count():
9494
# musca projects are too large to fit when compiled with gcc. LTO should fix that but it does not work (yet)
9595
if 'gcc' in toolchain and args.release:
9696
project_list = list(filter(lambda p: "musca" not in p, project_list))
97+
# remove all test projects from list
98+
project_list = list(filter(lambda p: not p.endswith("test_if"), project_list))
9799

98100
logging_level = logging.DEBUG if args.verbosity >= 2 else (logging.INFO if args.verbosity >= 1 else logging.WARNING)
99101
logging.basicConfig(format="%(asctime)s %(name)020s %(levelname)s\t%(message)s", level=logging_level)

0 commit comments

Comments
 (0)