Forum: Mikrocontroller und Digitale Elektronik Configurate uart without using stmcubeMx


von Gilles Patrick T. (gillespatrick_t)


Lesenswert?

I am currently working on a project to program a PLC. This one already 
has a program to control its operation. We are using the Nucleo board 
STM32F302RBT6. The goal is to extend the program to be able to integrate 
the uart communication. Unfortunately I can't configure the uart using 
the normal method on stmcubeMx because it would already damage the 
current control program. For the configuration I have chosen another 
method, that of copying all the lines of codes of configuration of the 
uart in my current program. In the files main.c, stm32f3xx_hal_msp.c and 
stm32f3xx_hal_conf.h I added all the necessary configurations as they 
appear in the uart configuration with stmcubeMx. In addition I added the 
stm32f3xx_hal_uart.c, stm32f3xx_hal_uart_ex.c, stm32f3xx_ll_usart.h, 
stm32f3xx_hal_uart.h,  stm32f3xx_hal_uart_ex.h files in the drivers 
where they belong. Unfortunately the uart communication still does not 
work and when I compile my program I get the following error: Break at 
address "0xfffffffe" with no debug information available, or outside of 
program code.

I try to debug the problem and I found that error appear during the 
clock configuration(SystemClock_Config) more specifically after  if 
(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK).

I can't explain the source of the error, because my chosen configuration 
is the following:

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART3;

 PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_HSI;

I chose the HSI to be sure that it will not be influenced.

I also checked, all configurations are made to work with the polling 
method.




would someone have some ideas or a method to help me to solve this 
problem?

von W.S. (Gast)


Lesenswert?

Gilles Patrick T. schrieb:
> For the configuration I have chosen another
> method, that of copying all the lines of codes of configuration of the
> uart in my current program. In the files main.c, stm32f3xx_hal_msp.c and
> stm32f3xx_hal_conf.h I added all the necessary configurations as they
> appear in the uart configuration with stmcubeMx.

To do it this way is in my opinion the wrong way. I prefer to hold all 
the necessary stuff in the low level driver, so it needs only 1 (one!) 
statement in config.c or main.c, for example:
  InitSerial1(57600); // the argument is the baud rate
Also the low level driver provides a set of functions to communicate, 
which ist device independent. This is important, when changing the 
actual platform or the vendor. So only the low level driver needs to be 
replaced while the higher level parts of the firmware are not touched.
Now, it may be some other kind of thinking and also another kind of 
developing a firmware with the software from ST compared to my way.

W.S.

von J. S. (jojos)


Lesenswert?

are you using interrupts and did you copy also the USARTn_IRQHandler 
from stm32f3xx_it? It is a weak function and if it is not overwritten, 
you'll get no syntax error but the software is simply not working.
Have you checked if anything is sent by using a scope or LA at the Tx 
line?

von STK500-Besitzer (Gast)


Lesenswert?

Gilles Patrick T. schrieb:
> because it would already damage the
> current control program

That shouldn't happen when you keep the user code in the designated 
segments.

If it's only fear of destruct the project copy the project somewhere 
else and make the changes to the configuration.

The other way is to copy the .ioc-file created by STM32CubeMx to another 
location and change the configuration as desired.
The use a diff tool and compare the created file.

von Gilles Patrick T. (gillespatrick_t)


Lesenswert?

J. S. schrieb:
> are you using interrupts and did you copy also the USARTn_IRQHandler
> from stm32f3xx_it? It is a weak function and if it is not overwritten,
> you'll get no syntax error but the software is simply not working.
> Have you checked if anything is sent by using a scope or LA at the Tx
> line?

l am not using an interrupt. to check if there is transmission of a 
signal I used an oscilloscope or Tera Term and so far I have no signal 
transmission

von W.S. (Gast)


Lesenswert?

Gilles Patrick T. schrieb:
> l am not using an interrupt.

It is important, that you do the setup in the right order:
1. enable the clock for port setup
2. enable the clock for the desired UART
3. set the port (e.g. the functions of the resp. port pins)
4. set the uart:
4a. the baud rate generator
4b. the general behaviour (# of bits, parity, interrupt etc.)

You also should provide a ISR, even if you do not use it. Just to 
override any crap (if so) in the libs of your Cube stuff. And DO NOT 
mistake some callback functions with the actual ISR functions. With KEIL 
and other commercial compilers a ISR looks so:
1
__irq void USART1_IRQHandler (void)
2
{ ...
And be sure, that the name of your ISR matches EXACTLY the name for the 
interrupt in the startup code. With the GCC this needs to be translated 
somewhat, because the GCC does not understand "__irq":
1
#if defined (GCC)
2
#define __irq  __attribute__ ((interrupt("IRQ")))
3
#endif

With this your UART should work perfectly. Please notice, that the 
interrupt from the UART is not edge triggered, but state triggered.

W.S.

von J. S. (jojos)


Lesenswert?

ok, when the int is not selected in the configuration than it cannot be 
the problem because it is also not enabled in the NVIC.

Have you checked if the USART3 programm is working without mixing the 
other stuff?
How do you add the clock config for USART3? Only these lines have to be 
added:
1
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART3;
2
  PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_HSI;
3
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
4
  {
5
    Error_Handler();
6
  }

I can imagine that using (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, 
FLASH_LATENCY_0) != HAL_OK) after activating the PLL can make problems, 
because for higher speed with PLL you need a FLASH_LATENCY_2.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.