2018-06-05 05:48 AM
Hello,
i use the stm nucleo 64 board and the stm/eclipse environment and i want to send string with usart1. Furthermore, i don't want to use cubemx and cmsis. Because it makes the code very unreadable... and I'm familiar with freertos syntax.
The project generated with cubemx, the usart1 transmit works.
But in my project i doesnt work. I think I have implemented all configurations and inits correct.
Here is the code:
#include 'stm32f3xx.h'
#include 'stm32f3xx_nucleo.h'
#include 'FreeRTOS.h'
#include 'task.h'
#include 'queue.h'
#include 'semphr.h'
#define LD2_Pin GPIO_PIN_5
#define LD2_GPIO_Port GPIOA
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)
/*
PA10USART1_RX
PA09USART1_TX
*/
UART_HandleTypeDef huart1;
uint8_t Test[] = 'ÿÿÿn0.val=249ÿÿÿ'; //Data to send
uint8_t page2[] = 'ÿÿÿpage 2ÿÿÿ'; //Data to send
uint8_t graph1[] = 'ÿÿÿva2.val=50ÿÿÿ'; //Data to send
uint8_t Data[4];
void SystemClock_Config(void);
static void mainProcess(void *pvParameters);
static void dispTask(void *pvParameters);
static void MX_USART1_UART_Init(void);
void _Error_Handler(char *, int);
int main(void)
{
SystemInit();
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
BSP_LED_Init(LED2);
MX_USART1_UART_Init();
while (1) {
HAL_Delay(150);
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
HAL_UART_Transmit(&huart1, graph1 ,sizeof(graph1), 50);
HAL_UART_Receive(&huart1, Data ,4, 500);
HAL_Delay(250);
}
xTaskCreate(mainProcess, 'mainP', (configMINIMAL_STACK_SIZE + 80), NULL, (tskIDLE_PRIORITY + 1), NULL);
xTaskCreate(dispTask, 'dispTask', (configMINIMAL_STACK_SIZE + 80), NULL, (tskIDLE_PRIORITY + 1), NULL);
vTaskStartScheduler();
for(;;);
}
static void mainProcess(__attribute__ ((unused)) void *pvParameters)
{
}
static void dispTask(__attribute__ ((unused)) void *pvParameters)
{
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_USART1
|RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_I2C1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_HSI;
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;
PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
}
/* USART1 init function */
static void MX_USART1_UART_Init(void)
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 9600;
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;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */
/* USER CODE END Callback 0 */
if (htim->Instance == TIM1) {
HAL_IncTick();
}
/* USER CODE BEGIN Callback 1 */
/* USER CODE END Callback 1 */
}
/**
* @brief This function is executed in case of error occurrence.
* @param file: The file name as string.
* @param line: The line in file as a number.
* @retval None
*/
void _Error_Handler(char *file, int line)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
while(1)
{
}
/* USER CODE END Error_Handler_Debug */
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
What else I have to implement, enable or config ?
Best regards
2018-06-07 02:52 AM
CubeMX also does unpredictable things, after the last update every time I make a configuration change in my project using CubeMX it deletes this line out of SystemClock_Config() and kills my project (STM32L452).
RCC_OscInitStruct.PLL.PLLM = 1;
Also has a habit of deleting any configuration I have added. Hopefully I will get to a point where I don't use it again.
At the moment I have a dummy project that I use as the target of CubeMX to test its output.
2018-06-07 05:51 AM
'
Furthermore, i don't want to use cubemx and cmsis.'
for non-cube routines, see examples here, for F0/F1 and F4 chips:
https://github.com/dannyf00/My-MCU-Libraries---2nd-try
they do use cmsis.
if you want to abandon CMSIS, it will be considerably more difficult, and incredibly foolish in my view, as you may have to recreate the header files and start-up files.
It might be better to pick a chip where cmsis is non-existent to start. Like older ARM7 or Luminary / TI chips - though TI does provide CMSIS support for some of its newer chips - you just need to find them.
Not using CMSIS makes zero sense, in my view.
2018-06-07 08:11 AM
And at it's lowest level CMSIS just creates some uniformity in the way vendors provide stm32f4xx.h type files describing the registers, and using structures, to allow easy access, portability and reuse.
If you choose to discard this, then you really need to own your decisions and carry your own weight.
2018-06-07 08:13 AM
The F3xx DSP and SPLs:
Or the F3 Discovery firmware package:
http://www.st.com/en/embedded-software/stsw-stm32118.html
AFAIK there is no SPL for any Nucleo. You would need to adapt the examples, which isn't too difficult, provided the peripherals/pins you wnat to use are available.
2018-06-07 10:43 AM
'
CubeMX also does unpredictable things'
Cube was designed without its user base in mind. Most of the times, you simply need to initialize a module, clock, interrupts and users can write the its own code easily. ST could have simply provided an explicitly coded initialization routine, without minimal layers, to simplify the life for everyone, include ST.
yet, they decided to create a monster that no one can tame.
2018-06-07 10:49 AM
>>
yet, they decided to create a monster that no one can tame.
Not sure I want to tame it, watching the dragon rampage and burn villages is far more entertaining from the sidelines.
2018-06-08 12:30 AM
Cube was designed without its user base in mind.
I don't think so.
Only the mainly targeted user is mostly of the 'don't know and don't care' type.