diff --git a/boards.txt b/boards.txt index 31c50cfa..b6dec4e8 100644 --- a/boards.txt +++ b/boards.txt @@ -275,6 +275,54 @@ Gnat-L082CZ.menu.opt.o3=Fastest Gnat-L082CZ.menu.opt.o3.build.flags.optimize=-O3 Gnat-L082CZ.menu.opt.o3.build.flags.ldspecs= +# Arduino MKRWAN 1300 +# --------------------------------------- +mkrwan.name=Arduino MKRWAN 1300 +mkrwan.vid.0=0x0483 +mkrwan.pid.0=0x374b + +mkrwan.upload.tool=stm32flash +mkrwan.upload.protocol= +mkrwan.upload.maximum_size=196608 +mkrwan.upload.maximum_data_size=20480 +mkrwan.upload.use_1200bps_touch=false +mkrwan.upload.wait_for_upload_port=false +mkrwan.upload.native_usb=false + +mkrwan.build.mcu=cortex-m0plus +mkrwan.build.f_cpu=32000000L +mkrwan.build.board=STM32L0_B_L072Z_LRWAN1 +mkrwan.build.arch=stm32l0 +mkrwan.build.core=arduino +mkrwan.build.vid=0x0483 +mkrwan.build.pid=0x374b +mkrwan.build.did=0xffff +mkrwan.build.extra_flags=-DSTM32L072xx -march=armv6-m -mthumb -mabi=aapcs -mfloat-abi=soft -fsingle-precision-constant +mkrwan.build.ldscript=linker_scripts/STM32L072CZ_FLASH.ld +mkrwan.build.openocdscript=openocd_scripts/b-l072z-lrwan1.cfg +mkrwan.build.variant=B-L072Z-LRWAN1 +mkrwan.build.variant_system_libs="-L{runtime.platform.path}/system/STM32L0xx/Lib" "-L{runtime.platform.path}/system/CMSIS/Lib" -lstm32l072xx -larm_cortexM0l_math +mkrwan.build.variant_system_include="-I{runtime.platform.path}/system/CMSIS/Include" "-I{runtime.platform.path}/system/CMSIS/Device/ST/STM32L0xx/Include" "-I{runtime.platform.path}/system/STM32L0xx/Include" + +mkrwan.menu.speed.32=32 MHz +mkrwan.menu.speed.32.build.f_cpu=32000000L +mkrwan.menu.speed.16=16 MHz (No USB) +mkrwan.menu.speed.16.build.f_cpu=16000000L +mkrwan.menu.speed.4=4.2 MHz (No USB) +mkrwan.menu.speed.4.build.f_cpu=4200000L + +mkrwan.menu.opt.os=Smallest Code +mkrwan.menu.opt.os.build.flags.optimize=-Os +mkrwan.menu.opt.os.build.flags.ldspecs=--specs=nano.specs +mkrwan.menu.opt.o1=Fast +mkrwan.menu.opt.o1.build.flags.optimize=-O1 +mkrwan.menu.opt.o1.build.flags.ldspecs= +mkrwan.menu.opt.o2=Faster +mkrwan.menu.opt.o2.build.flags.optimize=-O2 +mkrwan.menu.opt.o2.build.flags.ldspecs= +mkrwan.menu.opt.o3=Fastest +mkrwan.menu.opt.o3.build.flags.optimize=-O3 +mkrwan.menu.opt.o3.build.flags.ldspecs= # ST B-L072Z-LRWAN1 # --------------------------------------- diff --git a/cores/arduino/Uart.h b/cores/arduino/Uart.h index 622845d4..a94cc634 100644 --- a/cores/arduino/Uart.h +++ b/cores/arduino/Uart.h @@ -29,6 +29,7 @@ #pragma once #include "HardwareSerial.h" +#include "Callback.h" #define UART_RX_BUFFER_SIZE 64 #define UART_TX_BUFFER_SIZE 64 diff --git a/libraries/STM32L0/examples/MKRWANBridge/MKRWANBridge.ino b/libraries/STM32L0/examples/MKRWANBridge/MKRWANBridge.ino new file mode 100644 index 00000000..10e296b8 --- /dev/null +++ b/libraries/STM32L0/examples/MKRWANBridge/MKRWANBridge.ino @@ -0,0 +1,79 @@ +/* + MKRWAN Bridge + This sketch needs to be flashed on a MKR WAN 1300 to allow using the board as an STM32L0 target. + Once flashed using Arduino SAMD core, select Arduino MKRWAN 1300 target from STM32L0 core. + + This example code is in the public domain. +*/ + +int baud = 115200; +uint8_t parity = 0; + +void setup() { + Serial.begin(baud); + pinMode(LED_BUILTIN, OUTPUT); +} + +char rx_buf[512]; +char tx_buf[512]; + +int rx = 0; +int tx = 0; + +void doStuff() { + if (Serial.baud() != baud) { + baud = Serial.baud(); + if (baud == 2400) { + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + Serial2.begin(115200, SERIAL_8E1); + while (Serial2.available()) { + Serial2.read(); + } + digitalWrite(LED_BUILTIN, HIGH); + } else { + Serial2.begin(baud, SERIAL_8N1); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, LOW); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + digitalWrite(LED_BUILTIN, LOW); + } + } +} + +void loop() { + + doStuff(); + + while (Serial.available()) { // If anything comes in Serial (USB), + tx_buf[tx++] = Serial.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (tx > 0) { + Serial2.write(tx_buf, tx); + tx = 0; + } + + while (Serial2.available()) { // If anything comes in Serial (USB), + rx_buf[rx++] = Serial2.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (rx > 0) { + Serial.write(rx_buf, rx); + rx = 0; + } + + +} diff --git a/platform.txt b/platform.txt index 9dcaea51..8f9b847e 100644 --- a/platform.txt +++ b/platform.txt @@ -141,3 +141,18 @@ tools.stm32l0_openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{runt tools.stm32l0_openocd.erase.params.verbose=-d3 tools.stm32l0_openocd.erase.params.quiet=-d0 tools.stm32l0_openocd.erase.pattern= + +# STM32FLASH +tools.stm32flash.cmd=stm32flash +tools.stm32flash.path={runtime.platform.path}/tools/windows +tools.stm32flash.path.macosx={runtime.platform.path}/tools/macosx +tools.stm32flash.path.linux={runtime.platform.path}/tools/linux +tools.stm32flash.upload.params.verbose=-v +tools.stm32flash.upload.params.quiet= +tools.stm32flash.upload.pattern="{path}/{cmd}" {serial.port} -e 512 -b 2400 -w "{build.path}/{build.project_name}.dfu" +tools.stm32flash.program.params.verbose=-v +tools.stm32flash.program.params.quiet= +tools.stm32flash.program.pattern="{path}/{cmd}" {serial.port} -e 512 -b 2400 -w "{build.path}/{build.project_name}.dfu" +tools.stm32flash.erase.params.verbose=-v +tools.stm32flash.erase.params.quiet= +tools.stm32flash.erase.pattern="{path}/{cmd}" {serial.port} -e 512 -b 2400 \ No newline at end of file diff --git a/tools/linux/stm32flash b/tools/linux/stm32flash new file mode 100755 index 00000000..c7b527e5 Binary files /dev/null and b/tools/linux/stm32flash differ diff --git a/tools/macosx/stm32flash b/tools/macosx/stm32flash new file mode 100755 index 00000000..64aab557 Binary files /dev/null and b/tools/macosx/stm32flash differ diff --git a/tools/windows/stm32flash.exe b/tools/windows/stm32flash.exe new file mode 100755 index 00000000..3caabd11 Binary files /dev/null and b/tools/windows/stm32flash.exe differ