Using ARM mbed with customized boards and Atollic Truestudio

Finally I had some time to check out ARM mbed. I believe it is one of the best things happened in the history of embedded systems. It will create a vendor-free abstraction for embedded development and will also save millions of hours of coding and enable developers to focus on the value added parts of their projects.

I started using mbed for a wireless sensing project. I initially prototyped using STM Nucleo-401RE board. However, I designed a custom board using STM32F401RC, which has half the flash and 64kb RAM. Therefore, exporting a project directly from mbed online IDE doesn't work.

Exporting and configuring development environment for Hello World

In order to make the custom board work, I had to export Hello World project from the mbed online IDE with mbed-src and not with the mbed libraries. To do that, you just have to delete mbed library from the online compiler and import mbed-src to your project. Afterwards, you can export to your IDE. I am using Atollic Truestudio, which has a free version with no code size limits. It is Eclipse based so it is always easy to import from or export to Eclipse/GCC. 

To use the code with Atollic IDE, export the program for GCC ARM Embedded. After downloading, before copying the program to your workspace, create a new project in Atollic IDE and select your target device. Then, copy the downloaded project into your work space. View of my final project tree is below:

Project folder structure after importing mbed project manually
Note that you have to configure your C and C++ include paths to cover all mbed-src directories. You should also exclude STM32F4xx_StdPeriph_Driver from build, because mbed also takes care of it.

I excluded mbed-src/common/retarget.cpp from build, because it caused an error and I knew that I won't be using it. If you need it, I am sure you will find a way to fix that error too ;)

I also removed startup_stm32f401xe.S file included in mbed-src/cmsis..../TOOLCHAIN_GCC_ARM folder. system_stm32f4xx.c file also generates error because it has a duplicate in cmsis folder. So, exclude the one that comes with Atollic new project. 

Finally, remove stm32f4_flash.ld file and configure the project settings to use the one that is included in the mbed-src/cmsis..../TOOLCHAIN_GCC_ARM. In order to do that in Atollic IDE, enter to project settings and then tool settings. Click on General tab under C++ Linker and browse to the new linker script.

If you are using a different MCU of the same family like me, you have to configure the linker script file. If you don't configure the linker script file, the project will build without errors but it won't work when you download it to your board. In my case, I was using STM32F401RC compared to STM32F401RE. It had 256k flash compared to 512 in RE. It also had 64k RAM vs. 96k in RE. Modify the MEMORY part in the linker script file with respect to your MCU features. For my case 

/* mbed default for Nucleo401RE*/
MEMORY
  FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
  RAM (rwx)  : ORIGIN = 0x20000194, LENGTH = 96k - 0x194
}


/* Modify for STM32F401RC*/
MEMORY
  FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K
  RAM (rwx)  : ORIGIN = 0x20000194, LENGTH = 64k - 0x194
}

It should build without errors and work well after uploading to your custom board now. I didn't have time to follow these steps again, so let me know if anything is wrong.



Disclaimer
This is a personal blog. Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated. Any views or opinions are not intended to malign any religion, ethnic group, club, organization, company, or individual.All content provided on this blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.

Comments