K64 custom freedom bootloader with RTS support (RS485)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K64 custom freedom bootloader with RTS support (RS485)

802 Views
roymessinger
Contributor V

I've been working with the freedom bootloader on the FRDM-K64F board (UART1), and all worked well. I've now changed the FRDM board to my custom board (the RX,TX pins of the freedom_bootloader code did not change, as in the FRDM board I also changed to UART1 and it worked fine). I'm working with half duplex RS485.

I cannot connect with the KinetisFlashTool. I'm guessing the reason is my custom board is working with half duplex RS485. As such, I need to enable the RTS of the chip, just as I did with my application on this board:

UART1->MODEM |= UART_MODEM_TXRTSPOL(1);
UART1->MODEM |= UART_MODEM_TXRTSE(1);

My problem is I don't know where to put these 2 lines in the freedom_bootloader code. If placed in the wrong place (I guess before the UART is init) there's a hard fault.

I've found this function: scuart_poll_for_activity, but don't know if this is the correct place. 

When I click 'Connect' in the GUI of Kinetis FLash Tool, there's an autoBaudRate function which get interrupted, in which the baud rate is calculated (counts the transitions of some signal, I guess), then it goes to the UART configuarion function.

In my board the autoBaudRate function is not called, which leads me to the conclusion it is somehow connected to the RS485 half duplex issue?

Any ideas?

Thanks.

0 Kudos
6 Replies

476 Views
vicentegomez
NXP TechSupport
NXP TechSupport

Hi Roy 

If you want to use the RTS and/or CTS lines you need to create a driver to perform the Flow control communication, unfortunately, this driver is not implemented on KSDK, as you already got on this thread 

UART Flow control, K64

And also as I know the Kinetis Flash tool does not use the flow control.

Regards

Vicente

0 Kudos

476 Views
roymessinger
Contributor V

Hi vicentegomez

Indeed, as Mark pointed out, I want to write to the MODEM registers to enable the HW control flow:

UART1->MODEM |= UART_MODEM_TXRTSPOL(1);
UART1->MODEM |= UART_MODEM_TXRTSE(1);

 just as I did with my own application. If I do it before the clock is enabled to the UART1, I'm getting a hard fault.

I try to call the UART_Init function in fsl_uart.c, passing it with the correct values, but getting a kStatus_UART_BaudrateNotSupport return from the function and the UART is not init.

Thanks,

Roy

0 Kudos

476 Views
mjbcswitzerland
Specialist V

Roy

Why don't you just add the clock enable before the MODEM register writes? I expect that this will solve the issue.

POWER_UP(4, SIM_SCGC4_UART1);

UART1->MODEM |= UART_MODEM_TXRTSPOL(1);
UART1->MODEM |= UART_MODEM_TXRTSE(1);

You just need to find the suitable initialisation routine in your own framework. In case of difficulties the following will do it:

SIM_SCGC4 |= 0x800;

or

*(volatile unsigned long *)(0x40048034) |= 0x800;

Regards

 

Mark

 

 

 

 

Professional support for Kinetis: http://www.utasker.com/index.html
Remote desktop one-on-one coaching: http://www.utasker.com/services.html
Getting started to expert videos: https://www.youtube.com/results?search_query=utasker+shorts

0 Kudos

476 Views
roymessinger
Contributor V

Hi,

Thanks. I've just tried it, but it doesn't work (doesn't go to hardfault but not working). 

It's a pitty the remote update does not support half duplex RS485. I ought to know that before implementing my board.

Roy

0 Kudos

476 Views
mjbcswitzerland
Specialist V

Roy

If it doesn't work it may be that the UART initialisation is clearing the mode as a part of its procedure. You can see this by checking the MODEM register state before and after the initialisation: before it should have your value; after it may be gone. If this is the case search for the code that clears it and simply comment the line out.

It is not possible that it can't work - it is simply a case of controlling the code to do what you want it to do.

Regards

Mark

P.S. I expect that you can deactivate the Auto-Baud part because the PC tool works at a fixed Baud rate anyway. It can be set to match this.

P.P.S As I mentioned a few times before you could have done this with the uTasker project in a couple of hours and have been finished several weeks ago. Rather than giving tips I could have solved any issues for you and if you are working professionally saved you presumably a few thousand Dollars in working rates (or whoever is paying you for your time).

0 Kudos

476 Views
mjbcswitzerland
Specialist V

Hi

Roy doesn't need HW Flow control. He just need the automatic RS485 mode in the MODEM register to be enabled so that semi-duplex RS485 operates.

enable clocks to UART 1

UART1->MODEM |= UART_MODEM_TXRTSPOL(1);
UART1->MODEM |= UART_MODEM_TXRTSE(1);

should work, before the main UART initialisation.

Regards

Mark

Professional support for Kinetis: http://www.utasker.com/index.html
Remote desktop one-on-one coaching: http://www.utasker.com/services.html
Getting started to expert videos: https://www.youtube.com/results?search_query=utasker+shorts

0 Kudos