Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semtech SX1262 compatibility completion port #1

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

bdesterBE
Copy link
Collaborator

No description provided.

@bdesterBE bdesterBE self-assigned this Jan 4, 2024
@@ -58,25 +143,21 @@ uint32_t BoardGetRandomSeed( void )
return (mac_addr_bin[5] << 0) | (mac_addr_bin[4] << 8) | (mac_addr_bin[3] << 16) | (mac_addr_bin[2] << 24);
}

#include "nvs.h"

void BoardGetUniqueId( uint8_t *id )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure you want to use the DEVEUI here? all other implementations use something hardware unique - see

https://github.com/Lora-net/LoRaMac-node/blob/99c2e5378dde37e3331bf3efdf9df8f77d4847ee/src/boards/NucleoL152/board.c#L221

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'm glad you called this out, I was iffy on this commit. I am dropping it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of the reason either. Searching online about it, it seems like a bad idea to leave the reset pin floating/doesn't make any difference. I think I am going to leave it as disabled for now for these reasons.

Kconfig Outdated
help
Set the GPIO number used for IRQ (DIO1).

config LORAWAN_BUSY_GPIO
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least my module has no dedicated BUSY-GPIO as far I can remember - maybe it can be enabled?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdesterBE if its indeed an optional thing then you should make this config entry depend on another entry that enables it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added define guard to limit busy pin to boards that have one.

{
while(gpio_get_level(lora_spi.busy) == 1);
}

/*!
* \brief HW Reset of the radio
*/
void SX126xReset( void )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the reason, but in

https://github.com/manuelbl/ttn-esp32/blob/master/src/hal/hal_esp32.c

there is an option to keep reset floating

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of the reason either. Searching online it seems to be a bad idea to leave reset pin floating/doesn't make any difference, so I think I will just leave it disabled.

@ljakob
Copy link
Owner

ljakob commented Jan 5, 2024

Happy new year,
I've given some comments - but I'll merge it anyway. How far is your implementation? Would the hello world join TTN?
Cheers
Leif

@bdesterBE
Copy link
Collaborator Author

Happy new year, I've given some comments - but I'll merge it anyway. How far is your implementation? Would the hello world join TTN? Cheers Leif

Happy new year! Thank you for reviewing, I will fixup/respond to comments today. Please don't merge until you feel it is ready. @cmorganBE may also review.

@@ -0,0 +1,4 @@
description: LoRaWAN board port for ESP32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this more clear? this is loramacnode port for esp32 no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#define KHZ_PER_MHZ 1000
#define HZ_PER_MHZ (HZ_PER_KHZ * KHZ_PER_MHZ)

#define SX1262_SPI_CLOCK_SPEED_MHZ 16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 16mhz the max speed? if so I'd make another define or constant to define that and then assign that to the clock speed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the name of the define to include MAX for clarity

.command_bits = 8,
.address_bits = 16
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_DISABLED));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you know its SPI2?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why disable SPI_DMA?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding configuration. changed to use DMA, accident.

@@ -81,7 +83,8 @@ void BoardInitPeriph(void)
.mode = 0,
.spics_io_num = lora_spi.cs,
.command_bits = 8,
.address_bits = 16
.address_bits = 16,
.queue_size = 7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 7?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, can be 1. changing and added comment.


ESP_ERROR_CHECK(gpio_set_level(lora_spi.reset, 1));

// Hold low for at least 100us.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datasheet citation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

trans.tx_buffer = buffer;
trans.length = size * 8;

SX126xCheckDeviceReady();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if this never indicates ready? if we are ok with blocking at this point we should note the behavior in the README.md of this component to aid implementers in debugging

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this, and additional detail to the README

trans.cmd = RADIO_READ_BUFFER;
trans.addr = offset;
trans.rx_buffer = buffer;
trans.length = size * 8;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why size*8?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added link to docs on this

static portMUX_TYPE my_spinlock = portMUX_INITIALIZER_UNLOCKED;

static esp_timer_handle_t irq_timer_handle;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a timer for measuring the irq?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used to call the stack's internal TimerIRQHandler() function upon timer expiration.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable name is a little confusing. 'timer_handler' maybe? its unclear where its coming from, internal vs. external etc.

@@ -1,3 +1,3 @@
[submodule "src/LoRaMac-node"]
path = src/LoRaMac-node
url = https://github.com/Lora-net/LoRaMac-node.git
url = https://github.com/boston-engineering/LoRaMac-node.git
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in your fork here can you include output of the linking issue in the git commit log body? have you opened a PR against the upstream repo? we really want to avoid having to use a forked loramac-node if we can avoid it by getting your PR in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@bdesterBE bdesterBE force-pushed the bdd/sx1262_port branch 2 times, most recently from 72ef340 to 5f561b7 Compare January 8, 2024 03:44
@bdesterBE bdesterBE force-pushed the bdd/sx1262_port branch 4 times, most recently from b7d7fc9 to c908724 Compare January 25, 2024 02:31
@bdesterBE bdesterBE force-pushed the bdd/sx1262_port branch 2 times, most recently from adeb6d1 to b9b7596 Compare January 25, 2024 03:05
@brandester32
Copy link

@ljakob @cmorganBE Ready for review again. This has now been tested with an SX1262 devkit, and successfully sends join requests.

int64_t time_us = esp_timer_get_time();
uint32_t time_s = (uint32_t)(time_us / US_PER_S);

*milliseconds = (uint16_t)(time_us * US_PER_MS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't look correct, milliseconds appears to be the remainder of time since epoch when you've taken away all of the whole seconds.

…rypt() multiple definitions fix

Linking error:
.espressif/tools/xtensa-esp32s3-elf/esp-12.2.0_20230208/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/12.2.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/wpa_supplicant/libwpa_supplicant.a(crypto_mbedtls.c.obj): in function `aes_encrypt':
esp/esp-idf/components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c:421: multiple definition of `aes_encrypt'; esp-idf/LoRaMac-node-esp32/libLoRaMac-node-esp32.a(aes.c.obj):src/LoRaMac-node/src/peripherals/soft-se/aes.c:569: first defined here
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
… Remove hard-coding of RegionEU868 definition - should be determined by the application which regions are enabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants