Skip to content

Commit 09b30e3

Browse files
Fix UART Hang on Apollo3, fix a few other test issues (#480)
* Fix some Apollo3 UART issues, fix test skipped message not printing * Augh fix memap, fix referencing nonexistent target * Fix arduino pinmap test failing * Fix another hang bug, fix not printing certain test output * Remove some unused code
1 parent 853b8bf commit 09b30e3

File tree

8 files changed

+102
-35
lines changed

8 files changed

+102
-35
lines changed

features/frameworks/unity/source/unity.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@ void UnitySkipPrint(const char* msg, const UNITY_LINE_TYPE line)
12401240
UNITY_OUTPUT_CHAR(' ');
12411241
UnityPrint(msg);
12421242
}
1243+
UNITY_OUTPUT_CHAR('\n');
12431244
}
12441245

12451246
/*-----------------------------------------------*/

targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/PeripheralPins.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,68 @@ const PinMap PinMap_PWM_OUT[] = {
312312

313313
{NC, NC, 0}
314314
};
315+
316+
/************ GPIO ***************/
317+
318+
// Note that this is only used for testing, so that the test knows what are valid GPIO pins.
319+
// It's not used in normal usage.
320+
// Also, only the "pin" field is significant here. Other fields are don't cares.
321+
322+
const PinMap PinMap_GPIO[] = {
323+
{IO_0, 0, 0},
324+
{IO_1, 0, 0},
325+
{IO_2, 0, 0},
326+
{IO_3, 0, 0},
327+
{IO_4, 0, 0},
328+
{IO_5, 0, 0},
329+
{IO_6, 0, 0},
330+
{IO_7, 0, 0},
331+
{IO_8, 0, 0},
332+
{IO_9, 0, 0},
333+
{IO_10, 0, 0},
334+
{IO_11, 0, 0},
335+
{IO_12, 0, 0},
336+
{IO_13, 0, 0},
337+
{IO_14, 0, 0},
338+
{IO_15, 0, 0},
339+
{IO_16, 0, 0},
340+
{IO_17, 0, 0},
341+
{IO_18, 0, 0},
342+
{IO_19, 0, 0},
343+
{IO_20, 0, 0},
344+
{IO_21, 0, 0},
345+
{IO_22, 0, 0},
346+
{IO_23, 0, 0},
347+
{IO_24, 0, 0},
348+
{IO_25, 0, 0},
349+
{IO_26, 0, 0},
350+
{IO_27, 0, 0},
351+
{IO_28, 0, 0},
352+
{IO_29, 0, 0},
353+
{IO_39, 0, 0},
354+
{IO_40, 0, 0},
355+
{IO_41, 0, 0},
356+
{IO_44, 0, 0},
357+
{IO_47, 0, 0},
358+
{IO_48, 0, 0},
359+
{IO_49, 0, 0},
360+
361+
// Apollo3 I/O pins - BGA package only
362+
{IO_30, 0, 0},
363+
{IO_31, 0, 0},
364+
{IO_32, 0, 0},
365+
{IO_33, 0, 0},
366+
{IO_34, 0, 0},
367+
{IO_35, 0, 0},
368+
{IO_36, 0, 0},
369+
{IO_37, 0, 0},
370+
{IO_38, 0, 0},
371+
{IO_42, 0, 0},
372+
{IO_43, 0, 0},
373+
{IO_45, 0, 0},
374+
{IO_46, 0, 0},
375+
376+
{NC, NC, 0}
377+
};
378+
379+

targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/PeripheralPins.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "pinmap.h"
2424
#include "PeripheralNames.h"
2525

26+
2627
//*** I2C ***
2728
#if DEVICE_I2C
2829
extern const PinMap PinMap_I2C_SDA[];
@@ -70,4 +71,6 @@ extern const PinMap PinMap_QSPI_DATA2[];
7071
extern const PinMap PinMap_QSPI_DATA3[];
7172
#endif
7273

74+
extern const PinMap PinMap_GPIO[];
75+
7376
#endif

targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/gpio_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "mbed_assert.h"
2525
#include "gpio_api.h"
26+
#include "PeripheralPins.h"
2627

2728
/** Set the given pin as GPIO
2829
*
@@ -224,6 +225,5 @@ int gpio_read(gpio_t *obj)
224225
*/
225226
const PinMap *gpio_pinmap(void)
226227
{
227-
MBED_ASSERT(false);
228-
return NULL;
228+
return PinMap_GPIO;
229229
}

targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/serial_api.c

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#if DEVICE_SERIAL
2727

2828
#include "serial_api.h"
29+
#include "mbed_wait_api.h"
2930

3031
#include "mbed_assert.h"
3132
#include "PeripheralPins.h"
@@ -142,7 +143,8 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
142143
obj->serial.uart_control->cfg.ui32RxBufferSize = 0;
143144
obj->serial.uart_control->cfg.ui32TxBufferSize = 0;
144145

145-
obj->serial.uart_control->cfg.ui32FifoLevels = AM_HAL_UART_RX_FIFO_7_8;
146+
// Mbed expects an interrupt whenever we have at least one char in the Rx FIFO.
147+
obj->serial.uart_control->cfg.ui32FifoLevels = AM_HAL_UART_RX_FIFO_1_8;
146148

147149
// start UART instance
148150
MBED_ASSERT(am_hal_uart_initialize(uart, &(obj->serial.uart_control->handle)) == AM_HAL_STATUS_SUCCESS);
@@ -244,6 +246,7 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
244246
break;
245247
}
246248
// NVIC_SetVector(uart_irqs[obj->serial.index], vector);
249+
NVIC_ClearPendingIRQ((IRQn_Type)(UART0_IRQn + obj->serial.uart_control->inst));
247250
NVIC_EnableIRQ((IRQn_Type)(UART0_IRQn + obj->serial.uart_control->inst));
248251
} else { // disable
249252
switch (irq) {
@@ -275,6 +278,29 @@ int serial_getc(serial_t *obj)
275278

276279
do {
277280
am_hal_uart_transfer(obj->serial.uart_control->handle, &am_hal_uart_xfer_read_single);
281+
282+
// Seeing very odd behavior with this uart, where digital glitches on the line can cause the
283+
// framing error bit to set and then cause at least some of the data within the Rx FIFO to be
284+
// deleted. This causes an infinite hang, as Mbed requires serial_getc() to return a character
285+
// if serial_readable() returns true. This UART is not well documented, so unable to say if this
286+
// is an errata or some sort of odd design choice.
287+
// To avoid this, if we did not get any data and the framing error bit is set, simply clear the flag
288+
// and return an arbitrary character. This is a little awkward but prevents a hard-to-debug hang.
289+
if(bytes_read == 0 && UARTn(obj->serial.uart_control->inst)->RSR_b.FESTAT)
290+
{
291+
UARTn(obj->serial.uart_control->inst)->RSR_b.FESTAT = 0;
292+
return 'x';
293+
}
294+
295+
// Similar to above but with the overflow flag. Without this logic we can hang when receiving
296+
// at 921600 baud. Oddly, the overflow flag in RSR does not seem to be reliable, but the overflow
297+
// flag in IES seems to be. Not sure why this UART has two overflow flags in the first place, smh...
298+
if(bytes_read == 0 && UARTn(obj->serial.uart_control->inst)->IES_b.OERIS)
299+
{
300+
UARTn(obj->serial.uart_control->inst)->IEC_b.OEIC = 1;
301+
return 'x';
302+
}
303+
278304
} while (bytes_read == 0);
279305

280306
return (int)rx_c;
@@ -334,21 +360,6 @@ void serial_pinout_tx(PinName tx)
334360
MBED_ASSERT(0);
335361
}
336362

337-
#if DEVICE_SERIAL_FC
338-
339-
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
340-
{
341-
// todo:
342-
MBED_ASSERT(0);
343-
}
344-
345-
void serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap)
346-
{
347-
// todo:
348-
MBED_ASSERT(0);
349-
}
350-
#endif
351-
352363
const PinMap *serial_tx_pinmap(void)
353364
{
354365
return PinMap_UART_TX;
@@ -359,19 +370,6 @@ const PinMap *serial_rx_pinmap(void)
359370
return PinMap_UART_RX;
360371
}
361372

362-
#if DEVICE_SERIAL_FC
363-
364-
const PinMap *serial_cts_pinmap(void)
365-
{
366-
return PinMap_UART_CTS;
367-
}
368-
369-
const PinMap *serial_rts_pinmap(void)
370-
{
371-
return PinMap_UART_RTS;
372-
}
373-
#endif
374-
375373
static inline void uart_irq(uint32_t instance)
376374
{
377375
void *handle = ap3_uart_control[instance].handle;

targets/targets.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3594,7 +3594,7 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
35943594
// DISCO_H747I's attributes.
35953595
"inherits": [
35963596
"MCU_STM32H747xI_CM7",
3597-
"DISCO_H747"
3597+
"DISCO_H747I"
35983598
]
35993599
},
36003600
"DISCO_H747I_CM4": {

tools/cmake/mbed_target_functions.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ function(mbed_set_post_build target)
187187
mbed_post_build_function(${target})
188188
endif()
189189

190-
if(HAVE_MEMAP_DEPS)
191-
mbed_generate_map_file(${target})
192-
endif()
190+
mbed_generate_map_file(${target})
193191

194192
# Give chance to adjust MBED_UPLOAD_LAUNCH_COMMANDS or MBED_UPLOAD_RESTART_COMMANDS
195193
# for debug launch

tools/python/mbed_os_tools/test/host_tests_conn_proxy/conn_proxy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ def append(self, payload: bytes):
6262
before = line[:pos]
6363
after = line[pos + len(match):]
6464
if len(before) > 0:
65+
logger.prn_rxd(before)
6566
discarded.append(before)
6667
if len(after) > 0:
6768
# not a K,V pair part
69+
logger.prn_rxd(after)
6870
discarded.append(after)
6971
logger.prn_inf("found KV pair in stream: {{%s;%s}}, queued..."% (key, value))
7072
else:

0 commit comments

Comments
 (0)