Help on Porting Code from Keil to CubeIDE
Hi,
I have an ethernet application which is working in a Keil project, the app uses F103ZET6 and contains a UART and an SPI, all working in polling mode.
In order to port it to CubeIDE, I created a Cube project with F103ZET6, it has a RTC, a UART woking in interrupt mode, an SPI and some GPIOs necessary for the ethernet application. The Cube project is working except that the SPI is not tested, but to my understanding on the SPI, the configurations of the 2 SPIs in the Cube project and the Keil project are the same.
However, when I copied the ethernet application files (EXCLUDING the HAL drivers), the Cube project compiles without errors but not working on the same hardware environment on which the Keil project is working.
For identifying where the issue is, I am trying to do the things in the opposite way: copying the files related to the RTC, SPI, and UART from Cube to Keil. First, I copied RTC files (my app files and necessary HAL drivers) and modified the System Clock Configuration for LSI. It did not work. Then after having deleted the modifications for the RTC, I copied Uart related configuration to the Keil project as shown below:
1. the UART configuration to main.c
static void MX_USART1_UART_Init(void)
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
}
}
2. the implementation of HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) to main.c
3. call MX_USART1_UART_Init(void) in main.c
4. copied main.h to the Keil project
5. during writing this post, I happened to know the Cube-generated code in stm32f1xx_hal_msp.c are all project specific, so copied the function HAL_UART_MspInit(huart) to the main.c in Keil project
5. deleted original uart.c and uart.h in Keil project
Unfortunately, this still does not work. I do not see any printed texts on my PC as seen with my Cube project.
Did I miss anything? Are there any other UART relevant code that are generated by Cube, and I need to copy to Keil project?
Regards
Chao
