akael
Newbie level 4
Hello,
I am starting to use WCH microcontroller using MounRiver IDE, in particular the CH32V003F4U6, this uC has 16K flash and SRAM 2K,
I use this a simple code:
And everything is compiled well:
text data bss dec hex filename
5900 40 276 6216 1848 Reflow_HotPlate.elf
However, it doesn't print float variables, in order to do that, there's a option as shown below :
I used this option with CH32V203 and worked , but with this CH32V003, that has less memory, i didn't compiled, the error message is:
I can find howto print float, but I really want to understand (learn) why this is happening.
I hope someone could explain me the reason.
Thanks in advanced
Arlen
I am starting to use WCH microcontroller using MounRiver IDE, in particular the CH32V003F4U6, this uC has 16K flash and SRAM 2K,
I use this a simple code:
C:
#include "debug.h"
/* Global define */
_Bool Sx_Op_Flag = 0;
float Temperature = 0.0;
uint16_t iData_SPI=0;
/* Global Variable */
uint8_t val = 0;
void EXTI7_0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void EXTI7_0_IRQHandler(void){
if(EXTI_GetITStatus(EXTI_Line2)!=RESET){
printf("External Interrup\n\r");
//EXTI_ClearITPendingBit(EXTI_Line2);
EXTI_ClearFlag(EXTI_Line2);
}
}
void ExtInt_Init(void){
GPIO_InitTypeDef GPIO_InitStructure = {0};
EXTI_InitTypeDef EXTI_InitStructure = {0};
NVIC_InitTypeDef NVIC_InitStructure = {0};
RCC_APB1PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource2);
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_InitStructure.EXTI_Line = EXTI_Line2;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI7_0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_InitStructure);
}
/*********************************************************************
* @fn USARTx_CFG
*
* @brief Initializes the USART2 & USART3 peripheral.
*
* @return none
*/
void USARTx_CFG(void)
{
GPIO_InitTypeDef GPIO_InitStructure = {0};
USART_InitTypeDef USART_InitStructure = {0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_USART1, ENABLE);
/* USART1 TX-->D.5 RX-->D.6 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
}
/* SPI CONFIGURATION */
/*
* PC5 -> SCK
* PC6 -> MOSI
* PC7 -> MISO
* PC0 -> NSS
*
* */
void SPI_CFG(void){
GPIO_InitTypeDef GPIO_InitStructure = {0};
SPI_InitTypeDef SPI_InitStructure = {0};
NVIC_InitTypeDef NVIC_InitStructure = {0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_SPI1, ENABLE);
/* Configurate inputs*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_Init(SPI1, &SPI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI7_0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_Init(&NVIC_InitStructure);
// NSS
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_WriteBit(GPIOC, GPIO_Pin_0,Bit_SET);
SPI_Cmd( SPI1, ENABLE );
}
/*********************************************************************
* @fn main
*
* @brief Main program.
*
* @return none
*/
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
Delay_Init();
USART_Printf_Init(115200);
printf("SystemClk:%d\r\n",SystemCoreClock);
USARTx_CFG();
ExtInt_Init();
SPI_CFG();
while(1)
{
if (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE)== SET){
printf("IF \n");
//GPIO_WriteBit(GPIOB, GPIO_Pin_12,Bit_SET);
//Delay_Ms(30);
GPIO_WriteBit(GPIOC, GPIO_Pin_0,Bit_RESET);
SPI_I2S_SendData(SPI1, 0xAA0A);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)== RESET);
GPIO_WriteBit(GPIOC, GPIO_Pin_0,Bit_SET);
printf("Data in SPI1");
iData_SPI = SPI_I2S_ReceiveData(SPI1);
Sx_Op_Flag = (iData_SPI & 0x4)>>2;
if(Sx_Op_Flag){
printf("No sensor\n\r");
}else{
Temperature = 0.25 * (float)(iData_SPI>>3);
printf(" %2.2f C \r\n",Temperature);
}
}
Delay_Ms(400);
}
}
text data bss dec hex filename
5900 40 276 6216 1848 Reflow_HotPlate.elf
However, it doesn't print float variables, in order to do that, there's a option as shown below :
I used this option with CH32V203 and worked , but with this CH32V003, that has less memory, i didn't compiled, the error message is:
make -j4 all
c:/mounriver/mounriver_studio/toolchain/risc-v embedded gcc/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: Reflow_HotPlate.elf section "text" will not fit into region "FLASH"
c:/mounriver/mounriver_studio/toolchain/risc-v embedded gcc/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: region `FLASH' overflowed by 7408 bytes
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:56: Reflow_HotPlate.elf] Error 1
I can find howto print float, but I really want to understand (learn) why this is happening.
I hope someone could explain me the reason.
Thanks in advanced
Arlen
Last edited by a moderator: