B4R Tutorial How to Implement STM32 into B4R

Starchild

Active Member
Licensed User
Longtime User
I have changed the "How to Implement STM32" document.
Available from top post.

Note:
Improved B4R integration using the existing STM32 library define
_VARIANT_ARDUINO_STM32_
instead of my own define
USING_STM32

No need to add or remove a define from the B4R defines template when changing board types.

Wish:
It would now be possible to include the altered "Pin::setMode" code into B4R distribution so no additional patch would be required.

B4X:
    //*******************************************
    void Pin::setMode(Byte arduino_Mode) {
#ifdef _VARIANT_ARDUINO_STM32_
    WiringPinMode stm32_Mode;
    switch (arduino_Mode) {
        case INPUT:
        stm32_Mode = INPUT;
        break;
        case OUTPUT:
        stm32_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;
     }
     //******************************************
 

whcir

Member
Licensed User
Longtime User
Could someone wrap the files for the internal RTC for the STM32? Its looks pretty simple but I don't have the experience.

Thanks
 

Attachments

  • src.zip
    7.4 KB · Views: 513

whcir

Member
Licensed User
Longtime User

Starchild


Would it be possible to do the same thing with the Serial class and LOG display in board.cpp so when switching between AVR and STM32 I don't have to edit this file every time.

#else
//DEFINE_HWSERIAL(Serial, 3);// Use HW Serial 2 as "Serial"
DEFINE_HWSERIAL(Serial, 2); // changed for B4R
//DEFINE_HWSERIAL(Serial1, 2);
DEFINE_HWSERIAL(Serial1, 3); // changed for B4R
DEFINE_HWSERIAL(Serial2, 1);
#endif
 

Starchild

Active Member
Licensed User
Longtime User
This file "board.cpp" is part of the stm32 library. As such it does not need editting back and forth to use AVR then STM32 devices. The STM32 library is only used when compiling for STM32 devices.
 

Starchild

Active Member
Licensed User
Longtime User
Could someone wrap the files for the internal RTC for the STM32? Its looks pretty simple but I don't have the experience.

Thanks
I have had a look at the RTC class available for STM32. Unfortunately, it relies on the support of hardware interrupts to wake from Sleep. At this time B4R can not support the SLEEP modes of the STM32 making it impossible to support the RTC class.

However, I have created a Generic version of a Software Real Time Clock library for B4R. This is compatible with STM32.
This library is designed to support the features of B4R.
You can download the library (rSoftRtc) from here..

https://www.b4x.com/android/forum/threads/software-real-time-clock.77158/#content
 

derez

Expert
Licensed User
Longtime User

Using SCL=PB6 and SDA=PB7 I can see results on a LCD 1602, it does not use wire library, only LiquidCristal_I2C
 

derez

Expert
Licensed User
Longtime User

Using the stm32_rwire library I got error with STM32F103C8T6. I have modified Starchild's library (stm32_rWire.cpp) like this:
B4X:
Byte STM32_WireMaster::WriteTo2(Byte Address, bool SendStop, ArrayByte* Data) {
        Wire.beginTransmission(Address);
        byte b = Data->length;
        Wire.write((Byte*)Data->data, Data->length);
    //    if (SendStop) {
    //        Wire.i2c_stop();
    //    }
    //    Wire.endTransmission();
        Wire.endTransmission(SendStop);
        return b;
}

Now it works without errors and I have connected HMC5883L magnetometer successfuly (connecting SCL to PB6 and SDA to PB7), and MPU6050 IMU as well.
The programs are the same as this https://www.b4x.com/android/forum/t...nts-mpu-6050-and-magnetometer-hmc5883l.65917/
 
Last edited:

Starchild

Active Member
Licensed User
Longtime User

Thanks for discovering the fix.
I have updated the download of the "stm32_rwire.zip" library file to include this change now v1.11 at its original posting.
https://www.b4x.com/android/forum/threads/how-to-implement-stm32-into-b4r.68034/#post-433002
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…