CYPRESS s6e1c3 Series fm0+ 32-bit single-chip serial port uart0 problem

Source: Internet
Author: User

/*-----------------------------Prelude-----------------------------------*/

MCU model s6e1c32c (48pin), s6e1c32b (32pin)

This commissioning: uart0 "and SWD pin Reuse"
Because in the boot file: Jump to Systeminit () to initialize the system clock, and then jump to main (). As follows:

Reset_handler
LDR R0, =systeminit
BLX R0
LDR R0, =__iar_program_start
BX R0

/*-----------------------------Hard work-----------------------------------*/

1, actually in Main, Uartinit (115200); printf ("Let us jump ... \ r \ n"); and cannot be output. ,

2, the original fm0+ default does not give us to open the serial and IO pin clock. Need to add code like the Stm32 series:

  Clk_peripheralclockenable (Clkgategpio);
clk_peripheralclockenable (CLKGATEMFS0); Uart0 Clock

3, again with J-link debugging, run Fly: normal results. SWD is shared with uart0 to open uart0,swd natural failure. Unplug the debug line and switch to the TTL serial to view the information. or the egg!!

Been beaten up? ... No way!

4, Uart3 pin out, modify the serial port initialization code. Found a print message, thank God. There is hope.

5, the problem point may be in SWD's body, view SWD multiplexing configuration:setpinfunc_swclk (); Setpinfunc_swdio (); Then look inside [depth ~ connotation of a bit].

There is a definition: Bfm_gpio_epfr00_swden = 1; If the SWD function is turned off, i.e. Bfm_gpio_epfr00_swden = 0; Can you turn on the uart0 again?

6, try to be really, is the problem lies. When the Uart0 function is turned on, SWD cannot automatically disconnect. Manual operation is required.

/* Code-----------------------------------on-----------------------------*/

typedef void (*pfunction) (void);
U32 g_appaddr = 0x0;

void Remapvtor ();

void Exitiap (void)
{
U32 jumpaddress;
Pfunction jump_to_application;
D_p ("jump_to_application\n");
jumpaddress = * (vu32*) (g_appaddr + 4);
Jump_to_application = (pfunction) jumpaddress;

/* Initialize user application ' s Stack Pointer */
__set_msp (* (vu32*) g_appaddr);

Jump_to_application ();
}

#define Inituartio () {setpinfunc_sin0_0 (); Setpinfunc_sot0_0 ();}

#define SWD_ON () {SETPINFUNC_SWCLK (); Setpinfunc_swdio ();}
#define Swd_off () {Bfm_gpio_epfr00_swden = 0;}

int main(void)

{
Clk_peripheralclockenable (Clkgategpio);
Clk_peripheralclockenable (CLKGATEMFS0);//uart0 clock
Clk_peripheralclockenableall ();//can also turn on all clocks

//swd_on ();//Next debug turn on and Block Swd_off (); Download again
Uartinit (115200);
printf ("Let us jump ... \ r \ n");
Remapvtor ();
EXITIAP ();

printf ("Jump Faild!\r\n");
return 0;
}

Uart0.c

Void Uartinit (uint32_t baudrate)
{
stc_uart_irq_en_t stcinten;
stc_uart_irq_cb_t STCIRQCB;
Stc_mfs_ uart_config_t Stcuartconfig;

if (Uartch = = &uart0)//serial 0 multiplexing SWD need to manually close
{Swd_off ();} You can add a delay before the serial port configuration.

Pdl_zero_struct (stcuartconfig);

/* Initialize UART function I/o */
inituartio ();

/* Initialize UART rx/tx Interrupt */
STCINTEN.BRXIRQ = TRUE;
Stcinten.btxirq = FALSE;
Stcirqcb.pfn RXIRQCB = Uart_rx_irqhandler;
STCIRQCB.PFNTXIRQCB = NULL;
/* Initialize UART RX/TX Channel */
Stcuartconfig.enmode = uartnormal;
Stcuartconfig.u32bautrate = baudrate;< br> stcuartconfig.endatalength = uarteightbits;
Stcuartconfig.enparity = Uartparitynone;
Stcuartconfig.enstopbit = uartonestopbit;
Stcuartconfig.enbitdirection = Uartdatalsbfirst;
Stcuartconfig.binvertdata = FALSE;
Stcuartconfig.bhwflow = FALSE;
Stcuartconfig.pstcfifoconfig = NULL;
STCUARTCONFIG.BUSEEXTCLK = FALSE;
Stcuartconfig.pstcirqen = &stcIntEn;
STCUARTCONFIG.PSTCIRQCB = &stcIrqCb;
Stcuartconfig.btouchnvic = TRUE;
Mfs_uart_init (Uartch, &stcuartconfig);

/* Enable TX function of UART0 */
Mfs_uart_enablefunc (Uartch, Uartrx);
Mfs_uart_enablefunc (Uartch, UARTTX);

Return
}

void Uartsendbyte (uint8_t dat)
{
while (TRUE! = Mfs_uart_getstatus (Uartch, Uarttxidle));
while (TRUE! = Mfs_uart_getstatus (Uartch, uarttxempty)); /* Wait until TX buffer empty */
Mfs_uart_senddata (uartch, DAT);

Return
}

int putchar (int ch)
{
if (ch = = ' \ n ')
{
Uartsendbyte (' \ R ');
}
Uartsendbyte ((unsigned char) ch);
return ch;
}

/*-----------------------------Actual results-----------------------------------*/

Every implementation:printf ("Let us jump ... \ r \ n");

Just print let us jump ... and jump to the reset state, address 0;

The end of the cycle to jump, non-stop printing

Let us jump ...

Let us jump ...

Let us jump ...

Let us jump ...

CYPRESS s6e1c3 Series fm0+ 32-bit single-chip serial port uart0 problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.