ARMmbed / mbed-semtech-lora-rf-drivers

Semtech's LoRa RF drivers for mbed OS
Other
31 stars 25 forks source link

SX1262 pinmap not found for peripheral #59

Closed krakush closed 2 years ago

krakush commented 2 years ago

Target board: DISCO_F407VG Mbed version: 5.15 I am using radio modules based on SX1276, produced by different manufacturers. I want to try a 2W 1262 nicerf module (LoRa1262F30) but the application is crashing when i try to create an instance of SX126X_LoRaRadio. I create instances of SX1276_LoRaRadio and SX1272_LoRaRadio without any problem but when i try to create an instance of 126X I get this message:

++ MbedOS Error Info ++
Error Status: 0x80010130 Code: 304 Module: 1
Error Message: pinmap not found for peripheral
Location: 0x80060E1
Error Value: 0x44
Current Thread: main Id: 0x20002C00 Entry: 0x8008277 StackSize: 0x1000 StackMem: 0x20003A90 SP: 0x20004934
For more info, visit: https://mbed.com/s/error?error=0x80010130&tgt=DISCO_F407VG
-- MbedOS Error Info --

This line is causing the error message: SX126X_LoRaRadio mRadio(SPI3_MOSI, SPI3_MISO, SPI3_SCK, PA_14, PA_10, PD_1, PD_3, NC, NC, NC, NC);

The constructors of the all three drivers require 11 PinName for creating the instances. The first 6 are mandatory for SX1276 and SX1272. If i understand the datasheet of 1262 correctly, in addition to the first 6, the BUSY(PD_3) pin is also necessary to drive 1262 properly.

I am creating the instances of 1276 and 1272 with the below code. This one works for both only by changing SX1276_LoRaRadio to SX1272_LoRaRadio. I do not have any 1272 tranceiver module but 1276 works fine and the instance of 1272 is also created without any problem: SX1276_LoRaRadio Radio(SPI2_MOSI, SPI2_MISO, SPI2_SCK, PB_11, PE_15, PD_9, NC, NC, NC, NC, NC);

In SX126X_LoRaRadio source code none of the constructor arguments is assigned to N.C by default. So i thought I have to provide all the pin names to create the instance properly. I tried also in this way but it does not work. The code compiles in any ways and i get the bin file but I always get the above error message. I do not understand where i am doing the mistake. By the way there was another SX1276 module connected to SPI3 with the same pin assignments. I just changed the type name to SX126X_LoRaRadio and assigned PD_3 to BUSY.

jeromecoutant commented 2 years ago

Hi

SX126X_LoRaRadio mRadio(SPI3_MOSI, SPI3_MISO, SPI3_SCK, PA_14, PA_10, PD_1, PD_3, NC, NC, NC, NC);

Check if SPI3_MOSI, SPI3_MISO, SPI3_SCK are correct for a STM32F407VG MCU. "Easy" check could be to compare with this table: https://github.com/ARMmbed/stm32customtargets/blob/GENERIC_TARGET/TARGET_STM32F4/TARGET_GENERIC_STM32F407VE/PeripheralPins.c#L248-L276

jerome

krakush commented 2 years ago

Hello @jeromecoutant. Here is the pin assignment for SPI3. I created my own custom target in custom_targets.json by inheriting from the F407 family but my PinNames.h is the same with the one provided by mbed. Also there is almost no difference between my custom target configurations and DISCO_F407:

SPI3_MISO = PC_11,
SPI3_MOSI = PC_12,
SPI3_SCK = PC_10, 

I do not have doubts about the pin name assignments. I have two SX1276 connected to SPI2 and SPI3. Both are working. I just replaced the one on SPI3 with the nicerf SX1262 module by assigning PD_3 as the BUSY pin and changing the type name.

There is one small note. When there is something wrong in the program logic the discovery board either becomes irresponsive or works strangely. I use one of the on board leds as the heart beat indicator. It does not blink when I make a mistake in program logic and I do not see any debug messages on the serial terminal. Instead when there is a faulty hw configuration in the code, it still builds and creates the bin file but the red led between the mcu and the imu starts flashing once the mcu tries to execute the binary and usually i see a hard fault message on the serial terminal screen.

I do not try to access any methods of the mRadio object. The only thing i do at the first step is creating an instance of SX126X_LoRaRadio class. I do not see any error messages when I build the code. The reset pin of SX1276 (PE_15) is not used on our custom board. But one of the MCU pins is still assigned because it is manipulated by the radio driver. So I tried to asign NC to that pin and it crashed. Some of the pins are assigned to default NC in SX1276/72 drivers. The other NCs in my code are for DIO1 to DIO5, which are optional. Instead, in the constructor of SX126X_LoRaRadio none of the pins is default to NC. So I also tried to create an instance of SX126X_LoRaRadio by passing a pin name to all of the PinName arguments of the constructor. But this also did not help to solve my issue.

I am wondering one more thing. The error message shows the location of the error. I believe this is the location of the faulty instruction on the flash memory. I know mbed has a tool to translate the error messages but I am not sure if this is one of those kind of error messages. May ask whether there is a way to find the corresponding line in the code by translating this error message?

jeromecoutant commented 2 years ago

From

++ MbedOS Error Info ++
Error Status: 0x80010130 Code: 304 Module: 1
Error Message: pinmap not found for peripheral
Location: 0x80060E1
Error Value: 0x44
Current Thread: main Id: 0x20002C00 Entry: 0x8008277 StackSize: 0x1000 StackMem: 0x20003A90 SP: 0x20004934
For more info, visit: https://mbed.com/s/error?error=0x80010130&tgt=DISCO_F407VG
-- MbedOS Error Info --

Error seems to come from: https://github.com/ARMmbed/mbed-os/blob/master/hal/source/mbed_pinmap_common.c#L77

So pin=0x44 => PE_4 !!?

krakush commented 2 years ago

I am sorry I mixed the error messages in my first message. Here is the correct error message when I try to create the instance as SX126X_LoRaRadio mRadio(SPI3_MOSI, SPI3_MISO, SPI3_SCK, PA_14, PA_10, PD_1, PD_3, NC, NC, NC, NC); This time I also added "platform.error-filename-capture-enabled": true to my mbed_app.json. :

++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: pin != (PinName)NC
Location: 0x80074F7
File: /home/disco_try/mbed-os/targets/TARGET_STM/pinmap.c+62
Error Value: 0x0
Current Thread: main Id: 0x20002D58 Entry: 0x800881F StackSize: 0x1000 StackMem: 0x20003BE8 SP: 0x20004A3C
For more info, visit: https://mbed.com/s/error?error=0x80FF0144&tgt=DISCO_F407VG
-- MbedOS Error Info --

Then I tried again SX126X_LoRaRadio mRadio(SPI3_MOSI, SPI3_MISO, SPI3_SCK, PA_14, PA_10, PD_1, PD_3, PE_4, NC, NC, NC);. I did not know that the 'Error Value' parameter is specifying the pin map. Now with the help of the reply of @jeromecoutant I see there is something wrong with PinName freq_select. When I try to create the instance with this pin configuration i get:

++ MbedOS Error Info ++
Error Status: 0x80010130 Code: 304 Module: 1
Error Message: pinmap not found for peripheral
Location: 0x80065A7
File: mbed_pinmap_common.c+77
Error Value: 0x44
Current Thread: main Id: 0x20002D58 Entry: 0x800881F StackSize: 0x1000 StackMem: 0x20003BE8 SP: 0x20004A7C
For more info, visit: https://mbed.com/s/error?error=0x80010130&tgt=DISCO_F407VG
-- MbedOS Error Info --

I digged in a bit the driver source code and discovered that freq_select and device_select pins must have ADC functionality. Thank you for the support.