cancel
Showing results for 
Search instead for 
Did you mean: 

Newbie Q: Getting just GPIO to work with STM32CubeF0

gaurav2
Associate II
Posted on June 07, 2016 at 06:00

I am just getting started on STM32 micro-code development for a custom board built around the STM32F072. I downloaded the CubeF0 and was able to build a few sample projects.

I now want to extract just the GPIO parts (stm32f0xx_hal_gpio.c) and use that with my main.c but it appears that I need to include and link many other HAL parts as well. What is the bare minimum and how do I start turning off un-needed pieces?

For example, I think GPIO needs RCC to set peripheral clock. Which is fine. But then ''hal_rcc.c'' requires that I need ''hal_rcc_ex.h'' (extended) also otherwise compile error. Then I need to include ''hal_gpio_ex.h'' as well. It doesn't seem to stop. More and more header and .C files are required.

Any tips appreciated. Thanks a bunch.
3 REPLIES 3
Nesrine M_O
Lead II
Posted on June 07, 2016 at 11:07

Hi gaurav_stm,

1.You can start from GPIO examples under the STM32F0 cube firmware package, you find the needed include parts for your project

STM32Cube_FW_F0_V1.5.0\Projects\STM32F072B-Discovery\Examples\GPIO

2.Also you can generate your own initialization C code (pins, clock tree, peripherals, middleware) using STM32CubeMX tool 

3.For more details about CUBEMX please refer to the UM1718 User manual

-Syrine-

Posted on June 07, 2016 at 17:09

When you buy into this thick hardware abstraction layer model that's what's going to happen. Best to let the compiler/linker do dead code elimination on the pieces it needs.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gaurav2
Associate II
Posted on June 08, 2016 at 19:10

Folks, I made some progress with CubeF0 and USB CDC class to get printf working. However, no characters appear on the hyper-term. The code roughly looks like:

USBD_HandleTypeDef USBD_Device;

extern UART_HandleTypeDef UartHandle;

void main(void)

{

   uint8_t ch = 'a';

    HAL_Init();

    SystemClock_Config();

  

    /* Init Device Library */

    USBD_Init(&USBD_Device, &VCP_Desc, 0);

  

    /* Add Supported Class */

    USBD_RegisterClass(&USBD_Device, &USBD_CDC);

  

    /* Add CDC Interface Class */

    USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);

  

    /* Start Device Process */

    USBD_Start(&USBD_Device);

    

    while (1) {

        status = HAL_UART_Transmit(&UartHandle, (uint8_t *)&ch, 1, 10);

    }

}

However, nothing comes out on the Hyper-terminal connected on Windows. The HAL_Transmit_UART is going through but I fear that somehow the UART transmit data struct is not connected to the USB CDC class buffer and/or some DMA issue. 

I don't want to use DMA but not sure how to just be in polling mode and if the UART (huart->Instance->TDR) in stmf0xx_hal_uart.c is really giving the character to the CDC.

I think that USB CDC class transmits a packet in the USBD_CDC_TransmitPacket() function where it calls

      USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer, hcdc->TxLength);

Do I instead need to use HAL_UART_Transmit_IT() to transmit in interrupt mode for USB to recognize that data is pending? Otherwise I don't see how the HAL_UART_Transmit() connects to USB CDC. The _IT() version seems to connect via the UserTxBuffer[].

Any pointers in making progress will help me. Thanks.