Skip to content

Commit 68d8daa

Browse files
committed
Resolve UART ISR naming issues
- Call NVIC_SetRAM in supervisor/port.c to move NVIC table to RAM, enabling ISR RAM remapping. - Rename UART ISR to be generic for any UART IRQn. - Remove background led writes from background.c.
1 parent d47b882 commit 68d8daa

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

ports/analog/background.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@ extern const mxc_gpio_cfg_t led_pin[];
1919
extern const int num_leds;
2020

2121
/** NOTE: ALL "ticks" refer to a 1/1024 s period */
22-
static int status_led_ticks = 0;
22+
static int status_ticks = 0;
2323

2424
// This function is where port-specific background
2525
// tasks should be performed
2626
// Execute port specific actions during background tick. Only if ticks are enabled.
2727
void port_background_tick(void) {
28-
status_led_ticks++;
29-
30-
// Set an LED approx. 1/s
31-
if (status_led_ticks > 1024) {
32-
MXC_GPIO_OutToggle(led_pin[2].port, led_pin[2].mask);
33-
status_led_ticks = 0;
34-
}
28+
status_ticks++;
3529
}
3630

3731
// Execute port specific actions during background tasks. This is before the

ports/analog/common-hal/busio/UART.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static mxc_uart_parity_t convertParity(busio_uart_parity_t busio_parity) {
146146
}
147147
}
148148

149-
void UART0_IRQHandler(void) {
149+
void uart_isr(void) {
150150
for (int i = 0; i < NUM_UARTS; i++) {
151151
if (uarts_active & (1 << i)) {
152152
MXC_UART_AsyncHandler(MXC_UART_GET_UART(i));
@@ -237,6 +237,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
237237
self->error = E_NO_ERROR;
238238

239239
// Initialize ringbuffer for receiving data
240+
// FIXME: Either the use the ringbuf or get rid of it!
240241
if (self->rx_pin) {
241242
// if given a ringbuff, use that
242243
if (receiver_buffer) {
@@ -253,12 +254,18 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
253254
// Indicate to this module that the UART is active
254255
uarts_active |= (1 << self->uart_id);
255256

257+
// Set the timeout to a default value
258+
if (((timeout < 0.0) || (timeout > 100.0))) {
259+
self->timeout = 1.0;
260+
} else {
261+
self->timeout = timeout;
262+
}
256263

257264
/* Setup UART interrupt */
258265
NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(self->uart_id));
259266
NVIC_DisableIRQ(MXC_UART_GET_IRQ(self->uart_id));
260267
NVIC_SetPriority(MXC_UART_GET_IRQ(self->uart_id), UART_PRIORITY);
261-
NVIC_SetVector(MXC_UART_GET_IRQ(self->uart_id), (uint32_t)&UART0_IRQHandler);
268+
NVIC_SetVector(MXC_UART_GET_IRQ(self->uart_id), (uint32_t)uart_isr);
262269

263270
return;
264271
}

ports/analog/supervisor/port.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
// Sys includes
4141
#include "max32_port.h"
42+
#include "nvic_table.h"
4243

4344
// Timers
4445
#include "mxc_delay.h"
@@ -75,6 +76,13 @@ void SysTick_Handler(void) {
7576
safe_mode_t port_init(void) {
7677
int err = E_NO_ERROR;
7778

79+
// Set Vector Table to RAM & configure ARM core to use RAM-based ISRs
80+
// This allows definition of ISRs with custom names
81+
//
82+
// Useful for mapping ISRs with names not related to a specific IRQn.
83+
// Source: https://arm-software.github.io/CMSIS_5/Core/html/using_VTOR_pg.html
84+
NVIC_SetRAM();
85+
7886
// 1ms tick timer
7987
SysTick_Config(SystemCoreClock / 1000);
8088
NVIC_EnableIRQ(SysTick_IRQn);

0 commit comments

Comments
 (0)