How to establish a GIOstream and GDBusConnection to a cellular modem device - c

I am trying to use libmm-glib documentation to put together a program to gather cellular modem information on Linux (Ubuntu 20.04). My question is how do I establish a GIOStream, and subsequently a GDBusConnection to the device. Namely, my device when pinged from the command line shows 2 tty devies, but both are labelled as "ignore" (dev/ttyUSB4,dev/ttyUSB1). I have also tried using /dev/cdc-wdm0 to initialize the Gfile with no success.
Steps (code below):
get a GFile associated with the modem
a. What path should I use to the device?
construct a GIOStream to the modem with the GFile
construct a DBusConnection with the GIOStream
contruct a MMManager with the DBusConnection
Use MMManager to query the specific modem.
gcc main.c -I/usr/include/libmm-glib -I/usr/include/ModemManager -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include -lglib-2.0 -lz -lgio-2.0 -lpthread -lmm-glib
#include <libmm-glib.h>
#include <gio/gio.h>
//#include <gtk/gtk.h>
#include <stdio.h>
int main (void)
{
printf("begin 1\n");
GCancellable *cancellable;
GError **ppError;
MMManager *pManager;
GDBusAuthObserver *observer;
GDBusObjectManagerClientFlags flags = G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE;
const gchar *guid = NULL;
//g_type_init();
//GFile * save = g_file_new_for_path("/org/freedesktop/ModemManager1/Modem/3");
//GFile * save = g_file_new_for_path("/sys/devices/platform/soc#0/32c00000.bus/32e50000.usb/ci_hdrc.1/usb1/1-1/1-1.3");
GFile * save = g_file_new_for_path("/dev/ttyUSB0");
if(save == NULL)
{
printf("null GFile\n");
}
else
{
printf("GFile OK\n");
}
GFileIOStream *pStream = g_file_open_readwrite(save, NULL, NULL);
if(pStream == NULL)
{
printf("null pStream\n");
}
else
{
printf("pStream OK\n");
}
GDBusConnection *pConnection= g_dbus_connection_new_sync(pStream,
guid, // for authent. as a server
flags,
NULL, // observer,
NULL, // cancellable,
ppError);
if(pConnection == NULL)
{
printf("null GDBusConnection\n");
}
pManager = mm_manager_new_sync(pConnection,
flags,
cancellable,
ppError);
if(pManager == NULL)
{
printf("null pManager\n");
}
mm_manager_scan_devices_sync(pManager,
cancellable,
ppError);
MMObject modem;
printf("d\n");
//const gchar* pChar = mm_object_get_path(&modem);
//free resources here
printf("end\n");
return(0);
}
-----------------------------
General | path: /org/freedesktop/ModemManager1/Modem/3
| device id:
-----------------------------
Hardware | manufacturer: Telit
| model: LE910C4-NF
| firmware revision: 25.21.660 1 [Mar 04 2021 12:00:00]
| carrier config: default
| h/w revision: 1.30
| supported: gsm-umts, lte
| current: gsm-umts, lte
| equipment id:
-----------------------------
System | device: /sys/devices/platform/soc#0/32c00000.bus/32e50000.usb/ci_hdrc.1/usb1/1-1/1-1.3
| drivers: qmi_wwan, option
| plugin: telit
| primary port: cdc-wdm0
| ports: cdc-wdm0 (qmi), ttyUSB0 (ignored), ttyUSB1 (gps),
| ttyUSB4 (ignored), wwan0 (net)
-----------------------------
Status | state: failed
| failed reason: sim-missing
| power state: on
| signal quality: 0% (cached)
-----------------------------
Modes | supported: allowed: 3g; preferred: none
| allowed: 4g; preferred: none
| allowed: 3g, 4g; preferred: 4g
| allowed: 3g, 4g; preferred: 3g
| current: allowed: any; preferred: none
-----------------------------
Bands | supported: utran-4, utran-5, utran-2, eutran-2, eutran-4, eutran-5,
| eutran-12, eutran-13, eutran-14, eutran-66, eutran-71
-----------------------------
IP | supported: ipv4, ipv6, ipv4v6
-----------------------------
SIM | sim slot paths: slot 1: none (active)
| slot 2: none

Related

How to run FreeRTOS on TM4C129EXL? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I am working on a C project for the university where a CoAP server is to be hosted on a TM4C129EXL. It is particularly important to choose a FreeRTOS operating system. Unfortunately, I had to learn that Texas Instruments has stopped supporting FreeRTOS. There are no options for me to switch to another operating system. It is for this reason that I turn to you.
I'm looking for a sample program in which Free RTOS is executed on a TM4C129EXL board. In the best case, I would be happy about a Code Composer Studio Project, as this is the IDE we work with from the university.
If you do not have any sample code available, I would be happy to receive any other information regarding FreeRTOS and CoAP of course with reference to the TM4C129EXL.
You did not specify if you had any requirements in terms of FreeRTOS version, but you can either:
use the demo provided in file SW-EK-TM4C1294XL-2.1.4.178.exe available on TI WEB site as is - you will find it in directory examples\boards\ek-tm4c1294xl-boostxl-senshub\senshub_iot
use this example as a basis to use a more recent version of FreeRTOS: you just would have to replace FreeRTOS source code by the most recent one, and maybe to modify some code in the demo: some function names/signatures may have changed across major versions.
The procedure hereafter describes step by step how to create a minimalist FreeRTOS program with Code Composer Studio 10.3.0 and FreeRTOS v202104.00 in a Windows 10 environment using the second approach. You may have to adjust the drive letter to you specific setup, I am using D: for the purpose of this example..
Download Code Composer Studio 10.3.0, FreeRTOS v202104.00 and SW-EK-TM4C1294XL-2.1.4.178.exe.
Install Code Composer Studio with support for the Tiva-C MCU familly. When prompted for a workspace name, specify D:\ti\workspace_v10.
Unzip FreeRTOSv202104.00.zipinto D:\.
Unzip SW-EK-TM4C1294XL-2.1.4.178.exe into D:\SW-EK-TM4C1294XL-2.1.4.178.
Launch CCS
Use the menu item File/New/CCS Project, and create an 'Empty Project (with main.c).
[]
Click on the Finishbutton.
Create the following directories: D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\driverlib D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\inc D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOS-Kernel D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOS-Kernel\include D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOS-Kernel\portable\GCC D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOS-Kernel\portable\GCC\ARM_CM4F D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOS-Kernel\portable\MemMang
Copy D:\SW-EK-TM4C1294XL-2.1.4.178\examples\boards\ek-tm4c1294xl-boostxl-senshub\senshub_iot\FreeRTOSConfig.h into D:\ti\workspace_v10\TM4C129EXL-FreeRTOS
Copy all .h files from D:\SW-EK-TM4C1294XL-2.1.4.178\driverlib into D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\driverlib.
Copy D:\SW-EK-TM4C1294XL-2.1.4.178\driverlib\gcc\libdriver.a into D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\driverlib.
Copy all .hfiles from D:\SW-EK-TM4C1294XL-2.1.4.178\inc into D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\inc.
Copy all files present in D:\FreeRTOSv202104.00\FreeRTOS\Source\include into D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOS-Kernel\include.
Copy all .cfiles present in D:\FreeRTOSv202104.00\FreeRTOS\Source into D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOS-Kernel.
Copy all file present in D:\FreeRTOSv202104.00\FreeRTOS\Source\portable\GCC\ARM_CM4F into D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOS-Kernel\portable\GCC\ARM_CM4F
Copy D:\FreeRTOSv202104.00\FreeRTOS\Source\portable\MemMang\heap_4.c into D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOS-Kernel\portable\MemMang.
Edit D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\main.c, and replace its content by:
#include "FreeRTOS.h"
#include "task.h"
extern void prvSetupHardware();
extern void main_blinky();
int main(void)
{
/* Configure the hardware ready to run the demo. */
prvSetupHardware();
main_blinky();
/* Don't expect to reach here. */
return 0;
}
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName)
{
while(1)
{
}
}
Create a new file named D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\blinky.c with the following content:
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "FreeRTOS.h"
#include "task.h"
#include "sysctl.h"
static void prvLedToggleTask();
/* Priorities at which the tasks are created. */
#define mainTOGGLE_LED_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define TOGGLE_LED_DELAY_MS 200
void main_blinky()
{
/* create task */
xTaskCreate( prvLedToggleTask, "LED", configMINIMAL_STACK_SIZE, NULL, mainTOGGLE_LED_PRIORITY, NULL );
/* Start the tasks and timer running. */
vTaskStartScheduler();
}
static void prvLedToggleTask( void *pvParameters )
{
// Remove compiler warning about unused parameter. */
( void ) pvParameters;
for( ;; )
{
//
// Turn on the LED.
//
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
// Wait a bit
vTaskDelay( TOGGLE_LED_DELAY_MS);
//
// Turn off the LED.
//
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0);
// Wait a bit
vTaskDelay( TOGGLE_LED_DELAY_MS );
}
}
uint32_t g_ui32SysClock;
void prvSetupHardware()
{
// Configure PLL
g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
//
// Enable the GPIO port that is used for the on-board LED.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
//
// Check if the peripheral access is enabled.
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
{
}
//
// Enable the GPIO pin for the LED (PN0). Set the direction as output, and
// enable the GPIO pin for digital function.
//
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);
}
Edit tm4c1294ncpdt_startup_ccs_gcc.c: add the following lines after the line containing static void IntDefaultHandler(void);
extern void xPortPendSVHandler(void);
extern void vPortSVCHandler(void);
extern void xPortSysTickHandler(void);
The resulting code should look like:
void ResetISR(void);
static void NmiSR(void);
static void FaultISR(void);
static void IntDefaultHandler(void);
extern void xPortPendSVHandler(void);
extern void vPortSVCHandler(void);
extern void xPortSysTickHandler(void);
Edit tm4c1294ncpdt_startup_ccs_gcc.c: replace the default interrupt handler by the FreeRTOS one in array g_pfnVectors[].
Original code:
void (* const g_pfnVectors[])(void) =
{
(void (*)(void))((uint32_t)pui32Stack + sizeof(pui32Stack)),
// The initial stack pointer
ResetISR, // The reset handler
NmiSR, // The NMI handler
FaultISR, // The hard fault handler
IntDefaultHandler, // The MPU fault handler
IntDefaultHandler, // The bus fault handler
IntDefaultHandler, // The usage fault handler
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
IntDefaultHandler, // SVCall handler
IntDefaultHandler, // Debug monitor handler
0, // Reserved
IntDefaultHandler, // The PendSV handler
IntDefaultHandler, // The SysTick handler
Resulting code:
void (* const g_pfnVectors[])(void) =
{
(void (*)(void))((uint32_t)pui32Stack + sizeof(pui32Stack)),
// The initial stack pointer
ResetISR, // The reset handler
NmiSR, // The NMI handler
FaultISR, // The hard fault handler
IntDefaultHandler, // The MPU fault handler
IntDefaultHandler, // The bus fault handler
IntDefaultHandler, // The usage fault handler
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
vPortSVCHandler, // SVCall handler
IntDefaultHandler, // Debug monitor handler
0, // Reserved
xPortPendSVHandler, // The PendSV handler
xPortSysTickHandler, // The SysTick handler
Edit the project properties for the GCC Compiler directories, and add the following directories: ${workspace_loc:/${ProjName}/FreeRTOS-Kernel/include} ${workspace_loc:/${ProjName}/FreeRTOS-Kernel/portable/GCC/ARM_CM4F} ${workspace_loc:/${ProjName} ${workspace_loc:/${ProjName}/driverlib} and click on the Apply and close button.
Edit D:\ti\workspace_v10\TM4C129EXL-FreeRTOS\FreeRTOSConfig.h and delete the following lines:
#define configGENERATE_RUN_TIME_STATS 1
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() \
g_vulRunTimeStatsCountValue = 0ul
#define portGET_RUN_TIME_COUNTER_VALUE() g_vulRunTimeStatsCountValue
Edit the GCC compiler Command-line pattern and add the -mfloat-abi=hard option after ${flags} in the Command-line pattern:
${command} ${flags} -mfloat-abi=hard ${output_flag}${output} ${inputs}
Edit the GNU Linker Command-line pattern and add the -mfloat-abi=hard option after ${flags}:>br/>
${command} ${flags} -mfloat-abi=hard ${output_flag}${output} ${inputs}
Edit the GCC Linker libraries: add libdriver.a to the -l option, and ${workspace_loc:/${ProjName}/driverlib} to the -L option, then click on the Apply and close button.
Build your project - it should build without any errors.
Flash your project by running it.
In my case, I had to stop the project and to press the board resetbutton in order to the program to start.
Finally, the LED should start blinking every 200ms.
The complete list of files in the project once the project 'cleaned' should ultimately be:
Folder PATH listing for volume DATA
Volume serial number is 0E12-BCA2
D:.
| .ccsproject
| .cproject
| .project
| blinky.c
| FreeRTOSConfig.h
| main.c
| tm4c1294ncpdt.lds
| tm4c1294ncpdt_startup_ccs_gcc.c
|
+---.settings
| org.eclipse.cdt.codan.core.prefs
| org.eclipse.cdt.debug.core.prefs
| org.eclipse.core.resources.prefs
|
+---Debug
| | ccsObjs.opt
| | makefile
| | objects.mk
| | sources.mk
| | subdir_rules.mk
| | subdir_vars.mk
| | TM4C129EXL-FreeRTOS.map
| |
| +---driverlib
| | subdir_rules.mk
| | subdir_vars.mk
| |
| \---FreeRTOS-Kernel
| | subdir_rules.mk
| | subdir_vars.mk
| |
| \---portable
| +---GCC
| | \---ARM_CM4F
| | subdir_rules.mk
| | subdir_vars.mk
| |
| \---MemMang
| subdir_rules.mk
| subdir_vars.mk
|
+---driverlib
| adc.h
| aes.h
| can.h
| comp.h
| cpu.h
| crc.h
| debug.h
| des.h
| eeprom.h
| emac.h
| epi.h
| flash.h
| fpu.h
| gpio.h
| hibernate.h
| i2c.h
| interrupt.h
| lcd.h
| libdriver.a
| mpu.h
| onewire.h
| pin_map.h
| pwm.h
| qei.h
| rom.h
| rom_map.h
| rtos_bindings.h
| shamd5.h
| ssi.h
| sw_crc.h
| sysctl.h
| sysexc.h
| systick.h
| timer.h
| uart.h
| udma.h
| usb.h
| watchdog.h
|
+---FreeRTOS-Kernel
| | croutine.c
| | event_groups.c
| | list.c
| | queue.c
| | stream_buffer.c
| | tasks.c
| | timers.c
| |
| +---include
| | atomic.h
| | croutine.h
| | deprecated_definitions.h
| | event_groups.h
| | FreeRTOS.h
| | list.h
| | message_buffer.h
| | mpu_prototypes.h
| | mpu_wrappers.h
| | portable.h
| | projdefs.h
| | queue.h
| | semphr.h
| | StackMacros.h
| | stack_macros.h
| | stdint.readme
| | stream_buffer.h
| | task.h
| | timers.h
| |
| \---portable
| +---GCC
| | \---ARM_CM4F
| | port.c
| | portmacro.h
| |
| \---MemMang
| heap_4.c
|
\---inc
asmdefs.h
hw_adc.h
hw_aes.h
hw_can.h
hw_ccm.h
hw_comp.h
hw_des.h
hw_eeprom.h
hw_emac.h
hw_epi.h
hw_fan.h
hw_flash.h
hw_gpio.h
hw_hibernate.h
hw_i2c.h
hw_ints.h
hw_lcd.h
hw_memmap.h
hw_nvic.h
hw_onewire.h
hw_pwm.h
hw_qei.h
hw_shamd5.h
hw_ssi.h
hw_sysctl.h
hw_sysexc.h
hw_timer.h
hw_types.h
hw_uart.h
hw_udma.h
hw_usb.h
hw_watchdog.h
tm4c1294ncpdt.h

Can't access gpio line with gpiod_line_request_output() on Adafruit FT232H

I am using an Adafruit Ft232H breakout to add GPIO ports to my Linux pc. Although I had some success to flash a led with libftdi and bitbang mode, I don't have the same luck with libgpiod because gpiod_line_request_output is failing.
Some gpio information of my system:
sudo gpiodetect
gpiochip0 [ftdi-cbus] (4 lines)
sudo gpioinfo
gpiochip0 - 4 lines:
line 0: unnamed unused input active-high
line 1: unnamed unused input active-high
line 2: unnamed unused input active-high
line 3: unnamed unused input active-high
This is the C program which tries to access the line 0.
#include <stdio.h>
#include <stdlib.h>
#include <gpiod.h>
#define LINE_NUM 0
void gpio_fatal(struct gpiod_chip* chip, const char msg[20]);
int main(int argc, char** argv)
{
struct gpiod_chip* chip;
struct gpiod_line* line;
const char path[] = "/dev/gpiochip0";
chip = gpiod_chip_open(path);
if(!chip)
{
fprintf(stderr, "Error opening path\n");
return EXIT_FAILURE;
}
line = gpiod_chip_get_line(chip, LINE_NUM);
if(!line)
{
fprintf(stderr, "error getting this line\n");
return EXIT_FAILURE;
}
int ret = gpiod_line_request_output(line,
"ftdi-cbus",
1);
if(ret != 0)
gpio_fatal(chip, "Request output failed");
for(;;)
{
gpiod_line_set_value(line, 1);
printf("On\n");
sleep(1);
gpiod_line_set_value(line, 0);
printf("Off\n");
sleep(1);
}
gpiod_line_release(line);
gpiod_chip_close(chip);
return EXIT_SUCCESS;
}
void gpio_fatal(struct gpiod_chip* chip, const char* msg)
{
fprintf(stderr, "%s\n", msg);
gpiod_chip_close(chip);
exit(EXIT_FAILURE);
}
Running the executable with sudo gives me:
sudo g_gpiod/build/g_gpiod
Password:
Request output failed
gpiod.h states for the failing function the following:
/**
* #brief Reserve a single line, set the direction to output.
* #param line GPIO line object.
* #param consumer Name of the consumer.
* #param default_val Initial line value.
* #return 0 if the line was properly reserved, -1 on failure.
*/
int gpiod_line_request_output(struct gpiod_line *line,
const char *consumer, int default_val) GPIOD_API;
The parameters seem to be correct, for what reason could this be failing? Other examples using libftdi or CircuitPython can access the ports and work correctly.
You need to flash the EEPROM to set the function of pin C5, e.g. using the ftdi_eeprom command from libftdi. First, unload the ftdi_sio module and save the original EEPROM:
$ sudo rmmod ftdi_sio
$ sudo ftdi_eeprom --verbose --device i:0x0403:0x6014 ft232h-orig.conf
FTDI eeprom generator v0.17
(c) Intra2net AG and the libftdi developers <opensource#intra2net.com>
FTDI read eeprom: 0
EEPROM size: 256
VID: 0x0403
PID: 0x6014
Release: 0x0900
Bus Powered: 100 mA
Manufacturer: ÿÿÿÿÿÿÿÿ
Product: ÿÿÿÿÿÿ
Serial: ÿÿÿÿÿÿÿÿ
Checksum : ffff
PNP: 1
Channel A has Mode UART
FT1284 Mode Clock is idle LOW, MSB first, No Flow Control
ACBUS has 4 mA drive
ADBUS has 4 mA drive
C0 Function: TRISTATE
C1 Function: TRISTATE
C2 Function: TRISTATE
C3 Function: TRISTATE
C4 Function: TRISTATE
C5 Function: TRISTATE
C6 Function: TRISTATE
C7 Function: TRISTATE
C8 Function: DRIVE_1
C9 Function: DRIVE_0
FTDI close: 0
The file ft232h-orig.conf contains just a single line filename="ft232h-orig.bin".
You can control 4 GPIO pins of the FT232H using the ftdi_sio module:
| line | pin | remarks |
==========================
| 0 | C5 | - |
| 1 | C6 | - |
| 2 | C8 | red led |
| 3 | C9 | green led |
The Adafruit board has the cathodes of two LEDs (red and green) connected to pins C8 and C9. The default EEPROM has C9 set to DRIVE_0 so that the green LED is "on" when the board is powered up.
Here is my config file for ftdi_eeprom:
$ cat ft232h-libgpiod.conf
vendor_id="0x0403"
product_id="0x6014"
manufacturer="Adafruit"
product="FT232H Breakout"
# whatever
serial="20211223"
use_serial=true
max_power=100
self_powered=false
remote_wakeup=false
cha_type=UART
cha_vcp=false
cbush5=IOMODE
cbush6=IOMODE
# red led
cbush8=IOMODE
# green led
cbush9=DRIVE_0 # power-on indicator
#cbush9=IOMODE
$ sudo ftdi_eeprom --verbose --device i:0x0403:0x6014 --flash-eeprom ft232h-libgpiod.conf
Your program now works fine with line 0 on pin C5. As a bonus, you can now control the red LED with the libgpiod commands:
# turn red LED on (low active)
sudo gpioset gpiochip0 2=0

sim900 echoes to micro but does not do anything

I have got a sim900 module which has a rs232 serial port. when I connect it
to my computer it works fine on a terminal but when I connect it to an atmega16 micro controller it only echoes back what ever I send to it and does not answer to commands.
besides i use a max232 ic to convert rs232 to ttl.
#include <io.h>
#include <mega16a.h>
#include <alcd.h>
#include <delay.h>
#include <stdio.h>
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;
if(data!=0xd && data!= 0xa)lcd_putchar(data);
}
void main(void)
{
////////////////////////I/O REGISTERS
DDRB = 1 << DDB0;
///////////////////////USART REGISTERS
UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (0<<U2X) | (0<<MPCM);
UCSRB=(1<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (1<<RXEN) | (1<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);
UCSRC=(1<<URSEL) | (0<<UMSEL) | (0<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL);
UBRRH=0x00;
UBRRL=0x33;
///////////////////////ENABLE GLOBAL INTERUPTS
#asm("sei")
///////////////////////LCD CONFIGURATION
lcd_init(16);
lcd_gotoxy(0,0);
delay_ms(2000);
printf("ATE0\r\n");
delay_ms(2000);
printf("ATD+989190077175;\r\n");
delay_ms(20000);
while (1)
{
lcd_clear();
lcd_gotoxy(0,0);
// Please write your application code here
printf("AT\r\n");
delay_ms(2000);
}
}
You are obviously not talking to your SIM900.
The command "ATE0" you are issuing, is supposed to make SIM900 to switch the echo off. So, after that command you can't see echo from SIM.
Given the information you have provided I could suggest the following:
Check your max232 schematics. The easiest case here is the you have somehow Rx/Tx connected, which would explain both - you seeing the echo and not communicating with SIM. To troubleshoot that - just connect your max232 to the computer with serial terminal program and on the output side of the converter connect Rx/Tx. You should see the echo. Then disconnect them - you should not see the echo.
General suggestion - this is not the exactly the right place for such discussions. That's more Question/Answer knowledgebase.

Can´t erase data from flash memory (STM32)

I´m trying to save some data to flash memory on my STM32F407 board. Before I can save them I need to erase memory sector. I choosed 16 Kbytes Sector1 starting with address 0x08004000 and choosed Voltage range 2.1-2.7 V. I'm using HAL library.
Program stops responding after FLASH->CR |= FLASH_CR_STRT; line inside HAL_FLASHEx_Erase() -> FLASH_Erase_Sector() function.
I'm pretty sure it's my fault but I can't find out what is wrong.
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
FLASH_EraseInitTypeDef EraseInitStruct;
EraseInitStruct.Sector = FLASH_SECTOR_1;
EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_2;
EraseInitStruct.NbSectors = 1;
uint32_t SectorError = 0;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
HAL_FLASH_Lock();
return;
}
uint16_t data = 300;
//----------------------------write data
if (HAL_FLASH_Program(TYPEPROGRAM_WORD, start_address, data) != HAL_OK) {
HAL_FLASH_Lock();
return;
}
HAL_FLASH_Lock();
Did I choosed wrong voltage range or number of sectors?
Thanks for your answers.
If your program is bigger than 16k, then you've just managed to erase a part of it from flash. You should pick a sector from the end of the flash (but then the erase times will be longer), or rearrange the sections a bit in your linker configuration.
I found the solution. I used HAL_FLASH_Lock() function instead of HAL_FLASHEx_Erase() function and it works fine. I also changed SECTOR because I was accidently erasing my program.
unit32_t address = 0x0800C000;
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
FLASH_Erase_Sector(FLASH_SECTOR_3, VOLTAGE_RANGE_3);
//----------------------------write data
uint8_t data = 'A';
if (HAL_FLASH_Program(TYPEPROGRAM_BYTE, address, data) != HAL_OK) {
HAL_FLASH_Lock();
return;
}
HAL_FLASH_Lock();
Thanks for your help.

BBB - Trouble getting second SPI chip select with device tree

I have trouble to get second chip select working on the Beaglebone Black.
I used the .dts given in /lib/firmware with my distribution (Angstrom, kernel 3.8.13) :
/*
* Copyright (C) 2013 CircuitCo
*
* Virtual cape for SPI1 on connector pins P9.29 P9.31 P9.30 P9.28
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";
/* identification */
part-number = "BB-SPI1-01";
version = "00A0";
/* state the resources this cape uses */
exclusive-use =
/* the pin header uses */
"P9.31", /* spi1_sclk */
"P9.29", /* spi1_d0 */
"P9.30", /* spi1_d1 */
"P9.28", /* spi1_cs0 */
"P9.42", /* spi1_cs1 */
/* the hardware ip uses */
"spi1";
fragment#0 {
target = <&am33xx_pinmux>;
__overlay__ {
/* default state has all gpios released and mode set to uart1 */
bb_spi1_pins: pinmux_bb_spi1_pins {
pinctrl-single,pins = <
0x190 0x13 /* mcasp0_aclkx.spi1_sclk, OUTPUT_PULLUP | MODE3 */
0x194 0x33 /* mcasp0_fsx.spi1_d0, INPUT_PULLUP | MODE3 */
0x198 0x13 /* mcasp0_axr0.spi1_d1, OUTPUT_PULLUP | MODE3 */
0x19c 0x13 /* mcasp0_ahclkr.spi1_cs0, OUTPUT_PULLUP | MODE3 */
0x164 0x12 /* eCAP0_in_PWM0_out.spi1_cs1 OUTPUT_PULLUP | MODE2 */
>;
};
};
};
fragment#1 {
target = <&spi1>; /* spi1 is numbered correctly */
__overlay__ {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&bb_spi1_pins>;
#address-cells = <1>;
#size-cells = <0>;
cs-gpios = <&gpio4 17 0>, <&gpio1 7 0>;
spi1_0{
#address-cells = <1>;
#size-cells = <0>;
compatible = "spidev";
reg = <0>;
spi-max-frequency = <16000000>;
};
spi1_1{
#address-cells = <1>;
#size-cells = <0>;
compatible = "spidev";
reg = <1>;
spi-max-frequency = <16000000>;
};
};
};
};
I compiled it with dtc and activate it with uEnv.txt :
capemgr.enable_partno=BB-SPI1-01
(Both HDMI and HDMIN capes are disabled)
I have the twos SPI device shown in /dev/ :
/dev/spidev2.0 /dev/spidev2.1
and the pins are used by the spi interface as shown :
root#beaglebone:~# cat $PINS | grep spi1
pin 89 (44e10964): 481a0000.spi (GPIO UNCLAIMED) function pinmux_bb_spi1_pins group pinmux_bb_spi1_pins
pin 100 (44e10990): 481a0000.spi (GPIO UNCLAIMED) function pinmux_bb_spi1_pins group pinmux_bb_spi1_pins
pin 101 (44e10994): 481a0000.spi (GPIO UNCLAIMED) function pinmux_bb_spi1_pins group pinmux_bb_spi1_pins
pin 102 (44e10998): 481a0000.spi (GPIO UNCLAIMED) function pinmux_bb_spi1_pins group pinmux_bb_spi1_pins
pin 103 (44e1099c): 481a0000.spi (GPIO UNCLAIMED) function pinmux_bb_spi1_pins group pinmux_bb_spi1_pins
And the mode is good :
pin 89 (44e10964) 00000012 pinctrl-single
pin 100 (44e10990) 00000013 pinctrl-single
pin 101 (44e10994) 00000033 pinctrl-single
pin 102 (44e10998) 00000013 pinctrl-single
pin 103 (44e1099c) 00000013 pinctrl-single
I successfully use a programm in C which use the first spidev (spidev2.0) with the first chip select, but the there are nothing on pin 42 when I use spidev2.1 (MOSI,MISO and CLK are working though).
Any ideas ?
Thanks in advance
Well I found out the answer myself :
The pin 42 is special since it's connected to two I/O. So in order to use one of the I/O, you have to put the other one as input.
source : Beaglebone black system reference manual http://www.digikey.com/web%20export/supplier%20content/ti_296/mkt/boards/BBB_SRM.pdf?redirected=1 page 71.
But now i have an other issue really strange... I posted it here : Trouble with SPIDEV, device tree and .dtbo name with Beaglebone Black

Resources