Skip to content

Commit e8528fa

Browse files
committed
- Added 1/1024 s tick based on 4096 Hz RTC.
- Added simple status LED for initial testing - Generally cleaned up & implemented supervisor/port.c - Added some additional commenting from supervisor headers - Fixed a linkerscript issue copying .text into FLASH_ISR
1 parent 0374e99 commit e8528fa

9 files changed

Lines changed: 351 additions & 106 deletions

File tree

ports/analog/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ INC += \
7575
-I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Include \
7676
-I$(ADI_PERIPH)/Include/$(MCU_VARIANT_UPPER) \
7777
-I$(PERIPH_SRC)/SYS \
78-
-I$(PERIPH_SRC)/GPIO \
7978
-I$(PERIPH_SRC)/CTB \
80-
-I$(PERIPH_SRC)/ICC \
8179
-I$(PERIPH_SRC)/FLC \
80+
-I$(PERIPH_SRC)/GPIO \
81+
-I$(PERIPH_SRC)/ICC \
82+
-I$(PERIPH_SRC)/RTC \
8283
-I$(PERIPH_SRC)/UART \
8384

8485
INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC
@@ -103,6 +104,8 @@ SRC_MAX32 += \
103104
$(PERIPH_SRC)/GPIO/gpio_reva.c \
104105
$(PERIPH_SRC)/ICC/icc_$(DIE_TYPE).c \
105106
$(PERIPH_SRC)/ICC/icc_reva.c \
107+
$(PERIPH_SRC)/RTC/rtc_$(DIE_TYPE).c \
108+
$(PERIPH_SRC)/RTC/rtc_reva.c \
106109
$(PERIPH_SRC)/UART/uart_common.c \
107110
$(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \
108111
$(PERIPH_SRC)/UART/uart_revb.c \

ports/analog/background.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,41 @@
99
#include "supervisor/usb.h"
1010
#include "supervisor/shared/stack.h"
1111

12-
//TODO: IMPLEMENT
12+
#include "supervisor/max32_port.h"
1313

14-
void port_background_task(void) {
15-
return;
16-
}
14+
/** NOTE: ALL "ticks" refer to a 1/1024 s period */
15+
static int status_led_ticks=0;
16+
17+
extern mxc_gpio_cfg_t led_pin[];
18+
extern const unsigned int num_leds;
1719

20+
extern mxc_gpio_cfg_t pb_pin[];
21+
extern const unsigned int num_pbs;
22+
23+
// This function is where port-specific background
24+
// tasks should be performed
25+
// Execute port specific actions during background tick. Only if ticks are enabled.
1826
void port_background_tick(void) {
19-
return;
27+
status_led_ticks++;
28+
29+
// Set an LED approx. 1/s
30+
if (status_led_ticks > 1024)
31+
{
32+
MXC_GPIO_OutToggle(led_pin[0].port, led_pin[0].mask);
33+
status_led_ticks = 0;
34+
}
2035
}
2136

22-
void port_start_background_tick(void) {
23-
return;
37+
// Execute port specific actions during background tasks. This is before the
38+
// background callback system and happens *very* often. Use
39+
// port_background_tick() when possible.
40+
void port_background_task(void) {
2441
}
2542

43+
// Take port specific actions at the beginning and end of background ticks.
44+
// This is used e.g., to set a monitoring pin for debug purposes. "Actual
45+
// work" should be done in port_background_tick() instead.
46+
void port_start_background_tick(void) {
47+
}
2648
void port_finish_background_tick(void) {
27-
return;
2849
}

ports/analog/boards/APARD/board.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,22 @@
66

77
#include "supervisor/board.h"
88

9-
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
9+
// DEFAULT: Using the weak-defined supervisor/shared/board.c functions
10+
11+
/***** OPTIONAL BOARD-SPECIFIC FUNTIONS from supervisor/board.h *****/
12+
// Returns true if the user initiates safe mode in a board specific way.
13+
// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific
14+
// way.
15+
// bool board_requests_safe_mode(void);
16+
17+
// Initializes board related state once on start up.
18+
// void board_init(void);
19+
20+
// Reset the state of off MCU components such as neopixels.
21+
// void reset_board(void);
22+
23+
// Deinit the board. This should put the board in deep sleep durable, low power
24+
// state. It should not prevent the user access method from working (such as
25+
// disabling USB, BLE or flash) because CircuitPython may continue to run.
26+
// void board_deinit(void);
27+
/*******************************************************************/

ports/analog/linking/max32690_cktpy.ld

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
MEMORY {
22
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K
33
FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M
4-
FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 200K
5-
FLASH_FS (rw) : ORIGIN = 0x10032000, LENGTH = 64K
6-
FLASH_FIRMWARE (rx) : ORIGIN = 0x10042000, LENGTH = 0x002BE000
4+
FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 16K
5+
FLASH_FS (rw) : ORIGIN = 0x10004000, LENGTH = 64K
6+
FLASH_FIRMWARE (rx) : ORIGIN = 0x10014000, LENGTH = 0x10030000 - 80K
77
RAM (rwx): ORIGIN = 0x20000000, LENGTH = 1M
88
}
99
/* FLASH FIRMWARE: 0x10300000 (end) - 0x10042000 = 0x002BE000 */
@@ -21,14 +21,18 @@ SECTIONS {
2121
.isr_vector :
2222
{
2323
. = ALIGN(4);
24-
KEEP(*(.isr_vector)) /* Startup code */
25-
EXCLUDE_FILE (*riscv.o) *(.text*) /* program code, exclude RISCV code */
24+
/* Startup code */
25+
KEEP(*(.isr_vector*))
2626
} >FLASH_ISR
2727

2828
.text :
2929
{
3030
. = ALIGN(4);
3131
_text = .;
32+
33+
/* program code, exclude RISCV code */
34+
EXCLUDE_FILE (*riscv.o) *(.text*)
35+
3236
*(.rodata*) /* read-only data: "const" */
3337

3438
KEEP(*(.init))
@@ -142,17 +146,20 @@ SECTIONS {
142146
* size of stack_dummy section */
143147
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
144148
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
145-
__estack = __StackLimit; /* Provide _estack for CktPython */
149+
_estack = __StackLimit; /* Provide _estack for CktPython */
146150

147151
.heap (COPY):
148152
{
149153
. = ALIGN(4);
154+
__heap = .;
150155
PROVIDE ( end = . );
151156
PROVIDE ( _end = . );
152157
*(.heap*)
153158
__HeapLimit = ABSOLUTE(__StackLimit);
154159
} > RAM
155160

161+
__eheap = __HeapLimit;
162+
156163
PROVIDE(__stack = __StackTop);
157164

158165
/* Check if data + heap + stack exceeds RAM limit */

ports/analog/mpconfigport.mk

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ USB_NUM_ENDPOINT_PAIRS ?= 0
1111
LONGINT_IMPL ?= MPZ
1212
INTERNAL_LIBM ?= 1
1313

14+
INTERNAL_FLASH_FILESYSTEM = 1
15+
SPI_FLASH_FILESYSTEM = 0
16+
QSPI_FLASH_FILESYSTEM = 0
17+
18+
# TODO: Review flash filesystem funcs before flashing
19+
DISABLE_FILESYSTEM = 0
20+
1421
####################################################################################
1522
# Suggested config for first-time porting
1623
####################################################################################
@@ -31,6 +38,7 @@ CIRCUITPY_NVM = 0
3138
CIRCUITPY_AUDIOBUSIO = 0
3239
CIRCUITPY_AUDIOIO = 0
3340
CIRCUITPY_ROTARYIO = 0
41+
#todo: implement time/date based on RTC sec/subsec
3442
CIRCUITPY_RTC = 0
3543
CIRCUITPY_SDCARDIO = 0
3644
CIRCUITPY_FRAMEBUFFERIO = 0
@@ -60,8 +68,9 @@ CIRCUITPY_USB_HID = 0
6068
CIRCUITPY_USB_MIDI = 0
6169
# Does nothing without I2C
6270
CIRCUITPY_REQUIRE_I2C_PULLUPS = 0
71+
6372
# No requirements, but takes extra flash
64-
CIRCUITPY_ULAB = 0
73+
CIRCUITPY_ULAB = 1
6574
####################################################################################
6675
# Required for clean building (additional CircuittPython Defaults)
6776
####################################################################################
@@ -76,10 +85,3 @@ CIRCUITPY_BUSDEVICE = 0
7685
# TinyUSB will be added later.
7786
CIRCUITPY_TINYUSB = 0
7887
CIRCUITPY_PYUSB = 0
79-
80-
INTERNAL_FLASH_FILESYSTEM = 1
81-
SPI_FLASH_FILESYSTEM = 0
82-
QSPI_FLASH_FILESYSTEM = 0
83-
84-
# TODO: Review flash filesystem funcs before flashing
85-
DISABLE_FILESYSTEM = 0

ports/analog/mphalport.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11

22
#include "mphalport.h"
3-
#include "cmsis_gcc.h"
3+
#include "py/mphal.h"
44

5+
// includes __enable/__disable interrupts
6+
#include "mxc_sys.h"
57

6-
// TODO: Define tick & other port functions
8+
#include "shared-bindings/microcontroller/__init__.h"
79

10+
void mp_hal_delay_us(mp_uint_t delay) {
11+
common_hal_mcu_delay_us(delay);
12+
}
813

914
void mp_hal_disable_all_interrupts(void) {
1015
__disable_irq();

ports/analog/supervisor/internal_flash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifdef MAX32690
1111
#define MAX32_FLASH_SIZE 0x300000 // 3 MB
1212
#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64K
13-
#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10032000 // Load into the last MB of code/data storage???
13+
#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10040000 // Load into the last MB of code/data storage???
1414
#endif
1515

1616
#define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#ifndef MAX32_PORT_H
3+
#define MAX32_PORT_H
4+
5+
#include <stdint.h>
6+
7+
#include "mxc_sys.h"
8+
#include "mxc_pins.h"
9+
#include "gpio.h"
10+
#include "mxc_assert.h"
11+
12+
/** Linker variables defined....
13+
* _estack: end of the stack
14+
* _ebss: end of BSS section
15+
* _ezero: same as ebss (acc. to main.c)
16+
*/
17+
extern uint32_t _ezero;
18+
extern uint32_t _estack;
19+
extern uint32_t _ebss; // Stored at the end of the bss section (which includes the heap).
20+
extern uint32_t __stack, __heap;
21+
22+
extern uint32_t SystemCoreClock;
23+
24+
// Tick timer should be 1/1024 s. RTC Oscillator is usually 32.768 kHz ERTCO.
25+
#define TICKS_PER_SEC 1024
26+
27+
#ifdef MAX32690
28+
#define SUBSEC_PER_TICK 8 // 12-bit ssec register, ticks @ 4096 Hz
29+
#endif
30+
31+
#endif //MAX32_PORT_H

0 commit comments

Comments
 (0)