Adding Custom Board Questions/Feedback

tomvdb
Tue Jul 18, 2017 9:35 am
Hi,

Thanks for all the work on the STM Core for Arduino. It’s awesome.

At our local makerspace we have been putting together a stm32 based mini robot controller. It uses the STM32F042P6. The idea of using arduino to program it appeals to a lot of our members.

Image

I’ve spent some time following https://github.com/stm32duino/wiki/wiki … nt-(board) to add our board, modified files are here:https://github.com/tomvdb/EDUBOT

I managed to add it and compile the blink which is working :D I still need to test other pheriperals.

One of the issues I had along the way was with Step 5, adding the System Clock Configuration. The SystemClock_Config generated calls the Error_Handler function if there is an issue. This function is not part of stm32core so it fails compilation. I removed reference to it from the SystemClock_Config and it worked fine. Just something to take note off.

void SystemClock_Config(void)
{

RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.HSI14CalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}

/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}


tomvdb
Tue Jul 18, 2017 11:05 am
ok, I managed to hack a dfu loader together. It’s not pretty but it works:

I used this https://hackaday.io/project/4139-stm32- … -converter to convert the hex file to a dfu file, and then used the dfuse command line tool from st.

I had to change platforms.txt to generate a hex file instead of a bin file and also add the following dfu upload section:

# dfu upload
tools.dfu_upload.cmd=dfu_upload
tools.dfu_upload.cmd.windows=dfu_upload.bat
tools.dfu_upload.path.windows={runtime.tools.STM32Tools.path}/tools/win
tools.dfu_upload.path.macosx={runtime.tools.STM32Tools.path}/tools/macosx
tools.dfu_upload.path.linux={runtime.tools.STM32Tools.path}/tools/linux
tools.dfu_upload.path.linux64={runtime.tools.STM32Tools.path}/tools/linux64
tools.dfu_upload.upload.params.verbose=-d
tools.dfu_upload.upload.params.quiet=
tools.dfu_upload.upload.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.hex" "{build.path}/{build.project_name}.dfu"


Wi6Labs
Tue Jul 18, 2017 11:55 am
Hi tomvdb,

Thank you to use the STM32 Core for Arduino.
I’m enjoyed to see all is working for you.

One of the issues I had along the way was with Step 5, adding the System Clock Configuration. The SystemClock_Config generated calls the Error_Handler function if there is an issue. This function is not part of stm32core so it fails compilation. I removed reference to it from the SystemClock_Config and it worked fine. Just something to take note off.

It is sure something is missing inside the step 5. I will see with ST if we should add Error_Handler or a sentence inside the wiki.

ok, I managed to hack a dfu loader together. It’s not pretty but it works

Great job. It is true the native STM32 Core do not support (yet?) the DFU mode. Did you see the PR #61?
You could open a pull request to propose your work. The community could help you to make it more pretty ;)


tomvdb
Tue Jul 18, 2017 12:29 pm
Its looking very good. Very happy from my side so far. I tested the pwm and the analog inputs. All seems well. I did find a bug in pins_arduino.h regarding the digitalPinToInterrupt macro. It was missing a parentheses. Fixed that and now my interrupt works.

Pull request for the fix

https://github.com/stm32duino/Arduino_C … 32/pull/65

Great job. It is true the native STM32 Core do not support (yet?) the DFU mode. Did you see the PR #61?
You could open a pull request to propose your work. The community could help you to make it more pretty

I’ll checkout #61. I copied various files from other projects to make it work, so not sure I can just add it in. Also, it doesn’t have linux/mac binaries. Will still play with it.

Obviously I would like to have our other makerspace members play with it as well. But having a custom board it would mean that they need to do modifications, etc to stm32 arduino core. In short, can we do a pull request for adding custom boards ? or what would be the best way to handle it?


Wi6Labs
Wed Jul 19, 2017 9:20 am
Firstly, thank you for the fix.

Secondly, you’re right. Maybe I spoke too quickly. To add a custom board which impacts the core will be difficult.
But propose some features to the core because you find a way to add it and make it generic enough to work with all variants, we’ll take it.

I don’t have the final word. You open a real discussion about this subject.


tomvdb
Wed Jul 19, 2017 11:28 am
Ideally one would like to use the board manager to create a variant from my custom board that is dependent on the stm32-arduino core. So the user would need to install the stm32-core first and then my custom board (which essentially adds the variant).

Normally a custom board would not need to change any files to the core except for the following:

Edit cores/arduino/stm32/stm32_def_build.h and add the CMSIS_STARTUP_FILE definition.


tomvdb
Wed Jul 19, 2017 1:42 pm
ok, so I managed to figure out how to add a variant without messing with the core (with one exception). I basically created my own package for my board. This involves creating a json file with the download package information.

Mine is located here:

https://www.binaryspace.co.za/edubot/package_edubot_index.json


RogerClark
Wed Jul 19, 2017 9:55 pm
Thanks.

Someone on another forum recently told me about being able to add new boards to an existing core, but I have not had time to try it.

I will take a look at your files as if we can separate out the boards into different json files it will simply the number of variants in the core repo

We could also do things like bake json files for the blue pill and black pill etc etc


Wi6Labs
Thu Jul 20, 2017 1:06 pm
tomvdb,

The only change I still had to do to the original core was to add the correct definition of the cmsis startup file to cores/arduino/stm32/stm32_def_build.h, but since that is a generic partnumber and not linked to a specific board I’m thinking thats ok since it only needs to be added once for each part (and can be added to the core via a pull request or just by adding all the possibilities in one go).

It is planned to fully completed the stm32_def_build.h file. But PR works too ;)

Roger,

It will be great if it is possible. I will open an issue about this feature.


tomvdb
Fri Jul 21, 2017 11:21 am
We have been playing with it last night at our makerspace meetup and it worked great. Everyone could just install the stm32 arduino core using the boardsmanager and then my edubot variant (also using the boardsmanager). It went smoothly without issues and we had everyone up and running in minutes :)

fpiSTM
Mon Jul 31, 2017 3:56 pm
Hi Tom,

thanks for your feedback/contribution.
Your PR is merged.

To add a custom variant, you took the right approach as described in the Arduino 3rd party Hardware specification:
https://github.com/arduino/Arduino/wiki … nt-or-tool

About DFU, it is planned to add it. It was already added on an other repo and should be compatible. But I will check your implementation ;)


Leave a Reply

Your email address will not be published. Required fields are marked *