mcci-catena / arduino-lorawan

User-friendly library for using arduino-lmic with The Things Network and other LoRaWAN® networks
MIT License
274 stars 54 forks source link

Support STM32 Core Arduino?? #10

Closed sabas1080 closed 6 years ago

sabas1080 commented 6 years ago

Hi

Could this project support STM32 Core Arduino?

https://github.com/stm32duino/Arduino_Core_STM32

Thanks

terrillmoore commented 6 years ago

Probably. We are using this with our fork of the STM32 BSP (https://github.com/mcci-catena/Arduino_Core_STM32). But we're not testing with anything except STM32L082. You'll also need to use https://github.com/mcci-catena/arduino-lmic for a full LoRaWAN™ implementation.

sabas1080 commented 6 years ago

Excelent!

I have the next error

/kwv364sj5jlg24q8f_vqh5y40000gn/T/arduino_build_290692/libraries/arduino-lmic/lmic/lmic_us915.c.o: In functionLMICus915_dr2hsym': lmic_us915.c:(.text.LMICus915_dr2hsym+0x14): undefined reference to table_get_ostime' /var/folders/ng/kwv364sj5jlg24q8f_vqh5y40000gn/T/arduino_build_290692/libraries/arduino-lmic/lmic/radio.c.o: In functionradio_irq_handler': radio.c:(.text.radio_irq_handler+0x66): undefined reference to table_get_u2' collect2: error: ld returned 1 exit status

terrillmoore commented 6 years ago

table_get_u2 is defined by src/lmic/oslmic.h as an inline. and the definition is not conditioned on any symbols. So I'm not sure what the problem might be. Can you please list the usual things about your build environment?

sabas1080 commented 6 years ago

host (build) computer OS type and version: Mac OS High Sierra 10.13.3 Arduino environment version: 1.8.4 target board selected in the IDE, and options: RAK811 based in STM32L151, beta test https://github.com/stm32duino/Arduino_Core_STM32/pull/229 Which sketch are you trying to compile?


#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>

// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.
static const u1_t PROGMEM APPEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01 };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}

// This should also be in little endian format, see above.
static const u1_t PROGMEM DEVEUI[8]={ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}

// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
// The key shown here is the semtech default key.
static const u1_t PROGMEM APPKEY[16] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}

static uint8_t mydata[] = "Hello, world!";
static osjob_t sendjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;
/*
#define RADIO_RESET_PORT        PB13
#define RADIO_MOSI_PORT         PA7
#define RADIO_MISO_PORT         PA6
#define RADIO_SCLK_PORT         PA5
#define RADIO_NSS_PORT          PB0
#define RADIO_DIO_0_PORT        PA11
#define RADIO_DIO_1_PORT        PB1
#define RADIO_DIO_2_PORT        PA3
#define RADIO_DIO_3_PORT        PH0
#define RADIO_DIO_4_PORT        PC13
*/
// Pin mapping
const lmic_pinmap lmic_pins = {
    .nss = RADIO_NSS_PORT,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = RADIO_RESET_PORT,
    .dio = {RADIO_DIO_0_PORT, RADIO_DIO_1_PORT, RADIO_DIO_2_PORT},
};

void onEvent (ev_t ev) {
    Serial.print(os_getTime());
    Serial.print(": ");
    switch(ev) {
        case EV_SCAN_TIMEOUT:
            Serial.println(F("EV_SCAN_TIMEOUT"));
            break;
        case EV_BEACON_FOUND:
            Serial.println(F("EV_BEACON_FOUND"));
            break;
        case EV_BEACON_MISSED:
            Serial.println(F("EV_BEACON_MISSED"));
            break;
        case EV_BEACON_TRACKED:
            Serial.println(F("EV_BEACON_TRACKED"));
            break;
        case EV_JOINING:
            Serial.println(F("EV_JOINING"));
            break;
        case EV_JOINED:
            Serial.println(F("EV_JOINED"));
            {
              u4_t netid = 0;
              devaddr_t devaddr = 0;
              u1_t nwkKey[16];
              u1_t artKey[16];
              LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
              Serial.print("netid: ");
              Serial.println(netid, DEC);
              Serial.print("devaddr: ");
              Serial.println(devaddr, HEX);
              Serial.print("artKey: ");
              for (int i=0; i<sizeof(artKey); ++i) {
                Serial.print(artKey[i], HEX);
              }
              Serial.println("");
              Serial.print("nwkKey: ");
              for (int i=0; i<sizeof(nwkKey); ++i) {
                Serial.print(nwkKey[i], HEX);
              }
              Serial.println("");

              LMIC_setSeqnoUp(140);
            }
            // Disable link check validation (automatically enabled
            // during join, but not supported by TTN at this time).
            LMIC_setLinkCheckMode(0);
            break;
        case EV_RFU1:
            Serial.println(F("EV_RFU1"));
            break;
        case EV_JOIN_FAILED:
            Serial.println(F("EV_JOIN_FAILED"));
            break;
        case EV_REJOIN_FAILED:
            Serial.println(F("EV_REJOIN_FAILED"));
            break;
            break;
        case EV_TXCOMPLETE:
            Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
            if (LMIC.txrxFlags & TXRX_ACK)
              Serial.println(F("Received ack"));
            if (LMIC.dataLen) {
              Serial.println(F("Received "));
              Serial.println(LMIC.dataLen);
              Serial.println(F(" bytes of payload"));
            }
            // Schedule next transmission
            os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
            break;
        case EV_LOST_TSYNC:
            Serial.println(F("EV_LOST_TSYNC"));
            break;
        case EV_RESET:
            Serial.println(F("EV_RESET"));
            break;
        case EV_RXCOMPLETE:
            // data received in ping slot
            Serial.println(F("EV_RXCOMPLETE"));
            break;
        case EV_LINK_DEAD:
            Serial.println(F("EV_LINK_DEAD"));
            break;
        case EV_LINK_ALIVE:
            Serial.println(F("EV_LINK_ALIVE"));
            break;
         default:
            Serial.println(F("Unknown event"));
            break;
    }
}

void do_send(osjob_t* j){
    // Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
    } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
        Serial.println(F("Packet queued"));
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
    Serial.begin(9600);
    Serial.println(F("Starting"));

    #ifdef VCC_ENABLE
    // For Pinoccio Scout boards
    pinMode(VCC_ENABLE, OUTPUT);
    digitalWrite(VCC_ENABLE, HIGH);
    delay(1000);
    #endif

    // LMIC init
    os_init();
    // Reset the MAC state. Session and pending data transfers will be discarded.
    LMIC_reset();

    // Start job (sending automatically starts OTAA too)
    do_send(&sendjob);
}

void loop() {
    os_runloop_once();
}```

Thanks
terrillmoore commented 6 years ago

Thanks for posting the info. I don't see anything obvious that would cause this problem. Unfortunately I won't have time to try to duplicate your problem for the next several days.

You might try updating to Arduino 1.8.5, which is current, but I doubt that's the problem.

You might try double-checking your platform settings in the IDE, just to make sure you don't have a cached old build somewhere.

That said, 99% of the time, when there's a weird problem, it's due to the contents of ~/Documents/Arduino/libraries. My recommendation is that you temporarily rename that directory (libraries.hide or whatever), make a new one, and then git clone only the arduino-lmic library and its prerequisites to the new one. See if that works. Then add stuff back.

sabas1080 commented 6 years ago

I have changed libraries and nothing Compile with STM32L152 and ok STM32L0 and ok Only STM32151 not ok

terrillmoore commented 6 years ago

Bummer. Must be that they have a weird compile option in boards.txt or platforms.txt file for that target. Or possibly there's something wrong with the link script. If you are feeling adventurous, do a verbose compile for SMT32L152, and a verbose compile for STM32L151, and carefully compare the commands used. Wish I could help more.

sabas1080 commented 6 years ago

Thanks, I lacked Optimizations