Skip to content

Commit 2bf1ed7

Browse files
committed
- Move SysTick init from board_init to port_init. - Fix RTC issue with interrupt_after_ticks. - Move LED inidcator to STATUS_LED code.
1 parent cce1fbb commit 2bf1ed7

File tree

7 files changed

+34
-63
lines changed

7 files changed

+34
-63
lines changed

ports/analog/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ SRC_QSTR_PREPROCESSOR +=
259259
# Default build target
260260
all: $(BUILD)/firmware.elf $(BUILD)/firmware.hex $(BUILD)/firmware.bin
261261

262-
clean-max32:
262+
clean-all:
263263
rm -rf build-*
264264

265265
# Optional flash option when running within an installed MSDK to use OpenOCD

ports/analog/boards/apard32690/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For more info about AD-APARD32690-SL, visit our product webpages for datasheets,
1818
To build for this board, ensure you are in the `ports/analog` directory and run the following command. Note that passing in the `-jN` flag, where N is the # of cores on your machine, can speed up compile times.
1919

2020
```
21-
make BOARD=APARD
21+
make BOARD=apard32690
2222
```
2323

2424
#### Flashing this board

ports/analog/boards/apard32690/board.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,6 @@ uint32_t board_millis(void) {
4747

4848
// Initializes board related state once on start up.
4949
void board_init(void) {
50-
// 1ms tick timer
51-
SysTick_Config(SystemCoreClock / 1000); \
52-
53-
// Enable GPIO (enables clocks + common init for ports)
54-
for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) {
55-
MXC_GPIO_Init(0x1 << i);
56-
}
57-
58-
// Init Board LEDs
59-
/* setup GPIO for the LED */
60-
for (int i = 0; i < num_leds; i++) {
61-
// Set the output value
62-
MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask);
63-
MXC_GPIO_Config(&led_pin[i]);
64-
}
65-
66-
// Turn on one LED to indicate Sign of Life
67-
MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask);
6850
}
6951

7052
// Reset the state of off MCU components such as neopixels.

ports/analog/boards/apard32690/mpconfigboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@
3636
// #else
3737
// #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0)
3838
// #endif
39+
40+
#define MICROPY_HW_LED_STATUS (&pin_P2_01)

ports/analog/boards/max32690evkit/board.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ uint32_t board_millis(void) {
4646

4747
// Initializes board related state once on start up.
4848
void board_init(void) {
49-
// 1ms tick timer
50-
SysTick_Config(SystemCoreClock / 1000); \
51-
52-
// Enable GPIO (enables clocks + common init for ports)
53-
for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) {
54-
MXC_GPIO_Init(0x1 << i);
55-
}
56-
57-
// Init Board LEDs
58-
/* setup GPIO for the LED */
59-
for (int i = 0; i < num_leds; i++) {
60-
// Set the output value
61-
MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask);
62-
MXC_GPIO_Config(&led_pin[i]);
63-
}
64-
65-
// Turn on one LED to indicate Sign of Life
66-
MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask);
6749
}
6850

6951
// Reset the state of off MCU components such as neopixels.

ports/analog/boards/max32690evkit/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@
3636
// #else
3737
// #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0)
3838
// #endif
39+
40+
#define MICROPY_HW_LED_STATUS (&pin_P2_12)
41+
#define MICROPY_HW_LED_STATUS_INVERTED 1

ports/analog/supervisor/port.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ extern void NVIC_SystemReset(void) NORETURN;
6868
safe_mode_t port_init(void) {
6969
int err = E_NO_ERROR;
7070

71+
// 1ms tick timer
72+
SysTick_Config(SystemCoreClock / 1000);
73+
7174
// Enable GPIO (enables clocks + common init for ports)
7275
for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) {
7376
err = MXC_GPIO_Init(0x1 << i);
@@ -122,12 +125,18 @@ void RTC_IRQHandler(void) {
122125
// Read flags to clear
123126
int flags = MXC_RTC_GetFlags();
124127

125-
if (flags & MXC_F_RTC_CTRL_SSEC_ALARM) {
126-
MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM);
127-
}
128-
129-
if (flags & MXC_F_RTC_CTRL_TOD_ALARM) {
130-
MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM);
128+
switch (flags) {
129+
case MXC_F_RTC_CTRL_SSEC_ALARM:
130+
MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM);
131+
break;
132+
case MXC_F_RTC_CTRL_TOD_ALARM:
133+
MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM);
134+
break;
135+
case MXC_F_RTC_CTRL_RDY:
136+
MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_RDY);
137+
break;
138+
default:
139+
break;
131140
}
132141

133142
tick_flag = 1;
@@ -145,7 +154,7 @@ void reset_port(void) {
145154
}
146155

147156
// Reset to the bootloader
148-
// note: not implemented since max32 requires external stim ignals to
157+
// note: not implemented since max32 requires external signals to
149158
// activate bootloaders
150159
void reset_to_bootloader(void) {
151160
NVIC_SystemReset();
@@ -193,7 +202,6 @@ uint32_t port_get_saved_word(void) {
193202
uint64_t port_get_raw_ticks(uint8_t *subticks) {
194203
// Ensure we can read from ssec register as soon as we can
195204
// MXC function does cross-tick / busy checking of RTC controller
196-
__disable_irq();
197205
if (MXC_RTC->ctrl & MXC_F_RTC_CTRL_EN) {
198206
// NOTE: RTC_GetTime always returns BUSY if RTC is not running
199207
while ((MXC_RTC_GetTime(&sec, &subsec)) != E_NO_ERROR) {
@@ -203,7 +211,6 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) {
203211
sec = MXC_RTC->sec;
204212
subsec = MXC_RTC->ssec;
205213
}
206-
__enable_irq();
207214

208215
// Return ticks given total subseconds
209216
// ticks = TICKS/s * s + subsec/ subs/tick
@@ -220,41 +227,36 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) {
220227

221228
// Enable 1/1024 second tick.
222229
void port_enable_tick(void) {
223-
MXC_RTC_Start();
230+
while ( MXC_RTC_Start() == E_BUSY );
224231
}
225232

226233
// Disable 1/1024 second tick.
227234
void port_disable_tick(void) {
228-
MXC_RTC_Stop();
235+
while( MXC_RTC_Stop() == E_BUSY );
229236
}
230237

231238
// Wake the CPU after a given # of ticks or sooner
232239
void port_interrupt_after_ticks(uint32_t ticks) {
233240
uint32_t ticks_msec = 0;
234-
// Stop RTC & store current time & ticks
235-
port_disable_tick();
236-
port_get_raw_ticks(NULL);
237241

238-
ticks_msec = 1000 * ticks / TICKS_PER_SEC;
242+
ticks_msec = (ticks / TICKS_PER_SEC) * 1000;
239243

240-
while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE |
241-
MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) {
242-
}
243-
;
244+
// Disable RTC interrupts
245+
MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE |
246+
MXC_F_RTC_CTRL_TOD_ALARM_IE | MXC_F_RTC_CTRL_RDY_IE);
247+
248+
// Stop RTC & store current time & ticks
249+
port_get_raw_ticks(NULL);
244250

245251
// Clear the flag to be set by the RTC Handler
246252
tick_flag = 0;
247253

248254
// Subsec alarm is the starting/reload value of the SSEC counter.
249255
// ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0
250-
while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) == E_BUSY) {
251-
}
252-
while (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) {
253-
}
256+
while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) != E_SUCCESS) {}
254257

255-
NVIC_EnableIRQ(RTC_IRQn);
258+
MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE);
256259

257-
port_enable_tick();
258260
}
259261

260262
void port_idle_until_interrupt(void) {

0 commit comments

Comments
 (0)