Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 8 months ago.
ST nucleo F334R8 freeze with PA_9 set as PwmOut
Hi,
After I set the pin PA_9 to PWM mode, the code freeze - it never gets to the main function. I have a custom PCB, so I can't see if there is a runtime error. However, if I comment out the PwmOut line, it works again. Any workarround?
#include "mbed.h" #include "CANMsg.h" #define baudrate 115200 #define LD1 0x1 //rdeca #define LD2 0x2 //modra #define LD3 0x4 //zelena #define LD4 0x8 //rumena #define LD5 0x10 //rdeca #define THERMISTORNOMINAL 100000 //100k ohm termistor #define TEMPERATURENOMINAL 25 //temperatura @ 100k #define BCOEFFICIENT 4303 //B konstatna termistorja #define RP 5100 //predupor NTCja #define RD 10000 //delilnik napestosti NTC #define PELT_STAT 1 //1 = vkljucen, 0 = izkljucen /* Digitalni, analogni in PWM vhodi/izhodi za PELTIER */ AnalogIn NTC_signal(PC_0); // Analogni vhod za NTC peltier AnalogIn PELT_sns1(PB_0); // 24V input AnalogIn PELT_sns0(PA_2); // Vout iz regulatorja BusOut LEDS(PB_8, PB_9, PC_13, PC_14, PC_15); //Bus za ledice PwmOut PELT_pwm(PA_9); DigitalOut PELT_disable(PC_9); DigitalIn PELT_thshdn(PC_12); Serial pc(PC_4, PC_5); CAN can (PA_11,PA_12); //najprej CAN RX, potem CAN TX CANMsg rxMsg; CANMsg txMsg; float tempCalc (double adc) { /*(5.0V - Uadc)<- padec na 10k uporu (U/10000) <- tok cez upore 5100 (5k1) je upornost serisjkega upora*/ double T, U, Rntc; U = adc * 3.3; //napetost na PELT_ADC Rntc = ((5.0-U)/(U/RD)) - RP; T = Rntc / THERMISTORNOMINAL; // (R/Ro) T = log(T); // ln(R/Ro) T /= BCOEFFICIENT; // 1/B * ln(R/Ro) T += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) T = 1.0 / T; // Invertirano T -= 273.15; // iz K v C return (T); } void LEDtest() { for(int i = 0; i < 5; i++) { LEDS = 1<<i; wait(0.1); } LEDS = 0; LEDS = LD1; //testno prižge LED 1 (rdeca) } int main() { pc.baud(baudrate); // PELT_pwm.period_us(3); // if(PELT_STAT) { // PELT_disable = 1; // omogocen peltier // PELT_pwm.pulsewidth(0.2); // duty cycle 20% // } LEDtest(); while(1) { LEDS = 0x02; wait(0.05); float Tpelt = (float)tempCalc(NTC_signal.read()); //preberi adc PELT in preracunaj temperaturo float VregPelt = PELT_sns0 * 24; float Vpelt = PELT_sns1 * 24; pc.printf("Vpelt = %2.f V, VregPelt = %.2fV \r\n",Vpelt,VregPelt); pc.printf("TempPelt = %.2f\r\n",Tpelt); pc.printf("\033[3A"); //skoci na zacetek terminala LEDS = 0x00; // if(PELT_thshdn) { // PELT_disable = 0; // PELT_pwm.pulsewidth(0.0); // } wait(1.0); } }
I'd allso be gratefull if anyone has a inplementation example for HRTIM. I know I can use the HAL directly, but I never done this before. So any help/suggestion woud be very appreciated.
RGDS
Have you tried an offline IDE with debugging capability? As you say it is probably some runtime error. You might be able to detect it using strategic breakpoints or even just stepping through the startup sequence. Also if you dig into the source you might be able to change stdio uart for mbed messages and put in your serial port instead so you can redirect errors there. The uart for stdio is defined in PeripheralNames.h file:
\mbed-os\hal\targets\hal\TARGET_STM\TARGET_STM32F3\TARGET_NUCLEO_F334R8\PeripheralNames.h
And update the baud rate in mbed_config.h
I tried this on my Nucleo board and it seems to work. Stdio printf statements including mbed errors now going to a different uart.
posted by Graham S. 31 Mar 2017There is nothing wrong with uart. Uart works ok. The code freeze after I declare the PWM output to PA_9. I'm compiling offline, and debuging just seem to refresh systick timer and even if I debug line after line from the very begining, nothing happens. PA_9 seems a legit PWM pin. ?!
posted by Gorazd Rosbach 31 Mar 2017If you redirect stdio to the UART you have, mbed might tell you what the problem is.
posted by Graham S. 01 Apr 2017I tried to redirect STDIO to UART with no sucess. Can you try my code above on your nucleo? I don't have one, only my custom PCB. Thank you for your help!
posted by Gorazd Rosbach 03 Apr 2017