-
Notifications
You must be signed in to change notification settings - Fork 52
Creating a Board Support Package
Creating a Board Support Package can be a lengthy process, so please allocate several hours before starting. We would also like to remind users that the board configurations are not yet finalized, and will most likely continue changing for quite some time. While we will do our best to ensure all user-added board configurations can be built, we cannot guarantee that they will always work - that will be up to the community.
There are also plans to create a project template for creating new boards. Unfortunately, maintaining the template would be far too time consuming while the boards are in such a volatile state.
Before starting, please have the following:
- Llilum repo cloned on the machine
- mBed repo cloned on the machine
- Complete the setup steps and build the Zelig solution
- (Optional) Complete the SDK setup if adding BSP to SDK
A large portion of this demo is copying the configuration of a similar board, so in order to reduce the use of words "new board name" and "similar board name", "STM32L152" will be used instead of "new board" and "LPC1768" will be used instead of "similar board". We chose these because they are both Cortex-M3 boards. For Cortex-M4, it would be best to base it on the K64F BSP.
NOTE:
Please see this commit to see all of the changes made to add the STM32L152 BSP
- In Explorer, create a new folder called STM32L152 in
<repo root>\Zelig\BoardConfigurations\
- Open the BoardConfiguration solution under
<repo root>\Zelig\BoardConfigurations
- In Solution Explorer, add a new solution folder called "STM32L152"
- Add a new "Class Library" project called "Board" to the STM32L152 solution folder and set its location to
<repo root>\Zelig\BoardConfigurations\STM32L152
- Repeat step 3, with a project called "Configuration"
- In Solution Explorer, rename the Board project to "STM32L152" and the Configuration project to "STM32L152Configuration"
- Unload the STM32L152, and LPC1768 projects (right click -> unload project)
- From the LPC1768 csproj file, copy everything after the first "PropertyGroup" element, and replace the matching portions of the STM32L152 project (meaning leave the first property group alone, and replace everything else)
- Unload the LPC1767Configuration and STM32L152Configuration projects
- Copy the "OutputPath" elements from the LPC1768Configuration project to the STM32L152Configuration project
- Replace the ItemGroup with DLL references in STM32L152Configuration project, with the one in LPC1768Configuration project
- Reload all of the projects
- Open the properties for the STM32L152 project
- Set Assembly Name to "STM32L152", Default Namespace to "Microsoft.Llilum.STM32L152", and Target Framework to ".NET 4.5"
- Open the AssemplyInfo.cs file and set AssemblyTitle to "STM32L152" and AssemblyProduct to "STM32L152"
- Open the properties for STM32L152Configuration project
- THE NEXT 2 STEPS ARE IMPORTANT TO GET RIGHT. DEBUGGING ISSUES WILL BE DIFFICULT IF NAMING CONVENTION NOT FOLLOWED
- Change Assembly Name to "Microsoft.Llilum.BoardConfigurations.STM32L152" and DefaultNamespace to "Microsoft.Llilum.BoardConfigurations"
- Open the AssemblyInfo.cs file. Set AssemblyTitle and AssemblyProduct to "Microsoft.Llilum.BoardConfigurations.STM32L152"
- Add files called "Configuration.cs" and "STM32L152.FrontEndConfig" (text file) to the STM32L152Configuration project
- Open the STM32L152.FrontEndConfig file and open the LPC1768.FrontEndConfig file from the LPC1768Configuration project
- Copy the contents of the LPC1768.FrontEndConfig file into the STM32L152.FrontEndConfig file
- In STM32L152.FrontEndConfig, change all instances of "LPC1768" to "STM32L152"
- Follow steps 2-4 for the Configuration.cs file
- Change the CoreClockFrequency to that of the STM32L152 (32000000 for the STM32L152 Nucleo Board). RealTimeClockFrequency will be 1MHz on mBed
- This project should now be able to build
- In Explorer, open
<repo root>\Zelig\BoardConfigurations\STM32L152\Board
and<repo root>\Zelig\BoardConfigurations\LPC1768\Board
- Copy everything from LPC1768 to STM32L152 except for the Properties folder and the .csproj file
- You should be able to open all of the files in the STM32L152 project now
- Go through all of the files, and change all instances of "LPC1768" to "STM32L152"
- Open the mBed repo directory in explorer, and navigate to
<mbed repo>\libraries\mbed\targets\hal\TARGET_STM\TARGET_STM32L1
- Search for a file called "PinNames.h"
- Open the file, and copy the PinName enum into the GPIO.cs file PinName enum
- This step is less trivial: find the file that contains the Interrupt Numbers. For STM32L152 it is
<mbed repo>\libraries\mbed\targets\cmsis\TARGET_STM\TARGET_STM32L1\TARGET_NUCLEO_L152RE\stm32l152xe.h
- Copy the IRQn_Type enum contents into the IRQn enum in NVIC.cs
- Find the us_ticker.c file for the board being used (
<mbed root>\libraries\mbed\targets\hal\TARGET_STM\TARGET_STM32L1
), and determine what timer is being used (TIM5 in this case) - Set the IRQn value to the correct one for GetSystemTimerIRQNumber (TIM5_IRQn for STM32L152)
- Find the PinToIndex function, and change it to match the pins for your board. All pins should map from index 0 to PinCount-1
- Find and modify GetGpioPinIRQNumber to match what is being set in gpio_irq_init in mbed (
<mbed root>\libraries\mbed\targets\hal\TARGET_STM\TARGET_STM32L1\gpio_irq_api.c
) - This step is purely pattern matching: go through the board schematic, and determine which pins are used for which peripherals, and change values as appropriate
- Rebuild the solution, and if everything was done correctly, it should all compile.
- Go to mBed, create a simple program for your board, right click on the project, click Export, and Export for GCC (ARM Embedded)
- This will download a .ZIP file. Move the folder
<zip>\<program name>\mbed\TARGET_<platform>
to<llilum repo>\Zelig\mbed\
- Open the Makefile in the .ZIP and open the Makefile in
<llilum repo>\Zelig\LLVM2IR_results\mbed\simple
- In the makefile from the repo, add a section for STM32L152
- Copy all of the necessary variables from the ZIP makefile to the llilum repo one (SYS_OBJECTS, INCLUDE_PATHS, CC_FLAGS, etc.)
- Replace all instances of "./mbed" for the filepath to $(MBED_ROOT)
- Add "OBJECTS += $(TARGET)\startup_stm32l152xe.o" or the equivalent of that
- Remove the startup_stm32l152xe.o file from the SYS_OBJECTS variable
- Find the correct startup file in mbed (startup_stm32l152xe.S in a TOOLCHAIN_GCC_ARM directory) and copy it to the current directory. You may need to change the stack or heap size later, which this file will allow you to do.
- Compare the new section to the existing ones - ensure that everything looks like it matches the correct patterns
- (Optional) Copy main.cpp from the ZIP file to
<llilum repo>\Zelig\LLVM2IR_results\mbed\simple
and run "make STM32L152" from a command prompt. If everything builds, and then you have most likely succeeded.
If you are not able to build and run your code at the end of this section, DO NOT MOVE ON. Something is broken, and needs to be fixed before spending time on the SDK
- In the Llilum solution, Native project, there is a helpers.h file. Open it, and add a section for the STM32L152 header
- Find the "simple" project, and add a reference to "STM32L152.dll", which should be in the same place as "LPC1768.dll"
- Open the Program.cs file in the "simple" project, and comment out all of the #defines at the top, except for "USE_GPIO"
- Add a #define for STM32L152, and add code throught Program.cs, that sets up the right pins, and uses correct ports (essentially, modify the program so that it just blinks an LED)
- Right click, and build the simple project. If it builds, you can move on.
- Follow the steps from demo to set up the FrontEnd project. Notice the parameter being passed to debug
- Copy mbed_simple_LPC1768.FrontEndConfig, paste it there, and call it mbed_simple_STM32L152.FrontEndConfig
- Change the argument passed to FrontEnd debug, so that it reads
-cfg ..\..\..\..\Zelig\CompileTime\CodeGenerator\FrontEnd\mbed_simple_STM32L152.FrontEndConfig
- Open that file, and change all instances of "LPC1768" to "STM32L152" (there should be at least 3)
- Set FrontEnd as the startup project, hit F5, and hope for the best
- If the compiler succeeded, open a command prompt to
<llilum repo>\Zelig\LLVM2IR_results\mbed\simple
(the output should be in there) - Run
build.bat STM32L152
and if that succeeds, a folder called STM32L152 will be created, and the cmd window will not show any errors - Create a new deploySTM32L152.bat file, or copy STM32L152\mbed_simple.bin onto the connected mBed device
- (Optional) If blinky appears to work, modify Program.cs to make it blink slower. Why? Because when mBed runs into an error, it also starts blinking
If building with a makefile works for you, you can stop here. However, if you would like to have others use your board from the SDK, let's continue.
Do this part very carefully. This essentially becomes your makefile, and minor errors are hard to find
- Copy
<llilum repo>\VisualStudio\LlilumApplicationType\Llilum\1.0\Platforms\Llilum_LPC1768.props
into Llilum_STM32L152.props - Notice how the first 6 elements (such as LlilumTargetBrandLPC1768) match the folder structure in
<llilum repo>\Zelig\mbed\
- Change all instances of LPC1768 to STM32L152
- Open the makefile that you modified earlier, and the folder
<llilum repo>\Zelig\mbed\
- Navigate the folder structure, and replace the contents of the Board, Brand, Toolchain, Class, and BoardMbed elements
- If verifying this is too difficult, these values can be taken out of the makefile (just replace "$(MBED_ROOT)" with "$(LlilumSDK)mbed")
- All fields that do not use those elements that were replaced can be taken right out of the makefile. The mapping is below:
- LD_FLAGS -> LlilumLinkAdditionalOptions
- CC_SYMBOLS -> LlilumClPreprocessorDefs (remove -D and replace with ;)
- INCLUDE_PATHS -> LlilumClAdditionalIncludes
- SYS_OBJECTS -> LlilumLinkAdditionalDeps
- CPU -> LlilumClAdditionalOptions
- LIBRARY_PATHS -> LlilumLinkAdditionalLibDirs
- LD_SYS_LIBS -> LlilumLinkDeps
**NOTE: Remember the startup_STM.o file we removed from the original makefile? PUT IT BACK IN! It came from the SYS_OBJECTS variable, so put it into LlilumLinkAdditionalDeps **
- Open the solution in
<llilum repo>\VisualStudio\LlilumProjectType
- Open the Native.vcxproj file. Find the section for LPC1768, copy it, paste it below, and change all instances of LPC1768 to STM32L152 in it
- Find the .props file imports. Add a reference to the props file you just created
- Copy the LPC1768.FrontEndConfig file, paste it, and change all instances of LPC1768 to STM32L152
- In MyTemplate.vstemplate, add a new ProjectItem for STM32L152
- In Native.vcxproj, add a reference to the new FrontEndConfig file (towards the end, search for LPC1768.FrontEndConfig)
- Open Managed.csproj, and add a reference to the STM32L152.dll, just like the one for LPC1768
- Open
<llilum repo>\VisualStudio\LlilumApplicationType\Llilum\1.0\1033\Llilum.xml
and add a new enum for STM32L152 - In Visual Studio, click tools, Extentions and Updates, and uninstall the Llilum Application VSIX
- Delete the LLILUM_SDK environment variable
- Re-create and install the SDK (best to put it in the same place that it used to be) using the same steps as before
Open a new Visual Studio instance, create a Llilum Application, go to Native project properties/Llilum tab, change the Board to STM32L152 (which should now show up), and clicking apply should fill in all missing fields. Make sure that the FrontEndConfig property is pointing to the correct one (it will not be by default, use the full path if possible). Modify Program.cs to use the correct pins and board reference. CTRL+SHIFT+B to build everything after changing the FrontEndConfig. If the build succeeds, that's a good sign
NOTE: Deploy may not work on some boards. The .bin file is located in <solution dir>\ARM\Debug\
take that file, and put it on your board however you would like