8000 esp32: Merge with master. · pycom/pycom-micropython-sigfox@f4f56ab · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit f4f56ab

Browse files
author
Daniel Campora
committed
esp32: Merge with master.
1 parent 195813d commit f4f56ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+414
-270
lines changed

esp32/Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,23 @@ endif
1616

1717
TARGET ?= app
1818

19+
OEM ?= 0
20+
1921
# make 'release' the default build type
2022
BTYPE ?= release
2123

22-
# if the build directory is not given, make it reflect the board name.
23-
BUILD ?= build/$(BOARD)/$(BTYPE)
24+
LORA_BAND ?= USE_BAND_868
25+
ifeq ($(BOARD), LOPY)
26+
ifeq ($(LORA_BAND), USE_BAND_868)
27+
LORA_FREQ = 868
28+
else
29+
LORA_FREQ = 915
30+
endif
31+
BUILD = build/$(BOARD)_$(LORA_FREQ)/$(BTYPE)
32+
else
33+
LORA_FREQ =
34+
BUILD = build/$(BOARD)/$(BTYPE)
35+
endif
2436

2537
FROZEN_MPY_DIR = frozen
2638

@@ -41,6 +53,10 @@ else
4153
CFLAGS_XTENSA += -Og
4254
endif
4355

56+
ifeq ($(OEM), 1)
57+
CFLAGS_XTENSA += -DOEM_VERSION
58+
endif
59+
4460
CFLAGS = $(CFLAGS_XTENSA) -nostdlib -std=gnu99 -g3 -fstrict-volatile-bitfields -Iboards/$(BOARD)
4561

4662
LDFLAGS = -nostdlib -Wl,-Map=$(@:.elf=.map) -Wl,--no-check-sections -u call_user_start_cpu0

esp32/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ After that, build the ESP32 port for one of Pycom boards (first the bootloader,
1919

2020
$ cd ../esp32
2121
$ make BOARD=LOPY -j5 TARGET=boot
22-
$ make BOARD=LOPY -j5 TARGET=app clean
22+
$ make BOARD=LOPY -j5 LORA_BAND=USE_BAND_868 TARGET=app
2323

2424
Flash the board (connect P2 to GND and reset before starting):
2525

26-
$ make BOARD=LOPY flash
26+
$ make BOARD=LOPY -j5 LORA_BAND=USE_BAND_868 flash
2727

2828
Using frozen modules
2929
--------------------

esp32/application.mk

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,6 @@ BOOT_LDFLAGS = $(LDFLAGS) -T esp32.bootloader.ld -T esp32.rom.ld -T esp32.periph
264264
# add the application linker script(s)
265265
APP_LDFLAGS += $(LDFLAGS) -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld
266266

267-
LORA_BAND ?= USE_BAND_868
268-
ifeq ($(BOARD), LOPY)
269-
ifeq ($(LORA_BAND), USE_BAND_868)
270-
LORA_FREQ = 868
271-
else
272-
LORA_FREQ = 915
273-
endif
274-
else
275-
LORA_FREQ =
276-
endif
277-
278267
# add the application specific CFLAGS
279268
CFLAGS += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -D$(LORA_BAND) -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM
280269

@@ -361,7 +350,6 @@ $(BUILD)/application.a: $(OBJ)
361350
$(ECHO) "AR $@"
362351
$(Q) rm -f $@
363352
$(Q) $(AR) cru $@ $^
364-
365353
ifeq ($(BOARD), SIPY)
366354
$(BUILD)/application.elf: $(BUILD)/application.a $(BUILD)/esp32_out.ld
367355
$(ECHO) "LINK $@"

esp32/boards/LOPY/LOPY_868/script

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
["e", "0x8000", "0x1000"],
3+
["e", "0x110000", "0x1000"],
4+
["e", "0x210000", "0x1000"],
5+
["e", "0x320000", "0x1000"],
6+
["e", "0x37F000", "0x1000"],
7+
["w", "0x1000", "bootloader.bin"],
8+
["w", "0x8000", "partitions.bin"],
9+
["w", "0x10000", "lopy_868.bin"]
10+
]

esp32/boards/LOPY/LOPY_915/script

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
["e", "0x8000", "0x1000"],
3+
["e", "0x110000", "0x1000"],
4+
["e", "0x210000", "0x1000"],
5+
["e", "0x320000", "0x1000"],
6+
["e", "0x37F000", "0x1000"],
7+
["w", "0x1000", "bootloader.bin"],
8+
["w", "0x8000", "partitions.bin"],
9+
["w", "0x10000", "lopy_915.bin"]
10+
]

esp32/boards/LOPY/mpconfigboard.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,34 @@
1818

1919
#define MICROPY_HW_FLASH_SIZE (4 * 1024 * 1024)
2020

21-
#define MICROPY_LPWAN_DIO_PIN_NUM (23)
22-
#define MICROPY_LPWAN_DIO_PIN (pin_GPIO23)
21+
#if defined(OEM_VERSION)
22+
23+
#define MICROPY_LPWAN_RESET_PIN_NUM
24+
#define MICROPY_LPWAN_RESET_PIN_NAME
25+
#define MICROPY_LPWAN_RESET_PIN
26+
#define MICROPY_LPWAN_USE_RESET_PIN 0
27+
28+
#define MICROPY_LPWAN_DIO_PIN_NUM (23)
29+
#define MICROPY_LPWAN_DIO_PIN_NAME GPIO23
30+
#define MICROPY_LPWAN_DIO_PIN (pin_GPIO23)
31+
32+
#define MICROPY_LPWAN_NCS_PIN_NUM (18)
33+
#define MICROPY_LPWAN_NCS_PIN_NAME GPIO18
34+
#define MICROPY_LPWAN_NCS_PIN (pin_GPIO18)
35+
36+
#else
37+
38+
#define MICROPY_LPWAN_RESET_PIN_NUM (18)
39+
#define MICROPY_LPWAN_RESET_PIN_NAME GPIO18
40+
#define MICROPY_LPWAN_RESET_PIN (pin_GPIO18)
41+
#define MICROPY_LPWAN_USE_RESET_PIN 1
42+
43+
#define MICROPY_LPWAN_DIO_PIN_NUM (23)
44+
#define MICROPY_LPWAN_DIO_PIN_NAME GPIO23
45+
#define MICROPY_LPWAN_DIO_PIN (pin_GPIO23)
46+
47+
#define MICROPY_LPWAN_NCS_PIN_NUM (17)
48+
#define MICROPY_LPWAN_NCS_PIN_NAME GPIO17
49+
#define MICROPY_LPWAN_NCS_PIN (pin_GPIO17)
50+
51+
#endif

esp32/boards/SIPY/SIPY/script

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
["e", "0x8000", "0x1000"],
3+
["e", "0x110000", "0x1000"],
4+
["e", "0x210000", "0x1000"],
5+
["e", "0x320000", "0x1000"],
6+
["e", "0x37F000", "0x1000"],
7+
["w", "0x1000", "bootloader.bin"],
8+
["w", "0x8000", "partitions.bin"],
9+
["w", "0x10000", "sipy.bin"]
10+
]

esp32/boards/WIPY/WIPY/script

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
["e", "0x8000", "0x1000"],
3+
["e", "0x110000", "0x1000"],
4+
["e", "0x210000", "0x1000"],
5+
["e", "0x320000", "0x1000"],
6+
["e", "0x37F000", "0x1000"],
7+
["w", "0x1000", "bootloader.bin"],
8+
["w", "0x8000", "partitions.bin"],
9+
["w", "0x10000", "wipy.bin"]
10+
]

esp32/hal/esp32_mphal.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,19 @@ void mp_hal_feed_watchdog(void) {
7575
}
7676

7777
void mp_hal_delay_us(uint32_t us) {
78-
if (us < 1000) {
79-
ets_delay_us(us);
78+
if (us <= 1000) {
79+
if (us > 0) {
80+
ets_delay_us(us);
81+
}
8082
} else {
83+
uint32_t ms = us / 1000;
84+
us = us % 1000;
8185
MP_THREAD_GIL_EXIT();
82-
ets_delay_us(us);
86+
vTaskDelay (ms / portTICK_PERIOD_MS);
8387
MP_THREAD_GIL_ENTER();
88+
if (us > 0) {
89+
ets_delay_us(us);
90+
}
8491
}
8592
}
8693

esp32/lib/libbt.a

0 Bytes
Binary file not shown.

esp32/lib/libcxx.a

0 Bytes
Binary file not shown.

esp32/lib/libdriver.a

0 Bytes
Binary file not shown.

esp32/lib/libesp32.a

416 Bytes
Binary file not shown.

esp32/lib/libexpat.a

0 Bytes
Binary file not shown.

esp32/lib/libfreertos.a

1 KB
Binary file not shown.

esp32/lib/libjson.a

0 Bytes
Binary file not shown.

esp32/lib/liblog.a

0 Bytes
Binary file not shown.

esp32/lib/liblwip.a

16 Bytes
Binary file not shown.

esp32/lib/libmbedtls.a

0 Bytes
Binary file not shown.

esp32/lib/libmicro-ecc.a

0 Bytes
Binary file not shown.

esp32/lib/libnewlib.a

0 Bytes
Binary file not shown.

esp32/lib/libnghttp.a

0 Bytes
Binary file not shown.

esp32/lib/libnvs_flash.a

0 Bytes
Binary file not shown.

esp32/lib/libopenssl.a

0 Bytes
Binary file not shown.

esp32/lib/libsdmmc.a

0 Bytes
Binary file not shown.

esp32/lib/libspi_flash.a

0 Bytes
Binary file not shown.

esp32/lib/libtcpip_adapter.a

0 Bytes
Binary file not shown.

esp32/lib/libvfs.a

0 Bytes
Binary file not shown.

esp32/lib/libwpa_supplicant.a

0 Bytes
Binary file not shown.

esp32/lib/libxtensa-debug-module.a

0 Bytes
Binary file not shown.

esp32/lora/board.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Maintainer: Miguel Luis and Gregory Cristian
3636
#include <string.h>
3737
#include <stdint.h>
3838

39+
#include "py/mpconfig.h"
40+
3941
#include "lora/system/gpio.h"
4042
#include "lora/system/timer.h"
4143
#include "lora/system/spi.h"
@@ -57,14 +59,14 @@ Maintainer: Miguel Luis and Gregory Cristian
5759
* Board MCU pins definitions
5860
*/
5961

60-
#define RADIO_RESET GPIO18
62+
#define RADIO_RESET MICROPY_LPWAN_RESET_PIN_NAME
6163

6264
#define RADIO_MOSI GPIO27
6365
#define RADIO_MISO GPIO19
6466
#define RADIO_SCLK GPIO5
65-
#define RADIO_NSS GPIO17
67+
#define RADIO_NSS MICROPY_LPWAN_NCS_PIN_NAME
6668

67-
#define RADIO_DIO GPIO23
69+
#define RADIO_DIO MICROPY_LPWAN_DIO_PIN_NAME
6870

6971
void BoardInitPeriph( void );
7072

esp32/mods/analog.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "esp_types.h"
1717
#include "esp_err.h"
1818
#include "soc/soc.h"
19+
#include "adc.h"
1920

2021
#ifdef __cplusplus
2122
extern "C" {
@@ -53,13 +54,15 @@ typedef enum {
5354
ADC1_CH_MAX,
5455
} adc_channel_t;
5556

56-
typedef enum {
57-
ADC_ATTEN_0DB = 0,
58-
ADC_ATTEN_3DB,
59-
ADC_ATTEN_6DB,
60-
ADC_ATTEN_12DB,
61-
ADC_ATTEN_MAX,
62-
} adc_atten_t;
57+
// typedef enum {
58+
// ADC_ATTEN_0DB = 0,
59+
// ADC_ATTEN_3DB,
60+
// ADC_ATTEN_6DB,
61+
// ADC_ATTEN_12DB,
62+
// ADC_ATTEN_MAX,
63+
// } adc_atten_t;
64+
65+
#define ADC_ATTEN_MAX 4
6366

6467
typedef enum {
6568
DAC1_DIS_DAC2_DIS = 0, /*DAC1 disable, DAC2 disable*/

esp32/mods/machine_i2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ STATIC void mp_hal_i2c_init(machine_i2c_obj_t *self, uint32_t freq) {
132132
if (self->us_delay == 0) {
133133
self->us_delay = 1;
134134
}
135-
pin_config (self->scl, -1, -1, GPIO_MODE_INPUT_OUTPUT_OD, MACHPIN_PULL_UP, 0);
136-
pin_config (self->sda, -1, -1, GPIO_MODE_INPUT_OUTPUT_OD, MACHPIN_PULL_UP, 0);
135+
pin_config (self->scl, -1, -1, GPIO_MODE_INPUT_OUTPUT_OD, MACHPIN_PULL_UP, 1);
136+
pin_config (self->sda, -1, -1, GPIO_MODE_INPUT_OUTPUT_OD, MACHPIN_PULL_UP, 1);
137137
mp_hal_i2c_stop(self);
138138
}
139139

esp32/mods/machpin.c

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -194,23 +194,21 @@ static IRAM_ATTR void call_interrupt_handler (pin_obj_t *pin) {
194194
}
195195

196196
static IRAM_ATTR void machpin_intr_process (void* arg) {
197-
// ESP_INTR_DISABLE(ETS_GPIO_INUM);
198-
uint32_t gpio_intr_status = READ_PERI_REG(GPIO_STATUS_REG);
199-
uint32_t gpio_intr_status_h = READ_PERI_REG(GPIO_STATUS1_REG);
200-
201-
// clear the interrupts
202-
SET_PERI_REG_MASK(GPIO_STATUS_W1TC_REG, gpio_intr_status);
203-
SET_PERI_REG_MASK(GPIO_STATUS1_W1TC_REG, gpio_intr_status_h);
204197
uint32_t gpio_num = 0;
205198
uint32_t mask;
206199

200+
uint32_t gpio_intr_status = READ_PERI_REG(GPIO_STATUS_REG);
201+
uint32_t gpio_intr_status_h = READ_PERI_REG(GPIO_STATUS1_REG);
202+
207203
#ifdef MICROPY_LPWAN_DIO_PIN_NUM
208204
// fast path for the LPWAN DIO interrupt
209205
if (gpio_intr_status & (1 << MICROPY_LPWAN_DIO_PIN_NUM)) {
210206
((void(*)(void))MICROPY_LPWAN_DIO_PIN.handler)();
211207

212208
// clear this bit from the interrupt status
213209
gpio_intr_status &= ~(1 << MICROPY_LPWAN_DIO_PIN_NUM);
210+
// clear the interrupt
211+
SET_PERI_REG_MASK(GPIO_STATUS_W1TC_REG, (1 << MICROPY_LPWAN_DIO_PIN_NUM));
214212
}
215213
#endif
216214

@@ -235,29 +233,9 @@ static IRAM_ATTR void machpin_intr_process (void* arg) {
235233
mask <<= 1;
236234
}
237235

238-
// the next algorithm could be faster
239-
#if 0
240-
uint32_t n;
241-
for (;;) {
242-
n = __builtin_ffs(gpio_intr_status); // find first bit set
243-
if (n == 0) break;
244-
gpio_num += n;
245-
pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_num(&pin_cpu_pins_locals_dict, gpio_num - 1);
246-
mp_irq_handler(mp_irq_find(self));
247-
gpio_intr_status >>= n;
248-
}
249-
250-
gpio_num = 32;
251-
for (;;) {
252-
n = __builtin_ffs(gpio_intr_status_h); // find first bit set
253-
if (n == 0) break;
254-
gpio_num += n;
255-
pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_num(&pin_cpu_pins_locals_dict, gpio_num - 1);
256-
mp_irq_handler(mp_irq_find(self));
257-
gpio_intr_status_h >>= n;
258-
}
259-
#endif
260-
// ESP_INTR_ENABLE(ETS_GPIO_INUM);
236+
// clear the interrupts
237+
SET_PERI_REG_MASK(GPIO_STATUS_W1TC_REG, gpio_intr_status);
238+
SET_PERI_REG_MASK(GPIO_STATUS1_W1TC_REG, gpio_intr_status_h);
261239
}
262240

263241
/******************************************************************************

esp32/mods/machtimer.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,23 @@ void calibrate_us_timer(void) {
3838
us_timer_calibration = t2 - t1;
3939
}
4040

41-
void modtimer_init0(void) {
41+
void machtimer_init0(void) {
4242
timer_config_t config = {.alarm_en = false, .counter_en = false, .counter_dir = TIMER_COUNT_UP, .intr_type = TIMER_INTR_LEVEL, .auto_reload = false, .divider = 2};
4343

4444
init_alarm_heap();
4545

4646
timer_init(TIMER_GROUP_0, TIMER_0, &config);
47-
4847
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
48+
timer_enable_intr(TIMER_GROUP_0, TIMER_0);
4949
timer_start(TIMER_GROUP_0, TIMER_0);
5050
calibrate_us_timer();
5151
}
5252

53+
void machtimer_deinit(void) {
54+
timer_pause(TIMER_GROUP_0, TIMER_0);
55+
timer_disable_intr(TIMER_GROUP_0, TIMER_0);
56+
}
57+
5358
uint64_t get_timer_counter_value(void) {
5459
uint64_t t;
5560

esp32/mods/machtimer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
#ifndef MACHTIMER_H_
1111
#define MACHTIMER_H_
1212

13-
extern void modtimer_init0(void);
14-
uint64_t get_timer_counter_value(void);
13+
extern void machtimer_init0(void);
14+
extern void machtimer_deinit(void);
15+
extern uint64_t get_timer_counter_value(void);
1516

1617
extern const mp_obj_type_t mach_timer_type;
1718

0 commit comments

Comments
 (0)
0