quarta-feira, 2 de novembro de 2022

LOM204A - Programando com mynewt RTOS

  

O objetivo deste BLOG é demonstrar como é possível utilizar o RTOS Mynewt para programação do WISOL LOM204. Foi utilizado o Starter Kit LOM204 para o teste. O exemplo permitirá via linha de comandos o acesso à rede LoRaWAN e então será enviado um texto "HELLO" via OTA, AU915, ao servidor LoRaWAN CHIRPSTACK.

BETA - EM TESTES - APENAS PARA PROGRAMADORES COM mynewt RTOS

Baseado no B-L072Z-LRWAN1

Compilado no MYS2 (Linux no Windows)

Módulo

O que é ChirpStack
ChirpStack é um Servidor de Rede LoRaWAN de código aberto que pode ser usado para configurar redes LoRaWAN. O ChirpStack fornece uma interface web para o gerenciamento de gateways, dispositivos e inquilinos, bem como para configurar integrações de dados com os principais provedores de nuvem, bancos de dados e serviços comumente usados para lidar com dados de dispositivos. O ChirpStack fornece uma API baseada em gRPC que pode ser usada para integrar ou estender o ChirpStack.
mynewt
O que é o Apache mynewt
Construído para wireless

Atenda às demandas de seu aplicativo a partir de uma variedade de pilhas de rede de código aberto, por exemplo. Bluetooth de baixa energia 5, Bluetooth Mesh, Wi-Fi, LoRaWAN e muito mais ...

Implementação flexível e poderosa do BLE 5 (NimBLE)

  • Full stack, host only ou controller only - a sua escolha
  • Máximo rendimento de 2Mbps
  • Mais de 32 conexões simultâneas, múltiplas conexões em funções centrais e periféricas simultaneas

Mais sobre o NimBLE ...

  • Suporte LoRa PHY e LoRaWAN
  • Rádio LoRa PHY / transceptor (SX1276)
  • Protocolo LoRaWAN para terminais de classe A e classe C
  • API para uso de aplicativos com um aplicativo de amostra

Malha Bluetooth

  • Modelos de Fundação (função de servidor)
  • Portadores de aprovisionamento: PB-ADV e PB-GATT
  • Portadores de publicidade e GATT para transporte de mensagens
  • Recursos opcionais de retransmissão e proxy

Suporte nativo para TCP/IP, UDP

  • Suporta protocolos para redes restritas, por ex. CoAP e 6LoWPAN
Segurança desde o início

Certifique-se de que a segurança esteja incorporada no código, bem como o gerenciamento do ciclo de vida do produto.

  • Bootloader seguro para verificar a integridade e autenticidade do firmware
  • Identidade do dispositivo para provisionamento seguro
  • Transferências de dados autenticadas, autorizadas e criptografadas
  • Interface abstraída para aproveitar a segurança de hardware
  • Mais sobre a segurança do Mynewt OS ..

Operações prontas

Prepare sua rede de bilhões de IoT para monitoramento, solução de problemas, gerenciamento e atualização remotos.

  • Módulo de gerenciamento de imagens para permitir atualizações de firmware remotas eficientes, com reconhecimento de falhas e confiáveis
  • Módulos de log que podem ser chamados em vários níveis de granularidade, incluindo logs de reinicialização especializados
  • Módulos de estatísticas ricamente instrumentados para componentes do SO e interfaces de rede
  • Fácil de usar a estrutura do sensor para conectar uma variedade de sensores
  • Descoberta automática e gerenciamento usando OIC1.1, o padrão de plataforma IoT da OCF (Open Connectivity Foundation)

Fácil de usar

Componha, ajuste e crie sua imagem em horas ou até minutos.

  • Inicialização de hardware em arquivo de configuração única para o BSP escolhido
  • Inicialização de parâmetros de serviço em um único arquivo de configuração para o módulo escolhido, e. Controlador BLE
  • Gerenciamento inteligente de pacotes e construção usando a ferramenta Newt
  • Auditorias automáticas de configuração usando o Newt Tool

LOM204A e o Apache Mynewt

Como o módulo LOM204A é baseado no chip STM32L0 (CPU), será possível rodar o Apache Mynewt sem problemas. O usuário deve dar atenção ao mapeamento de GPIOS de acesso ao SX1276 (Semtech LoRa).


Instalando mynewt
wget -qO - https://raw.githubusercontent.com/JuulLabs-OSS/debian-mynewt/master/mynewt.gpg.key | sudo apt-key add -
$ sudo tee /etc/apt/sources.list.d/mynewt.list <<EOF
deb https://raw.githubusercontent.com/JuulLabs-OSS/debian-mynewt/master latest main
EOF
 sudo apt-get update

Agora instale o newt de duas formar, via apt-get install ou instalação do DEB.
$ sudo apt-get install newt



ubuntu@DESKTOP-GRCNLV8:~$ wget -qO - https://raw.githubusercontent.com/JuulLabs-OSS/debian-mynewt/master/mynewt.gpg.key | sudo apt-key add - OK ubuntu@DESKTOP-GRCNLV8:~$ sudo tee /etc/apt/sources.list.d/mynewt.list <<EOF > deb https://raw.githubusercontent.com/JuulLabs-OSS/debian-mynewt/master latest main > EOF deb https://raw.githubusercontent.com/JuulLabs-OSS/debian-mynewt/master latest main ubuntu@DESKTOP-GRCNLV8:~$ sudo apt-get update Get:1 https://raw.githubusercontent.com/JuulLabs-OSS/debian-mynewt/master latest InRelease [1794 B] Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease Hit:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease Get:5 https://raw.githubusercontent.com/JuulLabs-OSS/debian-mynewt/master latest/main amd64 Packages [533 B] Ign:6 https://artifacts.chirpstack.io/packages/3.x/deb stable InRelease Hit:7 http://archive.ubuntu.com/ubuntu focal-backports InRelease Err:8 https://artifacts.chirpstack.io/packages/3.x/deb stable Release Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate. Could not handshake: Error in the certificate verification. [IP: 188.166.134.65 443] Reading package lists... Done E: The repository 'https://artifacts.chirpstack.io/packages/3.x/deb stable Release' does not have a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. ubuntu@DESKTOP-GRCNLV8:~$ sudo apt-get install newt Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: binutils-arm-linux-gnueabi cpp-9-arm-linux-gnueabi cpp-arm-linux-gnueabi gcc-10-cross-base gcc-9-arm-linux-gnueabi-base gcc-9-cross-base libasan5-armel-cross libatomic1-armel-cross libc6-armel-cross libc6-dev-armel-cross libgcc-9-dev-armel-cross libgcc-s1-armel-cross libgomp1-armel-cross libidn11 libstdc++6-armel-cross libubsan1-armel-cross linux-libc-dev-armel-cross lynx-common Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: newt 0 upgraded, 1 newly installed, 0 to remove and 328 not upgraded. Need to get 2264 kB of archives. After this operation, 7554 kB of additional disk space will be used. Get:1 https://raw.githubusercontent.com/JuulLabs-OSS/debian-mynewt/master latest/main amd64 newt amd64 1.10.0-1 [2264 kB] Fetched 2264 kB in 1s (2516 kB/s) Selecting previously unselected package newt. (Reading database ... 76329 files and directories currently installed.) Preparing to unpack .../newt_1.10.0-1_amd64.deb ... Unpacking newt (1.10.0-1) ... Setting up newt (1.10.0-1) ... ubuntu@DESKTOP-GRCNLV8:~$

$ newt
Newt allows you to create your own embedded application based on the Mynewt
operating system. Newt provides both build and package management in a single
tool, which allows you to compose an embedded application, and set of
projects, and then build the necessary artifacts from those projects. For more
information on the Mynewt operating system, please visit
https://mynewt.apache.org/.

Please use the newt help command, and specify the name of the command you want
help for, for help on how to use a specific command

Usage:
  newt [flags]
  newt [command]

Examples:
  newt
  newt help [<command-name>]
    For help on <command-name>.  If not specified, print this message.

Available Commands:
  build        Build one or more targets
  clean        Delete build artifacts for one or more targets
  create-image Add image header to target binary
  debug        Open debugger session to target
  help         Help about any command
  info         Show project info
  install      Install project dependencies
  load         Load built target to board
  mfg          Manufacturing flash image commands
  new          Create a new project
  pkg          Create and manage packages in the current workspace
  resign-image Re-sign an image.
  run          build/create-image/download/debug <target>
  size         Size of target components
  sync         Synchronize project dependencies
  target       Commands to create, delete, configure, and query targets
  test         Executes unit tests for one or more packages
  upgrade      Upgrade project dependencies
  vals         Display valid values for the specified element type(s)
  version      Display the Newt version number

Flags:
  -h, --help              Help for newt commands
  -j, --jobs int          Number of concurrent build jobs (default 4)
  -l, --loglevel string   Log level (default "WARN")
  -o, --outfile string    Filename to tee output to
  -q, --quiet             Be quiet; only display error output
  -s, --silent            Be silent; don't output anything
  -v, --verbose           Enable verbose output when executing commands

Use "newt [command] --help" for more information about a command.
Instale agora o ToolChain para LINUX

GCC/Libc
$ sudo apt-get install gcc-multilib libc6-i386

ubuntu@DESKTOP-GRCNLV8:~$ sudo apt-get install gcc-multilib libc6-i386 Reading package lists... Done Building dependency tree Reading state information... Done gcc-multilib is already the newest version (4:9.3.0-1ubuntu2). The following packages were automatically installed and are no longer required: binutils-arm-linux-gnueabi cpp-9-arm-linux-gnueabi cpp-arm-linux-gnueabi gcc-10-cross-base gcc-9-arm-linux-gnueabi-base gcc-9-cross-base libasan5-armel-cross libatomic1-armel-cross libc6-armel-cross libc6-dev-armel-cross libgcc-9-dev-armel-cross libgcc-s1-armel-cross libgomp1-armel-cross libidn11 libstdc++6-armel-cross libubsan1-armel-cross linux-libc-dev-armel-cross lynx-common Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libc-dev-bin libc6 libc6-dev libc6-dev-i386 libc6-dev-x32 libc6-x32 Suggested packages: glibc-doc The following packages will be upgraded: libc-dev-bin libc6 libc6-dev libc6-dev-i386 libc6-dev-x32 libc6-i386 libc6-x32 7 upgraded, 0 newly installed, 0 to remove and 321 not upgraded. Need to get 14.7 MB of archives. After this operation, 13.3 kB of additional disk space will be used. Do you want to continue? [Y/n]


GDB (Debugger)
$ sudo apt-get install gdb

Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  gdb-doc gdbserver
The following NEW packages will be installed:
  gdb
...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up gdb (7.7.1-0ubuntu5~14.04.2) ...

ubuntu@DESKTOP-GRCNLV8:~$ sudo apt-get install gdb Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: binutils-arm-linux-gnueabi cpp-9-arm-linux-gnueabi cpp-arm-linux-gnueabi gcc-10-cross-base gcc-9-arm-linux-gnueabi-base gcc-9-cross-base libasan5-armel-cross libatomic1-armel-cross libc6-armel-cross libc6-dev-armel-cross libgcc-9-dev-armel-cross libgcc-s1-armel-cross libgomp1-armel-cross libidn11 libstdc++6-armel-cross libubsan1-armel-cross linux-libc-dev-armel-cross lynx-common Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: gdbserver libbabeltrace1 libc6-dbg libdw1 Suggested packages: gdb-doc The following NEW packages will be installed: gdb gdbserver libbabeltrace1 libc6-dbg libdw1 0 upgraded, 5 newly installed, 0 to remove and 321 not upgraded. Need to get 23.8 MB of archives. After this operation, 42.1 MB of additional disk space will be used. Do you want to continue? [Y/n]


Instale agora o CROSSTOOLS para ARM (LOM204A utiliza STM32L072)
$ sudo apt-get remove binutils-arm-none-eabi gcc-arm-none-eabi
$ sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
$ sudo apt-get update
$ sudo apt-get install gcc-arm-none-eabi

É hora de criar um projeto LoRaWAN e fazer a busca do repositório

Recomendo ler este link para ter uma ideia do conceito do Newt


Criando o projeto (LoRaWAN APP SHELL)
$ mkdir mynewt
$ cd mynewt
$ nano project.yml

# project.yml
project.name: "my_project"

project.repositories:
    - apache-mynewt-core
repository.apache-mynewt-core: type: github vers: 1-latest user: apache repo: mynewt-core
$ newt upgrade
Downloading repository mynewt-core (commit: master) from https://github.com/apache/mynewt-core.git Downloading repository mynewt-nimble (commit: master) from https://github.com/apache/mynewt-nimble.git Downloading repository mcuboot (commit: main) from https://github.com/mcu-tools/mcuboot.git Downloading repository mynewt-mcumgr (commit: master) from https://github.com/apache/mynewt-mcumgr.git Making the following changes to the project: apache-mynewt-core successfully upgraded to version 1.10.0 apache-mynewt-mcumgr successfully upgraded to version 0.3.0 apache-mynewt-nimble successfully upgraded to version 1.5.0 mcuboot successfully upgraded to version 1.7.2 ubuntu@DESKTOP-GRCNLV8:~/mynewt$
BOOT

ubuntu@DESKTOP-GRCNLV8:~/mynewt$ newt target create myLoRaWAN_boot
Target targets/myLoRaWAN_boot successfully created
ubuntu@DESKTOP-GRCNLV8:~/mynewt$ newt target set myLoRaWAN_boot bsp=@apache-mynewt-core/hw/bsp/b-l072z-lrwan1
Target targets/myLoRaWAN_boot successfully set target.bsp to @apache-mynewt-core/hw/bsp/b-l072z-lrwan1
ubuntu@DESKTOP-GRCNLV8:~/mynewt$ newt target set myLoRaWAN_boot build_profile=optimized
Target targets/myLoRaWAN_boot successfully set target.build_profile to optimized
ubuntu@DESKTOP-GRCNLV8:~/mynewt$ newt target set myLoRaWAN_boot target.app=@mcuboot/boot/mynewt
Target targets/myLoRaWAN_boot successfully set target.app to @mcuboot/boot/mynewt

APP

ubuntu@DESKTOP-GRNCNV8:~/mynewt$ newt target create myLoRaWAN
Target targets/myLoRaWAN successfully created
ubuntu@DESKTOP-GRNCNV8:~/mynewt$ newt target set myLoRaWAN bsp=@apache-mynewt-core/hw/bsp/b-l072z-lrwan1
Target targets/myLoRaWAN successfully set target.bsp to @apache-mynewt-core/hw/bsp/b-l072z-lrwan1
ubuntu@DESKTOP-GRNCNV8:~/mynewt$ newt target set myLoRaWAN app=@apache-mynewt-core/apps/lora_app_shell
Target targets/myLoRaWAN successfully set target.app to @apache-mynewt-core/apps/lora_app_shell
ubuntu@DESKTOP-GRNCNV8:~/mynewt$ newt target set myLoRaWAN build_profile=optimized
Target targets/myLoRaWAN successfully set target.build_profile to optimized

BUILD BOOT

ubuntu@DESKTOP-GRCNLV8:~/mynewt$ newt build myLoRaWAN_boot

BUILD APP

ubuntu@DESKTOP-GRCNLV8:~/mynewt$ newt build myLoRaWAN

JOIN BOOTLOADER+APP

ubuntu@DESKTOP-GRCNLV8:~/mynewt$ newt create-image myLoRaWAN 1.0.0





ubuntu@DESKTOP-GRCNLV8:~/mynewt$ newt build myLoRaWAN Building target targets/myLoRaWAN Error: In file included from repos/apache-mynewt-core/net/lora/node/include/node/mac/LoRaMac.h:54, from repos/apache-mynewt-core/net/lora/node/include/node/lora_priv.h:23, from repos/apache-mynewt-core/apps/lora_app_shell/src/las_cmd.c:27: repos/apache-mynewt-core/net/lora/node/include/node/lora_band.h:69:2: error: #error "Unknown region specified!" 69 | #error "Unknown region specified!" | ^~~~~ las_cmd.o: repos/apache-mynewt-core/apps/lora_app_shell/src/las_cmd.c \ repos/apache-mynewt-core/libc/baselibc/include/stdio.h \ repos/apache-mynewt-core/libc/baselibc/include/klibc/extern.h \ repos/apache-mynewt-core/libc/baselibc/include/klibc/inline.h \ repos/apache-mynewt-core/libc/baselibc/include/string.h \ repos/apache-mynewt-core/kernel/os/include/os/mynewt.h \ bin/targets/myLoRaWAN/generated/include/syscfg/syscfg.h \ repos/apache-mynewt-core/sys/sysdown/include/sysdown/sysdown.h \ repos/apache-mynewt-core/libc/baselibc/include/assert.h \ repos/apache-mynewt-core/kernel/os/include/os/os_fault.h \ repos/apache-mynewt-core/kernel/os/include/os/arch/cortex_m0/os/os_arch.h \ repos/apache-mynewt-core/hw/mcu/stm/stm32l0xx/include/mcu/cmsis_nvic.h \ repos/apache-mynewt-core/hw/mcu/stm/stm32l0xx/src/ext/Drivers/CMSIS/Device/ST/STM32L0xx/Include/stm32l0xx.h \ repos/apache-mynewt-core/hw/mcu/stm/stm32l0xx/src/ext/Drivers/CMSIS/Device/ST/STM32L0xx/Include/stm32l072xx.h \ repos/apache-mynewt-core/hw/cmsis-core/src/ext/core_cm0plus.h \ repos/apache-mynewt-core/hw/cmsis-core/src/ext/cmsis_version.h \ repos/apache-mynewt-core/hw/cmsis-core/src/ext/cmsis_compiler.h \ repos/apache-mynewt-core/hw/cmsis-core/src/ext/cmsis_gcc.h \ repos/apache-mynewt-core/hw/cmsis-core/src/ext/mynewt_cm0_vectab.h \ repos/apache-mynewt-core/hw/cmsis-core/src/ext/mpu_armv7.h \ repos/apache-mynewt-core/hw/mcu/stm/stm32l0xx/src/ext/Drivers/CMSIS/Device/ST/STM32L0xx/Include/system_stm32l0xx.h \ repos/apache-mynewt-core/hw/mcu/stm/stm32l0xx/include/mcu/cortex_m0.h \ repos/apache-mynewt-core/kernel/os/include/os/arch/common.h \ repos/apache-mynewt-core/kernel/os/include/os/os_error.h \ repos/apache-mynewt-core/hw/hal/include/hal/hal_system.h \ repos/apache-mynewt-core/hw/hal/include/hal/hal_debug.h \ repos/apache-mynewt-core/sys/sysinit/include/sysinit/sysinit.h \ bin/targets/myLoRaWAN/generated/include/sysflash/sysflash.h \ repos/apache-mynewt-core/sys/flash_map/include/flash_map/flash_map.h \ repos/apache-mynewt-core/kernel/os/include/os/os.h \ repos/apache-mynewt-core/libc/baselibc/include/stdlib.h \ repos/apache-mynewt-core/kernel/os/include/os/endian.h \ repos/apache-mynewt-core/kernel/os/include/os/os_callout.h \ repos/apache-mynewt-core/kernel/os/include/os/os_eventq.h \ repos/apache-mynewt-core/kernel/os/include/os/os_time.h \ repos/apache-mynewt-core/kernel/os/include/os/queue.h \ repos/apache-mynewt-core/sys/sys/include/sys/queue.h \ repos/apache-mynewt-core/kernel/os/include/os/os_cfg.h \ repos/apache-mynewt-core/kernel/os/include/os/os_cputime.h \ repos/apache-mynewt-core/hw/hal/include/hal/hal_timer.h \ repos/apache-mynewt-core/kernel/os/include/os/os_dev.h \ repos/apache-mynewt-core/kernel/os/include/os/os_heap.h \ repos/apache-mynewt-core/kernel/os/include/os/os_mbuf.h \ repos/apache-mynewt-core/kernel/os/include/os/os_mempool.h \ repos/apache-mynewt-core/kernel/os/include/os/os_mutex.h \ repos/apache-mynewt-core/kernel/os/include/os/os_sanity.h \ repos/apache-mynewt-core/kernel/os/include/os/os_sched.h \ repos/apache-mynewt-core/kernel/os/include/os/os_task.h \ repos/apache-mynewt-core/kernel/os/include/os/os_sem.h \ repos/apache-mynewt-core/kernel/os/include/os/os_trace_api.h \ repos/apache-mynewt-core/kernel/os/include/os/util.h \ repos/apache-mynewt-core/sys/defs/include/defs/error.h \ repos/apache-mynewt-core/sys/sys/include/sys/debug_panic.h \ bin/targets/myLoRaWAN/generated/include/logcfg/logcfg.h \ repos/apache-mynewt-core/sys/log/modlog/include/modlog/modlog.h \ repos/apache-mynewt-core/sys/log/full/include/log/log.h \ repos/apache-mynewt-core/util/cbmem/include/cbmem/cbmem.h \ repos/apache-mynewt-core/sys/log/common/include/log_common/log_common.h \ repos/apache-mynewt-core/sys/log/common/include/log_common/ignore.h \ repos/apache-mynewt-core/sys/console/full/include/console/console.h \ repos/apache-mynewt-core/sys/shell/include/shell/shell.h \ repos/apache-mynewt-core/util/streamer/include/streamer/streamer.h \ repos/apache-mynewt-core/util/parse/include/parse/parse.h \ repos/apache-mynewt-core/net/lora/node/include/node/lora_priv.h \ repos/apache-mynewt-core/net/lora/node/include/node/mac/LoRaMac.h \ repos/apache-mynewt-core/net/lora/node/include/node/utilities.h \ repos/apache-mynewt-core/net/lora/node/include/node/lora_band.h \ repos/apache-mynewt-core/hw/drivers/lora/sx1276/include/radio/radio.h \ repos/apache-mynewt-core/net/lora/node/include/node/mac/Region.h \ repos/apache-mynewt-core/net/lora/node/include/node/lora.h \ repos/apache-mynewt-core/sys/stats/full/include/stats/stats.h ubuntu@DESKTOP-GRCNLV8:~/mynewt$
Altere syscfg.yml
Em /home/ubuntu/mynewt/repos/apache-mynewt-core/hw/bsp/b-l072z-lrwan1
para ser compatível com os GPIOS utilizados para acesso ao SX1276

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

syscfg.defs:
    STM32_FLASH_SIZE_KB:
        description: 'Total flash size in KB.'
        value: 192

syscfg.vals:
    CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS
    COREDUMP_FLASH_AREA: FLASH_AREA_IMAGE_1
    I2C_0_PIN_SCL: MCU_GPIO_PORTB(8)
    I2C_0_PIN_SDA: MCU_GPIO_PORTB(9)
    LORA_NODE_DEBUG_LOG: 1
    LORA_MAC_TIMER_NUM: 0
    LORA_NODE_REGION: 2
    LORA_NODE_PUBLIC_NWK: 1
    LORA_NODE: 1
    NFFS_FLASH_AREA: FLASH_AREA_NFFS
    REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG
    SPI_0_MASTER: 1
    SPI_0_PIN_SCK: MCU_GPIO_PORTA(5)
    SPI_0_PIN_MOSI: MCU_GPIO_PORTA(7)
    SPI_0_PIN_MISO: MCU_GPIO_PORTA(6)
    SPI_0_PIN_SS: MCU_GPIO_PORTA(4)  
    STM32_CLOCK_AHB_DIVIDER: RCC_SYSCLK_DIV1
    STM32_CLOCK_APB1_DIVIDER: RCC_HCLK_DIV1
    STM32_CLOCK_APB2_DIVIDER: RCC_HCLK_DIV1
    STM32_CLOCK_HSE: 0
    STM32_CLOCK_HSE_BYPASS: 0
    STM32_CLOCK_HSI: 1
    STM32_CLOCK_HSI48: 0
    STM32_CLOCK_HSI_CALIBRATION: 16
    STM32_CLOCK_LSE: 0
    STM32_CLOCK_LSE_BYPASS: 0
    STM32_CLOCK_LSI: 1
    STM32_CLOCK_MSI: 0
    STM32_CLOCK_MSI_CALIBRATION: 0
    STM32_CLOCK_MSI_CLOCK_RANGE: RCC_MSIRANGE_5
    STM32_CLOCK_PLL_DIV: RCC_PLL_DIV2
    STM32_CLOCK_PLL_MUL: RCC_PLL_MUL4
    STM32_CLOCK_VOLTAGESCALING_CONFIG: PWR_REGULATOR_VOLTAGE_SCALE1
    STM32_FLASH_LATENCY: 1
    STM32_FLASH_PREFETCH_ENABLE: 0
    SX1276_SPI_CS_PIN: MCU_GPIO_PORTA(4)
    SX1276_SPI_IDX: 0
    SX1276_HF_USE_PA_BOOST: 1
    #low power
    SX1276_HAS_ANT_SW: 1
    TIMER_0_TIM: TIM2
    TIMER_1_TIM: TIM3
    TIMER_2_TIM: TIM21
    UART_0_PIN_RX: MCU_GPIO_PORTA(3)
    UART_0_PIN_TX: MCU_GPIO_PORTA(2)

Altere bsp.h em
\\wsl$\Ubuntu\home\ubuntu\mynewt\repos\apache-mynewt-core\hw\bsp\b-l072z-lrwan1\include\bsp

//#define LED_BLINK_PIN MCU_GPIO_PORTB(5) /* LD1 - green */ //#define LED_2 MCU_GPIO_PORTB(6) /* LD3 - blue */ //#define LED_3 MCU_GPIO_PORTB(7) /* LD4 - red */ //#define LED_4 MCU_GPIO_PORTA(5) /* LD2 - green */ /* SX1276 pins */ #define SX1276_DIO0 MCU_GPIO_PORTA(12) #define SX1276_DIO1 MCU_GPIO_PORTB(2) #define SX1276_DIO2 MCU_GPIO_PORTB(5) #define SX1276_DIO3 MCU_GPIO_PORTB(0) #define SX1276_DIO4 MCU_GPIO_PORTA(11) /* NOTE: DIO5 is not used, but must be defined */ #define SX1276_DIO5 (-1) #define SX1276_RXTX MCU_GPIO_PORTA(XX) #define SX1276_NRESET MCU_GPIO_PORTA(8)
#define SX1276_ANT_HF_CTRL MCU_GPIO_PORTA(15)





#define SX1276_RADIO_TCXO MCU_GPIO_PORTB(1)

Altere b-l072z-lrwan1.ld em
mynewt/repos/apache-mynewt-core/hw/bsp/b-l072z-lrwan1

para

FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 192K /* First image slot. */

Gere o HEX

ubuntu@DESKTOP-GRCNLV8:~/mynewt$ newt create-image myLoRaWAN 1.0.0
Compiling bin/targets/myLoRaWAN/generated/src/myLoRaWAN-sysinit-app.c
Archiving myLoRaWAN-sysinit-app.a
Linking /home/ubuntu/mynewt/bin/targets/myLoRaWAN/app/@apache-mynewt-core/apps/lora_app_shell/lora_app_shell.elf
App image successfully generated: /home/ubuntu/mynewt/bin/targets/myLoRaWAN/app/@apache-mynewt-core/apps/lora_app_shell/lora_app_shell.img

em 
/home/ubuntu/mynewt/bin/targets/myLoRaWAN/app/@apache-mynewt-core/apps/lora_app_shell
voce encontrará
lora_app.shell.hex

Configuração do APP (Credenciais)
Antes de criar o aplicativo e ingressar em uma rede LoRaWAN, você precisa de uma conta em um provedor de back-end LoRaWAN. Em seguida, crie um aplicativo LoRaWAN e registre seu dispositivo. Como este aplicativo foi fortemente testado com o backend fornecido pelo CHIRPSTACK. Assim que seu aplicativo e dispositivo forem criados e registrados, você terá várias informações (fornecidas pelo provedor LoRaWAN).
Assim que seu aplicativo e dispositivo forem criados e registrados, você terá várias informações fornecidas pelo provedor LoRaWAN:
  • O tipo de procedimento de JOIN: ABP (Ativação por personalização) ou OTAA (Ativação Over The Air) 
  • O dispositivo EUI: uma matriz de 8 bytes 
  • A aplicação EUI: uma matriz de 8 bytes 
  • A chave do aplicativo: uma matriz de 16 bytes 
  • O endereço do dispositivo: uma matriz de 4 bytes, necessária apenas com o procedimento de junção ABP 
  • A chave de sessão do aplicativo: uma matriz de 16 bytes, necessária apenas com o procedimento de junção ABP 
  • A chave de sessão de rede: uma matriz de 16 bytes, necessária apenas com o procedimento de junção ABP 
  • Depois de obter essas informações, edite o Makefile adequadamente ou use os comandos set/get no shell do aplicativo de teste.
Em RegionAU915.c (SUB-Bands) altere
/mynewt/repos/apache-mynewt-core/net/lora/node/src/mac/region



void RegionAU915InitDefaults( InitType_t type ) { switch( type ) { case INIT_TYPE_INIT: { // Channels // 125 kHz channels for( uint8_t i = 0; i < AU915_MAX_NB_CHANNELS - 8; i++ ) { Channels[i].Frequency = 915200000 + i * 200000; Channels[i].DrRange.Value = ( DR_5 << 4 ) | DR_0; Channels[i].Band = 0; } // 500 kHz channels for( uint8_t i = AU915_MAX_NB_CHANNELS - 8; i < AU915_MAX_NB_CHANNELS; i++ ) { Channels[i].Frequency = 915900000 + ( i - ( AU915_MAX_NB_CHANNELS - 8 ) ) * 1600000; Channels[i].DrRange.Value = ( DR_6 << 4 ) | DR_6; Channels[i].Band = 0; } // Initialize channels default mask ChannelsDefaultMask[0] = 0xFF00; ChannelsDefaultMask[1] = 0x0000; ChannelsDefaultMask[2] = 0x0000; ChannelsDefaultMask[3] = 0x0000; ChannelsDefaultMask[4] = 0x00FF; ChannelsDefaultMask[5] = 0x0000; // Copy channels default mask RegionCommonChanMaskCopy( ChannelsMask, ChannelsDefaultMask, 6 ); // Copy into channels mask remaining RegionCommonChanMaskCopy( ChannelsMaskRemaining, ChannelsMask, 6 ); break; } case INIT_TYPE_RESTORE: { // Copy channels default mask RegionCommonChanMaskCopy( ChannelsMask, ChannelsDefaultMask, 6 ); for( uint8_t i = 0; i < 6; i++ ) { // Copy-And the channels mask ChannelsMaskRemaining[i] &= ChannelsMask[i]; } break; } case INIT_TYPE_APP_DEFAULTS: { // Copy channels default mask RegionCommonChanMaskCopy( ChannelsMask, ChannelsDefaultMask, 6 ); // Copy into channels mask remaining RegionCommonChanMaskCopy( ChannelsMaskRemaining, ChannelsMask, 6 ); break; } default: { break; } } }













Na pasta

Utilize STM32 PROGRAMMER para gravar


Abra o Emulador de Terminal

PA2 e PA3 do LOM204 (TX/RX)

Lista de erros ao tentar JOIN
/home/ubuntu/mynewt/repos/apache-mynewt-core/net/lora/node/include/node

lora.h

/* Lora app return codes */
#define LORA_APP_STATUS_OK              (0)
#define LORA_APP_STATUS_NO_PORT         (1)
#define LORA_APP_STATUS_INVALID_PARAM   (2)
#define LORA_APP_STATUS_ENOMEM          (3)
#define LORA_APP_STATUS_INVALID_PORT    (4)
#define LORA_APP_STATUS_ALREADY_OPEN    (5)
#define LORA_APP_STATUS_JOIN_FAILURE    (6)
#define LORA_APP_STATUS_ALREADY_JOINED  (7)
#define LORA_APP_STATUS_NO_NETWORK      (8)

Comandos

Command

Description

help

Display list of available shell commands

stat

Display statistics. Syntax: stat <statistics group>. ‘stat’ with no group displays avaialable groups

tasks

Display OS tasks

mpool

Displays OS memory pools and memory pool statistics

date

Displays current date/time

las_wr_mib

Write lora MIB

las_rd_mib

Read lora MIB

las_rd_dev_eui

Read lora device EUI

las_wr_dev_eui

Write lora device EUI

las_rd_app_eui

Read lora application EUI

las_wr_app_eui

Write lora application EUI

las_rd_app_key

Read lora application key

las_wr_app_key

Write lora application key

las_app_port

Open/close lora application port

las_app_tx

Transmit on lora application port

las_join

Perform a lora OTA join

las_link_chk

Perform a lora link check

Sobre a SMARTCORE

A SmartCore fornece módulos para comunicação wireless, biometria, conectividade, rastreamento e automação.
Nosso portifólio inclui modem 2G/3G/4G/NB-IoT/Cat.M, satelital, módulos WiFi, Bluetooth, GNSS / GPS, Sigfox, LoRa, leitor de cartão, leitor QR code, mecanismo de impressão, mini-board PC, antena, pigtail, LCD, bateria, repetidor GPS e sensores.
Mais detalhes em www.smartcore.com.br 

Nenhum comentário:

Postar um comentário