micro-ROS / NuttX

Official micro-ROS RTOS
http://micro-ros.github.io/
Other
88 stars 34 forks source link

How to active/port new features to your board. #14

Closed jfm92 closed 6 years ago

jfm92 commented 6 years ago

This guide will show how to active/port a feature that it's available in your board, but it's not ported yet. This is useful to port new boards and change the pin mapping of a board, but those aspects will be touch in other guide. So we will follow as example how to port I2C to the STM32LDiscovery Kit which have I2C bus, but it's not ported yet.

Go to NuttX\Configs\stm32ldiscovery\include\board.h and add theses lines, in "preprocessor definitions":

imagen

This line is to give the direction and configuration of the pin that we will use. This data you can find in the architecture files of your board. For example for this case you can find in: NuttX\arch\arm\src\stm32\chip\stm32stm32l15xxx_pinmap.h

Here you can see the pin map of each peripheral of the architecture and which options are available to set the pin (Available in the previous file).

imagen

As you can see, seeing the different options that give us that file, you can also change the pin mapping of the board and add more buses (Like add more UART port).

Once you've add the new pins, some ports of boards, have the issue that they initialize the peripheral properly, so to solve this problem you can use the next issue: Modifying the boot sequence

And for last, check that the file stm32_boot.c have theses lines: imagen

jfm92 commented 6 years ago

Update:

After active the SPI connection, I found that some peripheral could be a little different to port from the generic path(Explained previously) and there are some thing that you must have in mind, because despite of NuttX try to be generic for all the boards that support, each architecture and each micro-controller might have some particularities.

First, when you declare a pin to be use as peripheral, double check in the architecture pin mapping that it's already declare everything and specially focus if the frequency declared is correct e.g. In the pin mapping of the stm32l15xxx arch the SPI pin declaration is like this: #define GPIO_SPI1_SCK_1 (GPIO_ALT | GPIO_AF5 | GPIO_PORTA | GPIO_PIN5) But the correct form is: #define GPIO_SPI1_SCK (GPIO_ALT |GPIO_SPEED_40MHz|GPIO_AF5 | GPIO_PORTA | GPIO_PIN5) Then some peripheral have like a generic initialization and then an specific initialization for each device that you want to connect. In the case of SPI, we have pin configuration like in the general case (Set SPI pins in the board.h file) But then it's necessary to set the pin that we're going to use with Chip Select, which in the majority of the cases is specific for each driver. The other thing that is different in the implementation of the SPI is that apart of use the SPI Bus, we are using GPIO pins in output or input config(For the chip select, for interruptions...), so we have an specific file(stm32_spi.c) where is initialization every thing so it's necessary to modify every time that we add a new SPI device. There is no a standard method because, each device is different, but you can open the file and it's easy to understand.