But looking at how Arduino.org, use the HAL at the same time as libmaple for the STAR OTTO..
I wonder if it may be possible to make the HAL into a library.
This may then allow people to use HAL functions for the advanced peripherals, or just to re-use exiting code that users the HAL.
The downside of this, would be the size of the HAL and of course its RAM usage (though I dont know how much of either it would consume)
Of course there may be some sort if major incompatibility, which precludes this at all.
But it may be worth investigating
I’ll take a look at what Arduino.org put in their HAL folder.
As far as I can tell they just call HAL_init() in the core and then seem to make HAL calls in various parts of the code, specifically the SPI and Wire
I have spend a lot of days studying the mbed source code, which is based on ST’s hal. mbed has three layers, on the bottom layer where are the hardware specific functions that are making direct use of hal/cmsis library, in the middle layer there is the C low level API which is common across all variants, and on top of them, the Classes of mbed API which is something like Arduino API.
I am thinking that the use of hal with same way like mbed is the correct way to do the core, and why not, to use some of low level mbed code to hide differences of different variants. I am not ready to show or to propose something, but it is something that I am thinking of it lately…
I looked at what they did for the STAR OTTO and it looks like they just removed one layer of directories and combined the CMSIS and the HAL directories into one folder called HAL
I don’t think this is a way to support more processor variants. But is probably a way to support the complex peripherals.
I don’t have time to look at it today, but I’ll see if I can hack something together in a day or two. (unless anyone beats me to it ![]()
I prefer to keep them in separate directories (sources and headers together), for example:
stm32f1-----------cmsis
|
-----hal
We may as well try to get them to work in their original locations e.g. CMSIS sub folder etc, and only combine if there are problems with separate folders
<…>
I wonder if it may be possible to make the HAL into a library.
<…>
No Worries…
I don’t seem to have much time to spend looking at anything at the moment.
I generally just see if I can put together a proof of concept in an hour or two, but if it looks like its going to take a lot of work, I usually put it on ice.
I just thought I’d post it as a thought bubble and get a bit of feedback first
I’ve had some success with this
This code now runs and blinks the LED on my Maple mini
#include <HAL.h>
#define LED PB1
int c=0;
void setup()
{
pinMode(LED,OUTPUT);
Serial.begin(115200);
}
void loop()
{
Serial.println(c++);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
delay(100);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);
delay(500);
}
I’ve had some success with this
This code now runs and blinks the LED on my Maple mini
So I’ve had to push this to the development branch of the repo.
Note.
Not everything in the HAL code is currently enabled.
I’ve just used the HAL conf file from the HAL MX core, which looks like this
#define HAL_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
//#define HAL_CAN_MODULE_ENABLED
//#define HAL_CEC_MODULE_ENABLED
//#define HAL_CORTEX_MODULE_ENABLED
//#define HAL_CRC_MODULE_ENABLED
//#define HAL_DAC_MODULE_ENABLED
//#define HAL_DMA_MODULE_ENABLED
//#define HAL_ETH_MODULE_ENABLED
//#define HAL_FLASH_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED
//#define HAL_I2S_MODULE_ENABLED
//#define HAL_IRDA_MODULE_ENABLED
//#define HAL_IWDG_MODULE_ENABLED
//#define HAL_NOR_MODULE_ENABLED
//#define HAL_NAND_MODULE_ENABLED
//#define HAL_PCCARD_MODULE_ENABLED
#define HAL_PCD_MODULE_ENABLED
//#define HAL_HCD_MODULE_ENABLED
//#define HAL_PWR_MODULE_ENABLED
//#define HAL_RCC_MODULE_ENABLED
//#define HAL_RTC_MODULE_ENABLED
//#define HAL_SD_MODULE_ENABLED
//#define HAL_SDRAM_MODULE_ENABLED
//#define HAL_SMARTCARD_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
//#define HAL_SRAM_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
//#define HAL_USART_MODULE_ENABLED
//#define HAL_WWDG_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
I re-exported the files from the Cube, after first enabling all possible interfaces so that all the available HAL files were exported by the Cube.
However I had to subsequently disable the CAN bus, as this interferes with USB.
I am looking for more examples of using the HAL, but most of the code I can find on the web seems to be for the Standard Peripheral Library rather than the HAL and the data structures etc don’t seem to have the same properties, and some functions are completely different or missing
As far as I can tell, the Cube is supposed to come with examples, but I can’t see any way to export examples and I can’t see any examples in the Cube files that are installed (as part of the Windows exe suite of files)
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:708:44: error: expected ‘)’ before ‘*’ token
#define GPIOA ((GPIO_TypeDef *) GPIOA_BASE)
I updated the files using new ones from the Cube, but it looks like the Cube generated a load of new files, as well as just replacing the old ones, and the new ones didnt get commited to git
So I’ve re-committed, and hopefully the example works now
PS.
What board did you select ?
Edit.
I did another clean export (from the Cube), as I thought perhaps I had some old files from the previous export, which were no longer used.
But there don’t seem to be any redundant files, just 3 files that had small changes.
So I’ve committed those changes,
I tested this with stm32f103RBT6
Arduino:1.6.5 (Windows 8.1), 板:”Generic STM32F103R series, STM32F103RB (20k RAM. 128k Flash), Serial”
In file included from C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f1xx.h:149:0,
from C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f1xx_hal_def.h:48,
from C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f1xx_hal_rcc.h:47,
from C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f1xx_hal_conf.h:218,
from C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f1xx_hal.h:48,
from C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/HAL.h:6,
from HAL_GPIO.ino:1:
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:713:44: error: expected ‘)’ before ‘*’ token
#define GPIOA ((GPIO_TypeDef *) GPIOA_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:62:31: note: in expansion of macro ‘GPIOA’
extern struct gpio_dev* const GPIOA;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:713:44: error: expected ‘)’ before ‘*’ token
#define GPIOA ((GPIO_TypeDef *) GPIOA_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:62:31: note: in expansion of macro ‘GPIOA’
extern struct gpio_dev* const GPIOA;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:713:44: error: expected initializer before ‘*’ token
#define GPIOA ((GPIO_TypeDef *) GPIOA_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:62:31: note: in expansion of macro ‘GPIOA’
extern struct gpio_dev* const GPIOA;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:714:44: error: expected ‘)’ before ‘*’ token
#define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:64:31: note: in expansion of macro ‘GPIOB’
extern struct gpio_dev* const GPIOB;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:714:44: error: expected ‘)’ before ‘*’ token
#define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:64:31: note: in expansion of macro ‘GPIOB’
extern struct gpio_dev* const GPIOB;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:714:44: error: expected initializer before ‘*’ token
#define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:64:31: note: in expansion of macro ‘GPIOB’
extern struct gpio_dev* const GPIOB;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:715:44: error: expected ‘)’ before ‘*’ token
#define GPIOC ((GPIO_TypeDef *) GPIOC_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:66:31: note: in expansion of macro ‘GPIOC’
extern struct gpio_dev* const GPIOC;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:715:44: error: expected ‘)’ before ‘*’ token
#define GPIOC ((GPIO_TypeDef *) GPIOC_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:66:31: note: in expansion of macro ‘GPIOC’
extern struct gpio_dev* const GPIOC;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:715:44: error: expected initializer before ‘*’ token
#define GPIOC ((GPIO_TypeDef *) GPIOC_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:66:31: note: in expansion of macro ‘GPIOC’
extern struct gpio_dev* const GPIOC;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:716:44: error: expected ‘)’ before ‘*’ token
#define GPIOD ((GPIO_TypeDef *) GPIOD_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:68:31: note: in expansion of macro ‘GPIOD’
extern struct gpio_dev* const GPIOD;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:716:44: error: expected ‘)’ before ‘*’ token
#define GPIOD ((GPIO_TypeDef *) GPIOD_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:68:31: note: in expansion of macro ‘GPIOD’
extern struct gpio_dev* const GPIOD;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:716:44: error: expected initializer before ‘*’ token
#define GPIOD ((GPIO_TypeDef *) GPIOD_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/gpio.h:68:31: note: in expansion of macro ‘GPIOD’
extern struct gpio_dev* const GPIOD;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:718:43: error: expected ‘)’ before ‘*’ token
#define ADC1 ((ADC_TypeDef *) ADC1_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/adc.h:46:30: note: in expansion of macro ‘ADC1’
extern const struct adc_dev *ADC1;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:718:43: error: expected ‘)’ before ‘*’ token
#define ADC1 ((ADC_TypeDef *) ADC1_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/adc.h:46:30: note: in expansion of macro ‘ADC1’
extern const struct adc_dev *ADC1;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:718:43: error: expected initializer before ‘*’ token
#define ADC1 ((ADC_TypeDef *) ADC1_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/adc.h:46:30: note: in expansion of macro ‘ADC1’
extern const struct adc_dev *ADC1;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:719:43: error: expected ‘)’ before ‘*’ token
#define ADC2 ((ADC_TypeDef *) ADC2_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/adc.h:48:30: note: in expansion of macro ‘ADC2’
extern const struct adc_dev *ADC2;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:719:43: error: expected ‘)’ before ‘*’ token
#define ADC2 ((ADC_TypeDef *) ADC2_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/adc.h:48:30: note: in expansion of macro ‘ADC2’
extern const struct adc_dev *ADC2;
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\HAL\src/stm32f103xb.h:719:43: error: expected initializer before ‘*’ token
#define ADC2 ((ADC_TypeDef *) ADC2_BASE)
^
C:\Users\Pan\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/stm32f1/include/series/adc.h:48:30: note: in expansion of macro ‘ADC2’
extern const struct adc_dev *ADC2;
^
I’m running IDE 1.6.9 and selected “STM32F103R series” as the board and tried all the variants and they all compiled for me.
I think the issue may be that the development branch may not work with 1.6.5 (sue to changes to platform.txt)
I tried both the bootloader and Serial upload methods
I wonder if something important has not been committed to github because of the .gitignore rules
I think I still have 1.6.5 on one of my old machines, I’ll try pulling the repo onto that machine and try it again.
I’m going try using the files from my 1.6.9 machine on the 1.6.5 machine (as I can’t run both IDEs on the same machine as it screws things up)
to see if the problem is the IDE of the files.
I’ll get back to you when I’ve figured out whats going on, i.e why it works on my 1.6.9 machine
Edit.
Just tried copying the files, and they don’t seem to compile, so this looks like its a difference between 1.6.5 and 1.6.9
I’ll need to get 1.6.9 onto a laptop and try download the files from git onto that machine and try to determine for sure if its the IDE version that is causing this
I just pulled the latest version of the development branch (using git) onto my laptop, which has IDE 1.6.9 on it, and it compiles OK.
Can you try updating to IDE 1.6.9 ??
the hal example test ok!!!
I’m not sure what’s changed between 1.6.5 and 1.6.9, but I don’t suppose it matters
However I just realized my HAL library is not actually calling HAL_init() as I didn’t construct a global instance of the library (which is normally done in the header)
I tried calling hal_init() in the sketch, but it looks like it screws up the system timing, and everything is going really slow.
I think this is almost certainly because I didn’t pay attention when I exported the files from the Cube and the clock configurations are incorrect. – I was just trying to get the cube to export as the files for as many peripherals as possible, and didnt consider looking at the clock config page ;-(
But I think that perhaps we can’t call HAL_init() as it may reconfigure a load of things that libmaple needs.
So perhaps its best if I comment out the call to HAL_init() in the class constructor, so there is no chance someone may instantiate the class themselves and therefor run HAL_init() without realizing thats whats happening
I think until I’ve found some more HAL examples e.g. DMA and DAC, that we won’t know which bits of HAL_init() need to be run
I’ve tried compiling some older examples, but often non – HAL examples don’t seem to compile, as function names and data structures seem to have changed
I just downloaded it
Interestingly, the zip file contains a complete copy of the HAL and CMSIS, so I suspect it may be easier to use this HAL rather than having to export it from the Cube, as you have to tick a load of check boxes to make the Cube export all its files (to support all the F103 internal devices e.g. GPIO, Timer, CAN, USB etc etc
Its getting too late for me to try the examples this evening as its already past 10pm, but I should have some time tomorrow to try out some of them.
If you have already installed the STM32CubeMX on your windows then go to
C:\Users\<USER>\STM32Cube\RepositoryIt looks like those files are the same as the download I just did via Ray’s link
Moreover, every time you do a “Check for Updates” from the CubeMX you get the new updated libraries/examples/projects in that folder.
Perhaps using those, partially hidden, files is a better way to update the HAL MX variants.
Because its just the HAL and CMSIS, and not the updated version of main.c etc
I found recently that the new version of the Cube had problems exporting, as the project file needed to be “migrated”, but the migration didn’t seem to work correctly ![]()
As for using them in arduino libraries, I am wondering how well those HAL libraries work – I did not find a lot of examples online either besides those come with the CUBE package. For some other vendors (like Microchip) – I do know their peripheral library is pretty bad and for sure not well tested – and you should always write your own! And @Ray mentioned in other threads, they do not want to make those library better for a reason.
I believe that the CMSIS is definitely the way to go, as it is ARM specification not ST or any other vendors. So, I kind of trust that.
But why HAL? – Can we expand libmaple with personal codes that may be more trustworthy than the vendor libraries ![]()
I think maintaining updates with HAL and trying to fix their bugs may be as time consuming as developing custom codes for new peripherals and chips.
<…>Can we expand libmaple with personal codes that may be more trustworthy than the vendor libraries
I think maintaining updates with HAL and trying to fix their bugs may be as time consuming as developing custom codes for new peripherals and chips.
Re: Why HAL
I was just curious about whether I could easy add the HAL as a library, as I thought it may be an easier way to add features like SDIO.
But. at the moment, I’m not sure whether its practical.
The push towards a CMSIS / HAL based core is a separate thread entirely thing, which has been discussed in several other threads.
I’ve had to install Atollic TrueStudio to run the Timer example in the debugger, to confirm it does work (and it does) but I’ve not had time to put breakpoints in the code and see how the interrupt functions are called.


