dragino / LoRa_STM32

Source code for Dragino LoRa module base on STM32 Chip
76 stars 77 forks source link

How to upload the source code to a LSN50 v2 LoRa node and how to properly import the source code to STM32CubeIDE? #21

Open MinhPham123456789 opened 1 year ago

MinhPham123456789 commented 1 year ago

Hi project authors, I am currently considering customising the purchased Dragino LSN50 v2 LoRa node. The link in README.md directing to the page showing how to use the source code is no longer unavailable. So how can one open/import the project into a STM32CubeIDE properly? In addition, how can one obtain the .ioc file which stores the STM32 chip set up to work with the code?

DominusFulguris commented 1 year ago

The LSN50 code base predates STM32CubeIDE and the use of ioc files.There is a special free Keil MDK licence code available from the ST website that you use to allow Keil to load and compile the source code. Only works with the STM32F0, STM32L0 and STM32G0 MCUs.See www2.keil.com/stmicroelectronics-stm32Source code I think is at github.com/dragino/LoRa_STM32

MinhPham123456789 commented 1 year ago

Hi Dominus, thank you for the response. By using the ARM Keil MDK, when importing the project, is the chip set-up also imported? And can one change the chip set-up to such changing pin functionality and so on?

DominusFulguris commented 1 year ago

I think you may have misunderstood how .ioc files work.

When using STM32CubeIDE or STM32CubeMX tools, you can do your “chip set-up” and record it in a .ioc file.

BUT – this file is not used by the chip!

The tools GENERATE your project source code FROM the .ioc file, building the needed configuration into the .c and .h source files. The tools also generate comments throughout the code (“/ USER CODE BEGIN /”, “/ USER CODE END /”) marking locations where user code (yours) can be inserted to implement your application.

At this point in your project, you have two choices:

  1. Add your code strictly inside the commented blocks of the generated code – in which case you will be able to alter chip configuration if needed from the ioc and regenerate the source code and this will keep any code in the “safe” commented blocks; or
  2. Ignore the commented blocks, add and change the project code as you like but then take on the task if implementing chip configuration changes manually in the source.

The original ST project sample code for LoRaWAN had already gone down the second path long before Dragino started adapting the code to their devices.

In other words, you don’t need an .ioc file to alter the chip configuration UNLESS you plan to regenerate your project.

Again, as this is important, there is no .ioc file from Dragino because the project was built before .ioc files existed.

When I was working on LSN50 code a couple of years ago, I did go back to the ST origin (I-CUBE-LRWAN) to get a “clean base” for my project as I needed LoRaWAN v1.0.3 to address regional support issues. This is still an option for you but you still don’t get the .ioc file support.

The other option you have is to start a brand new project with the STM32CubeIDE and build your own .ioc file from scratch. You can refer to the Dragino source and compare it to your new project’s generated source to see what configuration changes you need to make to get the same functional result. It is a bit of work but can be done. And would be the approach I would take these days (again, I need a later stack version).

Or just take the minimal path and adapt the Dragino code as it stands. In which case, you should look at the “Board Support Package” (BSP) folder under drivers and look at the contents of STM32L0xx_Nucleo as a starting point.

You should also look at bsp.c and stm32l0xx_hw_conf.h

In the Keil project, there are symbols defined in the project build that will likely need tweaking for your needs (e.g. REGION_...) as well as parameters in Commissioning.h

From: MinhPham123456789 @.> Sent: Monday, 28 November 2022 11:34 PM To: dragino/LoRa_STM32 @.> Cc: DominusFulguris @.>; Comment @.> Subject: Re: [dragino/LoRa_STM32] How to upload the source code to a LSN50 v2 LoRa node and how to properly import the source code to STM32CubeIDE? (Issue #21)

Hi Dominus, thank you for the response. By using the ARM Keil MDK, when importing the project, is the chip set-up also imported? And can one change the chip set-up to such changing pin functionality and so on?

— Reply to this email directly, view it on GitHub https://github.com/dragino/LoRa_STM32/issues/21#issuecomment-1329000132 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUKHXE657TAUW4AFUET6ZLWKSRDLANCNFSM6AAAAAASNHDBYY . You are receiving this because you commented. https://github.com/notifications/beacon/AAUKHXAJ646JIPVG3XDWTYLWKSRDLA5CNFSM6AAAAAASNHDBY2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSPG3XMI.gif Message ID: @. @.> >

MinhPham123456789 commented 1 year ago

Hi Dominus, I was able to set up the Arm Keil MDK and Vision IDE to open the source code project. Thank you very much for your support!

Dario503 commented 1 year ago

Code has errors to compile properly with ARM Compiler 6. Keil doesn't include Compiler 5 anymore. Did you run into this?

MinhPham123456789 commented 1 year ago

Yes, I got ARM compiler 6 and recognised that the source code requires compiler 5 and got it installed. I am working on how to write a driver in the Driver/Components/ directory, currently trying to set up UART pins to communicate with the sensor. It would be amazing to have some examples to look at, the sensor is A01NYUB.

Inrebusillis commented 1 year ago

Hi all, I need to attach a pressure/temperature sensor to a LSN50 V2 for a customer. ( 20 units) Sensor has an I2C interface and code is available. I was looking to the example for the like suggested in the LNS50 manual [https://github.com/dragino/LoRa_STM32/commit/08a9062a46d0f06fbabe4d8c94712ec968ff46b7?diff=split#diff-d6c907f9b81b8336b22ab6d477e912a3c4925248839d26691af33411ace88960] I have recognized by your comments above that I am totally underskilled from the task. Could I request you to perform the task for me? Of course I will compensate the effort. Please apologize me if this kind of request is in the wrong place or not conform to the guideline. ( dear admin, I promise will never happen again and I did not found any better place to made it on the web) Kind regards

MinhPham123456789 commented 1 year ago

Hi, It is quite challenging, I can show you the main road to discover and test cause it could be a bit overwhelming to look into the whole project 1) The new sensor script/code should be placed in Drivers/BSP/Components, this is also the starting point. In this directory, there are many example to look and mimic to write the new code 2) Add the new sensor variables to store values in the structure type variable "sensor_data" in bsp.h (this optional incase the existing variables can be reused) 3) Add mode in bsp.c, in the BSP_sensor_Init() to init the necessary set up to activate sensor 4) Add mode in bsp.c, in the BSP_sensor_Read() to run sensor and collect the data 5) Add mode in main.c, in the Send() to read the data inside the "sensor_data" variable send the data via LoRa

In each scripts, there are existing samples so it could be a bit complex but read and take note will make progress

Inrebusillis commented 1 year ago

WOW! Thanks, this is for sure the main road. I was thinking just to modify the sht31.c putting the correct address for my sensor as a quick and dirty solution for my own use. I suspect that will not work after reading your comment just to modify it with the correct value and recompile everything Thanks for your evaluation. best regards

ypkdani00 commented 1 year ago

Hello, if someone need it here you can find the code ported to STM32CubeIDE 1.12.1

https://github.com/ypkdani00/dragino_lsn50_v2

MinhPham123456789 commented 1 year ago

Thanks a lot @ypkdani00