TODOPIC

Otros Microcontroladores / Dispositivos programables => Microcontroladores ARM => Mensaje iniciado por: Carl47D en 12 de Septiembre de 2017, 22:00:59

Título: Agregar funciones LL de ST a un proyecto
Publicado por: Carl47D en 12 de Septiembre de 2017, 22:00:59
Que tal,

Estoy trabajando con el acelerómetro LIS3DSH que trae la F4Discovery, por ahora estoy haciéndolo con las funciones HAL y quisiera ver si con las funciones LL puedo tener transferencias más rápidas (sin usar interrupciones/DMA).

Del manual de la API (DM00105879):
Citar
Contrary to the HAL, the LL APIs are not provided for peripherals for which optimized access is not a key feature, or for those requiring heavy software configuration and/or complex upper level stack (such as FSMC, USB, SDMMC).

Sin embargo vienen documentadas las funciones LL para la mayoría de los periféricos, en mi caso estoy utilizando SPI y GPIO.

En otro tema del foro indican que se puede cambiar el uso de las HAL por las LL en Proyect -> Settings -> Advance Settings, pero al querer hacerlo solo me da como opción el usar las funciones HAL.

(https://i.imgur.com/J4DRj0b.png)

¿Existe otra forma para añadir las funciones LL a un proyecto?

Saludos
Título: Re:Agregar funciones LL de ST a un proyecto
Publicado por: tsk en 12 de Septiembre de 2017, 22:46:08
Para el F4 todavía CubeMX todavía no genera código con las LL, así que se tendría que hacer a mano.

Por ejemplo

Código: C
  1. /* LL drivers common to all LL examples */
  2. #include "stm32f4xx_ll_bus.h"
  3. #include "stm32f4xx_ll_rcc.h"
  4. #include "stm32f4xx_ll_system.h"
  5. #include "stm32f4xx_ll_utils.h"
  6. #include "stm32f4xx_ll_pwr.h"
  7. #include "stm32f4xx_ll_exti.h"
  8. #include "stm32f4xx_ll_gpio.h"
  9. #include "stm32f4xx_ll_adc.h"
  10. #include "stm32f4xx_ll_cortex.h"
  11. #include "stm32f4xx_ll_crc.h"
  12. #include "stm32f4xx_ll_dac.h"
  13. #include "stm32f4xx_ll_dma.h"
  14. #include "stm32f4xx_ll_dma2d.h"
  15. #include "stm32f4xx_ll_i2c.h"
  16. #include "stm32f4xx_ll_iwdg.h"
  17. #include "stm32f4xx_ll_rtc.h"
  18. #include "stm32f4xx_ll_spi.h"
  19. #include "stm32f4xx_ll_tim.h"
  20. #include "stm32f4xx_ll_usart.h"
  21. #include "stm32f4xx_ll_wwdg.h"
  22. #include "stm32f4xx_ll_rng.h"
  23. #include "stm32f4xx_ll_lptim.h""

Puedes extraer la plantilla del lugar donde están instaladas las librerías y comenzar a desarrollar de acuerdo a esas plantillas. La bueno de esto es que ambas pueden convivir, por lo que puedes generar un sistema base con las HAL que configure el reloj del sistema y todo lo demás lo puedes configurar con las LL.

Deja ver si puedo generar un proyecto simple y compilarlo.

Código: [Seleccionar]
STM32Cube/Repository/STM32Cube_FW_F4_V1.16.0/Projects/STM32F4-Discovery/Templates_LL
Al parecer si compila:

Código: C
  1. void usart_init()
  2. {
  3.         LL_USART_InitTypeDef USART_InitStruct;
  4.         LL_GPIO_InitTypeDef GPIO_InitStruct;
  5.  
  6.         LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
  7.         /**USART1 GPIO Configuration  
  8.   PA9   ------> USART1_TX
  9.   PA10   ------> USART1_RX
  10.   */
  11.   GPIO_InitStruct.Pin = LL_GPIO_PIN_9;
  12.   GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  13.   GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  14.   GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  15.   GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  16.   GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  17.   LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  18.  
  19.   GPIO_InitStruct.Pin = LL_GPIO_PIN_10;
  20.   GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  21.   GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  22.   GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  23.   GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  24.   GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  25.   LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  26.  
  27.   USART_InitStruct.BaudRate = 115200;
  28.   USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
  29.   USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
  30.   USART_InitStruct.Parity = LL_USART_PARITY_NONE;
  31.   USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
  32.   USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
  33.   USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
  34.   LL_USART_Init(USART1, &USART_InitStruct);
  35.  
  36.   LL_USART_DisableIT_CTS(USART1);
  37.  
  38.   LL_USART_ConfigAsyncMode(USART1);
  39.  
  40.   LL_USART_Enable(USART1);
  41. }

https://www.dropbox.com/s/w0vfz8k7uwn326h/DiscoveryTestLL.zip?dl=0

Inicialicé el uart1 (bueno eso creo porque no se quejó el compilador), en los includes agregé todos por aquello de las dudas, y en el make file agregé los .c de las LL además de agregar -DUSE_FULL_LL_DRIVER en C_DEFS

Hay bastantes ejemplos, pero viene en otra libería (la de los STM32L4)

Código: [Seleccionar]
STM32Cube/Repository/STM32Cube_FW_L4_V1.8.1/Projects/STM32L476RG-Nucleo/Examples_LL/SPI
Título: Re:Agregar funciones LL de ST a un proyecto
Publicado por: Carl47D en 12 de Septiembre de 2017, 23:35:24
Hola,

Importe el proyecto Template_LL y compila bien. Todos los spi32f4xx_hal_PPP.h y los stm32fxx_ll_PPP.h están en el directorio:
Citar
STM32Cube/Repository/STM32Cube_FW_F4_V1.16.0/Drivers/STM32F4xx_HAL_Driver/Inc
El path de ese directorio esta incluido en Project -> Properties -> C/C++ Build ->Settings -> MCU GCC Compiler -> Includes.

Con los proyectos generados por el Cube no se incluye ese directorio, se tiene una copia "local" del directorio Drivers (omitiendo los ll.h). Supongo que se puede indicar al Cube que no haga una copia local de Drivers y más bien use el Drivers "original" o incluir el path de arriba del post en los includes del proyecto.

Saludos
Título: Re:Agregar funciones LL de ST a un proyecto
Publicado por: tsk en 12 de Septiembre de 2017, 23:43:54
En Project->Settings->Code Generator

selecciona

Citar
Add necessary library files as reference in the toolchain project configuration file

Con eso te hace referencia a los includes y archivos .c, pero de todas formas va a omitir agregar los .c de las ll, por lo que los vas a tener que agregar de forma manual. Si el CubeMX generara para las LL lo haría de forma automática
Título: Re:Agregar funciones LL de ST a un proyecto
Publicado por: Carl47D en 13 de Septiembre de 2017, 13:54:18
Hola,

Hice un proyecto de prueba seleccionando la opción que me dijiste y agregué los .c como  referencias  (https://mcuoneclipse.com/2014/08/15/link-to-files-and-folders-in-eclipse/). Compilo exitosamente :mrgreen:, solo tengo que hacer pruebas para ver si vale la pena "bajar" de nivel de abstracción.

Saludos y gracias :)
Título: Re:Agregar funciones LL de ST a un proyecto
Publicado por: Carl47D en 26 de Octubre de 2017, 03:25:11
Update:
El 20 de Octubre salio una actualización para el STM CUBE, la versión 4.23, con esta versión ya se pueden seleccionar las librerías LL para micros de las series F2, F4 y F7.

Saludos