<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Kinetis Design StudioのトピックRe: Using C++ with Kinetis Design Studio 3.2.0 and MKW41Z_ConnSw_1.0.2</title>
    <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Using-C-with-Kinetis-Design-Studio-3-2-0-and-MKW41Z-ConnSw-1-0-2/m-p/597677#M7512</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alice,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the suggestion, it worked.&lt;/P&gt;&lt;P&gt;I guess it would be good for future versions of the Kinetis SDK to make sure that all interrupt handlers are wrapped to use C linkage.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Dec 2016 02:24:18 GMT</pubDate>
    <dc:creator>maxv</dc:creator>
    <dc:date>2016-12-14T02:24:18Z</dc:date>
    <item>
      <title>Using C++ with Kinetis Design Studio 3.2.0 and MKW41Z_ConnSw_1.0.2</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Using-C-with-Kinetis-Design-Studio-3-2-0-and-MKW41Z-ConnSw-1-0-2/m-p/597675#M7510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;There's a problem with using C++ and KDS 3.2.0 and the provided device drivers on an FRDM-KW41Z kit.&lt;/P&gt;&lt;P&gt;If I create a new project using the Kinetis SDK 2.x Project wizard:&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="172207_172207.PNG"&gt;&lt;IMG alt="172207_172207.PNG" src="https://community.nxp.com/t5/image/serverpage/image-id/122630iEC362C69D3A5B703/image-size/large?v=v2&amp;amp;px=999" title="172207_172207.PNG" /&gt;&lt;/SPAN&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="kds-2.PNG"&gt;&lt;IMG alt="kds-2.PNG" src="https://community.nxp.com/t5/image/serverpage/image-id/9478iE82DF85DF8624ED5/image-size/large?v=v2&amp;amp;px=999" title="kds-2.PNG" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="172259_172259.PNG"&gt;&lt;IMG alt="172259_172259.PNG" src="https://community.nxp.com/t5/image/serverpage/image-id/122631i3C75081F8F836F6D/image-size/large?v=v2&amp;amp;px=999" title="172259_172259.PNG" /&gt;&lt;/SPAN&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="kds-3.PNG"&gt;&lt;IMG alt="kds-3.PNG" src="https://community.nxp.com/t5/image/serverpage/image-id/9559iD9E485DCD558F0D2/image-size/large?v=v2&amp;amp;px=999" title="kds-3.PNG" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, if I replace the contents of main.c with those from the gpio_input_interrupt_frdmkw41z example:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE&gt;/*
 * Copyright (c) 2015, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 * of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 * list of conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "fsl_debug_console.h"
#include "fsl_port.h"
#include "fsl_gpio.h"
#include "fsl_common.h"
#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
/*******************************************************************************
 * Definitions
 ******************************************************************************/
#define BOARD_LED_GPIO BOARD_LED_RED_GPIO
#define BOARD_LED_GPIO_PIN BOARD_LED_RED_GPIO_PIN

#define BOARD_SW_GPIO BOARD_SW3_GPIO
#define BOARD_SW_PORT BOARD_SW3_PORT
#define BOARD_SW_GPIO_PIN BOARD_SW3_GPIO_PIN
#define BOARD_SW_IRQ BOARD_SW3_IRQ
#define BOARD_SW_IRQ_HANDLER BOARD_SW3_IRQ_HANDLER
#define BOARD_SW_NAME BOARD_SW3_NAME

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/
/* Whether the SW button is pressed */
volatile bool g_ButtonPress = false;

/*******************************************************************************
 * Code
 ******************************************************************************/
/*!
 * @brief Interrupt service fuction of switch.
 *
 * This function toggles the LED
 */
void BOARD_SW_IRQ_HANDLER(void)
{
 /* Clear external interrupt flag. */
 GPIO_ClearPinsInterruptFlags(BOARD_SW_GPIO, 1U &amp;lt;&amp;lt; BOARD_SW_GPIO_PIN);
 /* Change state of button. */
 g_ButtonPress = true;
 /* Toggle LED. */
 GPIO_TogglePinsOutput(BOARD_LED_GPIO, 1U &amp;lt;&amp;lt; BOARD_LED_GPIO_PIN);
}

/*!
 * @brief Main function
 */
int main(void)
{
 /* Define the init structure for the input switch pin */
 gpio_pin_config_t sw_config = {
 kGPIO_DigitalInput, 0,
 };

 /* Define the init structure for the output LED pin */
 gpio_pin_config_t led_config = {
 kGPIO_DigitalOutput, 0,
 };

 BOARD_InitPins();
 BOARD_BootClockRUN();
 BOARD_InitDebugConsole();

 /* Print a note to terminal. */
 PRINTF("\r\n GPIO Driver example\r\n");
 PRINTF("\r\n Press %s to turn on/off a LED \r\n", BOARD_SW_NAME);

 /* Init input switch GPIO. */
 PORT_SetPinInterruptConfig(BOARD_SW_PORT, BOARD_SW_GPIO_PIN, kPORT_InterruptFallingEdge);
 EnableIRQ(BOARD_SW_IRQ);
 GPIO_PinInit(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, &amp;amp;sw_config);

 /* Init output LED GPIO. */
 GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &amp;amp;led_config);

 while (1)
 {
 if (g_ButtonPress)
 {
 PRINTF(" %s is pressed \r\n", BOARD_SW_NAME);
 /* Reset state of button. */
 g_ButtonPress = false;
 }
 }
}&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And set the &lt;STRONG&gt;pinmux.c&lt;/STRONG&gt; settings to those of the gpio_input_interrupt_frdmkw41z example:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE&gt;void BOARD_InitPins(void)
{
 /* Initialize LPUART0 pins below */
 /* Ungate the port clock */
 CLOCK_EnableClock(kCLOCK_PortC);
 /* Affects PORTC_PCR6 register */
 PORT_SetPinMux(PORTC, 6U, kPORT_MuxAlt4);
 /* Affects PORTC_PCR7 register */
 PORT_SetPinMux(PORTC, 7U, kPORT_MuxAlt4);

 /* Affects PORTC_PCR4 register */
 port_pin_config_t config;
 config.pullSelect = kPORT_PullUp;
 config.mux = kPORT_MuxAsGpio;
 PORT_SetPinConfig(PORTC, 4U, &amp;amp;config);

 /* LED PIN_MUX Configuration */
 PORT_SetPinMux(PORTC, 1U, kPORT_MuxAsGpio);
}&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If I then rename &lt;STRONG&gt;main.c&lt;/STRONG&gt; to &lt;STRONG&gt;main.cpp&lt;/STRONG&gt; and recompile, everything builds fine.&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I then debug the program and press &lt;STRONG&gt;SW3&lt;/STRONG&gt; on the FRDM-KW41Z board, it always jumps to the wrong interrupt handler (which is by default an endless loop):&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="172260_172260.PNG"&gt;&lt;IMG alt="172260_172260.PNG" src="https://community.nxp.com/t5/image/serverpage/image-id/122632iE59B044C646FA383/image-size/large?v=v2&amp;amp;px=999" title="172260_172260.PNG" /&gt;&lt;/SPAN&gt;&lt;SPAN class="lia-inline-image-display-wrapper" image-alt="kds-4.PNG"&gt;&lt;IMG alt="kds-4.PNG" src="https://community.nxp.com/t5/image/serverpage/image-id/9560iE8B62CBE7E998B8B/image-size/large?v=v2&amp;amp;px=999" title="kds-4.PNG" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I'm not sure why this is the case, but this isn't something I would have expected.&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I build and run the program as &lt;STRONG&gt;main.c&lt;/STRONG&gt;, everything works correctly.&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached a ZIP file with the example project. Basically it's gpio_input_interrupt_frdmkw41z but using C++ to build it instead of C.&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This problem makes it effectively impossible to use C++ instead of C, since the only difference in builds is the compiler involved!&lt;/P&gt;&lt;P style="min- padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-338968" rel="noopener noreferrer" target="_blank"&gt;Test.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 13:50:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Using-C-with-Kinetis-Design-Studio-3-2-0-and-MKW41Z-ConnSw-1-0-2/m-p/597675#M7510</guid>
      <dc:creator>maxv</dc:creator>
      <dc:date>2020-11-02T13:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using C++ with Kinetis Design Studio 3.2.0 and MKW41Z_ConnSw_1.0.2</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Using-C-with-Kinetis-Design-Studio-3-2-0-and-MKW41Z-ConnSw-1-0-2/m-p/597676#M7511</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Max,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for i haven't this board , so i can not test your project.&lt;/P&gt;&lt;P&gt;I test a simple project include interrupt on other kenitis chip, only change the name main.c to main.cpp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;it can work well.&lt;/P&gt;&lt;P&gt;Could you please test a bare board project , without RTOS .&lt;/P&gt;&lt;P&gt;if still can not work, please add the below code&amp;nbsp; in the interrupt function :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="property macro token"&gt;#ifdef __cplusplus&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;extern&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C"&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&lt;SPAN class="property macro token"&gt;#endif&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;" interrupt function "&lt;/SPAN&gt; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 


&lt;SPAN class="property macro token"&gt;#ifdef __cplusplus&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;/* extern "C" */&lt;/SPAN&gt;
&lt;SPAN class="property macro token"&gt;#endif‍‍‍‍‍‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;or &lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;extern "C" {

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "interrupt function"

}&amp;nbsp; /* extern "C" */&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Alice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Dec 2016 07:58:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Using-C-with-Kinetis-Design-Studio-3-2-0-and-MKW41Z-ConnSw-1-0-2/m-p/597676#M7511</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2016-12-13T07:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using C++ with Kinetis Design Studio 3.2.0 and MKW41Z_ConnSw_1.0.2</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Using-C-with-Kinetis-Design-Studio-3-2-0-and-MKW41Z-ConnSw-1-0-2/m-p/597677#M7512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alice,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the suggestion, it worked.&lt;/P&gt;&lt;P&gt;I guess it would be good for future versions of the Kinetis SDK to make sure that all interrupt handlers are wrapped to use C linkage.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2016 02:24:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Using-C-with-Kinetis-Design-Studio-3-2-0-and-MKW41Z-ConnSw-1-0-2/m-p/597677#M7512</guid>
      <dc:creator>maxv</dc:creator>
      <dc:date>2016-12-14T02:24:18Z</dc:date>
    </item>
  </channel>
</rss>

