Spark Logic

B.A.S.I.C. for Arduino

STM32F103C8T6 LQFP48 Pinout
STM32F103RBT6 LQFP64 Pinout
GD32F103C8T6 LQFP48 Pinout

I came across this whilst trawling the internet a BASIC complier for arduino. It can be found at https://www.b4x.com/b4r.html. You can embed ‘C’ code and compiles / Uploads using the standard arduino.exe. At a guess it cross complies the basic code into some ‘C’ equivalent and then this is compiled and uploaded by arduino.exe.

I know all the purists out there will say you should be using a real language for this type of job blah blah blah. But if you just want to code something that turns a heater on if the temperature is too low and a fan on if the temperature is too high etc then it maybe the ideal thing. You can apparently look at the code it produces but I haven’t tried it yet. If so people could use it as a basic to C dictionary.

It looks like it may work with STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog with a little alterations as it uses a boards.txt file to add extra boards.

You can also call existing ‘C’ functions by using a RunNative so you can write wrappers for existing ‘C’ Libraries.

I will have a play with it next week and see how good/bad it is.

PS they also do the same for android and IOS so you can write a project which works partly on an android device an iphone and arduino and only use one language.

Replies20

Sun May 29, 2016 11:43 pm

https://www.b4x.com/store.html
Applications developed with B4A, B4i or B4J are royalty free.
Licenses are per developer. Each developer requires a single license.
Payments are done over a secured server.
After purchasing you will receive an email with a link to the full version and the license file. Email should arrive 10-15 minutes after you purchase.
Choose the FastSpring option to purchase with coupon codes. Enter the code in the second order page.

You may wish to look into:
https://github.com/esp8266/Basic

I know all the purists out there will say you should be using a real language for this type of job blah blah blah.

I do not have a “problem” with BASIC as a language … after all, Arduino is a pseudo-language in one sense – but the data types and syntax are more closely aligned to C/C++, IMO.

It looks like it may work with STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog with a little alterations…
Unlikely since the AVRAVRMicrocontrollers and processors…Arduino\libraries\U8glib\U8glib.cpp, C:\Program Files (x86)\Arduino\hardware\arduino\ avr \cores\arduino\HardwareSerial.h, C:\Program Files (x86)\Arduino/Blink3.ino, D:\Users\me\A…View in hardware catalog is 8-bit. But, I am often wrong.

My biggest poopoo about this product is that Microsoft’s .Net must be installed. It will be a cold day in Hades before I muck up my Linux installation with .Net.

Ray

Mon May 30, 2016 11:41 pm

I managed to get an hour to try B4R. I took the opportunity to upgrade to 1.69 and then tried the following Blinky example.

On the Uno it compiled and run straight away

#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region

Sub Process_Globals
Public Serial1 As Serial
Private Timer1 As Timer
Private pin13 As Pin
End Sub

Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
pin13.Initialize(13, pin13.MODE_OUTPUT)
Timer1.Initialize("Timer1_Tick", 1000) '1000ms = 1 second
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick
Dim currentState As Boolean = pin13.DigitalRead
Log("CurrentState: ", currentState)
Dim NewState As Boolean = Not(currentState)
Log("NewState: ", NewState)
pin13.DigitalWrite(NewState)
End Sub

Tue May 31, 2016 3:48 am

@simonf

Some of the errors are being caused because libmaple uses a special variable type/enum of WiringPinMode instead of a byte for the pinMode

I think the libmaple implementation is technically better that using byte, but it does cause incompatibilities sometimes, and I recall changing other things to resolve the same issue.

I’m not sure why there are issues with the definition of false

Its done the same way as the Arduino SAM core does it

Its probably best to try to compile the basic for the Arduino DueArduino DueDevelopment and computing boards… tool chain install is to use the Arduino.cc IDE, then use Board Manager to install “ Arduino Due ” … the tool chain gets installed as a by-product. But if you are not as lazy as…View in hardware catalog and see if it had the same issues, (and also compile for the Uno – or any AVRAVRMicrocontrollers and processors…Arduino\libraries\U8glib\U8glib.cpp, C:\Program Files (x86)\Arduino\hardware\arduino\ avr \cores\arduino\HardwareSerial.h, C:\Program Files (x86)\Arduino/Blink3.ino, D:\Users\me\A…View in hardware catalog core)

Tue May 31, 2016 12:48 pm

RogerClark wrote:@simonf

Some of the errors are being caused because libmaple uses a special variable type/enum of WiringPinMode instead of a byte for the pinMode

I think the libmaple implementation is technically better that using byte, but it does cause incompatibilities sometimes, and I recall changing other things to resolve the same issue.

Tue May 31, 2016 7:23 pm

On board pin #

I note that Raspberry PiRaspberry PiDevelopment and computing boards…ic stripe card reader. I’ve gutted it, extended the sides up to give more room for a raspberry pi , soundcard, and dc-dc power supply converter. I’m going to put a few knobs and a…View in hardware catalog named all the GPIO as GPIO-1, -2, etc. Unrelated to pin number on header connector. Everyone seems to easily adapt to that; e.g., the GPIO library class instances just use the GPIO number, and people have little color crib sheets to show what GPIO # is where on the header. Even though the header layout is the same for all boards expect one, and including the smaller Zero board.

I wonder if it was worth the hassle, in hindsight, for Arduino to fixate on port pin vs. board pin such that port pin is hidden from the coder.

Wed Jun 01, 2016 9:54 pm

stevech wrote:

I wonder if it was worth the hassle, in hindsight, for Arduino to fixate on port pin vs. board pin such that port pin is hidden from the coder.

Wed Jun 01, 2016 10:13 pm

[quote=”simonf”
It’s not the actual pin number vs port number that is the problem it the way the pinmode is stored, in this case passed.
The problem is the variable type used to describe the pin mode in arduino is byte whereas MapleMapleDevelopment and computing boards…expensive short of buying in bulk. many resort to usb-serial converters. today comes leaflabs maple , stm32duino it is ‘disruptive’ in a similar light, user customizable usb is no…View in hardware catalog /stm32duino uses an ENUM.
I had a quick look on the net and I remembered from my C# days that you could do something like this
enum MyEnum : unsigned char
{
i ,j, k, w
};

Sat Jun 11, 2016 1:17 pm

I have got B4R to compile successfully for the STM32Nucleo F103

I needed to make several changes.
Inside the B4R files and also inside the Arduino_STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog library files.

It does compile and run. ie. B4R Blink example.

But, I am getting an additional 64K added to the size of the output BIN file.
Even when I compile an empty project.

I think I have tracked it down to the B4Rscheduler.cpp file
I think it is in the class PollerNode and could be caused by the declare
void* tag;

I am wondering if this declare is likely to make a referance to 00000
in the ELF file and altermately causing the BIN to increae in size by 64K?
I believe for STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog code starts at the first 64K boundary.

Even though the file is 66K it still loads ok on the NucleoNucleoDevelopment and computing boards…o have this dev board for BlueNRG at a pretty hefty price tag though, hopefully the ‘ nucleo ’ & common dev board versions would be out soon Laughing … 007v1.html oops/oh found an…View in hardware catalog F1 (128K flash) but for a STM32F103C8STM32F103C8Microcontrollers and processors…017 8:28 am I am trying to get Phono’s library working on a MCP2551 and a blue pill ( STM32F103C8 ), I have it connected to a active CANBUS, and I have successfully received and s…View in hardware catalog board (64K flash) the resultant minimum size is 66K. The loader won’t pass it to the board.

I would appreciate any insight from anyone.
I can post my B4R mods if anyone is interested.

Sun Jun 12, 2016 3:45 am

I’m not sure if my last (very first) post was successful as I can’t find any reference to it.

I have got B4R compiling and running for the stm32NucleoF1 board.

Several changes were required to overcome incompatibility between the STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog libraries and the arduino AVRAVRMicrocontrollers and processors…Arduino\libraries\U8glib\U8glib.cpp, C:\Program Files (x86)\Arduino\hardware\arduino\ avr \cores\arduino\HardwareSerial.h, C:\Program Files (x86)\Arduino/Blink3.ino, D:\Users\me\A…View in hardware catalog libraries and B4R underlying C source files.

Below are my changes.

Mods for STM32F1
==============

This file details the changes made in implementing the Arduino_STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog
libraries and B4R libraries so that B4R can successfully compile to
target a STM32F103RBSTM32F103RBMicrocontrollers and processors…duino IDE 1.7.7 I dont have “STM32 to FLASH – no bootloadrer” board. I used “Generic STM32F103RB ”. In this tutorial there is step 12: “On the Maple mini, press and hold the “Butt…View in hardware catalog NucleoNucleoDevelopment and computing boards…o have this dev board for BlueNRG at a pretty hefty price tag though, hopefully the ‘ nucleo ’ & common dev board versions would be out soon Laughing … 007v1.html oops/oh found an…View in hardware catalog Dev board.

Other changes may still need to be made as further libraries and
hardware support are confirmed.

I have only made changes to support the STM32F1STM32F1Microcontrollers and processors…w I am not able to compile. Error message: “C:\arduino-1.6.12\hardware\Arduino_STM32\ STM32F1 \cores\maple/boards.h:39:25: fatal error: board/board.h: No such file or directory” I…View in hardware catalog series.
The Arduino_STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog libraries appear to support the other
microcontrollers in the ST family.

Last Revised: 10th June 2016

-------------------------------------------------------------------------
Added the following to lines to the STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog file:
..//Arduino_STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog /STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog /STM32F1STM32F1Microcontrollers and processors…w I am not able to compile. Error message: “C:\arduino-1.6.12\hardware\Arduino_STM32\ STM32F1 \cores\maple/boards.h:39:25: fatal error: board/board.h: No such file or directory” I…View in hardware catalog /cores/MapleMapleDevelopment and computing boards…expensive short of buying in bulk. many resort to usb-serial converters. today comes leaflabs maple , stm32duino it is ‘disruptive’ in a similar light, user customizable usb is no…View in hardware catalog /print.h

size_t print(const Printable&);
size_t println(const Printable&);

Also added:
#include "printable.h"
This file was already in the MapleMapleDevelopment and computing boards…expensive short of buying in bulk. many resort to usb-serial converters. today comes leaflabs maple , stm32duino it is ‘disruptive’ in a similar light, user customizable usb is no…View in hardware catalog folder just not included.

---------------------------------------------------------------------------
Seems that the STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog libraries use an enumerated type (WiringPinMode)
for the pin mode value. STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog supports many more pin modes.
In Arduino the pin mode is a numeric value only
defined as INPUT, OUTPUT and INPUT_PULLUP.
A type mismatch error occurs at compilation.
To translate the types, I edited the SetMode function in
the B4R file.
..//B4R/Libraries/rCore/B4RArduino.cpp

void Pin::setMode(Byte arduino_Mode) {
#ifdef USING_STM32
WiringPinMode stm32_Mode;
switch (arduino_Mode) {

case INPUT:

STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog _Mode = INPUT;

break;

case OUTPUT:

STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog _Mode = OUTPUT;
break;
case INPUT_PULLUP:

stm32_Mode = INPUT_PULLUP;
break;
}
pinMode(PinNumber, stm32_Mode);
#else
pinMode(PinNumber, arduino_Mode);
#endif
if (arduino_Mode == INPUT_PULLUP)
CurrentValue = true;
}

You need to define a compiler symbol "USING_STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog "to
..//B4R/Defines-Template.h

#define USING_STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog

Remove this define to compile B4R code for microcontrollers other
than STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog .

-------------------------------------------------------------------
Also need to extend the process timeout in B4R so that the
compilation results get displayed.
Menu: Tools/IDE-Options/Configure-Process-Timeout
Set it to 45 seconds.

------------------------------------------------------------------

Mon Jun 13, 2016 6:32 am

Further to my last post, the void* tag; declaration is not the cause of the extra memory allocation in the BIN.

I have tracked the problem down to the instantiation of a class to a pointer type.
Even when the class itself is empty, it doesn’t matter.

This is a simple Arduino code snippet to replicate the problem.

  class MyClass {
};

MyClass* fred;
void setup() {
fred = new MyClass();
}

Tue Jun 14, 2016 10:12 am

The reason the bin file is large, is that the “new” operator reads in a load of libraries.

This has been noted in other postings.

Normally with embedded programming, these objects would have static instantiations, but I presume its not possible in this case.

BTW.
Most STM32F103C8STM32F103C8Microcontrollers and processors…017 8:28 am I am trying to get Phono’s library working on a MCP2551 and a blue pill ( STM32F103C8 ), I have it connected to a active CANBUS, and I have successfully received and s…View in hardware catalog devices actually have 128k flash even though they are specc’ed at 64k.

Tue Jun 14, 2016 10:39 am

Just that if compiling to Arduino UnoArduino UnoDevelopment and computing boards…ime debugging. konczakp Mon Jul 18, 2016 12:18 pm OK, so I took working example from Arduino UNO . I’ve cut off everything from library that I don’t need and from rest I have crea…View in hardware catalog the difference is only 600 bytes not 64K.
I assumed there was something wrong with the handling of NEW for STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog .

Thanks.

Tue Jun 14, 2016 11:36 am

BTW.
Most STM32F103C8STM32F103C8Microcontrollers and processors…017 8:28 am I am trying to get Phono’s library working on a MCP2551 and a blue pill ( STM32F103C8 ), I have it connected to a active CANBUS, and I have successfully received and s…View in hardware catalog devices actually have 128k flash even though they are specc’ed at 64k.
Roger, how did you find out this?
How to check/reproduce?

Tue Jun 14, 2016 11:53 am

stevestrong wrote:BTW.
Most STM32F103C8STM32F103C8Microcontrollers and processors…017 8:28 am I am trying to get Phono’s library working on a MCP2551 and a blue pill ( STM32F103C8 ), I have it connected to a active CANBUS, and I have successfully received and s…View in hardware catalog devices actually have 128k flash even though they are specc’ed at 64k.
Roger, how did you find out this?
How to check/reproduce?

Tue Jun 14, 2016 11:59 am

Thanks Ray, good to know if one of my applications is missing only couple of bytes above the 64k limit :)

Tue Jun 14, 2016 12:24 pm

stevestrong wrote:Thanks Ray, good to know if one of my applications is missing only couple of bytes above the 64k limit :)

Tue Jun 14, 2016 10:22 pm

Offtopic… but just a note, that the GD32F103C8GD32F103C8Microcontrollers and processors…ith the various numbers used in the UART timing setup. I personally gave up using my GD32F103C8 boards, because I had issues with SPI not working with the ILI9341 display, and I d…View in hardware catalog only has 64k not 128k as its internal architecture is quite different.

Tue Jun 14, 2016 11:14 pm

RogerClark wrote:Offtopic… but just a note, that the GD32F103C8GD32F103C8Microcontrollers and processors…ith the various numbers used in the UART timing setup. I personally gave up using my GD32F103C8 boards, because I had issues with SPI not working with the ILI9341 display, and I d…View in hardware catalog only has 64k not 128k as its internal architecture is quite different.

Tue Jun 14, 2016 11:54 pm

Ray
Agreed. SPI doesn’t seem to work the same either.

Post a reply

Optional · up to 10 MiB